db

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Credential

type Credential struct {
	ID          manifold.ID       `json:"id"`
	Keys        map[string]string `json:"keys"`
	CustomNames map[string]string `json:"custom_names"`
	CreatedOn   time.Time         `json:"created_on"`
	// Internal Fields
	ResourceID manifold.ID `json:"-"`
}

Credential represents a credential set for a resource

type DB

type DB struct {
	ResourcesByID         map[manifold.ID]Resource
	CredentialsByResource map[manifold.ID][]Credential
	CredentialsByID       map[manifold.ID]Credential
	MeasuresByResource    map[manifold.ID][]Measure
}

DB functions as an in-memory database of marketplace entities

func New

func New() *DB

New creates a new DB instance in-memory

func (*DB) DeleteCredential

func (db *DB) DeleteCredential(id manifold.ID) bool

DeleteCredential removes a credential and returns true, false if there was no credential

func (*DB) DeleteResource

func (db *DB) DeleteResource(id manifold.ID) bool

DeleteResource removes a resource and returns true, false if there was no resource

func (*DB) GetCredential

func (db *DB) GetCredential(id manifold.ID) *Credential

GetCredential returns a credential based on it's id or nil, if it can't be found

func (*DB) GetCredentialsByResource

func (db *DB) GetCredentialsByResource(id manifold.ID) []Credential

GetCredentialsByResource returns a list of credentials or nil, for a ResourceID

func (*DB) GetMeasuresByResource

func (db *DB) GetMeasuresByResource(id manifold.ID) []Measure

GetMeasuresByResource returns a list of measures or nil, for a ResourceID

func (*DB) GetResource

func (db *DB) GetResource(id manifold.ID) *Resource

GetResource returns a resource based on it's id or nil, if it can't be found

func (*DB) PutCredential

func (db *DB) PutCredential(c Credential)

PutCredential stores the provided credential, it must have a ResourceID set!

func (*DB) PutMeasure

func (db *DB) PutMeasure(m Measure)

PutMeasure stores the provided measure, it must have a ResourceID set!

func (*DB) PutResource

func (db *DB) PutResource(r Resource)

PutResource stores the provided resource in the database

type Measure

type Measure struct {
	ResourceID  manifold.ID      `json:"resource_id"`
	PeriodStart time.Time        `json:"period_start"`
	PeriodEnd   time.Time        `json:"period_end"`
	Measures    map[string]int64 `json:"measures"`
	// Internal Fields
	UpdatedAt time.Time `json:"-"`
}

Measure represents a measures set for a resource

type Resource

type Resource struct {
	ID        manifold.ID         `json:"id"`
	Name      manifold.Name       `json:"name"`
	Label     manifold.Label      `json:"label"`
	Plan      manifold.Label      `json:"plan"`
	Product   manifold.Label      `json:"product"`
	Region    string              `json:"region"`
	Features  manifold.FeatureMap `json:"features,omitempty"`
	CreatedAt time.Time           `json:"created_at"`
	UpdatedAt time.Time           `json:"updated_at"`
	// Internal Fields
	State ResourceState `json:"-"`
}

Resource represents a resource provisioned through Grafton

type ResourceState

type ResourceState string

ResourceState defines the current state of the resource

const (
	// ResourceStateProvisioning defines the state for the resource when its "provisioning"
	ResourceStateProvisioning ResourceState = "provisioning"
	// ResourceStateProvisioned defines the state for the resource when its "provisioned"
	ResourceStateProvisioned ResourceState = "provisioned"
	// ResourceStateProvisionFailed defines the state for the resource when it has failed provisioning
	ResourceStateProvisionFailed ResourceState = "provision-failed"
	// ResourceStateDerovisioning defines the state for the resource when its "deprovisioning"
	ResourceStateDerovisioning ResourceState = "deprovisioning"
	// ResourceStateDeprovisioned defines the state for the resource when its "deprovisioned"
	ResourceStateDeprovisioned ResourceState = "deprovisioned"
)

Jump to

Keyboard shortcuts

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