plugin

package
v0.0.0-...-1fa52ee Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0, BSD-2-Clause, ISC, + 1 more Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AUTH_METHOD_BASIC  = "BasicAuth"
	AUTH_METHOD_TOKEN  = "AccessToken"
	AUTH_METHOD_APPKEY = "AppKey"
)

MultiAuth

View Source
const DOMAIN_TYPE_CICD = "CICD" //nolint
View Source
const DOMAIN_TYPE_CODE = "CODE" //nolint
View Source
const DOMAIN_TYPE_CODE_QUALITY = "CODEQUALITY" //nolint
View Source
const DOMAIN_TYPE_CODE_REVIEW = "CODEREVIEW" //nolint
View Source
const DOMAIN_TYPE_CROSS = "CROSS" //nolint
View Source
const DOMAIN_TYPE_TICKET = "TICKET" //nolint
View Source
const EncodeKeyEnvStr = "ENCRYPTION_SECRET"

Variables

Functions

func AesDecrypt

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

AesDecrypt AES decryption

func AesEncrypt

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

AesEncrypt AES encryption, CBC

func AllPlugins

func AllPlugins() map[string]PluginMeta

func Decrypt

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

Base64 + AES decryption using ENCRYPTION_SECRET in .env as key

func Encrypt

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

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

func FindPluginNameBySubPkgPath

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

func InitPlugins

func InitPlugins(basicRes context.BasicRes)

func MarshalScopeParams

func MarshalScopeParams(params interface{}) string

func PKCS7Padding

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

PKCS7Padding PKCS7 padding

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

PKCS7UnPadding PKCS7 unPadding

func RandomEncryptionSecret

func RandomEncryptionSecret() (string, errors.Error)

RandomEncryptionSecret will return a random string of length 128

func RegisterPlugin

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

func TraversalPlugin

func TraversalPlugin(handle PluginCallBack) errors.Error

func WrapTestConnectionErrResp

func WrapTestConnectionErrResp(basicRes context.BasicRes, err errors.Error) errors.Error

Types

type AccessTokenAuthenticator

type AccessTokenAuthenticator interface {
	GetAccessTokenAuthenticator() ApiAuthenticator
}

AccessTokenAuthenticator represents HTTP Bearer Authentication with Access Token

type ApiAsyncCallback

type ApiAsyncCallback func(*http.Response) errors.Error

ApiAsyncCallback FIXME ...

type ApiAuthenticator

type ApiAuthenticator interface {
	// SetupAuthentication is a hook function for connection to set up authentication for the HTTP request
	// before sending it to the server
	SetupAuthentication(request *http.Request) errors.Error
}

ApiAuthenticator is to be implemented by a Concreate Connection if Authorization is required

type ApiClient

type ApiClient interface {
	SetData(name string, data interface{})
	GetData(name string) interface{}
	SetHeaders(headers map[string]string)
	SetBeforeFunction(callback ApiClientBeforeRequest)
	GetBeforeFunction() ApiClientBeforeRequest
	SetAfterFunction(callback ApiClientAfterResponse)
	GetAfterFunction() ApiClientAfterResponse
	Get(path string, query url.Values, headers http.Header) (*http.Response, errors.Error)
	Post(path string, query url.Values, body interface{}, headers http.Header) (*http.Response, errors.Error)
}

ApiClientAbstract defines the functionalities needed by all plugins for Synchronized API Request

type ApiClientAfterResponse

type ApiClientAfterResponse func(res *http.Response) errors.Error

ApiClientAfterResponse FIXME ...

type ApiClientBeforeRequest

type ApiClientBeforeRequest func(req *http.Request) errors.Error

ApiClientBeforeRequest FIXME ...

type ApiConnection

type ApiConnection interface {
	GetEndpoint() string
	GetProxy() string
	GetRateLimitPerHour() int
}

ApiConnection represents a API Connection

type ApiGroup

type ApiGroup interface {
	GroupId() string
	GroupName() string
}

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

	User *common.User
}

ApiResourceInput Contains api request information

func (*ApiResourceInput) GetPlugin

func (input *ApiResourceInput) GetPlugin() string

GetPlugin get the plugin in context

type ApiResourceOutput

type ApiResourceOutput struct {
	Body        interface{} // response body
	Status      int
	File        *OutputFile
	ContentType string
	Header      http.Header // optional response header
}

ApiResourceOutput Describe response data of a api

type ApiScope

type ApiScope interface {
	ConvertApiScope() ToolLayerScope
}

type AppKeyAuthenticator

type AppKeyAuthenticator interface {
	GetAppKeyAuthenticator() ApiAuthenticator
}

AppKeyAuthenticator represents the API Key and Secret authentication mechanism

type BasicAuthenticator

type BasicAuthenticator interface {
	GetBasicAuthenticator() ApiAuthenticator
}

