contracts

package
v4.21.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const Expired = 8 * time.Hour

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplicationInterface

type ApplicationInterface interface {
	// IsDebug bool.
	IsDebug() bool

	// K8sClient return *K8sClient
	K8sClient() *K8sClient
	// SetK8sClient set *K8sClient
	SetK8sClient(*K8sClient)

	// Auth return AuthInterface.
	Auth() AuthInterface
	// SetAuth set AuthInterface.
	SetAuth(AuthInterface)

	// SetLocalUploader set local Uploader
	SetLocalUploader(Uploader)
	// LocalUploader get local Uploader
	LocalUploader() Uploader

	// SetUploader setter
	SetUploader(Uploader)
	// Uploader getter
	Uploader() Uploader

	// Bootstrap boots all.
	Bootstrap() error
	// Config app configuration.
	Config() *config.Config

	// DBManager db.
	DBManager() DBManager
	// DB instance.
	DB() *gorm.DB

	// Oidc sso cfg
	Oidc() OidcConfig
	// SetOidc setter
	SetOidc(OidcConfig)

	// AddServer add boot server
	AddServer(Server)
	// Run servers.
	Run() context.Context
	// Shutdown all servers.
	Shutdown()

	Done() <-chan struct{}

	BeforeServerRunHooks(Callback)
	RegisterBeforeShutdownFunc(Callback)
	RegisterAfterShutdownFunc(Callback)

	EventDispatcher() DispatcherInterface
	SetEventDispatcher(DispatcherInterface)

	SetPlugins(map[string]PluginInterface)
	GetPlugins() map[string]PluginInterface
	GetPluginByName(string) PluginInterface

	Singleflight() *singleflight.Group

	SetCache(CacheInterface)
	Cache() CacheInterface

	CacheLock() Locker
	SetCacheLock(Locker)

	SetTracer(trace.Tracer)
	GetTracer() trace.Tracer

	SetCronManager(CronManager)
	CronManager() CronManager
}

ApplicationInterface app.

type Archiver

type Archiver interface {
	Archive(sources []string, destination string) error
	Open(path string) (io.ReadCloser, error)
	Remove(path string) error
}

Archiver 不是很合理,但暂时这样

type AuditLogImpl added in v4.19.7

type AuditLogImpl interface {
	// GetUsername 获取用户
	GetUsername() string
	// GetAction 行为
	GetAction() types.EventActionType
	// GetMsg desc
	GetMsg() string
	// GetOldStr old config str
	GetOldStr() string
	// GetNewStr new config str
	GetNewStr() string
	// GetFileID file id
	GetFileID() int
}

type AuthInterface

type AuthInterface interface {
	Authenticator
	Sign(UserInfo) (*SignData, error)
}

type Authenticator

type Authenticator interface {
	VerifyToken(string) (*JwtClaims, bool)
}

type AuthorizeInterface

type AuthorizeInterface interface {
	Authorize(ctx context.Context, fullMethodName string) (context.Context, error)
}

type Bootstrapper

type Bootstrapper interface {
	// Bootstrap when app start.
	Bootstrap(ApplicationInterface) error
	// Tags boot tags.
	Tags() []string
}

Bootstrapper boots.

type BranchInterface

type BranchInterface interface {
	GetName() string
	IsDefault() bool
	GetWebURL() string
}

type CacheInterface

type CacheInterface interface {
	SetWithTTL(key CacheKeyInterface, value []byte, seconds int) error
	Remember(key CacheKeyInterface, seconds int, fn func() ([]byte, error)) ([]byte, error)
	Clear(key CacheKeyInterface) error
	Store() Store
}

type CacheKeyInterface

type CacheKeyInterface interface {
	String() string
	Slug() string
}

type Callback

type Callback func(ApplicationInterface)

type CancelSignaler

type CancelSignaler interface {
	Remove(id string)
	Has(id string) bool
	Cancel(id string)
	Add(id string, fn func(error)) error
	CancelAll()
}

type Command

