core

package
v0.15.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LOG_DEBUG = LogLevel(logrus.DebugLevel)
	LOG_INFO  = LogLevel(logrus.InfoLevel)
	LOG_WARN  = LogLevel(logrus.WarnLevel)
	LOG_ERROR = LogLevel(logrus.ErrorLevel)
)
View Source
const DOMAIN_TYPE_CICD = "CICD"
View Source
const DOMAIN_TYPE_CODE = "CODE"
View Source
const DOMAIN_TYPE_CODE_REVIEW = "CODEREVIEW"
View Source
const DOMAIN_TYPE_CROSS = "CROSS"
View Source
const DOMAIN_TYPE_TICKET = "TICKET"
View Source
const EncodeKeyEnvStr = "ENCODE_KEY"

Variables

Functions

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, errors.Error)

AES decryption

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, errors.Error)

AES encryption, CBC

func AllPlugins

func AllPlugins() map[string]PluginMeta

func Decrypt

func Decrypt(encKey, encryptedText string) (string, errors.Error)

Base64 + AES decryption using ENCODE_KEY in .env as key

func Encrypt

func Encrypt(encKey, plainText string) (string, errors.Error)

TODO: maybe move encryption/decryption into helper? AES + Base64 encryption using ENCODE_KEY in .env as key

func FindPluginNameBySubPkgPath

func FindPluginNameBySubPkgPath(subPkgPath string) (string, errors.Error)

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

PKCS7 padding

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

PKCS7 unPadding

func RandLetterBytes added in v0.12.0

func RandLetterBytes(n int) string

func RandomCapsStr

func RandomCapsStr(len int) string

A random string of length len uppercase characters

func RandomEncKey

func RandomEncKey() string

func RegisterPlugin

func RegisterPlugin(name string, plugin PluginMeta) errors.Error

func TraversalPlugin added in v0.13.0

func TraversalPlugin(handle PluginCallBack) errors.Error

Types

type ApiResourceHandler

type ApiResourceHandler func(input *ApiResourceInput) (*ApiResourceOutput, errors.Error)

type ApiResourceInput

type ApiResourceInput struct {
	Params  map[string]string      // path variables
	Query   url.Values             // query string
	Body    map[string]interface{} // json body
	Request *http.Request
}

Contains api request information

type ApiResourceOutput

type ApiResourceOutput struct {
	Body        interface{} // response body
	Status      int
	File        *OutputFile
	ContentType string
}

Describe response data of a api

type BasicRes added in v0.12.0

type BasicRes interface {
	// config
	GetConfigReader() ConfigReader
	GetConfig(name string) string
	// logger
	GetLogger() Logger
	NestedLogger(name string) BasicRes
	ReplaceLogger(logger Logger) BasicRes
	// dal
	GetDal() dal.Dal
}

BasicRes defines a set of fundamental resources that needed pretty much everywhere in our system

type BlueprintConnectionV100 added in v0.12.0

type BlueprintConnectionV100 struct {
	Plugin       string                `json:"plugin" validate:"required"`
	ConnectionId uint64                `json:"connectionId" validate:"required"`
	SkipOnFail   bool                  `json:"skipOnFail"`
	Scope        []*BlueprintScopeV100 `json:"scope" validate:"required"`
}

BlueprintConnectionV100 is the connection definition for protocol v1.0.0

type BlueprintConnectionV200 added in v0.15.0

type BlueprintConnectionV200 struct {
	Plugin       string                `json:"plugin" validate:"required"`
	ConnectionId uint64                `json:"connectionId" validate:"required"`
	Scopes       []*BlueprintScopeV200 `json:"scopes" validate:"required"`
}

BlueprintConnectionV200 contains the pluginName/connectionId and related Scopes,

type BlueprintScopeV100 added in v0.12.0

type BlueprintScopeV100 struct {
	Entities       []string        `json:"entities"`
	Options        json.RawMessage `json:"options"`
	Transformation json.RawMessage `json:"transformation"`
}

BlueprintScopeV100 is the scope definition for protocol v1.0.0

