tenant

package
v0.0.0-...-a423d60 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TableName specifies the name of the business tenant mappings table
	TableName string = `public.business_tenant_mappings`
	// IDColumn specifies the name of the id column in business tenant mappings table
	IDColumn string = "id"
	// ExternalNameColumn specifies the name of the external name column in business tenant mappings table
	ExternalNameColumn string = "external_name"
	// ExternalTenantColumn specifies the name of the external tenant column in business tenant mappings table
	ExternalTenantColumn string = "external_tenant"
	// TypeColumn specifies the name of the type column in business tenant mappings table
	TypeColumn string = "type"
	// ProviderNameColumn specifies the name of the provider column in business tenant mappings table
	ProviderNameColumn string = "provider_name"
	// StatusColumn specifies the name of the status column in business tenant mappings table
	StatusColumn string = "status"
)
View Source
const (
	// SubdomainLabelKey is the key of the tenant label for subdomain.
	SubdomainLabelKey = "subdomain"
	// RegionLabelKey is the key of the tenant label for region.
	RegionLabelKey = "region"
	// LicenseTypeLabelKey is the key of the tenant label for licensetype.
	LicenseTypeLabelKey = "licensetype"
	// CustomerIDLabelKey is the key of the SAP-managed customer subaccounts
	CustomerIDLabelKey = "customerId"
	// CostObjectIDLabelKey is the key for cost object tenant ID
	CostObjectIDLabelKey = "costObjectId"
	// CostObjectTypeLabelKey is the key for cost object tenant type
	CostObjectTypeLabelKey = "costObjectType"
)
View Source
const LocalTenantIDContextKey localTntIDCtxKey = iota

LocalTenantIDContextKey is the key under which the local tenant id is saved in a given context.Context.

View Source
const TenantContextKey tntCtxKey = iota

TenantContextKey is the key under which the TenantCtx is saved in a given context.Context.

Variables

This section is empty.

Functions

func IsAtomTenant

func IsAtomTenant(tenantType tenantpkg.Type) bool

IsAtomTenant checks whether the tenant comes from atom

func LoadFromContext

func LoadFromContext(ctx context.Context) (string, error)

LoadFromContext retrieves the internal tenant ID from the provided context. It returns error if such ID cannot be found.

func LoadLocalTenantIDFromContext

func LoadLocalTenantIDFromContext(ctx context.Context) (string, error)

LoadLocalTenantIDFromContext retrieves the local tenant ID from the provided context. It returns error if such ID cannot be found.

func MoveBeforeIfShould

func MoveBeforeIfShould(tenants []model.BusinessTenantMapping, parentTenantID, childTenantID string) ([]model.BusinessTenantMapping, bool)

MoveBeforeIfShould moves the tenant with id right before index only if it is not already before it

func NewConverter

func NewConverter() *converter

NewConverter returns a new Converter that can later be used to make the conversions between the GraphQL, service, and repository layer representations of a Compass tenant.

func NewRepository

func NewRepository(conv Converter) *pgRepository

NewRepository returns a new entity responsible for repo-layer tenant operations. All of its methods require persistence.PersistenceOp it the provided context.

func NewService

func NewService(tenantMapping TenantMappingRepository, uidService UIDService, converter BusinessTenantMappingConverter) *service

NewService returns a new object responsible for service-layer tenant operations.

func NewServiceWithLabels

func NewServiceWithLabels(tenantMapping TenantMappingRepository, uidService UIDService, labelRepo LabelRepository, labelUpsertSvc LabelUpsertService, converter BusinessTenantMappingConverter) *labeledService

NewServiceWithLabels returns a new entity responsible for service-layer tenant operations, including operations with labels like listing all labels related to the given tenant.

func SaveLocalTenantIDToContext

func SaveLocalTenantIDToContext(ctx context.Context, localTenantID string) context.Context

SaveLocalTenantIDToContext returns a child context of the provided context, including the provided local tenant id.

func SaveToContext

func SaveToContext(ctx context.Context, internalID, externalID string) context.Context

SaveToContext returns a child context of the provided context, including the provided tenant information. The internal tenant ID can be later retrieved from the context by calling LoadFromContext.

Types

type BusinessTenantMappingConverter

type BusinessTenantMappingConverter interface {
	MultipleToGraphQL(in []*model.BusinessTenantMapping) []*graphql.Tenant
	MultipleInputFromGraphQL(ctx context.Context, in []*graphql.BusinessTenantMappingInput, retrieveTenantTypeFn func(ctx context.Context, t string) (string, error)) ([]model.BusinessTenantMappingInput, error)
	InputFromGraphQL(ctx context.Context, tnt graphql.BusinessTenantMappingInput, externalTenantToType map[string]string, retrieveTenantTypeFn func(ctx context.Context, t string) (string, error)) (model.BusinessTenantMappingInput, error)
	ToGraphQL(in *model.BusinessTenantMapping) *graphql.Tenant
	TenantAccessInputFromGraphQL(in graphql.TenantAccessInput) (*model.TenantAccess, error)
	TenantAccessToGraphQL(in *model.TenantAccess) (*graphql.TenantAccess, error)
	TenantAccessToEntity(in *model.TenantAccess) *repo.TenantAccess
	TenantAccessFromEntity(in *repo.TenantAccess) *model.TenantAccess
}

