Documentation
¶
Index ¶
- type AlreadyExistsError
- type Connector
- type CreateEntitlementInputs
- type CreateEntitlementRepoInputs
- type Entitlement
- type EntitlementRepo
- type EntitlementType
- type EntitlementValue
- type GenericProperties
- type InvalidFeatureError
- type InvalidValueError
- type ListEntitlementsOrderBy
- type ListEntitlementsParams
- type NotFoundError
- type SubTypeConnector
- type TypedEntitlement
- type UpdateEntitlementUsagePeriodParams
- type UsagePeriod
- type WrongTypeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlreadyExistsError ¶
func (*AlreadyExistsError) Error ¶
func (e *AlreadyExistsError) Error() string
type Connector ¶
type Connector interface {
CreateEntitlement(ctx context.Context, input CreateEntitlementInputs) (*Entitlement, error)
GetEntitlement(ctx context.Context, namespace string, id string) (*Entitlement, error)
DeleteEntitlement(ctx context.Context, namespace string, id string) error
GetEntitlementValue(ctx context.Context, namespace string, subjectKey string, idOrFeatureKey string, at time.Time) (EntitlementValue, error)
GetEntitlementsOfSubject(ctx context.Context, namespace string, subjectKey models.SubjectKey) ([]Entitlement, error)
ListEntitlements(ctx context.Context, params ListEntitlementsParams) ([]Entitlement, error)
}
func NewEntitlementConnector ¶
func NewEntitlementConnector( entitlementRepo EntitlementRepo, featureConnector productcatalog.FeatureConnector, meterRepo meter.Repository, meteredEntitlementConnector SubTypeConnector, staticEntitlementConnector SubTypeConnector, booleanEntitlementConnector SubTypeConnector, ) Connector
type CreateEntitlementInputs ¶
type CreateEntitlementInputs struct {
Namespace string `json:"namespace"`
FeatureID *string `json:"featureId"`
FeatureKey *string `json:"featureKey"`
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 []byte `json:"config,omitempty"`
UsagePeriod *UsagePeriod `json:"usagePeriod,omitempty"`
}
func (CreateEntitlementInputs) GetType ¶
func (c CreateEntitlementInputs) GetType() EntitlementType
type CreateEntitlementRepoInputs ¶
type CreateEntitlementRepoInputs struct {
Namespace string `json:"namespace"`
FeatureID string `json:"featureId"`
FeatureKey string `json:"featureKey"`
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 []byte `json:"config,omitempty"`
UsagePeriod *UsagePeriod `json:"usagePeriod,omitempty"`
CurrentUsagePeriod *recurrence.Period `json:"currentUsagePeriod,omitempty"`
}
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"`
LastReset *time.Time `json:"lastReset,omitempty"`
// static
Config []byte `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 CreateEntitlementRepoInputs) (*Entitlement, error)
GetEntitlement(ctx context.Context, entitlementID models.NamespacedID) (*Entitlement, error)
GetEntitlementOfSubject(ctx context.Context, namespace string, subjectKey string, idOrFeatureKey string) (*Entitlement, error)
DeleteEntitlement(ctx context.Context, entitlementID models.NamespacedID) error
ListEntitlements(ctx context.Context, params ListEntitlementsParams) ([]Entitlement, error)
//FIXME: This is a terrbile hack
LockEntitlementForTx(ctx context.Context, entitlementID models.NamespacedID) error
UpdateEntitlementUsagePeriod(ctx context.Context, entitlementID models.NamespacedID, params UpdateEntitlementUsagePeriodParams) error
ListEntitlementsWithExpiredUsagePeriod(ctx context.Context, namespace string, highwatermark time.Time) ([]Entitlement, 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"`
FeatureKey string `json:"featureKey,omitempty"`
SubjectKey string `json:"subjectKey,omitempty"`
EntitlementType EntitlementType `json:"type,omitempty"`
UsagePeriod *UsagePeriod `json:"usagePeriod,omitempty"`
CurrentUsagePeriod *recurrence.Period `json:"currentUsagePeriod,omitempty"`
}
GenericProperties is the core fields of an entitlement that are always applicable regadless of type
type InvalidFeatureError ¶
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 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)
// Runs before creating the entitlement, building the Repository inputs.
// If it returns an error the operation has to fail.
BeforeCreate(entitlement CreateEntitlementInputs, feature productcatalog.Feature) (*CreateEntitlementRepoInputs, error)
// Runs after entitlement creation.
// If it returns an error the operation has to fail.
AfterCreate(ctx context.Context, entitlement *Entitlement) error
}
type TypedEntitlement ¶
type TypedEntitlement interface {
GetType() EntitlementType
}
type UpdateEntitlementUsagePeriodParams ¶
type UpdateEntitlementUsagePeriodParams struct {
NewAnchor *time.Time
CurrentUsagePeriod recurrence.Period
}
type UsagePeriod ¶
type UsagePeriod recurrence.Recurrence
func (UsagePeriod) GetCurrentPeriodAt ¶
func (u UsagePeriod) GetCurrentPeriodAt(at time.Time) (recurrence.Period, error)
The returned period is exclusive at the end end inclusive in the start
type WrongTypeError ¶
type WrongTypeError struct {
Expected EntitlementType
Actual EntitlementType
}
func (*WrongTypeError) Error ¶
func (e *WrongTypeError) Error() string
Source Files
¶
Click to show internal directories.
Click to hide internal directories.