type BlueprintScopeV200 added in v0.15.0

type BlueprintScopeV200 struct {
	Id       string   `json:"id"`
	Name     string   `json:"name"`
	Entities []string `json:"entities"`
}

BlueprintScopeV200 contains the `id` and `name` for a specific scope transformationRuleId should be deduced by the ScopeId

type BlueprintSyncPolicy added in v0.15.0

type BlueprintSyncPolicy struct {
	Version          string     `json:"version" validate:"required,semver,oneof=1.0.0"`
	SkipOnFail       bool       `json:"skipOnFail"`
	CreatedDateAfter *time.Time `json:"createdDateAfter"`
}

type CloseablePluginTask added in v0.12.0

type CloseablePluginTask interface {
	PluginTask
	Close(taskCtx TaskContext) errors.Error
}

CloseablePluginTask Extends PluginTask, and invokes a Close method after all subtasks are done or fail

type CompositeDataSourcePluginBlueprintV200 added in v0.15.0

type CompositeDataSourcePluginBlueprintV200 interface {
	PluginMeta
	DataSourcePluginBlueprintV200
}

CompositeDataSourcePluginBlueprintV200 is for unit test

type CompositeMetricPluginBlueprintV200 added in v0.15.0

type CompositeMetricPluginBlueprintV200 interface {
	PluginMeta
	MetricPluginBlueprintV200
}

CompositeMetricPluginBlueprintV200 is for unit test

type CompositePluginBlueprintV200 added in v0.15.0

type CompositePluginBlueprintV200 interface {
	PluginMeta
	DataSourcePluginBlueprintV200
	MetricPluginBlueprintV200
}

CompositeMetricPluginBlueprintV200 is for unit test

type ConfigReader added in v0.15.0

type ConfigReader interface {
	Get(key string) interface{}
	GetBool(name string) bool
	GetFloat64(key string) float64
	GetInt(key string) int
	GetInt64(key string) int64
	GetUint(key string) uint
	GetUint64(key string) uint64
	GetIntSlice(key string) []int
	GetString(key string) string
	GetStringMap(key string) map[string]interface{}
	GetStringMapString(key string) map[string]string
	GetStringSlice(key string) []string
	GetTime(key string) time.Time
	GetDuration(key string) time.Duration
	IsSet(key string) bool
	AllSettings() map[string]interface{}
}

type DataSourcePluginBlueprintV200 added in v0.15.0

type DataSourcePluginBlueprintV200 interface {
	MakeDataSourcePipelinePlanV200(
		connectionId uint64,
		scopes []*BlueprintScopeV200,
		syncPolicy BlueprintSyncPolicy,
	) (PipelinePlan, []Scope, errors.Error)
}

DataSourcePluginBlueprintV200 extends the V100 to provide support for Project, so that complex metrics like DORA can be implemented based on a set of Data Scopes

type ExecContext

type ExecContext interface {
	BasicRes
	GetName() string
	GetContext() context.Context
	GetData() interface{}
	SetProgress(current int, total int)
	IncProgress(quantity int)
}

ExecContext This interface define all resources that needed for task/subtask execution

type GrafanaDashboard added in v0.14.0

type GrafanaDashboard struct {
	ID                   string
	Title                string
	Description          string
	GrafanaDashboardJson string
}

type LogLevel

type LogLevel logrus.Level

type Logger

type Logger interface {
	IsLevelEnabled(level LogLevel) bool
	Printf(format string, a ...interface{})
	Log(level LogLevel, format string, a ...interface{})
	Debug(format string, a ...interface{})
	Info(format string, a ...interface{})
	// Warn logs a message. The err field can be left `nil`, otherwise the logger will format it into the message.
	Warn(err error, format string, a ...interface{})
	// Error logs an error. The err field can be left `nil`, otherwise the logger will format it into the message.
	Error(err error, format string, a ...interface{})
	// Nested return a new logger instance. `name` is the extra prefix to be prepended to each message. Leaving it blank
	// will add no additional prefix. The new Logger will inherit the properties of the original.
	Nested(name string) Logger
	// GetConfig Returns a copy of the LoggerConfig associated with this Logger. This is meant to be used by the framework.
	GetConfig() *LoggerConfig
	// SetStream sets the output of this Logger. This is meant to be used by the framework.
	SetStream(config *LoggerStreamConfig)
}

