claims

package
v1.0.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CollectionInstallations = "installations"
	CollectionRuns          = "runs"
	CollectionResults       = "results"
	CollectionOutputs       = "outputs"
)
View Source
const (
	// SchemaVersion represents the version associated with the schema
	// for all installation documents: installations, runs, results and outputs.
	SchemaVersion = schema.Version("1.0.0")
)

Variables

This section is empty.

Functions

func CNABSchemaVersion

func CNABSchemaVersion() schema.Version

CNABSchemaVersion is the schemaVersion value for CNAB documents such as claims.

Types

type ClaimStore

type ClaimStore struct {
	// contains filtered or unexported fields
}

ClaimStore is a persistent store for claims.

func NewClaimStore

func NewClaimStore(datastore storage.Store) ClaimStore

NewClaimStore creates a persistent store for claims using the specified backing datastore.

func (ClaimStore) GetInstallation

func (s ClaimStore) GetInstallation(namespace string, name string) (Installation, error)

func (ClaimStore) GetLastLogs

func (s ClaimStore) GetLastLogs(namespace string, installation string) (string, bool, error)

func (ClaimStore) GetLastOutput

func (s ClaimStore) GetLastOutput(namespace string, installation string, name string) (Output, error)

func (ClaimStore) GetLastOutputs

func (s ClaimStore) GetLastOutputs(namespace string, installation string) (Outputs, error)

func (ClaimStore) GetLastRun

func (s ClaimStore) GetLastRun(namespace string, installation string) (Run, error)

func (ClaimStore) GetLogs

func (s ClaimStore) GetLogs(runID string) (string, bool, error)

func (ClaimStore) GetResult

func (s ClaimStore) GetResult(id string) (Result, error)

func (ClaimStore) GetRun

func (s ClaimStore) GetRun(id string) (Run, error)

func (ClaimStore) Initialize

func (s ClaimStore) Initialize() error

func (ClaimStore) InsertInstallation

func (s ClaimStore) InsertInstallation(installation Installation) error

func (ClaimStore) InsertOutput

func (s ClaimStore) InsertOutput(output Output) error

func (ClaimStore) InsertResult

func (s ClaimStore) InsertResult(result Result) error

func (ClaimStore) InsertRun

func (s ClaimStore) InsertRun(run Run) error

func (ClaimStore) ListInstallations

func (s ClaimStore) ListInstallations(namespace string, name string, labels map[string]string) ([]Installation, error)

func (ClaimStore) ListOutputs

func (s ClaimStore) ListOutputs(resultID string) ([]Output, error)

func (ClaimStore) ListResults

func (s ClaimStore) ListResults(runID string) ([]Result, error)

func (ClaimStore) ListRuns

func (s ClaimStore) ListRuns(namespace string, installation string) ([]Run, error)

func (ClaimStore) RemoveInstallation

func (s ClaimStore) RemoveInstallation(namespace string, name string) error

RemoveInstallation and all associated data.

func (ClaimStore) UpdateInstallation

func (s ClaimStore) UpdateInstallation(installation Installation) error

func (ClaimStore) UpsertInstallation

func (s ClaimStore) UpsertInstallation(installation Installation) error

func (ClaimStore) UpsertRun

func (s ClaimStore) UpsertRun(run Run) error

type EncryptionHandler

type EncryptionHandler func([]byte) ([]byte, error)

EncryptionHandler is a function that transforms data by encrypting or decrypting it.

type Installation

