 Documentation
      ¶
      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 ¶
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 ¶
GetUsageByDateRange returns usage amount for all leases for input date range startDate and endDate are epoch Unix dates
func (*DB) GetUsageByPrincipal ¶
GetUsageByPrincipal returns usage amount for all leases for input Principal startDate is epoch Unix date
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 ¶
GetUsageOutput contains the scan results as well as the keys for retrieve the next page of the result set.
type MultipleReader ¶
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 ReaderWriter ¶
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
type SingleReader ¶
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