Logger General logger interface, can be used anywhere

type LoggerConfig added in v0.13.0

type LoggerConfig struct {
	Path   string
	Prefix string
}

LoggerConfig config related to the Logger. This needs to be serializable, so it can be passed around over the wire.

type LoggerStreamConfig added in v0.13.0

type LoggerStreamConfig struct {
	Path   string
	Writer io.Writer
}

LoggerStreamConfig stream related config to set on a Logger

type MetricPluginBlueprintV200 added in v0.15.0

type MetricPluginBlueprintV200 interface {
	MakeMetricPluginPipelinePlanV200(projectName string, options json.RawMessage) (PipelinePlan, errors.Error)
}

MetricPluginBlueprintV200 is similar to the DataSourcePluginBlueprintV200 but for Metric Plugin, take dora as an example, it doens't have any scope, nor does it produce any, however, it does require other plugin to be executed beforehand, like calcuating refdiff before it can connect PR to the right Deployment keep in mind it would be called IFF the plugin was enabled for the project.

type MigrationScript added in v0.15.0

type MigrationScript interface {
	Up(basicRes BasicRes) errors.Error
	Version() uint64
	Name() string
}

MigrationScript upgrades database to a newer version

type Migrator added in v0.15.0

type Migrator interface {
	Register(scripts []MigrationScript, comment string)
	Execute() errors.Error
	HasPendingScripts() bool
}

Migrator is responsible for making sure the registered scripts get applied to database and only once

type OutputFile added in v0.12.0

type OutputFile struct {
	ContentType string
	Data        []byte
}

OutputFile is the file returned

type PipelinePlan added in v0.12.0

type PipelinePlan []PipelineStage

PipelinePlan consist of multiple PipelineStages, they will be executed in sequential order

type PipelineStage added in v0.12.0

type PipelineStage []*PipelineTask

PipelineStage consist of multiple PipelineTasks, they will be executed in parallel

type PipelineTask added in v0.12.0

type PipelineTask struct {
	// Plugin name
	Plugin   string                 `json:"plugin" binding:"required"`
	Subtasks []string               `json:"subtasks"`
	Options  map[string]interface{} `json:"options"`
}

PipelineTask represents a smallest unit of execution inside a PipelinePlan

type PluginApi

type PluginApi interface {
	ApiResources() map[string]map[string]ApiResourceHandler
}

Implement this interface if plugin offered API Code sample to register a api on `sources/:connectionId`:

func (plugin Jira) ApiResources() map[string]map[string]core.ApiResourceHandler {
	return map[string]map[string]core.ApiResourceHandler{
		"connections/:connectionId": {
			"PUT":    api.PutConnection,
			"DELETE": api.DeleteConnection,
			"GET":    api.GetConnection,
		},
	}
}

type PluginBlueprintV100 added in v0.12.0

type PluginBlueprintV100 interface {
	// MakePipelinePlan generates `pipeline.tasks` based on `version` and `scope`
	//
	// `version` semver from `blueprint.settings.version`
	// `scope` arbitrary json.RawMessage, depends on `version`, for v1.0.0, it is an Array of Objects
	MakePipelinePlan(connectionId uint64, scope []*BlueprintScopeV100) (PipelinePlan, errors.Error)
}

PluginBlueprintV100 is used to support Blueprint Normal model, for Plugin and Blueprint to collaboarte and generate a sophisticated Pipeline Plan based on User Settings. V100 doesn't support Project, and being deprecated, please use PluginBlueprintV200 instead

type PluginCallBack added in v0.13.0

type PluginCallBack func(name string, plugin PluginMeta) errors.Error

type PluginDashboard added in v0.14.0

type PluginDashboard interface {
	Dashboards() []GrafanaDashboard
}

PluginDashboard return its dashboard which should be display at grafana

