tenant

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Overview

Package tenant provides the tenant-management business logic for the REST API: provisioning (did:plc key generation + PLC publication + upload-service registration), status updates, and deletion (with cascade + DID deactivation). It returns the known errors in errors.go so handlers can map them to HTTP responses; unexpected failures are returned wrapped for the handler to log.

Index

Constants

View Source
const (
	TenantNotFoundErrorName     = "TenantNotFound"
	RegionRequiredErrorName     = "RegionRequired"
	UnknownRegionErrorName      = "UnknownRegion"
	InvalidStatusErrorName      = "InvalidStatus"
	TenantNotDisabledErrorName  = "TenantNotDisabled"
	DIDRegistrationErrorName    = "DIDRegistration"
	UploadRegistrationErrorName = "UploadRegistration"
	DIDDeactivationErrorName    = "DIDDeactivation"
)

Error names for the tenant service's known errors, exported so callers can match on the stable Name() of a serialized failure.

Variables

View Source
var (
	// ErrTenantNotFound is returned when no tenant exists for the external id.
	ErrTenantNotFound = errors.New(TenantNotFoundErrorName, "tenant not found")
	// ErrRegionRequired is returned when a provision request omits the region.
	ErrRegionRequired = errors.New(RegionRequiredErrorName, "region is required")
	// ErrUnknownRegion is returned when no provider serves the requested region.
	ErrUnknownRegion = errors.New(UnknownRegionErrorName, "unknown region")
	// ErrInvalidStatus is returned when a status update names an unknown status.
	ErrInvalidStatus = errors.New(InvalidStatusErrorName, "invalid status")
	// ErrTenantNotDisabled is returned when deleting a tenant that is not disabled.
	ErrTenantNotDisabled = errors.New(TenantNotDisabledErrorName, "tenant must be disabled before deletion")
	// ErrDIDRegistration is returned when publishing the tenant's did:plc fails.
	ErrDIDRegistration = errors.New(DIDRegistrationErrorName, "failed to register tenant DID")
	// ErrUploadRegistration is returned when registering the tenant with the
	// upload service fails.
	ErrUploadRegistration = errors.New(UploadRegistrationErrorName, "failed to register tenant with upload service")
	// ErrDIDDeactivation is returned when deactivating the tenant's did:plc fails.
	ErrDIDDeactivation = errors.New(DIDDeactivationErrorName, "failed to deactivate tenant DID")
)

Known errors returned by the tenant Service. Handlers map these to HTTP status codes with errors.Is; anything else is an unexpected (500-class) failure. The operational failures (DID/upload) carry a fixed, caller-safe message — the underlying cause is logged by the service, not surfaced.

Functions

This section is empty.

Types

type Service

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

Service implements tenant-management operations shared by the REST handlers.

func New

func New(
	logger *zap.Logger,
	tenants tenantstore.Store,
	providers provider.Store,
	buckets bucket.Store,
	accessKeys accesskey.Store,
	delegations delegation.Store,
	secrets vault.Vault,
	plcClient *plc.DirectoryClient,
	upload *client.UploadClient,
) *Service

New constructs the tenant service.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, externalID string) error

Delete permanently deletes a tenant (which must be disabled), cascading to its buckets, access keys, and delegations, and deactivating its did:plc. It is idempotent: a missing tenant is a no-op.

Out of scope: deprovisioning the tenant's spaces from the Forge upload service (Sprue), for which there is no facility per the RFC.

func (*Service) Get

func (s *Service) Get(ctx context.Context, externalID string) (tenantstore.Record, error)

Get returns the tenant for externalID.

func (*Service) Provision

func (s *Service) Provision(ctx context.Context, externalID, region string) (tenantstore.Record, bool, error)

Provision provisions (or, idempotently, returns) the tenant for externalID: it generates a rotatable did:plc key, publishes it, registers the tenant with the upload service, and records it. created is false when an existing tenant is returned (including the concurrent-create winner).

func (*Service) SetStatus

func (s *Service) SetStatus(ctx context.Context, externalID, status string) error

SetStatus updates the tenant's access mode. status must be a recognized status.

Jump to

Keyboard shortcuts

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