core

package
v0.10.0-k8s3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const EncodeKeyEnvStr = "ENCODE_KEY"

Variables

View Source
var DateTimeFormats []DateTimeFormatItem

Functions

func AesDecrypt added in v0.8.0

func AesDecrypt(crypted, key []byte) ([]byte, error)

AES decryption

func AesEncrypt added in v0.8.0

func AesEncrypt(origData, key []byte) ([]byte, error)

AES encryption, CBC

func AllPlugins

func AllPlugins() map[string]PluginMeta

func ConvertStringToTime added in v0.4.0

func ConvertStringToTime(timeString string) (t time.Time, err error)

func DecodeMapStruct added in v0.6.0

func DecodeMapStruct(input map[string]interface{}, result interface{}) error

mapstructure.Decode with time.Time and Iso8601Time support

func Decrypt added in v0.10.0

func Decrypt(encKey, encryptedText string) (string, error)

Base64 + AES decryption using ENCODE_KEY in .env as key

func Encrypt added in v0.10.0

func Encrypt(encKey, plainText string) (string, 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, error)

func Iso8601TimeToTime added in v0.6.0

func Iso8601TimeToTime(iso8601Time *Iso8601Time) *time.Time

func PKCS7Padding added in v0.8.0

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

PKCS7 padding

func PKCS7UnPadding added in v0.8.0

func PKCS7UnPadding(origData []byte) []byte

PKCS7 unPadding

func RandomCapsStr added in v0.8.0

func RandomCapsStr(len int) string

A random string of length len uppercase characters

func RandomEncKey added in v0.10.0

func RandomEncKey() string

func RegisterPlugin

func RegisterPlugin(name string, plugin PluginMeta) error

Types

type ApiResourceHandler added in v0.3.0

type ApiResourceHandler func(input *ApiResourceInput) (*ApiResourceOutput, error)

type ApiResourceInput added in v0.3.0

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

Contains api request information

type ApiResourceOutput added in v0.3.0

type ApiResourceOutput struct {
	Body   interface{} // response body
	Status int
}

Describe response data of a api

type DateTimeFormatItem added in v0.4.0

type DateTimeFormatItem struct {
	Matcher *regexp.Regexp
	Format  string
}

TODO: move this to helper

type ExecContext added in v0.10.0

type ExecContext interface {
	GetName() string
	GetConfig(name string) string
	GetDb() *gorm.DB
	GetContext() context.Context
	GetLogger() Logger
	GetData() interface{}
	SetProgress(current int, total int)
	IncProgress(quantity int)
}

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

type Iso8601Time

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

type Iso8601Time time.Time

func (Iso8601Time) MarshalJSON

func (jt Iso8601Time) MarshalJSON() ([]byte, error)

func (*Iso8601Time) String

func (jt *Iso8601Time) String() string

func (*Iso8601Time) ToNullableTime added in v0.9.0

func (jt *Iso8601Time) ToNullableTime() *time.Time

func (*Iso8601Time) ToTime

func (jt *Iso8601Time) ToTime() time.Time

func (*Iso8601Time) UnmarshalJSON

func (jt *Iso8601Time) UnmarshalJSON(b []byte) error

type LogLevel added in v0.10.0

type LogLevel logrus.Level

type Logger added in v0.10.0

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(format string, a ...interface{})
	Error(format string, a ...interface{})
	// return a new logger which output nested log
	Nested(name string) Logger
}

General logger interface, can be used any where

type Migratable added in v0.10.0

type Migratable interface {
	MigrationScripts() []migration.Script
}

type PluginApi added in v0.10.0

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

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

func (plugin Jira) ApiResources() map[string]map[string]core.ApiResourceHandler {
	return map[string]map[string]core.ApiResourceHandler{
		"sources/:sourceId": {
			"PUT":    api.PutSource,
			"DELETE": api.DeleteSource,
			"GET":    api.GetSource,
		},
	}
}

type PluginInit added in v0.10.0

type PluginInit interface {
	Init(config *viper.Viper, logger Logger, db *gorm.DB) error
}

Implement this interface if plugin needed some initialization

type PluginMeta added in v0.10.0

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

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

func GetPlugin

func GetPlugin(name string) (PluginMeta, error)

type PluginTask added in v0.10.0

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

Implement this interface to let framework run tasks for you

type ProgressType added in v0.10.0

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

type RunningProgress added in v0.10.0

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

type SubTask added in v0.10.0

type SubTask interface {
	Execute() error
}

type SubTaskContext added in v0.10.0

type SubTaskContext interface {
	ExecContext
	TaskContext() TaskContext
}

This interface define all resources that needed for subtask execution

type SubTaskEntryPoint added in v0.10.0

type SubTaskEntryPoint func(c SubTaskContext) error

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

type SubTaskMeta added in v0.10.0

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

Meta data of a subtask

type TaskContext added in v0.10.0

type TaskContext interface {
	ExecContext
	SetData(data interface{})
	SubTaskContext(subtask string) (SubTaskContext, error)
}

This interface define all resources that needed for task execution

Jump to

Keyboard shortcuts

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