meteredentitlement

package
v1.0.0-beta.96 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEntitlementGrantOwnerAdapter

func NewEntitlementGrantOwnerAdapter(
	featureRepo productcatalog.FeatureRepo,
	entitlementRepo entitlement.EntitlementRepo,
	usageResetRepo UsageResetRepo,
	meterRepo meter.Repository,
	logger *slog.Logger,
) credit.OwnerConnector

Types

type BalanceHistoryParams

type BalanceHistoryParams struct {
	From           time.Time
	To             time.Time
	WindowSize     WindowSize
	WindowTimeZone time.Location
}

type Connector

type Connector interface {
	entitlement.SubTypeConnector

	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, params ResetEntitlementUsageParams) (balanceAfterReset *EntitlementBalance, err error)

	ResetEntitlementsWithExpiredUsagePeriod(ctx context.Context, namespace string, highwatermark time.Time) ([]models.NamespacedID, 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 NewMeteredEntitlementConnector

func NewMeteredEntitlementConnector(
	streamingConnector streaming.Connector,
	ownerConnector credit.OwnerConnector,
	balanceConnector credit.BalanceConnector,
	grantConnector credit.GrantConnector,
	entitlementRepo entitlement.EntitlementRepo,
) Connector

type CreateEntitlementGrantInputs

type CreateEntitlementGrantInputs struct {
	credit.CreateGrantInput
}

type Entitlement

type Entitlement struct {
	entitlement.GenericProperties

	// MeasureUsageFrom defines the time from which usage should be measured.
	// This is a global value, in most cases the same value as `CreatedAt` should be fine.
	MeasureUsageFrom time.Time `json:"measureUsageFrom,omitempty"`

	// IssueAfterReset defines an amount of usage that will be issued after a reset.
	// This affordance will only be usable until the next reset.
	IssuesAfterReset *float64 `json:"issueAfterReset,omitempty"`

	// IsSoftLimit defines if the entitlement is a soft limit. By default when balance falls to 0
	// access will be disabled. If this is a soft limit, access will be allowed nonetheless.
	IsSoftLimit bool `json:"isSoftLimit,omitempty"`

	// UsagePeriod defines the recurring period for usage calculations.
	UsagePeriod entitlement.UsagePeriod `json:"usagePeriod,omitempty"`

	// CurrentPeriod defines the current period for usage calculations.
	CurrentUsagePeriod recurrence.Period `json:"currentUsagePeriod,omitempty"`

	// LastReset defines the last time the entitlement was reset.
	LastReset time.Time `json:"lastReset"`
}

func ParseFromGenericEntitlement

func ParseFromGenericEntitlement(model *entitlement.Entitlement) (*Entitlement, error)

type EntitlementBalance

type EntitlementBalance struct {
	EntitlementID string    `json:"entitlementId"`
	Balance       float64   `json:"balance"`
	UsageInPeriod float64   `json:"usageInPeriod"`
	Overage       float64   `json:"overage"`
	StartOfPeriod time.Time `json:"startOfPeriod"`
}

type EntitlementBalanceHistoryWindow

type EntitlementBalanceHistoryWindow struct {
	From           time.Time
	To             time.Time
	UsageInPeriod  float64
	BalanceAtStart float64
	OverageAtStart float64
}

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 MeteredEntitlementValue

type MeteredEntitlementValue struct {
	Balance       float64   `json:"balance"`
	UsageInPeriod float64   `json:"usageInPeriod"`
	Overage       float64   `json:"overage"`
	StartOfPeriod time.Time `json:"startOfPeriod"`
	// contains filtered or unexported fields
}

func (*MeteredEntitlementValue) HasAccess

func (m *MeteredEntitlementValue) HasAccess() bool

type ResetEntitlementUsageParams

type ResetEntitlementUsageParams struct {
	At           time.Time
	RetainAnchor bool
}

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"
)

Jump to

Keyboard shortcuts

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