service

package
v0.38.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapper

type Mapper interface {
	IsMapper() bool

	Setup() error

	RefreshMetadata(ctx context.Context) ([]repository.UpdateEvent, error)
	ContainsNewInformation(ctx context.Context, event repository.UpdateEvent) bool

	GetSortedOwnerAliases(ctx context.Context) ([]string, error)
	GetOwner(ctx context.Context, ownerAlias string) (openapi.OwnerDto, error)
	WriteOwner(ctx context.Context, ownerAlias string, owner openapi.OwnerDto) (openapi.OwnerDto, error)
	DeleteOwner(ctx context.Context, ownerAlias string, jiraIssue string) (openapi.OwnerPatchDto, error)
	IsOwnerEmpty(ctx context.Context, ownerAlias string) bool

	GetSortedServiceNames(ctx context.Context) ([]string, error)
	GetService(ctx context.Context, serviceName string) (openapi.ServiceDto, error)
	WriteService(ctx context.Context, serviceName string, service openapi.ServiceDto) (openapi.ServiceDto, error)
	DeleteService(ctx context.Context, serviceName string, jiraIssue string) (openapi.ServicePatchDto, error)

	GetSortedRepositoryKeys(ctx context.Context) ([]string, error)
	GetRepository(ctx context.Context, repoKey string) (openapi.RepositoryDto, error)
	WriteRepository(ctx context.Context, repoKey string, repository openapi.RepositoryDto) (openapi.RepositoryDto, error)
	DeleteRepository(ctx context.Context, repoKey string, jiraIssue string) (openapi.RepositoryPatchDto, error)

	// WriteServiceWithChangedOwner groups the whole operation into a single commit.
	//
	// A service takes all its referenced repositories along, but unreferenced repositories will be missed and stay.
	// They can be moved as part of a repository update.
	WriteServiceWithChangedOwner(ctx context.Context, serviceName string, service openapi.ServiceDto) (openapi.ServiceDto, error)

	// WriteRepositoryWithChangedOwner groups the whole operation into a single commit.
	//
	// Note that you MUST NOT call this for a repo that is referenced by a service (needs to be verified before
	// calling this). If referenced, the repo can only change owners together with the service.
	// Use WriteServiceWithChangedOwner.
	WriteRepositoryWithChangedOwner(ctx context.Context, repoKey string, repository openapi.RepositoryDto) (openapi.RepositoryDto, error)
}

Mapper translates between the git repo representation (yaml) and the business entities.

It also performs commit workflows for the metadata repository.

It also performs the mapping between commit info and kafka messages for newly pulled commits (because this needs knowledge of the internal commit info structures).

Note that you are expected to hold the lock in Updater when you call any of this, so concurrent updates of the local git tree are avoided.

Anyway, Updater should be the only one making calls here, so this should just work.

type Owners

type Owners interface {
	IsOwners() bool

	Setup() error

	GetOwners(ctx context.Context) (openapi.OwnerListDto, error)
	GetOwner(ctx context.Context, ownerAlias string) (openapi.OwnerDto, error)

	GetAllGroupMembers(ctx context.Context, groupOwner string, groupName string) []string

	// CreateOwner returns the owner as it was created, with commit hash and timestamp filled in.
	CreateOwner(ctx context.Context, ownerAlias string, ownerDto openapi.OwnerCreateDto) (openapi.OwnerDto, error)

	// UpdateOwner returns the owner as it was committed, with commit hash and timestamp filled in.
	UpdateOwner(ctx context.Context, ownerAlias string, ownerDto openapi.OwnerDto) (openapi.OwnerDto, error)

	// PatchOwner returns the owner as it was committed, with commit hash and timestamp filled in.
	PatchOwner(ctx context.Context, ownerAlias string, ownerPatchDto openapi.OwnerPatchDto) (openapi.OwnerDto, error)

	DeleteOwner(ctx context.Context, ownerAlias string, deletionInfo openapi.DeletionDto) error
}

Owners provides the business logic for owner metadata.

type PRValidator added in v0.38.0

type PRValidator interface {
	IsPRValidator() bool

	// ValidatePullRequest validates the pull request, commenting on it and setting a build result.
	//
	// Failures to validate a pull request are not considered errors. Errors are only returned if
	// the process of validation could not be completed (failure to respond by git server,
	// could not obtain file list, etc.)
	ValidatePullRequest(ctx context.Context, id uint64, toRef string, fromRef string) error
}

PRValidator validates pull requests in the underlying repository to prevent bringing invalid content to the mainline.

type Repositories

type Repositories interface {
	IsRepositories() bool
	Setup() error

	// ValidRepositoryKey checks validity of a repository key and returns an error describing the problem if invalid
	ValidRepositoryKey(ctx context.Context, repoKey string) apierrors.AnnotatedError

	GetRepositories(ctx context.Context,
		ownerAliasFilter string, serviceNameFilter string,
		nameFilter string, typeFilter string) (openapi.RepositoryListDto, error)
	GetRepository(ctx context.Context, repoKey string) (openapi.RepositoryDto, error)

	// CreateRepository returns the repository as it was created, with commit hash and timestamp filled in.
	CreateRepository(ctx context.Context, key string, repositoryDto openapi.RepositoryCreateDto) (openapi.RepositoryDto, error)

	// UpdateRepository returns the repository as it was committed, with commit hash and timestamp filled in.
	//
	// Changing the owner of a repository is supported, unless it's still referenced by its service. In that case,
	// move the whole service (including its repositories).
	UpdateRepository(ctx context.Context, key string, repositoryDto openapi.RepositoryDto) (openapi.RepositoryDto, error)

	// PatchRepository returns the repository as it was committed, with commit hash and timestamp filled in.
	//
	// Changing the owner of a repository is supported, unless it's still referenced by its service. In that case,
	// move the whole service (including its repositories).
	PatchRepository(ctx context.Context, key string, repositoryPatchDto openapi.RepositoryPatchDto) (openapi.RepositoryDto, error)

	// DeleteRepository will fail if the repo is still referenced by its service. Delete that one first.
	DeleteRepository(ctx context.Context, key string, deletionInfo openapi.DeletionDto) error
}

