Documentation
¶
Overview ¶
Package marketplace provides a unified abstraction layer for cloud marketplace integrations across AWS, GCP, and Azure.
Index ¶
- Variables
- func RetryFunc(ctx context.Context, cfg RetryConfig, operation string, fn func() error) error
- type CloudProvider
- type EntitlementChecker
- type MeteringService
- type MultiCloudManager
- func (m *MultiCloudManager) CheckEntitlement(ctx context.Context, cloud CloudProvider, customerID string, feature string) error
- func (m *MultiCloudManager) IsActive(ctx context.Context, cloud CloudProvider, customerID string) (bool, error)
- func (m *MultiCloudManager) Provider(cloud CloudProvider) (Provider, error)
- func (m *MultiCloudManager) Register(p Provider)
- func (m *MultiCloudManager) ResolveSubscription(ctx context.Context, cloud CloudProvider, customerID string) (*Subscription, error)
- func (m *MultiCloudManager) SubmitUsage(ctx context.Context, cloud CloudProvider, records []UsageRecord) error
- type Provider
- type RetryConfig
- type Subscription
- type SubscriptionManager
- type UsageRecord
- type UsageTracker
Constants ¶
This section is empty.
Variables ¶
var ( ErrProviderNotRegistered = errors.New("marketplace: provider not registered") ErrNoActiveSubscription = errors.New("marketplace: no active subscription") ErrEntitlementDenied = errors.New("marketplace: entitlement denied") ErrMeteringFailed = errors.New("marketplace: metering submission failed") )
Common errors returned by marketplace operations.
Functions ¶
Types ¶
type CloudProvider ¶
type CloudProvider string
CloudProvider identifies which cloud marketplace a subscription originates from.
const ( AWS CloudProvider = "aws" GCP CloudProvider = "gcp" Azure CloudProvider = "azure" )
type EntitlementChecker ¶
type EntitlementChecker interface {
// CheckEntitlement returns nil if the customer is entitled to the given feature,
// or ErrEntitlementDenied otherwise.
CheckEntitlement(ctx context.Context, customerID string, feature string) error
}
EntitlementChecker verifies whether a customer is entitled to a specific feature.
type MeteringService ¶
type MeteringService interface {
// SubmitUsage sends a batch of usage records to the cloud provider's metering API.
SubmitUsage(ctx context.Context, records []UsageRecord) error
}
MeteringService submits consumption usage records to a cloud marketplace.
type MultiCloudManager ¶
type MultiCloudManager struct {
// contains filtered or unexported fields
}
MultiCloudManager routes marketplace operations to the correct cloud provider based on subscription source. It implements MeteringService, SubscriptionManager, and EntitlementChecker by delegating to registered providers.
func NewMultiCloudManager ¶
func NewMultiCloudManager(providers ...Provider) *MultiCloudManager
NewMultiCloudManager creates a manager with the given providers registered.
func (*MultiCloudManager) CheckEntitlement ¶
func (m *MultiCloudManager) CheckEntitlement(ctx context.Context, cloud CloudProvider, customerID string, feature string) error
CheckEntitlement verifies a customer's entitlement on the specified provider.
func (*MultiCloudManager) IsActive ¶
func (m *MultiCloudManager) IsActive(ctx context.Context, cloud CloudProvider, customerID string) (bool, error)
IsActive checks whether a customer has an active subscription on the specified provider.
func (*MultiCloudManager) Provider ¶
func (m *MultiCloudManager) Provider(cloud CloudProvider) (Provider, error)
Provider returns the registered provider for the given cloud, or an error if no provider is registered.
func (*MultiCloudManager) Register ¶
func (m *MultiCloudManager) Register(p Provider)
Register adds or replaces a provider in the manager.
func (*MultiCloudManager) ResolveSubscription ¶
func (m *MultiCloudManager) ResolveSubscription(ctx context.Context, cloud CloudProvider, customerID string) (*Subscription, error)
ResolveSubscription looks up a subscription by customer ID on the specified provider.
func (*MultiCloudManager) SubmitUsage ¶
func (m *MultiCloudManager) SubmitUsage(ctx context.Context, cloud CloudProvider, records []UsageRecord) error
SubmitUsage routes usage records to the specified cloud provider's metering service.
type Provider ¶
type Provider interface {
MeteringService
SubscriptionManager
EntitlementChecker
// Name returns the cloud provider identifier.
Name() CloudProvider
}
Provider bundles all marketplace operations for a single cloud provider.
type RetryConfig ¶ added in v1.12.0
type RetryConfig struct {
// MaxAttempts is the total number of attempts (including the first).
MaxAttempts int
// BaseDelay is the initial delay before the first retry.
BaseDelay time.Duration
// MaxJitter is the maximum random jitter added to each delay.
MaxJitter time.Duration
}
RetryConfig controls exponential backoff retry behavior for metering calls.
func DefaultRetryConfig ¶ added in v1.12.0
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns the standard retry configuration for marketplace metering: 3 attempts with 1s base delay and 500ms max jitter.
type Subscription ¶
type Subscription struct {
// ID is the cloud-provider-specific subscription identifier.
ID string
// CustomerID is the cloud-provider-specific customer identifier.
CustomerID string
// Provider indicates which cloud marketplace this subscription belongs to.
Provider CloudProvider
// ProductCode is the marketplace product identifier.
ProductCode string
// Status is the current subscription state (e.g., "active", "cancelled", "expired").
Status string
// Entitlements lists the features or tiers the customer is entitled to.
Entitlements []string
// ExpiresAt is when the subscription expires, if applicable.
ExpiresAt time.Time
}
Subscription represents a marketplace subscription.
type SubscriptionManager ¶
type SubscriptionManager interface {
// ResolveSubscription looks up a subscription by customer ID.
ResolveSubscription(ctx context.Context, customerID string) (*Subscription, error)
// IsActive returns whether the customer has an active subscription.
IsActive(ctx context.Context, customerID string) (bool, error)
}
SubscriptionManager resolves and manages marketplace subscriptions.
type UsageRecord ¶
type UsageRecord struct {
// CustomerID is the cloud-provider-specific customer identifier.
CustomerID string
// Dimension identifies what is being metered (e.g., "inference_tokens", "gpu_hours").
Dimension string
// Quantity is the amount consumed.
Quantity int64
// Timestamp is when the usage occurred.
Timestamp time.Time
}
UsageRecord represents a single unit of metered consumption.
type UsageTracker ¶
type UsageTracker struct {
// contains filtered or unexported fields
}
UsageTracker aggregates usage records in memory and flushes them to a MeteringService on demand or at a configured interval.
func NewUsageTracker ¶
func NewUsageTracker() *UsageTracker
NewUsageTracker creates an empty usage tracker.
func (*UsageTracker) Aggregate ¶
func (t *UsageTracker) Aggregate() map[string]map[string]int64
Aggregate returns the total quantity per (customerID, dimension) pair across all pending records without draining them.
func (*UsageTracker) Flush ¶
func (t *UsageTracker) Flush(ctx context.Context, svc MeteringService) (int, error)
Flush drains all pending records and submits them to the given metering service. Returns the number of records flushed and any error from submission.
func (*UsageTracker) Pending ¶
func (t *UsageTracker) Pending() int
Pending returns the number of buffered records.
func (*UsageTracker) Record ¶
func (t *UsageTracker) Record(customerID, dimension string, quantity int64)
Record adds a usage record to the pending buffer.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package aws provides AWS Marketplace integration for Zerfoo Cloud, including metering, subscription lifecycle management, entitlement verification, and token-based billing.
|
Package aws provides AWS Marketplace integration for Zerfoo Cloud, including metering, subscription lifecycle management, entitlement verification, and token-based billing. |
|
Package azure provides Azure Marketplace integration for Zerfoo Cloud, including SaaS Fulfillment API v2, Marketplace Metering Service, subscription lifecycle management, and webhook handling.
|
Package azure provides Azure Marketplace integration for Zerfoo Cloud, including SaaS Fulfillment API v2, Marketplace Metering Service, subscription lifecycle management, and webhook handling. |
|
Package gcp provides GCP Marketplace integration for Zerfoo Cloud, including Cloud Commerce Partner Procurement API integration, SaaS entitlement management, Service Control API usage metering, and token-based billing.
|
Package gcp provides GCP Marketplace integration for Zerfoo Cloud, including Cloud Commerce Partner Procurement API integration, SaaS entitlement management, Service Control API usage metering, and token-based billing. |