type Command interface {
	//Name 名称
	Name() string
	//Func 方法
	Func() func()
	//Expression cron 表达式: "* * * * * *"
	Expression() string
	//Cron 自定义 expression "* * * * * *"
	Cron(expression string) Command
	//EverySecond 每 1 秒
	EverySecond() Command
	//EveryTwoSeconds 每 2 秒
	EveryTwoSeconds() Command
	//EveryThreeSeconds 每 3 秒
	EveryThreeSeconds() Command
	//EveryFourSeconds 每 4 秒
	EveryFourSeconds() Command
	//EveryFiveSeconds 每 5 秒
	EveryFiveSeconds() Command
	//EveryTenSeconds 每 10 秒
	EveryTenSeconds() Command
	//EveryFifteenSeconds 每 15 秒
	EveryFifteenSeconds() Command
	//EveryThirtySeconds 每 30 秒
	EveryThirtySeconds() Command
	//EveryMinute 每分钟
	EveryMinute() Command
	//EveryTwoMinutes 每 2 分钟
	EveryTwoMinutes() Command
	//EveryThreeMinutes 每 3 分钟
	EveryThreeMinutes() Command
	//EveryFourMinutes 每 4 分钟
	EveryFourMinutes() Command
	//EveryFiveMinutes 每 5 分钟
	EveryFiveMinutes() Command
	//EveryTenMinutes 每 10 分钟
	EveryTenMinutes() Command
	//EveryFifteenMinutes 每 15 分钟
	EveryFifteenMinutes() Command
	//EveryThirtyMinutes 每 30 分钟
	EveryThirtyMinutes() Command
	//Hourly 每小时
	Hourly() Command
	//HourlyAt 每小时的第几分钟
	HourlyAt([]int) Command
	//EveryTwoHours 每 2 小时
	EveryTwoHours() Command
	//EveryThreeHours 每 3 小时
	EveryThreeHours() Command
	//EveryFourHours 每 4 小时
	EveryFourHours() Command
	//EverySixHours 每 6 小时
	EverySixHours() Command
	//Daily 每天
	Daily() Command
	//DailyAt 每天几点(time: "2:00")
	DailyAt(time string) Command
	//At alias of DailyAt
	At(string) Command
	//Weekdays 工作日 1-5
	Weekdays() Command
	//Weekends 周末
	Weekends() Command
	//Mondays 周一
	Mondays() Command
	//Tuesdays 周二
	Tuesdays() Command
	//Wednesdays 周三
	Wednesdays() Command
	//Thursdays 周四
	Thursdays() Command
	//Fridays 周五
	Fridays() Command
	//Saturdays 周六
	Saturdays() Command
	//Sundays 周日
	Sundays() Command
	//Weekly 每周一
	Weekly() Command
	//WeeklyOn 周日几(day) 几点(time: "0:0")
	WeeklyOn(day int, time string) Command
	Monthly() Command
	// MonthlyOn dayOfMonth: 1, time: "0:0"
	MonthlyOn(dayOfMonth string, time string) Command
	//LastDayOfMonth 每月最后一天
	LastDayOfMonth(time string) Command
	// Quarterly 每季度执行
	Quarterly() Command
	// QuarterlyOn 每季度的第几天,几点(time: "0:0")执行
	QuarterlyOn(dayOfQuarter string, time string) Command
	//Yearly 每年
	Yearly() Command
	//YearlyOn 每年几月(month) 哪天(dayOfMonth) 时间(time: "0:0")
	YearlyOn(month string, dayOfMonth string, time string) Command
	//Days 天(0-6: 周日-周六)
	Days([]int) Command
}

type CommitInterface

type CommitInterface interface {
	GetID() string
	GetShortID() string
	GetTitle() string
	GetCommittedDate() *time.Time
	GetAuthorName() string
	GetAuthorEmail() string
	GetCommitterName() string
	GetCommitterEmail() string
	GetCreatedAt() *time.Time
	GetMessage() string
	GetProjectID() int64
	GetWebURL() string
}

type Container

type Container struct {
	Namespace string `json:"namespace"`
	Pod       string `json:"pod"`
	Container string `json:"container"`
}

type CopyFileToPodResult

type CopyFileToPodResult struct {
	TargetDir     string
	ErrOut        string
	StdOut        string
	ContainerPath string
	FileName      string
}

type CronManager

type CronManager interface {
	NewCommand(name string, fn func() error) Command
	Run(context.Context) error
	Shutdown(context.Context) error

	List() []Command
}

type CronRunner

type CronRunner interface {
	AddCommand(name string, expression string, fn func()) error
	Run(context.Context) error
	Shutdown(context.Context) error
}

type DBManager

type DBManager interface {
	DB() *gorm.DB
	SetDB(*gorm.DB)

	AutoMigrate(dst ...any) error
}