type Installation struct {
	// SchemaVersion is the version of the installation state schema.
	SchemaVersion schema.Version `json:"schemaVersion" yaml:"schemaVersion" toml:"schemaVersion"`

	// Name of the installation. Immutable.
	Name string `json:"name" yaml:"name" toml:"name"`

	// Namespace in which the installation is defined.
	Namespace string `json:"namespace" yaml:"namespace" toml:"namespace"`

	// Created timestamp of the installation.
	Created time.Time `json:"created" yaml:"created" toml:"created"`

	// Modified timestamp of the installation.
	Modified time.Time `json:"modified" yaml:"modified" toml:"modified"`

	// BundleRepository is the OCI repository of the current bundle definition.
	BundleRepository string `json:"bundleRepository,omitempty" yaml:"bundleRepository,omitempty" toml:"bundleRepository,omitempty"`

	// BundleVersion is the current version of the bundle.
	BundleVersion string `json:"bundleVersion,omitempty" yaml:"bundleVersion,omitempty" toml:"bundleVersion,omitempty"`

	// BundleDigest is the current digest of the bundle.
	BundleDigest string `json:"bundleDigest,omitempty" yaml:"bundleDigest,omitempty" toml:"bundleDigest,omitempty"`

	// BundleTag is the OCI tag of the current bundle definition.
	BundleTag string `json:"bundleTag,omitempty" yaml:"bundleTag,omitempty" toml:"bundleTag,omitempty"`

	// Custom extension data applicable to a given runtime.
	// TODO(carolynvs): remove and populate in ToCNAB when we firm up the spec
	Custom interface{} `json:"custom,omitempty" yaml:"custom,omitempty" toml:"custom,omitempty"`

	// Labels applied to the installation.
	Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty" toml:"labels,omitempty"`

	// Parameters specified by the user through overrides.
	// Does not include defaults, or values resolved from parameter sources.
	Parameters map[string]interface{} `json:"parameters,omitempty" yaml:"parameters,omitempty" toml:"parameters,omitempty"`

	// CredentialSets that should be included when the bundle is reconciled.
	CredentialSets []string `json:"credentialSets,omitempty" yaml:"credentialSets,omitempty" toml:"credentialSets,omitempty"`

	// ParameterSets that should be included when the bundle is reconciled.
	ParameterSets []string `json:"parameterSets,omitempty" yaml:"parameterSets,omitempty" toml:"parameterSets,omitempty"`

	// Status of the installation.
	Status InstallationStatus `json:"status,omitempty" yaml:"status,omitempty" toml:"status,omitempty"`
}

func NewInstallation

func NewInstallation(namespace string, name string) Installation

func (*Installation) Apply

func (i *Installation) Apply(input Installation)

Apply user-provided changes to an existing installation. Only updates fields that users are allowed to modify. For example, Name, Namespace and Status cannot be modified.

func (*Installation) ApplyResult

func (i *Installation) ApplyResult(run Run, result Result)

ApplyResult updates cached status data on the installation from the last bundle run.

func (Installation) DefaultDocumentFilter

func (i Installation) DefaultDocumentFilter() interface{}

func (Installation) GetBundleReference

func (i Installation) GetBundleReference() (cnab.OCIReference, bool, error)

func (Installation) NewRun

func (i Installation) NewRun(action string) Run

NewRun creates a run of the current bundle.

func (*Installation) SetLabel

func (i *Installation) SetLabel(key string, value string)

SetLabel on the installation.

func (Installation) String

func (i Installation) String() string

func (Installation) ToCNAB

func (i Installation) ToCNAB() cnab.Installation

func (*Installation) TrackBundle

func (i *Installation) TrackBundle(ref cnab.OCIReference)

TrackBundle updates the bundle that the installation is tracking.

func (*Installation) Validate

func (i *Installation) Validate() error

Validate the installation document and report the first error.

type InstallationStatus

type InstallationStatus struct {
	// RunID of the bundle execution that last altered the installation status.
	RunID string `json:"runId" yaml:"runId" toml:"runId"`

	// Action of the bundle run that last informed the installation status.
	Action string `json:"action" yaml:"action" toml:"action"`

	// ResultID of the result that last informed the installation status.
	ResultID string `json:"resultId" yaml:"resultId" toml:"resultId"`

	// ResultStatus is the status of the result that last informed the installation status.
	ResultStatus string `json:"resultStatus" yaml:"resultStatus" toml:"resultStatus"`

	// InstallationCompleted indicates if the install action has successfully completed for this installation.
	// Once that state is reached, Porter should not allow it to be reinstalled as a protection from installations
	// being overwritten.
	InstallationCompleted bool `json:"installationCompleted" yaml:"installationCompleted" toml:"installationCompleted"`

	// BundleReference of the bundle that last altered the installation state.
	BundleReference string `json:"bundleReference" yaml:"bundleReference" toml:"bundleReference"`

	// BundleVersion is the version of the bundle that last altered the installation state.
	BundleVersion string `json:"bundleVersion" yaml:"bundleVersion" toml:"bundleVersion"`

	// BundleDigest is the digest of the bundle that last altered the installation state.
	BundleDigest string `json:"bundleDigest" yaml:"bundleDigest" toml:"bundleDigest"`
}

InstallationStatus's purpose is to assist with making porter list be able to display everything with a single database query. Do not replicate data available on Run and Result here.

type Output

type Output struct {
	SchemaVersion schema.Version `json:"schemaVersion" yaml:"schemaVersion" toml:"schemaVersion"`
	Name          string         `json:"name" yaml:"name" toml:"name"`
	Namespace     string         `json:"namespace" yaml:"namespace" toml:"namespace"`
	Installation  string         `json:"installation" yaml:"installation" toml:"installation"`
	RunID         string         `json:"runId" yaml:"runId" toml:"runId"`
	ResultID      string         `json:"resultId" yaml:"resultId" toml:"resultId"`
	Value         []byte         `json:"value" yaml:"value" toml:"value"`
}

