usage

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// DynamoDB Client
	Client *dynamodb.DynamoDB
	// Name of the Usage table
	UsageTableName   string
	PartitionKeyName string
	SortKeyName      string
	// Use Consistent Reads when scanning or querying.  When possbile.
	ConsistentRead bool
}

DB contains DynamoDB client and table names

func New

func New(client *dynamodb.DynamoDB, usageTableName string, partitionKeyName string, sortKeyName string) *DB

New creates a new usage DB Service struct, with all the necessary fields configured.

func NewFromEnv

func NewFromEnv() (*DB, error)

NewFromEnv creates a DB instance configured from environment variables. Requires env vars for:

- AWS_CURRENT_REGION - USAGE_CACHE_DB

func (*DB) GetUsage

func (db *DB) GetUsage(input GetUsageInput) (GetUsageOutput, error)

GetUsage takes a set of filtering criteria and scans the Usage table for the matching records.

func (*DB) GetUsageByDateRange

func (db *DB) GetUsageByDateRange(startDate time.Time, endDate time.Time) ([]*Usage, error)

GetUsageByDateRange returns usage amount for all leases for input date range startDate and endDate are epoch Unix dates

func (*DB) GetUsageByPrincipal

func (db *DB) GetUsageByPrincipal(startDate time.Time, principalID string) ([]*Usage, error)

GetUsageByPrincipal returns usage amount for all leases for input Principal startDate is epoch Unix date

func (*DB) PutUsage

func (db *DB) PutUsage(input Usage) error

PutUsage adds an item to Usage DB

type DBer

type DBer interface {
	PutUsage(input Usage) error
	GetUsageByDateRange(startDate time.Time, endDate time.Time) ([]*Usage, error)
	GetUsageByPrincipal(startDate time.Time, principalID string) ([]*Usage, error)
}

The DBer interface includes all methods used by the DB struct to interact with Usage DynamoDB. This is useful if we want to mock the DB service.

type GetUsageInput

type GetUsageInput struct {
	StartKeys   map[string]string
	PrincipalID string
	AccountID   string
	StartDate   time.Time
	Limit       int64
}

GetUsageInput contains the filtering criteria for the GetUsage scan.

type GetUsageOutput

type GetUsageOutput struct {
	Results  []*Usage
	NextKeys map[string]string
}

GetUsageOutput contains the scan results as well as the keys for retrieve the next page of the result set.

type MultipleReader

type MultipleReader interface {
	List(query *Usage) (*Usages, error)
}

MultipleReader reads multiple usages from the data store

type NewServiceInput

type NewServiceInput struct {
	DataSvc ReaderWriter
}

NewServiceInput Input for creating a new Service

type NewUsageInput

type NewUsageInput struct {
	PrincipalID  string
	AccountID    string
	StartDate    int64
	EndDate      int64
	CostAmount   float64
	CostCurrency string
	TimeToLive   int64
}

NewUsageInput has the input for create a new usage record

type Reader

type Reader interface {
	SingleReader
	MultipleReader
}

Reader data Layer

type ReaderWriter

type ReaderWriter interface {
	Reader
	Writer
}

ReaderWriter includes Reader and Writer interfaces

type Service

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

Service is a type corresponding to a Usage table record

func NewService

func NewService(input NewServiceInput) *Service

NewService creates a new instance of the Service

func (*Service) Create

func (a *Service) Create(data *Usage) (*Usage, error)

Create creates a new usage record

func (*Service) Get

func (a *Service) Get(startDate int64, principalID string) (*Usage, error)

Get returns an usage from startDate and principalID

func (*Service) List

func (a *Service) List(query *Usage) (*Usages, error)

List Get a list of usages based on a query

type SingleReader

type SingleReader interface {
	Get(startDate int64, principalID string) (*Usage, error)
}

SingleReader Reads Usage information from the data store

type Usage

type Usage struct {
	PrincipalID     *string  `json:"principalId,omitempty" dynamodbav:"PrincipalId" schema:"principalId,omitempty"`              // User Principal ID
	AccountID       *string  `json:"accountId,omitempty" dynamodbav:"AccountId,omitempty" schema:"accountId,omitempty"`          // AWS Account ID
	StartDate       *int64   `json:"startDate,omitempty" dynamodbav:"StartDate" schema:"startDate,omitempty"`                    // Usage start date Epoch Timestamp
	EndDate         *int64   `json:"endDate,omitempty" dynamodbav:"EndDate,omitempty" schema:"endDate,omitempty"`                // Usage ends date Epoch Timestamp
	CostAmount      *float64 `json:"costAmount,omitempty" dynamodbav:"CostAmount,omitempty" schema:"costAmount,omitempty"`       // Cost Amount for given period
	CostCurrency    *string  `json:"costCurrency,omitempty" dynamodbav:"CostCurrency,omitempty" schema:"costCurrency,omitempty"` // Cost currency
	TimeToLive      *int64   `json:"timeToLive,omitempty" dynamodbav:"TimeToLive,omitempty" schema:"timeToLive,omitempty"`       // ttl attribute
	Limit           *int64   `json:"-" dynamodbav:"-" schema:"limit,omitempty"`
	NextStartDate   *int64   `json:"-" dynamodbav:"-" schema:"nextStartDate,omitempty"`
	NextPrincipalID *string  `json:"-" dynamodbav:"-" schema:"nextPrincipalId,omitempty"`
}

Usage item

func NewUsage

func NewUsage(input NewUsageInput) (*Usage, error)

NewUsage creates a new instance of usage

func (*Usage) Validate

func (u *Usage) Validate() error

Validate the account data

type Usages

type Usages []Usage

Usages is a list of type Usage

type Writer

type Writer interface {
	Write(i *Usage) error
}

Writer put an item into the data store

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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