lease

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: 12 Imported by: 0

Documentation

Index

Constants

View Source
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

func NewLease

func NewLease(input NewLeaseInput) *Lease

NewLease creates a new instance of lease

func (*Lease) Validate

func (l *Lease) Validate() error

Validate the lease data

type Leases

type Leases []Lease

Leases is a list of type Lease

type MultipleReader

type MultipleReader interface {
	List(*Lease) (*Leases, error)
}

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 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 Lease 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 *Lease, principalSpentAmount float64) (*Lease, error)

Create creates a new lease using the data provided. Returns the lease record

func (*Service) Delete

func (a *Service) Delete(ID string) (*Lease, error)

Delete finds a given lease and checks if it's active and then updates it to status `Inactive`. Returns the lease.

func (*Service) Get

func (a *Service) Get(ID string) (*Lease, error)

Get returns a lease from ID

func (*Service) GetByAccountIDAndPrincipalID added in v0.30.1

func (a *Service) GetByAccountIDAndPrincipalID(accountID string, principalID string) (*Lease, error)

GetByAccountIDAndPrincipalID gets the Lease record by AccountID and PrincipalID

func (*Service) List

func (a *Service) List(query *Lease) (*Leases, error)

List Get a list of leases based on Principal ID

func (*Service) ListPages

func (a *Service) ListPages(query *Lease, fn func(*Leases) bool) error

ListPages runs a function on each page in a list

func (*Service) Save

func (a *Service) Save(data *Lease) error

Save writes the record to the dataSvc

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

const (
	// StatusEmpty status
	StatusEmpty Status = ""
	// StatusActive status
	StatusActive Status = "Active"
	// StatusInactive status
	StatusInactive Status = "Inactive"
)

func ParseStatus

func ParseStatus(status string) (Status, error)

ParseStatus - parses the string into an account status.

func (Status) StatusPtr

func (c Status) StatusPtr() *Status

StatusPtr returns a pointer to the string value of Status

func (Status) String

func (c Status) String() string

String returns the string value of Status

func (Status) StringPtr

func (c Status) StringPtr() *string

StringPtr returns a pointer to the string value of 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

type Writer

type Writer interface {
	Write(input *Lease, lastModifiedOn *int64) 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