Repositories provides the business logic for repository metadata.

type Services

type Services interface {
	IsServices() bool

	Setup() error

	GetServices(ctx context.Context, ownerAliasFilter string) (openapi.ServiceListDto, error)
	GetService(ctx context.Context, serviceName string) (openapi.ServiceDto, error)

	// CreateService returns the service as it was created, with commit hash and timestamp filled in.
	CreateService(ctx context.Context, serviceName string, serviceDto openapi.ServiceCreateDto) (openapi.ServiceDto, error)

	// UpdateService returns the service as it was committed, with commit hash and timestamp filled in.
	//
	// Changing the owner of a service is supported, and will also move any referenced repositories to the new owner.
	UpdateService(ctx context.Context, serviceName string, serviceDto openapi.ServiceDto) (openapi.ServiceDto, error)

	// PatchService returns the service as it was committed, with commit hash and timestamp filled in.
	//
	// Changing the owner of a service is supported, and will also move any referenced repositories to the new owner.
	PatchService(ctx context.Context, serviceName string, servicePatchDto openapi.ServicePatchDto) (openapi.ServiceDto, error)

	// DeleteService deletes a service, but leaves its repositories behind
	//
	// Reason: they still need to be configured by bit-brother.
	DeleteService(ctx context.Context, serviceName string, deletionInfo openapi.DeletionDto) error
}

Services provides the business logic for service metadata.

type Trigger

type Trigger interface {
	IsTrigger() bool
	Setup() error
	Teardown()
}

Trigger triggers update runs in Updater.

Trigger events occur on initial app startup (before it becomes healthy), and periodically

type Updater

type Updater interface {
	IsUpdater() bool

	Setup() error

	// StartReceivingEvents starts receiving events. Called by Trigger after it has initially populated the cache.
	StartReceivingEvents(ctx context.Context) error

	// WithMetadataLock is a convenience function that will obtain the lock on the metadata repo, call
	// the closure, and then free the lock.
	//
	// Note that a child context (!) is passed through to your function, so other methods of Updater can know
	// that you are holding the lock at the moment.
	//
	// Any error closure returns is passed through, and the lock is finally released.
	WithMetadataLock(ctx context.Context, closure func(context.Context) error) error

	// PerformFullUpdate is called by Trigger both for initial cache population and periodic updates.
	//
	// It does not send any kafka events - one situation where it might be called is when an event
	// has been received.
	//
	// Both the git tree and all caches are updated.
	PerformFullUpdate(ctx context.Context) error

	// PerformFullUpdateWithNotifications is called when the webhook is triggered.
	//
	// Unlike PerformFullUpdate this version sends out kafka events for any new commits.
	//
	// Both the git tree and all caches are updated.
	PerformFullUpdateWithNotifications(ctx context.Context) error

	// WriteOwner returns the owner as written, with commit hash and timestamp filled in.
	//
	// Sends a kafka event and updates the cache.
	WriteOwner(ctx context.Context, ownerAlias string, validOwnerDto openapi.OwnerDto) (openapi.OwnerDto, error)

	// DeleteOwner deletes an owner.
	//
	// Sends a kafka event and updates the cache.
	DeleteOwner(ctx context.Context, ownerAlias string, deletionInfo openapi.DeletionDto) error

	CanDeleteOwner(ctx context.Context, ownerAlias string) bool

	// WriteService returns the service as written, with commit hash and timestamp filled in.
	//
	// This supports changing the owner.
	//
	// Assumes up-to-date cache.
	//
	// Sends a kafka event and updates the cache.
	WriteService(ctx context.Context, serviceName string, validServiceDto openapi.ServiceDto) (openapi.ServiceDto, error)

	// DeleteService deletes a service.
	//
	// Sends a kafka event and updates the cache.
	DeleteService(ctx context.Context, serviceName string, deletionInfo openapi.DeletionDto) error

	// WriteRepository returns the repository as written, with commit hash and timestamp filled in.
	//
	// This supports changing the owner, unless the repository is referenced by a service, then you should not call this.
	//
	// Assumes up-to-date cache.
	//
	// Sends a kafka event and updates the cache.
	WriteRepository(ctx context.Context, key string, repository openapi.RepositoryDto) (openapi.RepositoryDto, error)

	// DeleteRepository deletes a repository.
	//
	// Sends a kafka event and updates the cache.
	DeleteRepository(ctx context.Context, key string, deletionInfo openapi.DeletionDto) error

	// CanMoveOrDeleteRepository checks that no service still references the repository key.
	//
	// Expects a current cache and you must be holding the lock.
	CanMoveOrDeleteRepository(ctx context.Context, key string) (bool, error)
}

Updater is the central orchestrator component that manages information flow.

Jump to

Keyboard shortcuts

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