type PluginIcon added in v0.14.0

type PluginIcon interface {
	SvgIcon() string
}

PluginIcon return its icon (.svg text)

type PluginInit

type PluginInit interface {
	Init(basicRes BasicRes) errors.Error
}

PluginInit Implement this interface if plugin needed some initialization

type PluginMeta

type PluginMeta interface {
	Description() string
	// PkgPath information lost when compiled as plugin(.so)
	RootPkgPath() string
}

PluginMeta is the Minimal features a plugin should comply, should be implemented by all plugins

func GetPlugin

func GetPlugin(name string) (PluginMeta, errors.Error)

type PluginMetric added in v0.15.0

type PluginMetric interface {
	// returns a list of required data entities and expected features.
	// [{ "model": "cicd_tasks", "requiredFields": {"column": "type", "execptedValue": "Deployment"}}, ...]
	RequiredDataEntities() (data []map[string]interface{}, err errors.Error)

	// returns if the metric depends on Project for calculation.
	// Currently, only dora would return true.
	IsProjectMetric() bool

	// indicates which plugins must be executed before executing this one.
	// declare a set of dependencies with this
	RunAfter() ([]string, errors.Error)

	// returns an empty pointer of the plugin setting struct.
	// (no concrete usage at this point)
	Settings() (p interface{})
}

type PluginMigration added in v0.15.0

type PluginMigration interface {
	MigrationScripts() []MigrationScript
}

PluginMigration is implemented by the plugin to declare all migration script that have to be applied to the database

type PluginModel added in v0.13.0

type PluginModel interface {
	// This method returns all models of the current plugin
	GetTablesInfo() []dal.Tabler
}

type PluginSource added in v0.15.0

type PluginSource interface {
	Connection() interface{}
	Scope() interface{}
	TransformationRule() interface{}
}

PluginSource abstracts data sources

type PluginTask

type PluginTask interface {
	// SubTaskMetas return all available subtasks, framework will run them for you in order
	SubTaskMetas() []SubTaskMeta
	// PrepareTaskData based on task context and user input options, return data that shared among all subtasks
	PrepareTaskData(taskCtx TaskContext, options map[string]interface{}) (interface{}, errors.Error)
}

PluginTask Implement this interface to let framework run tasks for you

type ProgressType

type ProgressType int
const (
	TaskSetProgress ProgressType = iota
	TaskIncProgress
	SubTaskSetProgress
	SubTaskIncProgress
	SetCurrentSubTask
)

type RunningProgress

type RunningProgress struct {
	Type          ProgressType
	Current       int
	Total         int
	SubTaskName   string
	SubTaskNumber int
}

type Scope added in v0.15.0

type Scope interface {
	ScopeId() string
	ScopeName() string
	TableName() string
}

Scope represents the top level entity for a data source, i.e. github repo, gitlab project, jira board. They turn into repo, board in Domain Layer. In Apache Devlake, a Project is essentially a set of these top level entities, for the framework to maintain these relationships dynamically and automatically, all Domain Layer Top Level Entities should implement this interface

type SubTask

type SubTask interface {
	// Execute FIXME ...
	Execute() errors.Error
}

type SubTaskContext

type SubTaskContext interface {
	ExecContext
	TaskContext() TaskContext
}

SubTaskContext This interface define all resources that needed for subtask execution

type SubTaskEntryPoint

type SubTaskEntryPoint func(c SubTaskContext) errors.Error

SubTaskEntryPoint All subtasks from plugins should comply to this prototype, so they could be orchestrated by framework

type SubTaskMeta

type SubTaskMeta struct {
	Name       string
	EntryPoint SubTaskEntryPoint
	// Required SubTask will be executed no matter what
	Required         bool
	EnabledByDefault bool
	Description      string
	DomainTypes      []string
}

SubTaskMeta Metadata of a subtask

type TaskContext

type TaskContext interface {
	ExecContext
	SetData(data interface{})
	SubTaskContext(subtask string) (SubTaskContext, errors.Error)
}

TaskContext This interface define all resources that needed for task execution

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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