service

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SelectTenantErrMsg      = "could not select tenant"
	UpdateTenantErrMsg      = "could not update tenant"
	DeleteTenantErrMsg      = "could not delete tenant"
	TenantNotFoundMsg       = "tenant not found"
	TenantUnavailableErrMsg = "tenant is unavailable"
)
View Source
const (
	SelectSystemErrMsg                  = "could not select system"
	UpdateSystemErrMsg                  = "could not update system"
	DeleteSystemErrMsg                  = "could not delete system"
	SystemNotFoundMsg                   = "system not found"
	SystemUnavailableErrMsg             = "system is unavailable"
	TenantStatusTransitionNotAllowedMsg = "tenant status transition not allowed"
	InvalidTenantStatusMsg              = "invalid tenant status"
)
View Source
const (
	SelectAuthErrMsg     = "could not select auth"
	UpdateAuthErrMsg     = "could not update auth"
	AuthNotFoundErrMsg   = "auth not found"
	AuthAlreadyExistsMsg = "auth with the given external ID already exists"
	AuthInvalidStatusMsg = "invalid auth status"
)
View Source
const (
	MissingLabelKeysMsg = "missing label keys"
	MissingLabelsMsg    = "missing labels"
	EmptyLabelKeysMsg   = "label keys cannot be empty"
	UserGroupsNilMsg    = "user groups cannot be nil"
)
View Source
const (
	AttrRegion       = "region"
	AttrTenantLinked = "tenant_linked"
	AttrStatus       = "status"
	ErrDomainMetrics = "metrics"
)

Variables

View Source
var (
	ErrTenantSelect                     = status.Error(codes.Internal, SelectTenantErrMsg)
	ErrTenantUpdate                     = status.Error(codes.Internal, UpdateTenantErrMsg)
	ErrTenantDelete                     = status.Error(codes.Internal, DeleteTenantErrMsg)
	ErrTenantIDFormat                   = status.Error(codes.InvalidArgument, "tenant ID is not valid")
	ErrTenantNotFound                   = status.Error(codes.NotFound, TenantNotFoundMsg)
	ErrTenantUnavailable                = status.Error(codes.FailedPrecondition, TenantUnavailableErrMsg)
	ErrTenantEncoding                   = status.Error(codes.Internal, "failed to encode tenant data")
	ErrTenantStatusTransitionNotAllowed = errors.New(TenantStatusTransitionNotAllowedMsg)
	ErrInvalidTenantStatus              = errors.New(InvalidTenantStatusMsg)
	ErrTenantUserGroups                 = status.Error(codes.InvalidArgument, UserGroupsNilMsg)
)
View Source
var (
	ErrSystemSelect                         = status.Error(codes.Internal, SelectSystemErrMsg)
	ErrSystemUpdate                         = status.Error(codes.Internal, UpdateSystemErrMsg)
	ErrSystemDelete                         = status.Error(codes.Internal, DeleteSystemErrMsg)
	ErrExternalIDIsEmpty                    = status.Error(codes.InvalidArgument, "external ID cannot be empty")
	ErrRegionIsEmpty                        = status.Error(codes.InvalidArgument, "region cannot be empty")
	ErrSystemNotFound                       = status.Error(codes.NotFound, SystemNotFoundMsg)
	ErrSystemIsLinkedToTenant               = status.Error(codes.FailedPrecondition, "system is linked to the tenant")
	ErrSystemIsNotLinkedToTenant            = status.Error(codes.FailedPrecondition, "system is not linked to the tenant")
	ErrSystemLinkedToDifferentTenant        = status.Error(codes.FailedPrecondition, "system is linked to a different tenant")
	ErrSystemHasL1KeyClaim                  = status.Error(codes.FailedPrecondition, "system has active l1 key claim")
	ErrSystemUnavailable                    = status.Error(codes.FailedPrecondition, SystemUnavailableErrMsg)
	ErrNoTenantID                           = status.Error(codes.InvalidArgument, "no tenantID provided")
	ErrSystemListNotAllowed                 = status.Error(codes.InvalidArgument, "need either externalID and region or tenantID to list systems")
	ErrRegisterSystemNotAllowedWithTenantID = status.Error(codes.InvalidArgument, "system cannot be registered because other system(s) with same external ID and type are already linked to a different tenant")
	ErrSystemProtoConversion                = status.Error(codes.Internal, "failed to convert system to proto message struct")
	ErrTooManyTypes                         = status.Error(codes.FailedPrecondition, "cannot determine type")
)
View Source
var (
	ErrTranCtxTimeout          = status.Error(codes.Aborted, "transaction was aborted due to timeout, please try again")
	ErrPanic                   = status.Error(codes.Internal, "an unexpected error occurred on the server, please try again")
	ErrKeyClaimAlreadyActive   = status.Error(codes.FailedPrecondition, "key claim is already active")
	ErrKeyClaimAlreadyInactive = status.Error(codes.FailedPrecondition, "key claim is already inactive")
	ErrMissingLabelKeys        = status.Error(codes.InvalidArgument, MissingLabelKeysMsg)
	ErrMissingLabels           = status.Error(codes.InvalidArgument, MissingLabelsMsg)
	ErrEmptyLabelKeys          = status.Error(codes.InvalidArgument, EmptyLabelKeysMsg)
	ErrValidationConversion    = status.Error(codes.Internal, "validation conversion error")
	ErrValidationFailed        = status.Error(codes.InvalidArgument, "validation failed")
)
View Source
var (
	ErrWrongConnectionType = errors.New("wrong initiator type")
	ErrUnexpectedJobType   = errors.New("unexpected job type")
)
View Source
var AuthNonUpdatableState = map[string]struct{}{
	authgrpc.AuthStatus_AUTH_STATUS_REMOVED.String():        {},
	authgrpc.AuthStatus_AUTH_STATUS_APPLYING_ERROR.String(): {},
}