type DeployMsger

type DeployMsger interface {
	Msger
	ProcessPercentMsger

	SendDeployedResult(t websocket.ResultType, msg string, p *types.ProjectModel)
}

type DispatcherInterface

type DispatcherInterface interface {
	// Listen Register an event listener with the dispatcher.
	Listen(Event, Listener)

	// HasListeners Determine if a given event has listeners.
	HasListeners(Event) bool

	// Dispatch Fire an event and call the listeners.
	Dispatch(Event, any) error

	// Forget Remove a set of listeners from the dispatcher.
	Forget(Event)

	// GetListeners get all listeners by event.
	GetListeners(Event) []Listener
}

type Event

type Event string

func (Event) Is

func (e Event) Is(event Event) bool

func (Event) String

func (e Event) String() string

type ExecRequestBuilder

type ExecRequestBuilder interface {
	BuildExecRequest(namespace, pod string, peo *corev1.PodExecOptions) ExecUrlBuilder
}

type ExecUrlBuilder

type ExecUrlBuilder interface {
	URL() *url.URL
}

type FanOutInterface

type FanOutInterface[T runtime.Object] interface {
	RemoveListener(key string)
	AddListener(key string, ch chan<- Obj[T])
	Distribute(done <-chan struct{})
}

type FanOutType

type FanOutType int
const (
	Add FanOutType = iota
	Update
	Delete
)

type File

type File interface {
	io.ReadWriteCloser
	io.StringWriter
	Name() string
	Stat() (os.FileInfo, error)
	Seek(offset int64, whence int) (ret int64, err error)
}

type FileInfo

type FileInfo interface {
	Path() string
	Size() uint64
	LastModified() time.Time
}

type Helmer

type Helmer interface {
	UpgradeOrInstall(ctx context.Context, releaseName, namespace string, ch *chart.Chart, valueOpts *values.Options, fn WrapLogFn, wait bool, timeoutSeconds int64, dryRun bool, desc string) (*release.Release, error)
	Rollback(releaseName, namespace string, wait bool, log LogFn, dryRun bool) error
	Uninstall(releaseName, namespace string, log LogFn) error
	ReleaseStatus(releaseName, namespace string) types.Deploy
	PackageChart(path string, destDir string) (string, error)
}

type Job

type Job interface {
	Stop(error)
	IsNotDryRun() bool

	ID() string
	GlobalLock() Job
	Validate() Job
	LoadConfigs() Job
	Run() Job
	Finish() Job
	Error() error
	Manifests() []string

	OnError(p int, fn func(err error, sendResultToUser func())) Job
	OnSuccess(p int, fn func(err error, sendResultToUser func())) Job
	OnFinally(p int, fn func(err error, sendResultToUser func())) Job
}

type JwtClaims

type JwtClaims struct {
	*jwt.StandardClaims
	UserInfo UserInfo `json:"user_info"`
}

type K8sClient

type K8sClient struct {
	Client        kubernetes.Interface
	MetricsClient versioned.Interface
	RestConfig    *restclient.Config

	PodInformer cache.SharedIndexInformer
	PodLister   v1.PodLister

	SecretInformer cache.SharedIndexInformer
	SecretLister   v1.SecretLister

	ReplicaSetLister appsv1.ReplicaSetLister
	ServiceLister    v1.ServiceLister
	IngressLister    networkingv1.IngressLister

	EventInformer cache.SharedIndexInformer

	EventFanOut FanOutInterface[*eventsv1.Event]
	PodFanOut   FanOutInterface[*corev1.Pod]
}

type ListBranchResponseInterface

type ListBranchResponseInterface interface {
	GetItems() []BranchInterface
	// contains filtered or unexported methods
}

type ListProjectResponseInterface

type ListProjectResponseInterface interface {
	GetItems() []ProjectInterface
	// contains filtered or unexported methods
}

type Listener

type Listener func(any, Event) error

type Locker

type Locker interface {
	ID() string
	Type() string
	Acquire(key string, seconds int64) bool
	RenewalAcquire(key string, seconds int64, renewalSeconds int64) (releaseFn func(), acquired bool)
	Release(key string) bool
	ForceRelease(key string) bool
	Owner(key string) string
}

type LogFn

type LogFn func(format string, v ...any)

type LoggerInterface

