premium

package
v4.72.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MPL-2.0 Imports: 30 Imported by: 1

Documentation

Index

Constants

View Source
const (
	UsageIncreaseMethodUnset = iota
	UsageIncreaseMethodTotal
	UsageIncreaseMethodBreakdown
)
View Source
const (
	BatchLimitHeader            = "x-cq-batch-limit"
	MinimumUpdateIntervalHeader = "x-cq-minimum-update-interval"
	MaximumUpdateIntervalHeader = "x-cq-maximum-update-interval"
	QueryIntervalHeader         = "x-cq-query-interval"
)
View Source
const DefaultMaxQuotaFailures = 10 // 5 minutes
View Source
const DefaultQuotaCheckInterval = 30 * time.Second

Variables

View Source
var (
	ErrInvalidLicenseSignature = errors.New("invalid license signature")
	ErrLicenseNotValidYet      = errors.New("license not valid yet")
	ErrLicenseExpired          = errors.New("license expired")
	ErrLicenseNotApplicable    = errors.New("license not applicable to this plugin")
)

Functions

func ContainsPaidTables

func ContainsPaidTables(tables schema.Tables) bool

ContainsPaidTables returns true if any of the tables are paid

func MakeAllTablesPaid

func MakeAllTablesPaid(tables schema.Tables) schema.Tables

MakeAllTablesPaid sets all tables to paid (including relations)

func WithCancelOnQuotaExceeded

func WithCancelOnQuotaExceeded(ctx context.Context, qm QuotaMonitor, ops ...QuotaCheckOption) (context.Context, error)

WithCancelOnQuotaExceeded monitors the quota usage at intervals defined by duration and cancels the context if the quota is exceeded

Types

type AWSLicenseManagerInterface added in v4.62.0

type AWSLicenseManagerInterface interface {
	CheckoutLicense(ctx context.Context, params *licensemanager.CheckoutLicenseInput, optFns ...func(*licensemanager.Options)) (*licensemanager.CheckoutLicenseOutput, error)
}

type AWSMarketplaceClientInterface added in v4.58.0

type AWSMarketplaceClientInterface interface {
	MeterUsage(ctx context.Context, params *marketplacemetering.MeterUsageInput, optFns ...func(*marketplacemetering.Options)) (*marketplacemetering.MeterUsageOutput, error)
}

type BatchUpdater

type BatchUpdater struct {

	// State
	sync.Mutex
	// contains filtered or unexported fields
}

func (*BatchUpdater) CheckQuota added in v4.68.0

func (u *BatchUpdater) CheckQuota(ctx context.Context) (CheckQuotaResult, error)

func (*BatchUpdater) Close

func (u *BatchUpdater) Close() error

func (*BatchUpdater) Increase

func (u *BatchUpdater) Increase(rows uint32) error

func (*BatchUpdater) IncreaseForTable added in v4.41.0

func (u *BatchUpdater) IncreaseForTable(table string, rows uint32) error

func (*BatchUpdater) TeamName added in v4.21.1

func (u *BatchUpdater) TeamName() string

type CQLicenseClient added in v4.62.0

type CQLicenseClient struct {
	// contains filtered or unexported fields
}

func NewLicenseClient added in v4.62.0

func NewLicenseClient(ctx context.Context, logger zerolog.Logger, ops ...LicenseClientOptions) (CQLicenseClient, error)

func (CQLicenseClient) ValidateLicense added in v4.62.0

func (lc CQLicenseClient) ValidateLicense(ctx context.Context) error

type CheckQuotaResult added in v4.68.0

type CheckQuotaResult struct {
	// HasQuota is true if the quota has not been exceeded
	HasQuota bool

	// SuggestedQueryInterval is the suggested interval to wait before querying the API again
	SuggestedQueryInterval time.Duration
}

type ErrNoQuota

type ErrNoQuota struct {
	// contains filtered or unexported fields
}

func (ErrNoQuota) Error added in v4.21.1

func (e ErrNoQuota) Error() string

type License added in v4.24.0

type License struct {
	LicensedTo string    `json:"licensed_to"`       // Customers name, e.g. "Acme Inc"
	Plugins    []string  `json:"plugins,omitempty"` // List of plugins, each in the format <org>/<kind>/<name>, e.g. "cloudquery/source/aws". Optional, if empty all plugins are allowed.
	IssuedAt   time.Time `json:"issued_at"`
	ValidFrom  time.Time `json:"valid_from"`
	ExpiresAt  time.Time `json:"expires_at"`
}

func UnpackLicense added in v4.24.0

func UnpackLicense(lic []byte) (*License, error)

func (*License) IsValid added in v4.24.0

func (l *License) IsValid(logger zerolog.Logger) error