Functions

func ErrorWithParams

func ErrorWithParams(err error, params ...any) error

ErrorWithParams will return an error with new message, where params get appended at end of the error message. If the input is normal error then error is wrapped. If the input is a GRPC error it will create a new GRPC error. Note GRPC error returned cannot be used to check `errors.Is`.

Types

type Auth added in v1.2.0

type Auth struct {
	authgrpc.UnimplementedServiceServer
	// contains filtered or unexported fields
}

Auth implements the procedure calls defined as protobufs. See https://github.com/openkcm/api-sdk/blob/main/proto/kms/api/cmk/registry/auth/v1/auth.proto.

func NewAuth added in v1.2.0

func NewAuth(repo repository.Repository, orbital *Orbital, validation *validation.Validation) *Auth

NewAuth creates and return a new instance of Auth. It also registers the job handlers to the Orbital instance.

func (*Auth) ApplyAuth added in v1.2.0

ApplyAuth creates a new auth and starts a job to apply it to the linked tenant. If an auth with the same external ID already exists, it returns success to make the action idempotent.

func (*Auth) ConfirmJob added in v1.2.0

func (a *Auth) ConfirmJob(ctx context.Context, job orbital.Job) (orbital.JobConfirmResult, error)

ConfirmJob confirms that the auth associated with the job exists.

func (*Auth) GetAuth added in v1.2.0

GetAuth retrieves an auth by its external ID.

func (*Auth) HandleJobCanceled added in v1.2.0

func (a *Auth) HandleJobCanceled(ctx context.Context, job orbital.Job) error

HandleJobCanceled updates auth when the job is canceled.

func (*Auth) HandleJobDone added in v1.2.0

func (a *Auth) HandleJobDone(ctx context.Context, job orbital.Job) error

HandleJobDone updates auth when the job is done.

func (*Auth) HandleJobFailed added in v1.2.0

func (a *Auth) HandleJobFailed(ctx context.Context, job orbital.Job) error

HandleJobFailed updates auth when the job is failed.

func (*Auth) ListAuths added in v1.6.0