func (Output) DefaultDocumentFilter

func (o Output) DefaultDocumentFilter() interface{}

func (Output) GetSchema

func (o Output) GetSchema(b cnab.ExtendedBundle) (definition.Schema, bool)

GetSchema returns the schema for the output from the specified bundle, or false if the schema is not defined.

type OutputMetadata

type OutputMetadata = cnabclaims.OutputMetadata

type Outputs

type Outputs struct {
	// contains filtered or unexported fields
}

func NewOutputs

func NewOutputs(outputs []Output) Outputs

func (Outputs) GetByIndex

func (o Outputs) GetByIndex(i int) (Output, bool)

func (Outputs) GetByName

func (o Outputs) GetByName(name string) (Output, bool)

func (Outputs) Len

func (o Outputs) Len() int

func (Outputs) Less

func (o Outputs) Less(i, j int) bool

func (Outputs) Swap

func (o Outputs) Swap(i, j int)

type Provider

type Provider interface {
	// InsertInstallation saves a new Installation document.
	InsertInstallation(installation Installation) error

	// InsertRun saves a new Run document.
	InsertRun(run Run) error

	// InsertResult saves a new Result document.
	InsertResult(result Result) error

	// InsertOutput saves a new Output document.
	InsertOutput(output Output) error

	// UpdateInstallation saves changes to an existing Installation document.
	UpdateInstallation(installation Installation) error

	// UpsertRun saves changes a Run document, creating it if it doesn't already exist.
	UpsertRun(run Run) error

	// UpsertInstallation saves an Installation document, creating it if it doesn't already exist.
	UpsertInstallation(installation Installation) error

	// GetInstallation retrieves an Installation document by name.
	GetInstallation(namespace string, name string) (Installation, error)

	// ListInstallations returns Installations sorted in ascending order by the namespace and then name.
	ListInstallations(namespace string, name string, labels map[string]string) ([]Installation, error)
	// ListRuns returns Run documents sorted in ascending order by ID.
	ListRuns(namespace string, installation string) ([]Run, error)

	// ListResults returns Result documents sorted in ascending order by ID.
	ListResults(runID string) ([]Result, error)

	// ListOutputs returns Output documents sorted in ascending order by name.
	ListOutputs(resultID string) ([]Output, error)

	// GetRun returns a Run document by ID.
	GetRun(id string) (Run, error)

	// GetResult returns a Result document by ID.
	GetResult(id string) (Result, error)

	// GetLastRun returns the last run of an Installation.
	GetLastRun(namespace string, installation string) (Run, error)

	// GetLastOutput returns the most recent value (last) of the specified
	// Output associated with the installation.
	GetLastOutput(namespace string, installation string, name string) (Output, error)

	// GetLastOutputs returns the most recent (last) value of each Output
	// associated with the installation.
	GetLastOutputs(namespace string, installation string) (Outputs, error)

	// RemoveInstallation by its name.
	RemoveInstallation(namespace string, name string) error

	// GetLogs returns the logs from the specified Run.
	GetLogs(runID string) (logs string, hasLogs bool, err error)

	// GetLastLogs returns the logs from the last run of an Installation.
	GetLastLogs(namespace string, installation string) (logs string, hasLogs bool, err error)
}

Provider is an interface for interacting with Porter's claim data.

type Result

type Result struct {
	// SchemaVersion of the document.
	SchemaVersion schema.Version `json:"schemaVersion" yaml:"schemaVersion" toml:"schemaVersion"`

	// ID of the result.
	ID string `json:"_id" yaml:"_id" toml:"_id"`

	// Created timestamp of the result.
	Created time.Time `json:"created" yaml:"created" toml:"created"`

	// Namespace of the installation.
	Namespace string `json:"namespace" yaml:"namespace" toml:"namespace"`

	// Installation name that owns this result.
	Installation string `json:"installation" yaml:"installation" toml:"installation"`

	// RunID of the run that generated this result.
	RunID string `json:"runId" yaml:"runId" toml:"runId"`

	// Message communicates the outcome of the operation.
	Message string `json:"message,omitempty" yaml:"message,omitempty" toml:"message,omitempty"`

	// Status of the operation, for example StatusSucceeded.
	Status string `json:"status" yaml:"status" toml:"status"`

	// OutputMetadata generated by the operation, mapping from the output names to
	// metadata about the output.
	OutputMetadata OutputMetadata `json:"outputs" yaml:"outputs" toml:"outputs"`

	// Custom extension data applicable to a given runtime.
	Custom interface{} `json:"custom,omitempty" yaml:"custom,omitempty" toml:"custom,omitempty"`
}

