treport

package module
v0.0.0-...-c42f907 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 32 Imported by: 0

README

treport

A fast scalable repository scanning tool

Status

Under development...

Features

  • Scan files existing in the repository with arbitrary logic
  • You can choose what to scan from all commits, merge commits, or heads only
  • Scanning logic can be developed in multiple languages
  • Scanning logic can be provided as a gRPC based plugin
  • Scan results by each plugin can be typed on a protocol buffer basis and can be type-safely referenced by all plugins
  • Pipeline processing that combines plugins
  • Scalable
  • Caching for the scan results
  • Various output formats
  • Declarative description of plugins in YAML

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Handshake = plugin.HandshakeConfig{
		ProtocolVersion:  1,
		MagicCookieKey:   "TREPORT_PLUGIN",
		MagicCookieValue: "treport",
	}
	BuiltinPluginNames = []string{
		"size",
	}
	BuiltinPlugins []*Plugin
)
View Source
var (
	ErrNoData = fmt.Errorf("data doesn't exist")
)

Functions

func ErrInvalidRepositoryPath

func ErrInvalidRepositoryPath(path string) error

func Serve

func Serve(scanner GRPCScanner, logger Logger)

Types

type ActionType

type ActionType int
const (
	Deleted ActionType = iota
	Added
	Updated
)

func (ActionType) String

func (t ActionType) String() string

type AuthConfig

type AuthConfig struct {
	UserEnv     string `yaml:"user"`
	PasswordEnv string `yaml:"password"`
}

func (*AuthConfig) BasicAuth

func (c *AuthConfig) BasicAuth() *http.BasicAuth

func (*AuthConfig) Password

func (c *AuthConfig) Password() string

func (*AuthConfig) User

func (c *AuthConfig) User() string

type Change

type Change struct {
	From   *File
	To     *File
	Action ActionType
}

type Changes

type Changes []*Change

type Client

type Client struct {
	// contains filtered or unexported fields
}

func (*Client) Scan

func (c *Client) Scan(ctx context.Context, scanctx *ScanContext) (*treportproto.ScanResponse, error)

func (*Client) Stop

func (c *Client) Stop()

type Clients

type Clients []*Client

func (Clients) Stop

func (c Clients) Stop()

type Commit

type Commit struct {
	Hash         string
	Author       *Signature
	Committer    *Signature
	PGPSignature string
	Message      string
	TreeHash     string
	ParentHashes []string
}

type Config

type Config struct {
	Project   ProjectConfig     `yaml:"project"`
	Plugin    *PluginConfig     `yaml:"plugin"`
	Pipelines []*PipelineConfig `yaml:"pipelines"`
}

func LoadConfig

func LoadConfig(path string) (*Config, error)

func (*Config) CachePath

func (c *Config) CachePath() string

func (*Config) MountPath

func (c *Config) MountPath() string

func (*Config) PluginPath

func (c *Config) PluginPath() string

func (*Config) PluginVersionDB

func (c *Config) PluginVersionDB() (*PluginVersionDB, error)

func (*Config) RepoPath

func (c *Config) RepoPath() string

type File

type File struct {
	Name string
	Mode FileMode
	Size int64
	Hash string
}

type FileMode

type FileMode uint32

type GRPCScanner

type GRPCScanner interface {
	Scan(*ScanContext) (*Response, error)
}

type InvalidRepositoryPathError

type InvalidRepositoryPathError struct {
	Path string
}

func (*InvalidRepositoryPathError) Error

type Logger

type Logger = hclog.Logger

type Pipeline

type Pipeline struct {
	ID        PipelineID
	Repos     []*PipelineRepository
	Config    *PipelineConfig
	CachePath string
}

func CreatePipelines

func CreatePipelines(ctx context.Context, cfg *Config) ([]*Pipeline, error)

func (*Pipeline) Cleanup

func (p *Pipeline) Cleanup()

type PipelineConfig

type PipelineConfig struct {
	Name       string              `yaml:"name"`
	Desc       string              `yaml:"desc"`
	Strategy   Strategy            `yaml:"strategy"`
	Repository []*RepositoryConfig `yaml:"repository"`
	Steps      []*StepConfig       `yaml:"steps"`
}

type PipelineID

type PipelineID string

type PipelineRepository

type PipelineRepository struct {
	*Repository
	Steps     []*Step
	CachePath string
}

func (*PipelineRepository) Cleanup

func (r *PipelineRepository) Cleanup()

type Plugin

type Plugin struct {
	Name      string
	Args      []string
	Repo      *Repository
	CachePath string
	Client    *Client
	// contains filtered or unexported fields
}

func (*Plugin) Cleanup

func (p *Plugin) Cleanup()