BusinessTenantMappingConverter is used to convert the internally used tenant representation model.BusinessTenantMapping into the external GraphQL representation graphql.Tenant.

type BusinessTenantMappingService

type BusinessTenantMappingService interface {
	List(ctx context.Context) ([]*model.BusinessTenantMapping, error)
	ListPageBySearchTerm(ctx context.Context, searchTerm string, pageSize int, cursor string) (*model.BusinessTenantMappingPage, error)
	ListLabels(ctx context.Context, tenantID string) (map[string]*model.Label, error)
	GetTenantByExternalID(ctx context.Context, externalID string) (*model.BusinessTenantMapping, error)
	GetTenantByID(ctx context.Context, id string) (*model.BusinessTenantMapping, error)
	UpsertMany(ctx context.Context, tenantInputs ...model.BusinessTenantMappingInput) (map[string]tenantpkg.Type, error)
	UpsertSingle(ctx context.Context, tenantInput model.BusinessTenantMappingInput) (string, error)
	Update(ctx context.Context, id string, tenantInput model.BusinessTenantMappingInput) error
	DeleteMany(ctx context.Context, externalTenantIDs []string) error
	GetLowestOwnerForResource(ctx context.Context, resourceType resource.Type, objectID string) (string, error)
	GetInternalTenant(ctx context.Context, externalTenant string) (string, error)
	CreateTenantAccessForResourceRecursively(ctx context.Context, tenantAccess *model.TenantAccess) error
	DeleteTenantAccessForResourceRecursively(ctx context.Context, tenantAccess *model.TenantAccess) error
	GetTenantAccessForResource(ctx context.Context, tenantID, resourceID string, resourceType resource.Type) (*model.TenantAccess, error)
	GetParentsRecursivelyByExternalTenant(ctx context.Context, externalTenant string) ([]*model.BusinessTenantMapping, error)
	UpsertLabel(ctx context.Context, tenantID, key string, value interface{}) error
}

BusinessTenantMappingService is responsible for the service-layer tenant operations.

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
}

Client is responsible for making HTTP requests.

type Converter

type Converter interface {
	ToEntity(in *model.BusinessTenantMapping) *tenant.Entity
	FromEntity(in *tenant.Entity) *model.BusinessTenantMapping
}

Converter converts tenants between the model.BusinessTenantMapping service-layer representation of a tenant and the repo-layer representation tenant.Entity.

type FetchOnDemandAPIConfig

type FetchOnDemandAPIConfig struct {
	TenantOnDemandURL string `envconfig:"optional,APP_FETCH_TENANT_URL"`
	IsDisabled        bool   `envconfig:"default=false,APP_DISABLE_TENANT_ON_DEMAND_MODE"`
}

FetchOnDemandAPIConfig is the configuration needed for tenant on demand fetch API

type Fetcher

type Fetcher interface {
	FetchOnDemand(ctx context.Context, tenant, parentTenant string) error
}

Fetcher calls an API which fetches details for the given tenant from an external tenancy service, stores the tenant in the Compass DB and returns 200 OK if the tenant was successfully created.

func NewFetchOnDemandService

func NewFetchOnDemandService(client Client, config FetchOnDemandAPIConfig) Fetcher

NewFetchOnDemandService returns object responsible for fetching tenants

type LabelRepository

type LabelRepository interface {
	ListForObject(ctx context.Context, tenant string, objectType model.LabelableObject, objectID string) (map[string]*model.Label, error)
}

LabelRepository is responsible for the repo-layer label operations.

type LabelUpsertService

type LabelUpsertService interface {
	UpsertLabel(ctx context.Context, tenant string, labelInput *model.LabelInput) error
}

LabelUpsertService is responsible for creating, or updating already existing labels, and their label definitions.

type Resolver

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

Resolver is the resolver responsible for tenant-related GraphQL requests.

func NewResolver

NewResolver returns the GraphQL resolver for tenants.

func (*Resolver) AddTenantAccess

func (r *Resolver) AddTenantAccess(ctx context.Context, in graphql.TenantAccessInput) (*graphql.TenantAccess, error)

AddTenantAccess adds a tenant access record for tenantID about resourceID

func (*Resolver) Delete

func (r *Resolver) Delete(ctx context.Context, externalTenantIDs []string) (int, error)

Delete deletes tenants

func (*Resolver) Labels

func (r *Resolver) Labels(ctx context.Context, obj *graphql.Tenant, key *string) (graphql.Labels, error)

Labels transactionally retrieves all existing labels of the given tenant if it exists.

func (*Resolver) RemoveTenantAccess

func (r *Resolver) RemoveTenantAccess(ctx context.Context, tenantID, resourceID string, resourceType graphql.TenantAccessObjectType) (*graphql.TenantAccess, error)

