Documentation
¶
Index ¶
- Constants
- type AccountServicer
- type Eventer
- type Lease
- type Leases
- type MultipleReader
- type NewLeaseInput
- type NewServiceInput
- type Reader
- type ReaderWriter
- type Service
- func (a *Service) Create(data *Lease, principalSpentAmount float64) (*Lease, error)
- func (a *Service) Delete(ID string) (*Lease, error)
- func (a *Service) Get(ID string) (*Lease, error)
- func (a *Service) GetByAccountIDAndPrincipalID(accountID string, principalID string) (*Lease, error)
- func (a *Service) List(query *Lease) (*Leases, error)
- func (a *Service) ListPages(query *Lease, fn func(*Leases) bool) error
- func (a *Service) Save(data *Lease) error
- type SingleReader
- type Status
- type StatusReason
- type Writer
Constants ¶
const (
Weekly = "WEEKLY"
)
Weekly
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountServicer ¶
type AccountServicer interface {
// EndLease indicates that the provided account is no longer leased.
Reset(id string) (*account.Account, error)
}
AccountServicer is a partial implementation of the accountiface.Servicer interface, with only the methods needed by the LeaseService
type Eventer ¶
type Eventer interface {
LeaseCreate(account *Lease) error
LeaseEnd(account *Lease) error
LeaseUpdate(old *Lease, new *Lease) error
}
Eventer for publishing events
type Lease ¶
type Lease struct {
AccountID *string `json:"accountId,omitempty" dynamodbav:"AccountId" schema:"accountId,omitempty"` // AWS Account ID
PrincipalID *string `json:"principalId,omitempty" dynamodbav:"PrincipalId" schema:"principalId,omitempty"` // Azure User Principal ID
ID *string `json:"id,omitempty" dynamodbav:"Id,omitempty" schema:"id,omitempty"` // Lease ID
Status *Status `json:"leaseStatus,omitempty" dynamodbav:"LeaseStatus,omitempty" schema:"status,omitempty"` // Status of the Lease
StatusReason *StatusReason `json:"leaseStatusReason,omitempty" dynamodbav:"LeaseStatusReason,omitempty" schema:"-"` // Reason for the status of the lease
CreatedOn *int64 `json:"createdOn,omitempty" dynamodbav:"CreatedOn,omitempty" schema:"createdOn,omitempty"` // Created Epoch Timestamp
LastModifiedOn *int64 `json:"lastModifiedOn,omitempty" dynamodbav:"LastModifiedOn,omitempty" schema:"lastModifiedOn,omitempty"` // Last Modified Epoch Timestamp
BudgetAmount *float64 `json:"budgetAmount,omitempty" dynamodbav:"BudgetAmount,omitempty" schema:"budgetAmount,omitempty"` // Budget Amount allocated for this lease
BudgetCurrency *string `json:"budgetCurrency,omitempty" dynamodbav:"BudgetCurrency,omitempty" schema:"budgetCurrency,omitempty"` // Budget currency
BudgetNotificationEmails *[]string `` // Budget notification emails
/* 133-byte string literal not displayed */
StatusModifiedOn *int64 `json:"leaseStatusModifiedOn,omitempty" dynamodbav:"LeaseStatusModifiedOn,omitempty" schema:"leaseStatusModifiedOn,omitempty"` // Last Modified Epoch Timestamp
ExpiresOn *int64 `json:"expiresOn,omitempty" dynamodbav:"ExpiresOn,omitempty" schema:"expiresOn,omitempty"` // Lease expiration time as Epoch
Metadata map[string]interface{} `json:"metadata,omitempty" dynamodbav:"Metadata,omitempty" schema:"-"`
Limit *int64 `json:"-" dynamodbav:"-" schema:"limit,omitempty"`
NextAccountID *string `json:"-" dynamodbav:"-" schema:"nextAccountId,omitempty"`
NextPrincipalID *string `json:"-" dynamodbav:"-" schema:"nextPrincipalId,omitempty"`
}
Lease is a type corresponding to a Lease table record
type MultipleReader ¶
MultipleReader reads multiple items from the data store
type NewLeaseInput ¶
type NewLeaseInput struct {
AccountID string
PrincipalID string
BudgetAmount float64
BudgetCurrency string
BudgetNotificationEmails []string
Metadata map[string]interface{}
ExpiresOn int64
}
NewLeaseInput contains all the data for creating a new Lease
type NewServiceInput ¶
type NewServiceInput struct {
DataSvc ReaderWriter
EventSvc Eventer
AccountSvc AccountServicer
DefaultLeaseLengthInDays int `env:"DEFAULT_LEASE_LENGTH_IN_DAYS" envDefault:"7"`
PrincipalBudgetAmount float64 `env:"PRINCIPAL_BUDGET_AMOUNT" envDefault:"1000.00"`
PrincipalBudgetPeriod string `env:"PRINCIPAL_BUDGET_PERIOD" envDefault:"Weekly"`
MaxLeaseBudgetAmount float64 `env:"MAX_LEASE_BUDGET_AMOUNT" envDefault:"1000.00"`
MaxLeasePeriod int64 `env:"MAX_LEASE_PERIOD" envDefault:"704800"`
}
NewServiceInput Input for creating a new Service
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 Lease table record
func NewService ¶
func NewService(input NewServiceInput) *Service
NewService creates a new instance of the Service
func (*Service) Create ¶
Create creates a new lease using the data provided. Returns the lease record
func (*Service) Delete ¶
Delete finds a given lease and checks if it's active and then updates it to status `Inactive`. Returns the lease.
func (*Service) GetByAccountIDAndPrincipalID ¶
func (a *Service) GetByAccountIDAndPrincipalID(accountID string, principalID string) (*Lease, error)
GetByAccountIDAndPrincipalID gets the Lease record by AccountID and PrincipalID
type SingleReader ¶
type SingleReader interface {
Get(leaseID string) (*Lease, error)
GetByAccountIDAndPrincipalID(accountID string, principalID string) (*Lease, error)
}
SingleReader Reads an item information from the data store
type Status ¶
type Status string
Status is a lease status type
func ParseStatus ¶
ParseStatus - parses the string into an account status.
type StatusReason ¶
type StatusReason string
StatusReason provides consistent verbiage for lease status change reasons.
const ( // StatusReasonExpired means the lease has past its expiresOn date and therefore expired. StatusReasonExpired StatusReason = "Expired" // StatusReasonOverBudget means the lease is over its budgeted amount and is therefore reset/reclaimed. StatusReasonOverBudget StatusReason = "OverBudget" // StatusReasonOverPrincipalBudget means the lease is over its principal budgeted amount and is therefore reset/reclaimed. StatusReasonOverPrincipalBudget StatusReason = "OverPrincipalBudget" // StatusReasonDestroyed means the lease has been deleted via an API call or other user action. StatusReasonDestroyed StatusReason = "Destroyed" // StatusReasonActive means the lease is still active. StatusReasonActive StatusReason = "Active" // StatusReasonRolledBack means something happened in the system that caused the lease to be inactive // based on an error happening and rollback occuring StatusReasonRolledBack StatusReason = "Rollback" // StatusReasonAccountOrphaned means that the health of the account was compromised. The account has been orphaned // which means the leases are also made Inactive StatusReasonAccountOrphaned StatusReason = "LeaseAccountOrphaned" )
func (StatusReason) StatusReasonPtr ¶
func (c StatusReason) StatusReasonPtr() *StatusReason
StatusReasonPtr returns a pointer to the string value of StatusReason