plugin

package
v0.0.0-...-7d3b672 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: Apache-2.0 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 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

Types

type AccessTokenAuthenticator

type AccessTokenAuthenticator interface {
	GetAccessTokenAuthenticator() ApiAuthenticator
}

AccessTokenAuthenticator represents HTTP Bearer Authentication with Access Token

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 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
}

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
}

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 BlueprintConnectionV200

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 BlueprintScopeV200

type BlueprintScopeV200 struct {
	Id   string `json:"id"`
	Name string `json:"name"`
	// Deprecated: Entities is moved to the ScopeConfig struct
	Entities []string `json:"entities"`
}

BlueprintScopeV200 contains the `id` and `name` for a specific scope

type BlueprintSyncPolicy

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

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{}, valdator *validator.Validate) errors.Error
}

ConnectionValidator represents the API Connection would validate its fields with customized logic

type DataSourcePluginBlueprintV200

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 {
	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 GenericPipelinePlan

type GenericPipelinePlan[T any] []GenericPipelineStage[T]

type GenericPipelineStage

type GenericPipelineStage[T any] []*GenericPipelineTask[T]

type GenericPipelineTask

type GenericPipelineTask[T any] struct {
	Plugin   string   `json:"plugin" binding:"required"`
	Subtasks []string `json:"subtasks"`
	Options  T        `json:"options"`
}

type GrafanaDashboard

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

type MetricPluginBlueprintV200

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

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 PipelinePlan

type PipelinePlan []PipelineStage

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

func (PipelinePlan) IsEmpty

func (plan PipelinePlan) IsEmpty() bool

IsEmpty checks if a PipelinePlan is empty

type PipelineStage

type PipelineStage []*PipelineTask

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

type PipelineTask

type PipelineTask GenericPipelineTask[map[string]interface{}]

PipelineTask represents a smallest unit of execution inside a PipelinePlan

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 apihelperabstract.ApiClientAbstract) 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) (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

} // 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
}

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

type ToolLayerScope

type ToolLayerScope interface {
	Scope
	ScopeParams() interface{}
}

Jump to

Keyboard shortcuts

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