Documentation
¶
Index ¶
- func NewEntitlementGrantOwnerAdapter(featureRepo productcatalog.FeatureRepo, entitlementRepo EntitlementRepo, ...) credit.OwnerConnector
- type BalanceHistoryParams
- type CreateEntitlementGrantInputs
- type CreateEntitlementInputs
- type Entitlement
- type EntitlementAlreadyExistsError
- type EntitlementBalance
- type EntitlementBalanceConnector
- type EntitlementBalanceHistoryWindow
- type EntitlementConnector
- type EntitlementGrant
- type EntitlementNotFoundError
- type EntitlementRepo
- type EntitlementRepoCreateEntitlementInputs
- type EntitlementValue
- type UsageResetNotFoundError
- type UsageResetRepo
- type UsageResetTime
- type WindowSize
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEntitlementGrantOwnerAdapter ¶
func NewEntitlementGrantOwnerAdapter( featureRepo productcatalog.FeatureRepo, entitlementRepo EntitlementRepo, usageResetRepo UsageResetRepo, meterRepo meter.Repository, logger *slog.Logger, ) credit.OwnerConnector
Types ¶
type BalanceHistoryParams ¶
type CreateEntitlementGrantInputs ¶
type CreateEntitlementGrantInputs struct {
credit.CreateGrantInput
}
type CreateEntitlementInputs ¶
type Entitlement ¶
type Entitlement struct {
models.NamespacedModel
models.ManagedModel
ID string `json:"id,omitempty"`
FeatureID string `json:"featureId,omitempty"`
MeasureUsageFrom time.Time `json:"measureUsageFrom,omitempty"`
SubjectKey string `json:"subjectKey,omitempty"`
}
type EntitlementAlreadyExistsError ¶
type EntitlementAlreadyExistsError struct {
EntitlementID string
FeatureID string
SubjectKey string
}
func (*EntitlementAlreadyExistsError) Error ¶
func (e *EntitlementAlreadyExistsError) Error() string
type EntitlementBalance ¶
type EntitlementBalanceConnector ¶
type EntitlementBalanceConnector interface {
GetEntitlementBalance(ctx context.Context, entitlementID models.NamespacedID, at time.Time) (*EntitlementBalance, error)
GetEntitlementBalanceHistory(ctx context.Context, entitlementID models.NamespacedID, params BalanceHistoryParams) ([]EntitlementBalanceHistoryWindow, credit.GrantBurnDownHistory, error)
ResetEntitlementUsage(ctx context.Context, entitlementID models.NamespacedID, resetAt time.Time) (balanceAfterReset *EntitlementBalance, err error)
// GetEntitlementGrantBalanceHistory(ctx context.Context, entitlementGrantID EntitlementGrantID, params BalanceHistoryParams) ([]EntitlementBalanceHistoryWindow, error)
CreateGrant(ctx context.Context, entitlement models.NamespacedID, inputGrant CreateEntitlementGrantInputs) (EntitlementGrant, error)
ListEntitlementGrants(ctx context.Context, entitlementID models.NamespacedID) ([]EntitlementGrant, error)
}
func NewEntitlementBalanceConnector ¶
func NewEntitlementBalanceConnector( streamingConnector streaming.Connector, ownerConnector credit.OwnerConnector, balanceConnector credit.BalanceConnector, grantConnector credit.GrantConnector, ) EntitlementBalanceConnector
type EntitlementConnector ¶
type EntitlementConnector 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, entitlementId models.NamespacedID, at time.Time) (EntitlementValue, error)
}
func NewEntitlementConnector ¶
func NewEntitlementConnector( entitlementBalanceConnector EntitlementBalanceConnector, entitlementRepo EntitlementRepo, featureConnector productcatalog.FeatureConnector, ) EntitlementConnector
type EntitlementGrant ¶
type EntitlementGrant struct {
credit.Grant
// "removing" fields
OwnerID string `json:"-"`
ResetMaxRollover float64 `json:"-"`
// "adding" fields
EntitlementID string `json:"entitlementId"`
NextRecurrence *time.Time `json:"nextRecurrence,omitempty"`
MaxRolloverAmount float64 `json:"maxRolloverAmount"`
}
func GrantFromCreditGrant ¶
func GrantFromCreditGrant(grant credit.Grant) (*EntitlementGrant, error)
type EntitlementNotFoundError ¶
type EntitlementNotFoundError struct {
EntitlementID models.NamespacedID
}
func (*EntitlementNotFoundError) Error ¶
func (e *EntitlementNotFoundError) Error() string
type EntitlementRepo ¶
type EntitlementRepo interface {
// Entitlement Management
GetEntitlementsOfSubject(ctx context.Context, namespace string, subjectKey models.SubjectKey) ([]Entitlement, error)
CreateEntitlement(ctx context.Context, entitlement EntitlementRepoCreateEntitlementInputs) (*Entitlement, error)
GetEntitlement(ctx context.Context, entitlementID models.NamespacedID) (*Entitlement, error)
//FIXME: This is a terrbile hack
LockEntitlementForTx(ctx context.Context, entitlementID models.NamespacedID) error
entutils.TxCreator
entutils.TxUser[EntitlementRepo]
}
type EntitlementValue ¶
type UsageResetNotFoundError ¶
type UsageResetNotFoundError struct {
EntitlementID models.NamespacedID
}
func (UsageResetNotFoundError) Error ¶
func (e UsageResetNotFoundError) Error() string
type UsageResetRepo ¶
type UsageResetRepo interface {
Save(ctx context.Context, usageResetTime UsageResetTime) error
GetLastAt(ctx context.Context, entitlementID models.NamespacedID, at time.Time) (*UsageResetTime, error)
GetBetween(ctx context.Context, entitlementID models.NamespacedID, from time.Time, to time.Time) ([]UsageResetTime, error)
entutils.TxCreator
entutils.TxUser[UsageResetRepo]
}
type UsageResetTime ¶
type UsageResetTime struct {
models.NamespacedModel
ResetTime time.Time
EntitlementID string
}
type WindowSize ¶
type WindowSize string
const ( // We don't support minute precision as that results in an extremely heavy calculation // WindowSizeMinute WindowSize = "MINUTE" WindowSizeHour WindowSize = "HOUR" WindowSizeDay WindowSize = "DAY" )
Source Files
¶
Click to show internal directories.
Click to hide internal directories.