entitlement

package
v1.0.0-beta.95 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlreadyExistsError

type AlreadyExistsError struct {
	EntitlementID string
	FeatureID     string
	SubjectKey    string
}

func (*AlreadyExistsError) Error

func (e *AlreadyExistsError) Error() string

type Connector

type Connector interface {
	// Entitlement Management
	CreateEntitlement(ctx context.Context, input CreateEntitlementInputs) (*Entitlement, error)
	GetEntitlementsOfSubject(ctx context.Context, namespace string, subjectKey models.SubjectKey) ([]Entitlement, error)
	GetEntitlementValue(ctx context.Context, namespace string, subjectKey string, id string, at time.Time) (EntitlementValue, error)

	ListEntitlements(ctx context.Context, params ListEntitlementsParams) ([]Entitlement, error)
}

func NewEntitlementConnector

func NewEntitlementConnector(
	entitlementRepo EntitlementRepo,
	featureConnector productcatalog.FeatureConnector,
	meteredEntitlementConnector SubTypeConnector,
	staticEntitlementConnector SubTypeConnector,
	booleanEntitlementConnector SubTypeConnector,
) Connector

type CreateEntitlementInputs

type CreateEntitlementInputs struct {
	Namespace       string            `json:"namespace"`
	FeatureID       string            `json:"featureId"`
	SubjectKey      string            `json:"subjectKey"`
	EntitlementType EntitlementType   `json:"type"`
	Metadata        map[string]string `json:"metadata,omitempty"`

	MeasureUsageFrom *time.Time   `json:"measureUsageFrom,omitempty"`
	IssueAfterReset  *float64     `json:"issueAfterReset,omitempty"`
	IsSoftLimit      *bool        `json:"isSoftLimit,omitempty"`
	Config           *string      `json:"config,omitempty"`
	UsagePeriod      *UsagePeriod `json:"usagePeriod,omitempty"`
}

func (CreateEntitlementInputs) GetType

type Entitlement

type Entitlement struct {
	GenericProperties

	// All none-core fields are optional
	// metered
	MeasureUsageFrom *time.Time `json:"_,omitempty"`
	IssueAfterReset  *float64   `json:"issueAfterReset,omitempty"`
	IsSoftLimit      *bool      `json:"isSoftLimit,omitempty"`

	// static
	Config *string `json:"config,omitempty"`
}

Normalized representation of an entitlement in the system

func (Entitlement) GetType

func (e Entitlement) GetType() EntitlementType

type EntitlementRepo

type EntitlementRepo interface {
	// Entitlement Management
	GetEntitlementsOfSubject(ctx context.Context, namespace string, subjectKey models.SubjectKey) ([]Entitlement, error)
	CreateEntitlement(ctx context.Context, entitlement CreateEntitlementInputs) (*Entitlement, error)
	GetEntitlement(ctx context.Context, entitlementID models.NamespacedID) (*Entitlement, error)
	GetEntitlementOfSubject(ctx context.Context, namespace string, subjectKey string, id string) (*Entitlement, error)

	ListEntitlements(ctx context.Context, params ListEntitlementsParams) ([]Entitlement, error)

	//FIXME: This is a terrbile hack
	LockEntitlementForTx(ctx context.Context, entitlementID models.NamespacedID) error

	entutils.TxCreator
	entutils.TxUser[EntitlementRepo]
}

type EntitlementType

type EntitlementType string
const (
	// EntitlementTypeMetered represents entitlements where access is determined by usage and balance calculations
	EntitlementTypeMetered EntitlementType = "metered"
	// EntitlementTypeStatic represents entitlements where access is described by a static configuration
	EntitlementTypeStatic EntitlementType = "static"
	// EntitlementTypeBoolean represents boolean access
	EntitlementTypeBoolean EntitlementType = "boolean"
)

func (EntitlementType) StrValues

func (e EntitlementType) StrValues() []string

func (EntitlementType) String

func (e EntitlementType) String() string

func (EntitlementType) Values

func (e EntitlementType) Values() []EntitlementType

type EntitlementValue

type EntitlementValue interface {
	HasAccess() bool
}

type GenericProperties

type GenericProperties struct {
	models.NamespacedModel
	models.ManagedModel

	Metadata map[string]string `json:"metadata,omitempty"`

	ID              string          `json:"id,omitempty"`
	FeatureID       string          `json:"featureId,omitempty"`
	SubjectKey      string          `json:"subjectKey,omitempty"`
	EntitlementType EntitlementType `json:"type,omitempty"`

	UsagePeriod *UsagePeriod `json:"usagePeriod,omitempty"`
}

GenericProperties is the core fields of an entitlement that are always applicable regadless of type

type InvalidFeatureError

type InvalidFeatureError struct {
	FeatureID string
	Message   string
}

func (*InvalidFeatureError) Error

func (e *InvalidFeatureError) Error() string

type InvalidValueError

type InvalidValueError struct {
	Message string
	Type    EntitlementType
}

func (*InvalidValueError) Error

func (e *InvalidValueError) Error() string

type ListEntitlementsOrderBy

type ListEntitlementsOrderBy string
const (
	ListEntitlementsOrderByCreatedAt ListEntitlementsOrderBy = "created_at"
	ListEntitlementsOrderByUpdatedAt ListEntitlementsOrderBy = "updated_at"
)

type ListEntitlementsParams

type ListEntitlementsParams struct {
	Namespace string
	Limit     int
	Offset    int
	OrderBy   ListEntitlementsOrderBy
}

type NotFoundError

type NotFoundError struct {
	EntitlementID models.NamespacedID
}

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type SubTypeConnector

type SubTypeConnector interface {
	GetValue(entitlement *Entitlement, at time.Time) (EntitlementValue, error)
	SetDefaultsAndValidate(entitlement *CreateEntitlementInputs) error

	// ValidateForFeature validates the entitlement against the feature.
	ValidateForFeature(entitlement *CreateEntitlementInputs, feature productcatalog.Feature) error
}

type TypedEntitlement

type TypedEntitlement interface {
	GetType() EntitlementType
}

type UsagePeriod

type UsagePeriod struct {
	Anchor   time.Time           `json:"anchor"`
	Interval UsagePeriodInterval `json:"interval"`
}

type UsagePeriodInterval

type UsagePeriodInterval string
const (
	UsagePeriodIntervalDay   UsagePeriodInterval = "DAY"
	UsagePeriodIntervalWeek  UsagePeriodInterval = "WEEK"
	UsagePeriodIntervalMonth UsagePeriodInterval = "MONTH"
	UsagePeriodIntervalYear  UsagePeriodInterval = "YEAR"
)

func (UsagePeriodInterval) StrValues

func (u UsagePeriodInterval) StrValues() []string

func (UsagePeriodInterval) Values

type WrongTypeError

type WrongTypeError struct {
	Expected EntitlementType
	Actual   EntitlementType
}

func (*WrongTypeError) Error

func (e *WrongTypeError) Error() string

Jump to

Keyboard shortcuts

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