func (*Plugin) DeleteCache

func (p *Plugin) DeleteCache() error

func (*Plugin) GetCache

func (p *Plugin) GetCache(commitID string) (*treportproto.ScanResponse, error)

func (*Plugin) Scan

func (p *Plugin) Scan(ctx context.Context, scanctx *ScanContext) error

func (*Plugin) Setup

func (p *Plugin) Setup(args []string) error

func (*Plugin) StoreCache

func (p *Plugin) StoreCache(commitID string, cache *treportproto.ScanResponse) error

type PluginConfig

type PluginConfig struct {
	Scanner []*RepositoryConfig `yaml:"scanner"`
	Storer  []*RepositoryConfig `yaml:"storer"`
}

type PluginExecConfig

type PluginExecConfig struct {
	Name string
	Args []string
}

type PluginID

type PluginID string

type PluginVersion

type PluginVersion struct {
	Name            string
	Version         int
	LastUpdatedTime time.Time
}

type PluginVersionDB

type PluginVersionDB struct {
	// contains filtered or unexported fields
}

func (*PluginVersionDB) IsUpdated

func (db *PluginVersionDB) IsUpdated(plg *Plugin) (bool, error)

func (*PluginVersionDB) Update

func (db *PluginVersionDB) Update(plg *Plugin) error

type ProjectConfig

type ProjectConfig struct {
	Path string `yaml:"path"`
}

func (*ProjectConfig) MountPath

func (c *ProjectConfig) MountPath() string

type Repository

type Repository struct {
	*git.Repository
	ID string
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(ctx context.Context, mountPath string, cfg *RepositoryConfig) (*Repository, error)

func (*Repository) AllCommits

func (r *Repository) AllCommits(ctx context.Context, cb func(*ScanContext) error) error

func (*Repository) AllMergeCommits

func (r *Repository) AllMergeCommits(ctx context.Context, cb func(*ScanContext) error) error

func (*Repository) BaseBranch

func (r *Repository) BaseBranch() (*config.Branch, error)

func (*Repository) HeadOnly

func (r *Repository) HeadOnly(ctx context.Context, cb func(*ScanContext) error) error

func (*Repository) Sync

func (r *Repository) Sync(ctx context.Context, branch plumbing.ReferenceName) error

type RepositoryConfig

type RepositoryConfig struct {
	Name   string      `yaml:"name"`
	Repo   string      `yaml:"repo"`
	Path   string      `yaml:"path"`
	Branch string      `yaml:"branch"`
	Rev    string      `yaml:"rev"`
	Auth   *AuthConfig `yaml:"auth"`
}

func (*RepositoryConfig) RepoPath

func (c *RepositoryConfig) RepoPath() (string, error)

func (*RepositoryConfig) UnmarshalYAML

func (c *RepositoryConfig) UnmarshalYAML(b []byte) error

type Response

type Response struct {
	// contains filtered or unexported fields
}

func ToResponse

func ToResponse(data proto.Message) (*Response, error)

type ScanContext

type ScanContext struct {
	context.Context
	Commit     *Commit
	Snapshot   *Snapshot
	Changes    Changes
	Repository *Repository
	Data       map[string]*treportproto.ScanResponse
	// contains filtered or unexported fields
}

func (*ScanContext) GetData

func (c *ScanContext) GetData(msg proto.Message) error

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(cfg *Config) *Scanner

func (*Scanner) Scan

func (s *Scanner) Scan(ctx context.Context) error

type ScannerPlugin

type ScannerPlugin struct {
	plugin.Plugin
	Scanner GRPCScanner
}

func (*ScannerPlugin) GRPCClient

func (p *ScannerPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

func (*ScannerPlugin) GRPCServer

func (p *ScannerPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error

type Signature

type Signature struct {
	Name  string
	Email string
	When  time.Time
}

type Snapshot

type Snapshot struct {
	Hash    string
	Entries []*File
}

type Step

type Step struct {
	Idx       int
	Plugins   []*Plugin
	CachePath string
}

func (*Step) Cleanup

func (s *Step) Cleanup()

func (*Step) DeleteCache

func (s *Step) DeleteCache() error

func (*Step) PluginIDs

func (s *Step) PluginIDs() []string

type StepConfig

type StepConfig struct {
	Plugins []*PluginExecConfig
}

func (*StepConfig) UnmarshalYAML

func (c *StepConfig) UnmarshalYAML(b []byte) error

type Strategy

type Strategy string
const (
	AllMergeCommit Strategy = "allMergeCommit"
	AllCommit      Strategy = "allCommit"
	HeadOnly       Strategy = "headOnly"
)

Directories

Path Synopsis
internal
plugin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL