domain

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: AGPL-3.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KL_ADMIN = "kloudlite"
)

Variables

View Source
var Module = fx.Module(
	"domain",
	fx.Provide(
		func(e *env.Env,
			logger logging.Logger,
			repositoryRepo repos.DbRepo[*entities.Repository],
			credentialRepo repos.DbRepo[*entities.Credential],
			buildRepo repos.DbRepo[*entities.Build],
			buildCacheRepo repos.DbRepo[*entities.BuildCacheKey],
			tagRepo repos.DbRepo[*entities.Digest],
			buildRunRepo repos.DbRepo[*entities.BuildRun],
			iamClient iam.IAMClient,
			cacheClient kv.BinaryDataRepo,
			authClient auth.AuthClient,
			github Github,
			gitlab Gitlab,
			resourceEventPublisher ResourceEventPublisher,
			dispatcher ResourceDispatcher,
		) (Domain, error) {
			return &Impl{
				repositoryRepo:         repositoryRepo,
				credentialRepo:         credentialRepo,
				iamClient:              iamClient,
				envs:                   e,
				digestRepo:             tagRepo,
				logger:                 logger,
				cacheClient:            cacheClient,
				buildRepo:              buildRepo,
				buildCacheRepo:         buildCacheRepo,
				buildRunRepo:           buildRunRepo,
				authClient:             authClient,
				github:                 github,
				gitlab:                 gitlab,
				resourceEventPublisher: resourceEventPublisher,
				dispatcher:             dispatcher,
			}, nil
		}),
)

Functions

func BuildUrl

func BuildUrl(repo, pullToken string) (string, error)

func Nonce

func Nonce(size int) string

Nonce generates a random string of length size

Types

type BuildJobTemplateData

type BuildJobTemplateData struct {
	AccountName string
	Name        string
	Namespace   string
	Labels      map[string]string
	Annotations map[string]string

	Registry     dbv1.Registry
	Caches       []dbv1.Cache
	Resource     dbv1.Resource
	GitRepo      dbv1.GitRepo
	BuildOptions *dbv1.BuildOptions

	CredentialsRef common_types.SecretRef
}

type CheckNameAvailabilityOutput

type CheckNameAvailabilityOutput struct {
	Result         bool     `json:"result"`
	SuggestedNames []string `json:"suggestedNames,omitempty"`
}

type Domain