func (*Auth) RemoveAuth added in v1.2.0

RemoveAuth marks an auth for removal by its external ID and starts a job to remove it from the linked tenant. If the auth does not exist or is not in APPLIED status, it returns an error. If the linked tenant does not exist or is not active, it returns an error.

func (*Auth) ResolveTasks added in v1.2.0

func (a *Auth) ResolveTasks(ctx context.Context, job orbital.Job, targetsByRegion map[string]orbital.ManagerTarget) (orbital.TaskResolverResult, error)

ResolveTasks determines the tasks to be executed for a given job.

type JobHandler added in v1.1.0

type JobHandler interface {
	ConfirmJob(ctx context.Context, job orbital.Job) (orbital.JobConfirmResult, error)
	ResolveTasks(ctx context.Context, job orbital.Job, targets map[string]orbital.ManagerTarget) (orbital.TaskResolverResult, error)
	HandleJobDone(ctx context.Context, job orbital.Job) error
	HandleJobCanceled(ctx context.Context, job orbital.Job) error
	HandleJobFailed(ctx context.Context, job orbital.Job) error
}

JobHandler defines the lifecycle callbacks for job processing.

type Mapping added in v1.7.0

type Mapping struct {
	mappinggrpc.UnimplementedServiceServer
	// contains filtered or unexported fields
}

Mapping implements the procedure calls defined as protobufs. See https://github.com/openkcm/api-sdk/blob/main/proto/kms/api/cmk/registry/mapping/v1/mapping.proto.

func NewMapping added in v1.7.0

func NewMapping(repo repository.Repository, meters *Meters, validation *validation.Validation) *Mapping

NewMapping creates and returns a new instance of Mapping.

func (*Mapping) Get added in v1.7.0

Get gets the mapped tenant from the system.

func (*Mapping) MapSystemToTenant added in v1.7.0

MapSystemToTenant links Systems to the Tenant.

func (*Mapping) UnmapSystemFromTenant added in v1.7.0

UnmapSystemFromTenant unlinks Systems from the Tenant.

type Meters

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

func InitMeters

func InitMeters(ctx context.Context, cfgApp *commoncfg.Application, db *gorm.DB) (*Meters, error)

type Orbital

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

Orbital manages jobs and their execution targets.

func NewOrbital

func NewOrbital(ctx context.Context, db *gorm.DB, cfg config.Orbital) (*Orbital, error)

NewOrbital initializes the Orbital manager with the provided database and target configurations. It sets up the AMQP clients for each target and starts the manager.

func (*Orbital) PrepareJob

func (o *Orbital) PrepareJob(ctx context.Context, data []byte, externalID, jobType string) error

PrepareJob creates a new job with the given data, external ID, and job type.

func (*Orbital) RegisterJobHandler added in v1.1.0

func (o *Orbital) RegisterJobHandler(jobType string, handler JobHandler)

RegisterJobHandler registers a JobHandler for a specific job type.

type System

type System struct {
	systemgrpc.UnimplementedServiceServer
	// contains filtered or unexported fields
}

System implements the procedure calls defined as protobufs. See https://github.com/openkcm/api-sdk/blob/main/proto/kms/api/cmk/registry/system/v1/system.proto.

func NewSystem

func NewSystem(repo repository.Repository, meters *Meters, validation *validation.Validation) *System

NewSystem creates and return a new instance of System.

func (*System) DeleteSystem

DeleteSystem handles the deletion of a new System. The response contains deletion status and error if failed.

func (*System) ListSystems

ListSystems retrieves a list of Systems based on optional query parameters such as tenant_id. region and external_id To retrieve sSystems one of tenant_id or a combination of region and external_id must be provided.

func (*System) RegisterSystem

RegisterSystem handles the creation of a new System. The response contains the created System's ID.

func (*System) RemoveSystemLabels

RemoveSystemLabels removes the specified labels from the System identified by its external ID and region. If one or more label keys are not found, they will be ignored. If the update is successful, a success message will be returned, otherwise an error will be returned.