func NewResult

func NewResult() Result

func (Result) DefaultDocumentFilter

func (r Result) DefaultDocumentFilter() interface{}

func (Result) NewOutput

func (r Result) NewOutput(name string, data []byte) Output

type Run

type Run struct {
	// SchemaVersion of the document.
	SchemaVersion schema.Version `json:"schemaVersion" yaml:"schemaVersion" toml:"schemaVersion"`

	// ID of the Run.
	ID string `json:"_id" yaml:"_id", toml:"_id"`

	// Created timestamp of the Run.
	Created time.Time `json:"created" yaml:"created", toml:"created"`

	// Namespace of the installation.
	Namespace string `json:"namespace" yaml:"namespace", toml:"namespace"`

	// Installation name.
	Installation string `json:"installation" yaml:"installation", toml:"installation"`

	// Revision of the installation.
	Revision string `json:"revision" yaml:"revision", toml:"revision"`

	// Action executed against the installation.
	Action string `json:"action" yaml:"action", toml:"action"`

	// Bundle is the definition of the bundle.
	Bundle bundle.Bundle `json:"bundle" yaml:"bundle", toml:"bundle"`

	// BundleReference is the canonical reference to the bundle used in the action.
	BundleReference string `json:"bundleReference" yaml:"bundleReference", toml:"bundleReference"`

	// BundleDigest is the digest of the bundle.
	// TODO(carolynvs): populate this
	BundleDigest string `json:"bundleDigest" yaml:"bundleDigest", toml:"bundleDigest"`

	// Parameters are the key/value pairs that were passed in during the operation.
	Parameters map[string]interface{} `json:"parameters" yaml:"parameters", toml:"parameters"`

	// Custom extension data applicable to a given runtime.
	// TODO(carolynvs): remove custom and populate it in ToCNAB
	Custom interface{} `json:"custom" yaml:"custom", toml:"custom"`
}

Run represents the execution of an installation's bundle.

func NewRun

func NewRun(namespace string, installation string) Run

NewRun creates a run with default values initialized.

func (Run) DefaultDocumentFilter

func (r Run) DefaultDocumentFilter() interface{}

func (Run) NewResult

func (r Run) NewResult(status string) Result

NewRun creates a result for the current Run.

func (Run) NewResultFrom

func (r Run) NewResultFrom(cnabResult cnab.Result) Result

NewResultFrom creates a result from the output of a CNAB run.

func (Run) ShouldRecord

func (r Run) ShouldRecord() bool

ShouldRecord the current run in the Installation history. Runs are only recorded for actions that modify the bundle resources, or for stateful actions. Stateless actions do not require an existing installation or credentials, and are for actions such as documentation, dry-run, etc.

func (Run) ToCNAB

func (r Run) ToCNAB() cnab.Claim

ToCNAB associated with the Run.

type TestClaimProvider

type TestClaimProvider struct {
	ClaimStore
	storage.TestStore
	// contains filtered or unexported fields
}

func NewTestClaimProvider

func NewTestClaimProvider(t *testing.T) *TestClaimProvider

func NewTestClaimProviderFor

func NewTestClaimProviderFor(t *testing.T, testStore storage.TestStore) *TestClaimProvider

func (*TestClaimProvider) CreateInstallation

func (p *TestClaimProvider) CreateInstallation(i Installation, transformations ...func(i *Installation)) Installation

CreateInstallation creates a new test installation and saves it.

func (*TestClaimProvider) CreateOutput added in v0.28.0

func (p *TestClaimProvider) CreateOutput(o Output, transformations ...func(o *Output)) Output

CreateOutput creates a new output from the specified claim and result and saves it.

func (*TestClaimProvider) CreateResult added in v0.28.0

func (p *TestClaimProvider) CreateResult(r Result, transformations ...func(r *Result)) Result

CreateResult creates a new result from the specified claim and saves it.

func (*TestClaimProvider) CreateRun

func (p *TestClaimProvider) CreateRun(r Run, transformations ...func(r *Run)) Run

CreateRun creates a new claim and saves it.

func (*TestClaimProvider) SetMutableInstallationValues

func (p *TestClaimProvider) SetMutableInstallationValues(i *Installation)

func (*TestClaimProvider) SetMutableResultValues

func (p *TestClaimProvider) SetMutableResultValues(r *Result)

func (*TestClaimProvider) SetMutableRunValues

func (p *TestClaimProvider) SetMutableRunValues(r *Run)

func (*TestClaimProvider) Teardown

func (p *TestClaimProvider) Teardown() error

Jump to

Keyboard shortcuts

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