type Domain interface {
	ProcessRegistryEvents(ctx context.Context, events []entities.Event, logger logging.Logger) error

	CheckUserNameAvailability(ctx RegistryContext, username string) (*CheckNameAvailabilityOutput, error)

	// registry
	ListRepositories(ctx RegistryContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Repository], error)
	CreateRepository(ctx RegistryContext, repoName string) (*entities.Repository, error)
	DeleteRepository(ctx RegistryContext, repoName string) error

	// tags
	ListRepositoryDigests(ctx RegistryContext, repoName string, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Digest], error)
	DeleteRepositoryDigest(ctx RegistryContext, repoName string, digest string) error

	// credential
	ListCredentials(ctx RegistryContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Credential], error)
	CreateCredential(ctx RegistryContext, credential entities.Credential) (*entities.Credential, error)
	DeleteCredential(ctx RegistryContext, userName string) error
	CreateAdminCredential(ctx RegistryContext, credential entities.Credential) (*entities.Credential, error)

	GetToken(ctx RegistryContext, username string) (string, error)
	GetTokenKey(ctx context.Context, username string, accountname string) (string, error)

	AddBuild(ctx RegistryContext, build entities.Build) (*entities.Build, error)
	UpdateBuild(ctx RegistryContext, id repos.ID, build entities.Build) (*entities.Build, error)
	UpdateBuildInternal(ctx context.Context, build *entities.Build) (*entities.Build, error)
	ListBuilds(ctx RegistryContext, repoName string, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Build], error)
	GetBuild(ctx RegistryContext, buildId repos.ID) (*entities.Build, error)
	DeleteBuild(ctx RegistryContext, buildId repos.ID) error
	TriggerBuild(ctx RegistryContext, buildId repos.ID) error

	// webhook
	ParseGithubHook(eventType string, hookBody []byte) (*GitWebhookPayload, error)
	ParseGitlabHook(eventType string, hookBody []byte) (*GitWebhookPayload, error)

	GithubInstallationToken(ctx context.Context, repoUrl string) (string, error)
	GithubListInstallations(ctx context.Context, userId repos.ID, pagination *types.Pagination) ([]*entities.GithubInstallation, error)
	GithubListRepos(ctx context.Context, userId repos.ID, installationId int64, pagination *types.Pagination) (*entities.GithubListRepository, error)
	GithubSearchRepos(ctx context.Context, userId repos.ID, q, org string, pagination *types.Pagination) (*entities.GithubSearchRepository, error)
	GithubListBranches(ctx context.Context, userId repos.ID, repoUrl string, pagination *types.Pagination) ([]*entities.GitBranch, error)
	GithubAddWebhook(ctx context.Context, userId repos.ID, repoUrl string) (repos.ID, error)

	GitlabListGroups(ctx context.Context, userId repos.ID, query *string, pagination *types.Pagination) ([]*entities.GitlabGroup, error)
	GitlabListRepos(ctx context.Context, userId repos.ID, gid string, query *string, pagination *types.Pagination) ([]*entities.GitlabProject, error)
	GitlabListBranches(ctx context.Context, userId repos.ID, repoId string, query *string, pagination *types.Pagination) ([]*entities.GitBranch, error)
	GitlabAddWebhook(ctx context.Context, userId repos.ID, repoId string) (*int, error)
	GitlabPullToken(ctx context.Context, userId repos.ID) (string, error)

	GetBuildTemplate(obj BuildJobTemplateData) ([]byte, error)

	ListBuildsByGit(ctx context.Context, repoUrl, branch, provider string) ([]*entities.Build, error)

	// AddBuildCache(ctx RegistryContext, buildCache entities.BuildCacheKey) (*entities.BuildCacheKey, error)
	// UpdateBuildCache(ctx RegistryContext, id repos.ID, buildCache entities.BuildCacheKey) (*entities.BuildCacheKey, error)
	// DeleteBuildCache(ctx RegistryContext, id repos.ID) error
	// ListBuildCaches(ctx RegistryContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.BuildCacheKey], error)
	ListBuildRuns(ctx RegistryContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.BuildRun], error)
	GetLatestBuildRun(ctx RegistryContext, buildId repos.ID) (*entities.BuildRun, error)
	GetBuildRun(ctx RegistryContext, buildId repos.ID, runName string) (*entities.BuildRun, error)
	OnBuildRunUpdateMessage(ctx RegistryContext, buildRun entities.BuildRun, status t.ResourceStatus, opts UpdateAndDeleteOpts) error

	OnBuildRunDeleteMessage(ctx RegistryContext, buildRun entities.BuildRun) error
	OnBuildRunApplyErrorMessage(ctx RegistryContext, clusterName string, name string, errorMsg string) error
	// ListBuildsByCache(ctx RegistryContext, cacheId repos.ID, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Build], error)
	CreateBuildRun(ctx RegistryContext, build *entities.Build, hook *GitWebhookPayload, pullToken string, seed string) error
}

type ErrEventNotSupported

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

func (*ErrEventNotSupported) Error

func (e *ErrEventNotSupported) Error() string

type GitWebhookPayload

type GitWebhookPayload struct {
	GitProvider string `json:"git_provider,omitempty"`
	RepoUrl     string `json:"repo_url,omitempty"`
	GitBranch   string `json:"git_branch,omitempty"`
	CommitHash  string `json:"commit_hash,omitempty"`
}

type Github

type Github interface {
	Callback(ctx context.Context, code, state string) (*github.User, *oauth2.Token, error)
	GetToken(ctx context.Context, token *oauth2.Token) (*oauth2.Token, error)
	GetInstallationToken(ctx context.Context, repoUrl string) (string, error)

	ListInstallations(ctx context.Context, accToken *entities.AccessToken, pagination *types.Pagination) ([]*github.Installation, error)
	ListRepos(ctx context.Context, accToken *entities.AccessToken, instId int64, pagination *types.Pagination) (*github.ListRepositories, error)
	SearchRepos(ctx context.Context, accToken *entities.AccessToken, q, org string, pagination *types.Pagination) (*github.RepositoriesSearchResult, error)
	ListBranches(ctx context.Context, accToken *entities.AccessToken, repoUrl string, pagination *types.Pagination) ([]*github.Branch, error)
	CheckWebhookExists(ctx context.Context, token *entities.AccessToken, repoUrl string, webhookId *entities.GithubWebhookId) (bool, error)
	AddWebhook(ctx context.Context, accToken *entities.AccessToken, repoUrl string, webhookUrl string) (*entities.GithubWebhookId, error)
	DeleteWebhook(ctx context.Context, accToken *entities.AccessToken, repoUrl string, hookId entities.GithubWebhookId) error
	GetLatestCommit(ctx context.Context, accToken *entities.AccessToken, repoUrl string, branchName string) (string, error)
}

type Gitlab

