Documentation ¶
Index ¶
- Variables
- func CountAvailable[T AvailabilityMarker](resources []T) int
- func CountOlder(duration time.Duration, accounts []Resource) (int, error)
- func CountToCleanup[T AvailabilityMarker](resources []T) int
- func CountUsed[T AvailabilityMarker](resources []T) int
- func DeletePlacementByServiceUuid(dbpool *pgxpool.Pool, accountProvider AwsAccountProvider, serviceUuid string) error
- func Sort[T Sortable](accounts []T, by string) []T
- func Used[T AvailabilityMarker](resources []T) []T
- type Account
- type AvailabilityMarker
- type AwsAccount
- func (a AwsAccount) GetLastStatus(dbpool *pgxpool.Pool) (*LifecycleResourceJob, error)
- func (a AwsAccount) GetUpdatedAt() time.Time
- func (a AwsAccount) NameInt() int
- func (a AwsAccount) Start(creds *ststypes.Credentials) error
- func (a AwsAccount) Status(creds *ststypes.Credentials, job *LifecycleResourceJob) (Status, error)
- func (a AwsAccount) Stop(creds *ststypes.Credentials) error
- type AwsAccountProvider
- type AwsAccountWithCreds
- type AwsIamKey
- type Instance
- type LifecyclePlacementJob
- type LifecycleResourceJob
- type Model
- type Placement
- func (p *Placement) Delete(dbpool *pgxpool.Pool, accountProvider AwsAccountProvider) error
- func (p *Placement) GetLastStatus(dbpool *pgxpool.Pool) ([]*LifecycleResourceJob, error)
- func (p *Placement) LoadResources(accountProvider AwsAccountProvider) error
- func (p *Placement) LoadResourcesWithCreds(accountProvider AwsAccountProvider) error
- func (p *Placement) Render(w http.ResponseWriter, r *http.Request) error
- func (p *Placement) Save(dbpool *pgxpool.Pool) error
- type PlacementWithCreds
- type Placements
- type Resource
- type ResourceWithCreds
- type Sortable
- type Status
- type Token
- type Tokens
Constants ¶
This section is empty.
Variables ¶
var ErrAccountNotFound = errors.New("account not found")
var ErrNoClaim = errors.New("no claim")
var ErrNoEnoughAccountsAvailable = errors.New("no enough accounts available")
Functions ¶
func CountAvailable ¶
func CountAvailable[T AvailabilityMarker](resources []T) int
CountAvailable return the number of resources not in use
func CountOlder ¶
CountOlder returns the number of accounts in use for more than N day
func CountToCleanup ¶
func CountToCleanup[T AvailabilityMarker](resources []T) int
CountToCleanup return the number of accounts to cleanup
func CountUsed ¶
func CountUsed[T AvailabilityMarker](resources []T) int
CountUsed return the number of resources in use
func DeletePlacementByServiceUuid ¶
func DeletePlacementByServiceUuid(dbpool *pgxpool.Pool, accountProvider AwsAccountProvider, serviceUuid string) error
DeletePlacementByServiceUuid deletes a placement by ServiceUuid
Types ¶
type AvailabilityMarker ¶
type AvailabilityMarker interface {
// contains filtered or unexported methods
}
type AwsAccount ¶
type AwsAccount struct { Account Kind string `json:"kind"` // "aws_account" Name string `json:"name"` AccountID string `json:"account_id"` Zone string `json:"zone"` HostedZoneID string `json:"hosted_zone_id"` ConanStatus string `json:"conan_status,omitempty"` ConanTimestamp time.Time `json:"conan_timestamp,omitempty"` ConanHostname string `json:"conan_hostname,omitempty"` }
func (AwsAccount) GetLastStatus ¶ added in v0.3.0
func (a AwsAccount) GetLastStatus(dbpool *pgxpool.Pool) (*LifecycleResourceJob, error)
func (AwsAccount) GetUpdatedAt ¶
func (a AwsAccount) GetUpdatedAt() time.Time
func (AwsAccount) NameInt ¶
func (a AwsAccount) NameInt() int
func (AwsAccount) Start ¶ added in v0.3.0
func (a AwsAccount) Start(creds *ststypes.Credentials) error
Start method starts all the stopped instances in the account
func (AwsAccount) Status ¶ added in v0.3.0
func (a AwsAccount) Status(creds *ststypes.Credentials, job *LifecycleResourceJob) (Status, error)
Status method returns the status of all the instances in the account
func (AwsAccount) Stop ¶ added in v0.3.0
func (a AwsAccount) Stop(creds *ststypes.Credentials) error
Stop method stops all the running instances in the account
type AwsAccountProvider ¶
type AwsAccountProvider interface { FetchByName(name string) (AwsAccount, error) FetchAll() ([]AwsAccount, error) FetchAllToCleanup() ([]AwsAccount, error) FetchAllSorted(by string) ([]AwsAccount, error) FetchAllByServiceUuid(serviceUuid string) ([]AwsAccount, error) FetchAllByServiceUuidWithCreds(serviceUuid string) ([]AwsAccountWithCreds, error) Request(service_uuid string, count int, annotations map[string]string) ([]AwsAccountWithCreds, error) MarkForCleanup(name string) error MarkForCleanupByServiceUuid(serviceUuid string) error DecryptSecret(encrypted string) (string, error) }
AwsAccountProvider interface to interact with different databases: dynamodb and postgresql
type AwsAccountWithCreds ¶
type AwsAccountWithCreds struct { AwsAccount Credentials []any `json:"credentials"` }
type LifecyclePlacementJob ¶ added in v0.3.0
type LifecyclePlacementJob struct { Model PlacementID int `json:"placement_id"` Status string `json:"status"` Action string `json:"lifecycle_action"` Request any `json:"request,omitempty"` RequestID string `json:"request_id,omitempty"` DbPool *pgxpool.Pool `json:"dbpool"` }
func GetLifecyclePlacementJob ¶ added in v0.3.0
func GetLifecyclePlacementJob(dbpool *pgxpool.Pool, id int) (*LifecyclePlacementJob, error)
GetLifecyclePlacementJob returns a LifecyclePlacementJob by ID
func GetLifecyclePlacementJobByRequestID ¶ added in v0.3.3
func GetLifecyclePlacementJobByRequestID(dbpool *pgxpool.Pool, requestID string) (*LifecyclePlacementJob, error)
GetLifecyclePlacementJob returns a LifecyclePlacementJob by ID
func (*LifecyclePlacementJob) Claim ¶ added in v0.3.0
func (j *LifecyclePlacementJob) Claim() error
ClaimPlacementJob claims a placement job by setting the status to initializing
func (*LifecyclePlacementJob) Create ¶ added in v0.3.3
func (j *LifecyclePlacementJob) Create() error
Create creates a new LifecyclePlacementJob by inserting it into the database
func (*LifecyclePlacementJob) GlobalStatus ¶ added in v0.3.3
func (j *LifecyclePlacementJob) GlobalStatus() (string, error)
GlobalStatus returns the status of a LifecyclePlacementJob considering all it's children
func (*LifecyclePlacementJob) SetStatus ¶ added in v0.3.0
func (j *LifecyclePlacementJob) SetStatus(status string) error
SetLifecycleResourceJobStatus sets the status of a LifecycleResourceJob
type LifecycleResourceJob ¶ added in v0.3.0
type LifecycleResourceJob struct { Model ResourceName string `json:"resource_name"` ResourceType string `json:"resource_type"` ParentID int `json:"parent_id,omitempty"` Status string `json:"status"` Action string `json:"lifecycle_action"` Request any `json:"request,omitempty"` RequestID string `json:"request_id,omitempty"` DbPool *pgxpool.Pool `json:"dbpool,omitempty"` Result Status `json:"lifecycle_result,omitempty"` }
func GetLifecycleResourceJob ¶ added in v0.3.0
func GetLifecycleResourceJob(dbpool *pgxpool.Pool, id int) (*LifecycleResourceJob, error)
GetLifecycleResourceJob returns a LifecycleResourceJob by ID
func GetLifecycleResourceJobByRequestID ¶ added in v0.3.3
func GetLifecycleResourceJobByRequestID(dbpool *pgxpool.Pool, requestID string) (*LifecycleResourceJob, error)
func (*LifecycleResourceJob) Claim ¶ added in v0.3.0
func (j *LifecycleResourceJob) Claim() error
ClaimResourceJob claims a resource job by setting the status to initializing
func (*LifecycleResourceJob) Create ¶ added in v0.3.0
func (j *LifecycleResourceJob) Create() error
Create creates a new LifecycleResourceJob by inserting it into the database
func (*LifecycleResourceJob) SetStatus ¶ added in v0.3.0
func (j *LifecycleResourceJob) SetStatus(status string) error
SetLifecycleResourceJobStatus sets the status of a LifecycleResourceJob
type Placement ¶
type Placement struct { Model ServiceUuid string `json:"service_uuid"` Resources []any `json:"resources,omitempty"` Annotations map[string]string `json:"annotations"` Request any `json:"request"` }
func GetPlacement ¶
GetPlacement returns a placement by ID
func GetPlacementByServiceUuid ¶
GetPlacementByServiceUuid returns a placement by service_uuid
func (*Placement) Delete ¶
func (p *Placement) Delete(dbpool *pgxpool.Pool, accountProvider AwsAccountProvider) error
func (*Placement) GetLastStatus ¶ added in v0.3.3
func (p *Placement) GetLastStatus(dbpool *pgxpool.Pool) ([]*LifecycleResourceJob, error)
func (*Placement) LoadResources ¶
func (p *Placement) LoadResources(accountProvider AwsAccountProvider) error
func (*Placement) LoadResourcesWithCreds ¶ added in v0.3.1
func (p *Placement) LoadResourcesWithCreds(accountProvider AwsAccountProvider) error
type PlacementWithCreds ¶
type Placements ¶
type Placements []Placement
func GetAllPlacements ¶
func GetAllPlacements(dbpool *pgxpool.Pool) (Placements, error)
func (Placements) Render ¶
func (p Placements) Render(w http.ResponseWriter, r *http.Request) error
type ResourceWithCreds ¶
type Status ¶ added in v0.3.0
type Status struct { AccountName string `json:"account_name"` AccountKind string `json:"account_kind"` Instances []Instance `json:"instances"` UpdatedAt time.Time `json:"updated_at,omitempty"` Status string `json:"status,omitempty"` }
Status type
func MakeStatus ¶ added in v0.3.3
func MakeStatus(job *LifecycleResourceJob) Status