type LoggerInterface interface {
	Debug(v ...any)
	Debugf(format string, v ...any)
	Warning(v ...any)
	Warningf(format string, v ...any)
	Info(v ...any)
	Infof(format string, v ...any)
	Error(v ...any)
	Errorf(format string, v ...any)
	Fatal(v ...any)
	Fatalf(format string, v ...any)
}

type MessageItem

type MessageItem struct {
	Msg  string
	Type MessageType

	Containers []*types.Container
}

type MessageType

type MessageType uint8
const (
	MessageSuccess MessageType
	MessageError
	MessageText
)

type Msger

type Msger interface {
	SendEndError(error)
	SendError(error)
	SendMsg(string)
	SendProtoMsg(WebsocketMessage)
	SendMsgWithContainerLog(msg string, containers []*types.Container)
}

type Obj

type Obj[T runtime.Object] interface {
	Type() FanOutType
	Old() T
	Current() T
}

func NewObj

func NewObj[T runtime.Object](old T, current T, t FanOutType) Obj[T]

type OidcClaims

type OidcClaims struct {
	LogoutUrl string `json:"logout_url"`
	OpenIDClaims
}

func (OidcClaims) ToUserInfo

func (c OidcClaims) ToUserInfo() UserInfo

type OidcConfig

type OidcConfig map[string]OidcConfigItem

type OidcConfigItem

type OidcConfigItem struct {
	Provider           *oidc.Provider
	Config             oauth2.Config
	EndSessionEndpoint string
}

type OpenIDClaims

type OpenIDClaims struct {
	Sub                 string         `json:"sub"`
	Name                string         `json:"name"`
	GivenName           string         `json:"given_name"`
	FamilyName          string         `json:"family_name"`
	MiddleName          string         `json:"middle_name"`
	Nickname            string         `json:"nickname"`
	PreferredUsername   string         `json:"preferred_username"`
	Profile             string         `json:"profile"`
	Picture             string         `json:"picture"`
	Website             string         `json:"website"`
	Email               string         `json:"email"`
	EmailVerified       bool           `json:"email_verified"`
	Gender              string         `json:"gender"`
	Birthdate           string         `json:"birthdate"`
	Zoneinfo            string         `json:"zoneinfo"`
	Locale              string         `json:"locale"`
	PhoneNumber         string         `json:"phone_number"`
	PhoneNumberVerified bool           `json:"phone_number_verified"`
	Address             map[string]any `json:"address"`
	UpdatedAt           int            `json:"updated_at"`
}

type Percentable

type Percentable interface {
	Current() int64
	Add()
	To(percent int64)
}

type Picture

type Picture struct {
	Url       string
	Copyright string
}

type PipelineInterface

type PipelineInterface interface {
	GetID() int64
	GetProjectID() int64
	GetStatus() Status
	GetRef() string
	GetSHA() string
	GetWebURL() string
	GetUpdatedAt() *time.Time
	GetCreatedAt() *time.Time
}

type PluginInterface

type PluginInterface interface {
	// Name plugin name.
	Name() string
	// Initialize init plugin.
	Initialize(args map[string]any) error
	// Destroy plugin.
	Destroy() error
}

type PodFileCopier

type PodFileCopier interface {
	Copy(namespace, pod, container, fpath, targetContainerDir string, clientSet kubernetes.Interface, config *restclient.Config) (*CopyFileToPodResult, error)
}

type ProcessPercentMsger

type ProcessPercentMsger interface {
	SendProcessPercent(int64)
}

type ProjectInterface

type ProjectInterface interface {
	GetID() int64
	GetName() string
	GetDefaultBranch() string
	GetPath() string
	GetWebURL() string
	GetAvatarURL() string
	GetDescription() string
}

type ProjectPodEventPublisher

type ProjectPodEventPublisher interface {
	Publish(nsID int64, pod *corev1.Pod) error
}

type ProjectPodEventSubscriber

type ProjectPodEventSubscriber interface {
	Join(projectID int64) error
	Leave(nsID int64, projectID int64) error
	Run(ctx context.Context) error
}

type PtyHandler

type PtyHandler interface {
	io.Reader
	io.Writer
	remotecommand.TerminalSizeQueue

	Container() Container
	SetShell(string)
	Toast(string) error

	Send(*websocket.TerminalMessage) error
	Resize(remotecommand.TerminalSize) error

	Recorder() RecorderInterface

	ResetTerminalRowCol(bool)
	Rows() uint16
	Cols() uint16

	Close(string) bool
	IsClosed() bool
}