RemoveTenantAccess removes the tenant access record for tenantID about resourceID

func (*Resolver) RootTenants

func (r *Resolver) RootTenants(ctx context.Context, externalTenant string) ([]*graphql.Tenant, error)

RootTenants fetches the top parents external IDs for a given externalTenant

func (*Resolver) SetTenantLabel

func (r *Resolver) SetTenantLabel(ctx context.Context, tenantID, key string, value interface{}) (*graphql.Label, error)

SetTenantLabel sets a label to tenant

func (*Resolver) Tenant

func (r *Resolver) Tenant(ctx context.Context, externalID string) (*graphql.Tenant, error)

Tenant first checks whether a tenant with the provided external ID exists in the Compass DB. If it doesn't, it calls an API which fetches details for the given tenant from an external tenancy service, stores the tenant in the Compass DB and returns 200 OK if the tenant was successfully created. Finally, it retrieves a tenant with the provided external ID from the Compass storage.

func (*Resolver) TenantByID

func (r *Resolver) TenantByID(ctx context.Context, internalID string) (*graphql.Tenant, error)

TenantByID retrieves a tenant with the provided internal ID from the Compass storage.

func (*Resolver) TenantByLowestOwnerForResource

func (r *Resolver) TenantByLowestOwnerForResource(ctx context.Context, resourceStr, objectID string) (string, error)

TenantByLowestOwnerForResource retrieves a tenant with the provided internal ID from the Compass storage.

func (*Resolver) Tenants

func (r *Resolver) Tenants(ctx context.Context, first *int, after *graphql.PageCursor, searchTerm *string) (*graphql.TenantPage, error)

Tenants transactionally retrieves a page of tenants present in the Compass storage by a search term. If the search term is missing it will be ignored in the resulting tenant subset.

func (*Resolver) Update

Update update single tenant. The parent IDs from the input are INTERNAL IDs

func (*Resolver) Write

func (r *Resolver) Write(ctx context.Context, inputTenants []*graphql.BusinessTenantMappingInput) ([]string, error)

Write creates new global and subaccounts

func (*Resolver) WriteSingle

func (r *Resolver) WriteSingle(ctx context.Context, inputTenant graphql.BusinessTenantMappingInput) (string, error)

WriteSingle creates a single tenant

type TenantCtx

type TenantCtx struct {
	InternalID string
	ExternalID string
}

TenantCtx is the structure can be saved in a request context. It is used to determine the tenant context in which the request is being executed.

func LoadTenantPairFromContext

func LoadTenantPairFromContext(ctx context.Context) (TenantCtx, error)

LoadTenantPairFromContext retrieves the whole tenant context from the provided request context. It returns error if such ID cannot be found.

func LoadTenantPairFromContextNoChecks

func LoadTenantPairFromContextNoChecks(ctx context.Context) (TenantCtx, error)

LoadTenantPairFromContextNoChecks retrieves the whole tenant context from the provided request context. Checks for the values of the InternalID/ExternalID are not included and should be done outside the func case by case.

type TenantMappingRepository

type TenantMappingRepository interface {
	UnsafeCreate(ctx context.Context, item model.BusinessTenantMapping) (string, error)
	Upsert(ctx context.Context, item model.BusinessTenantMapping) (string, error)
	Update(ctx context.Context, model *model.BusinessTenantMapping) error
	Get(ctx context.Context, id string) (*model.BusinessTenantMapping, error)
	GetByExternalTenant(ctx context.Context, externalTenant string) (*model.BusinessTenantMapping, error)
	Exists(ctx context.Context, id string) (bool, error)
	List(ctx context.Context) ([]*model.BusinessTenantMapping, error)
	ListPageBySearchTerm(ctx context.Context, searchTerm string, pageSize int, cursor string) (*model.BusinessTenantMappingPage, error)
	ExistsByExternalTenant(ctx context.Context, externalTenant string) (bool, error)
	DeleteByExternalTenant(ctx context.Context, externalTenant string) error
	GetLowestOwnerForResource(ctx context.Context, resourceType resource.Type, objectID string) (string, error)
	ListByExternalTenants(ctx context.Context, externalTenant []string) ([]*model.BusinessTenantMapping, error)
	ListByParentAndType(ctx context.Context, parentID string, tenantType tenantpkg.Type) ([]*model.BusinessTenantMapping, error)
	ListByType(ctx context.Context, tenantType tenantpkg.Type) ([]*model.BusinessTenantMapping, error)
	ListByIds(ctx context.Context, ids []string) ([]*model.BusinessTenantMapping, error)
	ListByIdsAndType(ctx context.Context, ids []string, tenantType tenantpkg.Type) ([]*model.BusinessTenantMapping, error)
	GetParentsRecursivelyByExternalTenant(ctx context.Context, externalTenant string) ([]*model.BusinessTenantMapping, error)
}

TenantMappingRepository is responsible for the repo-layer tenant operations.

type UIDService

type UIDService interface {
	Generate() string
}

UIDService is responsible for generating GUIDs, which will be used as internal tenant IDs when tenants are created.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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