type Gitlab interface {
	Callback(ctx context.Context, code, state string) (*gitlab.User, *oauth2.Token, error)
	ListGroups(ctx context.Context, token *entities.AccessToken, query *string, pagination *types.Pagination) ([]*entities.GitlabGroup, error)
	ListRepos(ctx context.Context, token *entities.AccessToken, gid string, query *string, pagination *types.Pagination) ([]*gitlab.Project, error)
	ListBranches(ctx context.Context, token *entities.AccessToken, repoId string, query *string, pagination *types.Pagination) ([]*gitlab.Branch, error)
	CheckWebhookExists(ctx context.Context, token *entities.AccessToken, repoId string, webhookId *entities.GitlabWebhookId) (bool, error)
	AddWebhook(ctx context.Context, token *entities.AccessToken, repoId string) (*int, error)
	DeleteWebhook(ctx context.Context, token *entities.AccessToken, repoUrl string, hookId entities.GitlabWebhookId) error
	RepoToken(ctx context.Context, token *entities.AccessToken) (*oauth2.Token, error)
	GetRepoId(repoUrl string) string
	GetLatestCommit(ctx context.Context, token *entities.AccessToken, repoUrl string, branchName string) (string, error)
	GetTriggerWebhookUrl() string
}

type Impl

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

func (*Impl) AddBuild

func (d *Impl) AddBuild(ctx RegistryContext, build entities.Build) (*entities.Build, error)

func (*Impl) CheckUserNameAvailability

func (d *Impl) CheckUserNameAvailability(ctx RegistryContext, username string) (*CheckNameAvailabilityOutput, error)

func (*Impl) CreateAdminCredential

func (d *Impl) CreateAdminCredential(ctx RegistryContext, credential entities.Credential) (*entities.Credential, error)

func (*Impl) CreateBuildRun

func (d *Impl) CreateBuildRun(ctx RegistryContext, build *entities.Build, hook *GitWebhookPayload, pullToken string, seed string) error

func (*Impl) CreateCredential

func (d *Impl) CreateCredential(ctx RegistryContext, credential entities.Credential) (*entities.Credential, error)

CreateCredential implements Domain.

func (*Impl) CreateRepository

func (d *Impl) CreateRepository(ctx RegistryContext, repoName string) (*entities.Repository, error)

CreateRepository implements Domain.

func (*Impl) DeleteBuild

func (d *Impl) DeleteBuild(ctx RegistryContext, buildId repos.ID) error

func (*Impl) DeleteCredential

func (d *Impl) DeleteCredential(ctx RegistryContext, userName string) error

DeleteCredential implements Domain.

func (*Impl) DeleteRepository

func (d *Impl) DeleteRepository(ctx RegistryContext, repoName string) error

DeleteRepository implements Domain.

func (*Impl) DeleteRepositoryDigest

func (d *Impl) DeleteRepositoryDigest(ctx RegistryContext, repoName string, digest string) error

func (*Impl) GetBuild

func (d *Impl) GetBuild(ctx RegistryContext, buildId repos.ID) (*entities.Build, error)

func (*Impl) GetBuildRun

func (d *Impl) GetBuildRun(ctx RegistryContext, buildId repos.ID, runName string) (*entities.BuildRun, error)

func (*Impl) GetBuildTemplate

func (*Impl) GetBuildTemplate(obj BuildJobTemplateData) ([]byte, error)

func (*Impl) GetLatestBuildRun

func (d *Impl) GetLatestBuildRun(ctx RegistryContext, buildId repos.ID) (*entities.BuildRun, error)

func (*Impl) GetToken

func (d *Impl) GetToken(ctx RegistryContext, username string) (string, error)

func (*Impl) GetTokenKey

func (d *Impl) GetTokenKey(ctx context.Context, username string, accountname string) (string, error)

func (*Impl) GithubAddWebhook

func (d *Impl) GithubAddWebhook(ctx context.Context, userId repos.ID, repoUrl string) (repos.ID, error)

func (*Impl) GithubInstallationToken

func (d *Impl) GithubInstallationToken(ctx context.Context, repoUrl string) (string, error)

func (*Impl) GithubListBranches

func (d *Impl) GithubListBranches(ctx context.Context, userId repos.ID, repoUrl string, pagination *types.Pagination) ([]*entities.GitBranch, error)

func (*Impl) GithubListInstallations

func (d *Impl) GithubListInstallations(ctx context.Context, userId repos.ID, pagination *types.Pagination) ([]*entities.GithubInstallation, error)

func (*Impl) GithubListRepos

func (d *Impl) GithubListRepos(ctx context.Context, userId repos.ID, installationId int64, pagination *types.Pagination) (*entities.GithubListRepository, error)

func (*Impl) GithubSearchRepos

func (d *Impl) GithubSearchRepos(ctx context.Context, userId repos.ID, q, org string, pagination *types.Pagination) (*entities.GithubSearchRepository, error)

func (*Impl) GitlabAddWebhook

func (d *Impl) GitlabAddWebhook(ctx context.Context, userId repos.ID, repoId string) (*int, error)

func (*Impl) GitlabListBranches