BasicAuthenticator represents HTTP Basic Authentication

type CacheableConnection

type CacheableConnection interface {
	ApiConnection
	GetHash() string
}

type CloseablePluginTask

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

type CompositeDataSourcePluginBlueprintV200 interface {
	PluginMeta
	DataSourcePluginBlueprintV200
}

CompositeDataSourcePluginBlueprintV200 is for unit test

type CompositeMetricPluginBlueprintV200

type CompositeMetricPluginBlueprintV200 interface {
	PluginMeta
	MetricPluginBlueprintV200
}

CompositeMetricPluginBlueprintV200 is for unit test

type CompositePluginBlueprintV200

type CompositePluginBlueprintV200 interface {
	PluginMeta
	DataSourcePluginBlueprintV200
	MetricPluginBlueprintV200
}

CompositePluginBlueprintV200 is for unit test

type CompositeProjectMapper

type CompositeProjectMapper interface {
	PluginMeta
	ProjectMapper
}

CompositeProjectMapper is for unit test

type ConnectionValidator

type ConnectionValidator interface {
	ValidateConnection(connection interface{}, validator *validator.Validate) errors.Error
}

TODO: deprecated, remove ConnectionValidator represents the API Connection would validate its fields with customized logic

type DataSourcePluginBlueprintV200

type DataSourcePluginBlueprintV200 interface {
	MakeDataSourcePipelinePlanV200(
		connectionId uint64,
		scopes []*models.BlueprintScope,
	) (models.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 {
	corecontext.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

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

type MetricPluginBlueprintV200

type MetricPluginBlueprintV200 interface {
	MakeMetricPluginPipelinePlanV200(projectName string, options json.RawMessage) (models.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

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

MigrationScript upgrades database to a newer version

type Migrator

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 MultiAuthenticator

type MultiAuthenticator interface {
	GetAuthMethod() string
}

MultiAuthenticator represents the API Connection supports multiple authorization methods

type OutputFile

type OutputFile struct {
	ContentType string
	Data        []byte
}

OutputFile is the file returned

type PluginApi

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

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

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

type PluginCallBack

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

type PluginDashboard

type PluginDashboard interface {
	Dashboards() []GrafanaDashboard
}

PluginDashboard return its dashboard which should be display at grafana

type PluginIcon

type PluginIcon interface {
	SvgIcon() string
}

PluginIcon return its icon (.svg text)

type PluginInit

type PluginInit interface {
	Init(basicRes context.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
	Name() 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

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

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

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

type PluginOpenApiSpec

type PluginOpenApiSpec interface {
	OpenApiSpec() string
}

PluginApiSpec let a plugin document its API with an OpenAPI spec. This is useful for remote plugins because whose standardized API spec template need to be instantiated with remote plugin's specific schemas, something that is not supported by swaggo.

type PluginSource

type PluginSource interface {
	Connection() dal.Tabler
	Scope() ToolLayerScope
	ScopeConfig() dal.Tabler
}

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 PrepareApiClient

type PrepareApiClient interface {
	PrepareApiClient(apiClient ApiClient) errors.Error
}

PrepareApiClient is to be implemented by the concrete Connection which requires preparation for the ApiClient created by NewApiClientFromConnection, i.e. fetch token for future requests

type ProgressType

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

type ProjectMapper

type ProjectMapper interface {
	MapProject(projectName string, scopes []Scope) (models.PipelinePlan, errors.Error)
}

ProjectMapper is implemented by the plugin org, which binding project and scopes

type RunningProgress

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

} // nolint

type Scope

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

} // nolint

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
	Dependencies     []*SubTaskMeta
	DependencyTables []string
	ProductTables    []string
	ForceRunOnResume bool // Should a subtask be ran dispite it was finished before
}

SubTaskMeta Metadata of a subtask

type TaskContext

type TaskContext interface {
	ExecContext
	SetData(data interface{})
	SetSyncPolicy(syncPolicy *models.SyncPolicy)
	SyncPolicy() *models.SyncPolicy
	SubTaskContext(subtask string) (SubTaskContext, errors.Error)
}

TaskContext This interface define all resources that needed for task execution

type ToolLayerApiConnection

type ToolLayerApiConnection interface {
	ApiConnection
	ToolLayerConnection
}

type ToolLayerConnection

type ToolLayerConnection interface {
	dal.Tabler
	ConnectionId() uint64
}

type ToolLayerScope

type ToolLayerScope interface {
	dal.Tabler
	Scope
	ScopeFullName() string
	ScopeParams() interface{}
	ScopeConnectionId() uint64
	ScopeScopeConfigId() uint64
}

type ToolLayerScopeConfig

type ToolLayerScopeConfig interface {
	dal.Tabler
	ScopeConfigId() uint64
	ScopeConfigConnectionId() uint64
}

Jump to

Keyboard shortcuts

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