func (*System) SetSystemLabels

SetSystemLabels sets the labels for the System identified by its external ID and region. Existing labels with the same keys will be overwritten. If the update is successful, a success message will be returned, otherwise an error will be returned.

func (*System) UpdateSystemL1KeyClaim

UpdateSystemL1KeyClaim updates the l1_key_claim parameter of the System identified by its system_id.

func (*System) UpdateSystemStatus

UpdateSystemStatus updates the status of the System identified by its ID. The status can be one of a predefined set of values. If the update is successful, a success message will be returned, otherwise an error will be returned.

type Tenant

type Tenant struct {
	tenantgrpc.UnimplementedServiceServer
	// contains filtered or unexported fields
}

Tenant implements the procedure calls defined as protobufs. See https://github.com/openkcm/api-sdk/blob/main/proto/kms/api/cmk/registry/tenant/v1/tenant.proto.

func NewTenant

func NewTenant(repo repository.Repository, orbital *Orbital, meters *Meters, validation *validation.Validation) *Tenant

NewTenant creates and returns a new instance of Tenant.

func (*Tenant) BlockTenant

BlockTenant updates the status of a Tenant to BLOCKED. If the update is successful, a success message will be returned, otherwise an error will be returned.

func (*Tenant) ConfirmJob added in v1.1.0

func (t *Tenant) ConfirmJob(ctx context.Context, job orbital.Job) (orbital.JobConfirmResult, error)

ConfirmJob checks if a job can be confirmed based on tenant existence and tenant status.

func (*Tenant) GetTenant added in v1.1.0

GetTenant retrieves the details of a Tenant by its ID. If the Tenant is found, its details will be returned, otherwise an error will be returned.

func (*Tenant) HandleJobCanceled added in v1.1.0

func (t *Tenant) HandleJobCanceled(ctx context.Context, job orbital.Job) error

HandleJobCanceled applies the changes to the tenant based on the job type when the job is canceled.

func (*Tenant) HandleJobDone added in v1.1.0

func (t *Tenant) HandleJobDone(ctx context.Context, job orbital.Job) error

HandleJobDone applies the changes to the tenant based on the job type when the job is done.

func (*Tenant) HandleJobFailed added in v1.1.0

func (t *Tenant) HandleJobFailed(ctx context.Context, job orbital.Job) error

HandleJobFailed applies the changes to the tenant based on the job type when the job is failed.

func (*Tenant) ListTenants

ListTenants retrieves a list of Tenants based on optional query parameters such as id, name, region, owner_id, and owner_type. Retrieves all Tenants if all query parameters are empty.

func (*Tenant) RegisterTenant

RegisterTenant handles the creation of a new Tenant. The response contains the created Tenant's ID.

func (*Tenant) RemoveTenantLabels

RemoveTenantLabels removes the specified labels from the Tenant identified by its external ID and region. If one or more label keys are not found, they will be ignored. If the update is successful, a success message will be returned, otherwise an error will be returned.

func (*Tenant) ResolveTasks added in v1.1.0

func (t *Tenant) ResolveTasks(_ context.Context, job orbital.Job, targetsByRegion map[string]orbital.ManagerTarget) (orbital.TaskResolverResult, error)

ResolveTasks creates a task for the job based on the tenant's region.

func (*Tenant) SetTenantLabels

SetTenantLabels sets the labels for the Tenant identified by its ID. Existing labels with the same keys will be overwritten. If the update is successful, a success message will be returned, otherwise an error will be returned.

func (*Tenant) SetTenantUserGroups added in v1.1.0

func (*Tenant) TerminateTenant

TerminateTenant updates the status of a Tenant to TERMINATED. If the update is successful, a success message will be returned, otherwise an error will be returned.

func (*Tenant) UnblockTenant

UnblockTenant updates the status of a Tenant to ACTIVE. If the update is successful, a success message will be returned, otherwise an error will be returned.

Jump to

Keyboard shortcuts

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