PtyHandler is what remotecommand expects from a pty

type PubSub

type PubSub interface {
	ProjectPodEventSubscriber
	ProjectPodEventPublisher

	Info() any
	Uid() string
	ID() string
	ToSelf(WebsocketMessage) error
	ToAll(WebsocketMessage) error
	ToOthers(WebsocketMessage) error
	Subscribe() <-chan []byte
	Close() error
}

type RecorderInterface

type RecorderInterface interface {
	Resize(cols, rows uint16)
	Write(data string) (err error)
	Close() error
	SetShell(string)
	GetShell() string
}

type ReleaseInstaller

type ReleaseInstaller interface {
	Chart() *chart.Chart
	Run(stopCtx context.Context, messageCh SafeWriteMessageChInterface, percenter Percentable, isNew bool, desc string) (*release.Release, error)

	Logs() []string
}

type RemoteExecutor

type RemoteExecutor interface {
	WithMethod(method string) RemoteExecutor
	WithContainer(namespace, pod, container string) RemoteExecutor
	WithCommand(cmd []string) RemoteExecutor
	Execute(ctx context.Context, clientSet kubernetes.Interface, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error
}

type SafeWriteMessageChInterface

type SafeWriteMessageChInterface interface {
	Close()
	Chan() <-chan MessageItem
	Send(m MessageItem)
}

type Server

type Server interface {
	// Run server.
	Run(context.Context) error
	// Shutdown server.
	Shutdown(context.Context) error
}

Server define booting server.

type SessionMapper

type SessionMapper interface {
	Send(message *websocket.TerminalMessage)
	Get(sessionId string) (PtyHandler, bool)
	Set(sessionId string, session PtyHandler)
	CloseAll()
	Close(sessionId string, status uint32, reason string)
}

type SignData

type SignData struct {
	Token     string
	ExpiredIn int64
}

type Status

type Status = string
const (
	StatusUnknown Status = "unknown"
	StatusSuccess Status = "success"
	StatusFailed  Status = "failed"
	StatusRunning Status = "running"
)

type Store added in v4.19.7

type Store interface {
	Get(key string) (value []byte, err error)
	Set(key string, value []byte, expireSeconds int) (err error)
	Delete(key string) error
}

type UploadType

type UploadType string
const (
	Local UploadType = "local"
	S3    UploadType = "s3"
)

type Uploader

type Uploader interface {
	Disk(string) Uploader
	Type() UploadType
	DeleteDir(dir string) error
	DirSize() (int64, error)
	Delete(path string) error
	Exists(path string) bool
	MkDir(path string, recursive bool) error
	AbsolutePath(path string) string
	Put(path string, content io.Reader) (FileInfo, error)
	Read(string string) (io.ReadCloser, error)
	Stat(file string) (FileInfo, error)
	AllDirectoryFiles(dir string) ([]FileInfo, error)
	NewFile(path string) (File, error)
	RemoveEmptyDir() error
	UnWrap() Uploader
}

type UserInfo

type UserInfo struct {
	ID      string   `json:"id"`
	Email   string   `json:"email"`
	Name    string   `json:"name"`
	Picture string   `json:"picture"`
	Roles   []string `json:"roles"`

	LogoutUrl string `json:"logout_url"`
}

func (UserInfo) GetID

func (ui UserInfo) GetID() string

func (UserInfo) IsAdmin

func (ui UserInfo) IsAdmin() bool

func (*UserInfo) Json

func (ui *UserInfo) Json() string

type WebsocketConn

type WebsocketConn interface {
	Close() error
	SetWriteDeadline(t time.Time) error
	WriteMessage(messageType int, data []byte) error
	SetReadLimit(limit int64)
	SetReadDeadline(t time.Time) error
	SetPongHandler(h func(appData string) error)
	ReadMessage() (messageType int, p []byte, err error)
	NextWriter(messageType int) (io.WriteCloser, error)
}

type WebsocketMessage

type WebsocketMessage interface {
	proto.Message
	GetMetadata() *websocket.Metadata
}

type WrapLogFn

type WrapLogFn func(container []*types.Container, format string, v ...any)

func (WrapLogFn) UnWrap

func (l WrapLogFn) UnWrap() func(format string, v ...any)

Jump to

Keyboard shortcuts

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