type LicenseClientOptions added in v4.62.0

type LicenseClientOptions func(updater *CQLicenseClient)

func WithAWSLicenseManagerClient added in v4.62.0

func WithAWSLicenseManagerClient(awsLicenseManagerClient AWSLicenseManagerInterface) LicenseClientOptions

func WithLicenseFileOrDirectory added in v4.62.0

func WithLicenseFileOrDirectory(licenseFileOrDirectory string) LicenseClientOptions

func WithMeta added in v4.62.0

func WithMeta(meta plugin.Meta) LicenseClientOptions

type LicenseWrapper added in v4.24.0

type LicenseWrapper struct {
	LicenseBytes []byte `json:"license"`
	Signature    string `json:"signature"` // crypto
}

type NoOpUsageClient added in v4.24.0

type NoOpUsageClient struct {
	TeamNameValue string
}

func (NoOpUsageClient) CheckQuota added in v4.68.0

func (NoOpUsageClient) Close added in v4.24.0

func (NoOpUsageClient) Close() error

func (NoOpUsageClient) Increase added in v4.24.0

func (NoOpUsageClient) Increase(_ uint32) error

func (NoOpUsageClient) IncreaseForTable added in v4.41.1

func (NoOpUsageClient) IncreaseForTable(_ string, _ uint32) error

func (*NoOpUsageClient) TeamName added in v4.24.0

func (n *NoOpUsageClient) TeamName() string

type QuotaCheckOption

type QuotaCheckOption func(*quotaChecker)

func WithQuotaCheckPeriod

func WithQuotaCheckPeriod(duration time.Duration) QuotaCheckOption

WithQuotaCheckPeriod controls the time interval between quota checks

func WithQuotaMaxConsecutiveFailures

func WithQuotaMaxConsecutiveFailures(n int) QuotaCheckOption

WithQuotaMaxConsecutiveFailures controls the number of consecutive failed quota checks before the context is cancelled

type QuotaMonitor

type QuotaMonitor interface {
	// TeamName returns the team name
	TeamName() string
	// CheckQuota checks if the quota has been exceeded
	CheckQuota(context.Context) (CheckQuotaResult, error)
}

type TokenClient added in v4.19.1

type TokenClient interface {
	GetToken() (auth.Token, error)
	GetTokenType() auth.TokenType
}

type UsageClient

type UsageClient interface {
	QuotaMonitor
	// Increase updates the usage by the given number of rows
	Increase(uint32) error
	// IncreaseForTable updates the usage of a table by the given number of rows
	IncreaseForTable(string, uint32) error
	// Close flushes any remaining rows and closes the quota service
	Close() error
}

func NewUsageClient

func NewUsageClient(meta plugin.Meta, ops ...UsageClientOptions) (UsageClient, error)

type UsageClientOptions

type UsageClientOptions func(updater *BatchUpdater)

func WithAPIClient

func WithAPIClient(apiClient *cqapi.ClientWithResponses) UsageClientOptions

WithAPIClient sets the API client to use - defaults to a client using a bearer token generated from the refresh token stored in the configuration

func WithAWSMarketplaceClient added in v4.58.0

func WithAWSMarketplaceClient(awsMarketplaceClient AWSMarketplaceClientInterface) UsageClientOptions

WithAWSMarketplaceClient sets the AWS Marketplace client to use - defaults to marketplacemetering.NewFromConfig()

func WithBatchLimit

func WithBatchLimit(batchLimit uint32) UsageClientOptions

WithBatchLimit sets the maximum number of rows to update in a single request

func WithLogger

func WithLogger(logger zerolog.Logger) UsageClientOptions

WithLogger sets the logger to use - defaults to a no-op logger

func WithMaxRetries

func WithMaxRetries(maxRetries int) UsageClientOptions

WithMaxRetries sets the maximum number of retries to update the usage in case of an API error

func WithMaxTimeBetweenFlushes

func WithMaxTimeBetweenFlushes(maxTimeBetweenFlushes time.Duration) UsageClientOptions

WithMaxTimeBetweenFlushes sets the flush duration - the time at which an update will be triggered even if the batch limit is not reached

func WithMaxWaitTime

func WithMaxWaitTime(maxWaitTime time.Duration) UsageClientOptions

WithMaxWaitTime sets the maximum time to wait before retrying a failed update

func WithMinTimeBetweenFlushes

func WithMinTimeBetweenFlushes(minTimeBetweenFlushes time.Duration) UsageClientOptions

WithMinTimeBetweenFlushes sets the minimum time between updates

func WithURL

func WithURL(url string) UsageClientOptions

WithURL sets the API URL to use - defaults to https://api.cloudquery.io

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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