func (d *Impl) GitlabListBranches(ctx context.Context, userId repos.ID, repoId string, query *string, pagination *types.Pagination) ([]*entities.GitBranch, error)

func (*Impl) GitlabListGroups

func (d *Impl) GitlabListGroups(ctx context.Context, userId repos.ID, query *string, pagination *types.Pagination) ([]*entities.GitlabGroup, error)

func (*Impl) GitlabListRepos

func (d *Impl) GitlabListRepos(ctx context.Context, userId repos.ID, gid string, query *string, pagination *types.Pagination) ([]*entities.GitlabProject, error)

func (*Impl) GitlabPullToken

func (d *Impl) GitlabPullToken(ctx context.Context, userId repos.ID) (string, error)

func (*Impl) ListBuildRuns

func (d *Impl) ListBuildRuns(ctx RegistryContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.BuildRun], error)

func (*Impl) ListBuilds

func (d *Impl) ListBuilds(ctx RegistryContext, repoName string, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Build], error)

func (*Impl) ListBuildsByGit

func (d *Impl) ListBuildsByGit(ctx context.Context, repoUrl, branch, provider string) ([]*entities.Build, error)

func (*Impl) ListCredentials

func (d *Impl) ListCredentials(ctx RegistryContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Credential], error)

ListCredentials implements Domain.

func (*Impl) ListRepositories

func (d *Impl) ListRepositories(ctx RegistryContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Repository], error)

ListRepositories implements Domain.

func (*Impl) ListRepositoryDigests

func (d *Impl) ListRepositoryDigests(ctx RegistryContext, repoName string, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Digest], error)

func (*Impl) MatchRecordVersion

func (d *Impl) MatchRecordVersion(annotations map[string]string, rv int) (int, error)

func (*Impl) OnBuildRunApplyErrorMessage

func (d *Impl) OnBuildRunApplyErrorMessage(ctx RegistryContext, clusterName string, name string, errorMsg string) error

func (*Impl) OnBuildRunDeleteMessage

func (d *Impl) OnBuildRunDeleteMessage(ctx RegistryContext, buildRun entities.BuildRun) error

func (*Impl) OnBuildRunUpdateMessage

func (d *Impl) OnBuildRunUpdateMessage(ctx RegistryContext, buildRun entities.BuildRun, status t2.ResourceStatus, opts UpdateAndDeleteOpts) error

func (*Impl) ParseGithubHook

func (d *Impl) ParseGithubHook(eventType string, hookBody []byte) (*GitWebhookPayload, error)

func (*Impl) ParseGitlabHook

func (d *Impl) ParseGitlabHook(eventType string, hookBody []byte) (*GitWebhookPayload, error)

func (*Impl) ProcessRegistryEvents

func (d *Impl) ProcessRegistryEvents(ctx context.Context, events []entities.Event, logger logging.Logger) error

func (*Impl) TriggerBuild

func (d *Impl) TriggerBuild(ctx RegistryContext, buildId repos.ID) error

func (*Impl) UpdateBuild

func (d *Impl) UpdateBuild(ctx RegistryContext, id repos.ID, build entities.Build) (*entities.Build, error)

func (*Impl) UpdateBuildInternal

func (d *Impl) UpdateBuildInternal(ctx context.Context, build *entities.Build) (*entities.Build, error)

type PublishMsg

type PublishMsg string
const (
	PublishAdd    PublishMsg = "added"
	PublishDelete PublishMsg = "deleted"
	PublishUpdate PublishMsg = "updated"
)

type RegistryContext

type RegistryContext struct {
	context.Context
	UserId      repos.ID
	UserName    string
	AccountName string
	UserEmail   string
}

func NewRegistryContext

func NewRegistryContext(parent context.Context, userId repos.ID, accountName string) RegistryContext

func (RegistryContext) GetAccountName

func (c RegistryContext) GetAccountName() string

func (RegistryContext) GetUserEmail

func (c RegistryContext) GetUserEmail() string

func (RegistryContext) GetUserId

func (c RegistryContext) GetUserId() repos.ID

func (RegistryContext) GetUserName

func (c RegistryContext) GetUserName() string

type ResourceDispatcher

type ResourceDispatcher interface {
	ApplyToTargetCluster(ctx RegistryContext, clusterName string, obj client.Object, recordVersion int) error
	DeleteFromTargetCluster(ctx RegistryContext, clusterName string, obj client.Object) error
}

type ResourceEventPublisher

type ResourceEventPublisher interface {
	PublishBuildRunEvent(cluster *entities.BuildRun, msg PublishMsg)
	PublishBuildCacheEvent(buildcache *entities.BuildCacheKey, msg PublishMsg)
}

type UpdateAndDeleteOpts

type UpdateAndDeleteOpts struct {
	MessageTimestamp time.Time
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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