Documentation ¶
Overview ¶
Package claim manages data associated with the Claim Spec https://github.com/cnabio/cnab-spec/blob/cnab-claim-1.0.0-DRAFT+b5ed2f3/400-claims.md
There are three types of claim data: Claim, Result and Output. How they are stored is not dictated by the spec, however we have selected access patterns around the lowest common denominator (filesystem). Each implementation has metadata available that allow for optimizations, for example using queries based on a foreign key, if the underlying storage systems supports it. The claim data creates a hierarchy representing a fourth type of data that isn't stored but is represented in-memory: Installation.
Below is the general layout of the data assuming the filesystem as the storage layer. Claims are grouped by the name of the installation, and keyed by the claim ID. Results are grouped by the claim ID and keyed by the result ID. Outputs are grouped by the result ID and are keyed by the "ResultID-OutputName" to generate a unique key. The groups allow for querying by storage systems that support it.
claims/
INSTALLATION/ CLAIM_ID
results/
CLAIM_ID/ RESULT_ID
outputs/
RESULT_ID/ RESULT_ID-OUTPUT_NAME
Example ¶
claims/
mysql/ 01EAZDEPCBPEEHQG9C4AF5X1PY.json (install) 01EAZDEW0R8MQ0GS5D5EAQA2J9.json (upgrade) wordpress/ 01EAZDF3ARH5J2D7A30A8Z9QRW.json (install)
results/
01EAZDEPCBPEEHQG9C4AF5X1PY/ (mysql - install) 01EAZDGPM8EQKXA544AHCBMYXH.json (success) 01EAZDEW0R8MQ0GS5D5EAQA2J9 (mysql - upgrade) 01EAZDHFZJE34ND6GE3BVPP1JA (success) 01EAZDF3ARH5J2D7A30A8Z9QRW (wordpress - install) 01EAZDJ8FPR0CD8BNG8EBBGA0N (running)
outputs/
01EAZDGPM8EQKXA544AHCBMYXH/ 01EAZDGPM8EQKXA544AHCBMYXH-CONNECTIONSTRING
Index ¶
- Constants
- Variables
- func GetDefaultSchemaVersion() schema.Version
- func MustNewULID() string
- func NewULID() (string, error)
- type Claim
- func (c Claim) GetLastResult() (Result, error)
- func (c Claim) GetStatus() string
- func (c Claim) HasLogs() (hasLogs bool, ok bool)
- func (c Claim) IsModifyingAction() (bool, error)
- func (c Claim) NewClaim(action string, bun bundle.Bundle, parameters map[string]interface{}) (Claim, error)
- func (c Claim) NewResult(status string) (Result, error)
- func (c Claim) Validate() error
- type Claims
- type Installation
- type InstallationByModified
- type InstallationByName
- type Output
- type OutputMetadata
- func (o *OutputMetadata) GetContentDigest(outputName string) (string, bool)
- func (o *OutputMetadata) GetGeneratedByBundle(outputName string) (bool, bool)
- func (o OutputMetadata) GetMetadata(outputName string, metadataKey string) (string, bool)
- func (o *OutputMetadata) SetContentDigest(outputName string, contentDigest string) error
- func (o *OutputMetadata) SetGeneratedByBundle(outputName string, generatedByBundle bool) error
- func (o *OutputMetadata) SetMetadata(outputName string, metadataKey string, value string) error
- type Outputs
- type Result
- type Results
Constants ¶
const ( StatusSucceeded = "succeeded" StatusCanceled = "canceled" StatusFailed = "failed" StatusRunning = "running" StatusPending = "pending" StatusUnknown = "unknown" // Deprecated: StatusSuccess has been replaced by StatusSucceeded. StatusSuccess = StatusSucceeded // Deprecated: StatusFailure has been replaced by StatusFailed. StatusFailure = StatusFailed )
Status constants define the CNAB status fields on a Result.
const ( ActionInstall = "install" ActionUpgrade = "upgrade" ActionUninstall = "uninstall" ActionUnknown = "unknown" )
Action constants define the CNAB action to be taken
const ( // OutputContentDigest is the output metadata key for the output's content digest. OutputContentDigest = "contentDigest" // OutputGeneratedByBundle is the output metadata key for if the output was // defined by the bundle and the value was set by the invocation image. Some // outputs are created by the executing driver or CNAB tool. OutputGeneratedByBundle = "generatedByBundle" // OutputInvocationImageLogs is a well-known output name used to store the logs from the invocation image. OutputInvocationImageLogs = "io.cnab.outputs.invocationImageLogs" )
Output constants define metadata about outputs that may be stored on a claim Result.
const CNABSpecVersion string = "cnab-claim-1.0.0-DRAFT+b5ed2f3"
CNABSpecVersion represents the CNAB Spec version of the Claim that this library implements This value is prefixed with e.g. `cnab-claim-` so isn't itself valid semver.
Variables ¶
var ValidName = regexp.MustCompile("^[a-zA-Z0-9._-]+$")
ValidName is a regular expression that indicates whether a name is a valid claim name.
Functions ¶
func GetDefaultSchemaVersion ¶
GetDefaultSchemaVersion returns the default semver CNAB schema version of the Claim that this library implements
func MustNewULID ¶
func MustNewULID() string
MustNewULID generates a string representation of a ULID and panics on failure instead of returning an error.
Types ¶
type Claim ¶
type Claim struct { // SchemaVersion is the version of the claim schema. SchemaVersion schema.Version `json:"schemaVersion"` // Id of the claim. ID string `json:"id"` // Installation name. Installation string `json:"installation"` // Revision of the installation. Revision string `json:"revision"` // Created timestamp of the claim. Created time.Time `json:"created"` // Action executed against the installation. Action string `json:"action"` // Bundle is the definition of the bundle. Bundle bundle.Bundle `json:"bundle"` // BundleReference is the canonical reference to the bundle used in the action. BundleReference string `json:"bundleReference,omitempty"` // Parameters are the key/value pairs that were passed in during the operation. Parameters map[string]interface{} `json:"parameters,omitempty"` // Custom extension data applicable to a given runtime. Custom interface{} `json:"custom,omitempty"` // contains filtered or unexported fields }
Claim is an installation claim receipt.
Claims represent information about a particular installation, and provide the necessary data to upgrade and uninstall a CNAB package.
func New ¶
func New(installation string, action string, bun bundle.Bundle, parameters map[string]interface{}) (Claim, error)
New creates a new Claim initialized for an operation.
func (Claim) GetLastResult ¶
GetLastResult returns the most recent (last) result associated with the claim.
func (Claim) HasLogs ¶ added in v0.18.0
HasLogs indicates if logs were persisted for the bundle action. When ok is false, this indicates that the result is indeterminate because results are not loaded on the claim.
func (Claim) IsModifyingAction ¶
IsModifyingAction determines if the Claim's action modifies the bundle. Non-modifying actions are not required to be persisted by the Claims spec.
func (Claim) NewClaim ¶
func (c Claim) NewClaim(action string, bun bundle.Bundle, parameters map[string]interface{}) (Claim, error)
NewClaim is a convenience for creating a new claim from an existing claim.
type Installation ¶
Installation represents the installation of a bundle.
func NewInstallation ¶
func NewInstallation(name string, claims []Claim) Installation
NewInstallation creates an Installation and ensures the contained data is sorted.
func (Installation) GetInstallationTimestamp ¶
func (i Installation) GetInstallationTimestamp() (time.Time, error)
GetInstallationTimestamp searches the claims associated with the installation for the first claim for Install and returns its timestamp.
func (Installation) GetLastClaim ¶
func (i Installation) GetLastClaim() (Claim, error)
GetLastClaim returns the most recent (last) claim associated with the installation.
func (Installation) GetLastResult ¶
func (i Installation) GetLastResult() (Result, error)
GetLastResult returns the most recent (last) result associated with the installation.
func (Installation) GetLastStatus ¶
func (i Installation) GetLastStatus() string
GetLastStatus returns the status from the most recent (last) result associated with the installation, or "unknown" if it cannot be determined.
type InstallationByModified ¶
type InstallationByModified []Installation
InstallationByModified sorts installations by which has been modified most recently Assumes that the installation's claims have already been sorted first, for example with SortClaims or manually.
func (InstallationByModified) Len ¶
func (ibm InstallationByModified) Len() int
func (InstallationByModified) Less ¶
func (ibm InstallationByModified) Less(i, j int) bool
func (InstallationByModified) SortClaims ¶
func (ibm InstallationByModified) SortClaims()
SortClaims presorts the claims on each installation before the installations can be sorted.
func (InstallationByModified) Swap ¶
func (ibm InstallationByModified) Swap(i, j int)
type InstallationByName ¶
type InstallationByName []Installation
func (InstallationByName) Len ¶
func (ibn InstallationByName) Len() int
func (InstallationByName) Less ¶
func (ibn InstallationByName) Less(i, j int) bool
func (InstallationByName) Swap ¶
func (ibn InstallationByName) Swap(i, j int)
type Output ¶
type Output struct { // Name of the output. Name string // Value of the output persisted to storage. Value []byte // contains filtered or unexported fields }
Output represents a bundle output generated by an operation.
func (Output) GetDefinition ¶
GetDefinition returns the output definition, or false if the output is not defined.
type OutputMetadata ¶
OutputMetadata is the output metadata from an operation. Any metadata can be stored, however this provides methods for safely querying and retrieving well-known metadata.
func (*OutputMetadata) GetContentDigest ¶
func (o *OutputMetadata) GetContentDigest(outputName string) (string, bool)
GetContentDigest for the specified output.
func (*OutputMetadata) GetGeneratedByBundle ¶ added in v0.18.0
func (o *OutputMetadata) GetGeneratedByBundle(outputName string) (bool, bool)
GetGeneratedByBundle flag for the specified output.
func (OutputMetadata) GetMetadata ¶ added in v0.18.0
func (o OutputMetadata) GetMetadata(outputName string, metadataKey string) (string, bool)
GetMetadata for the specified output and key.
func (*OutputMetadata) SetContentDigest ¶
func (o *OutputMetadata) SetContentDigest(outputName string, contentDigest string) error
SetContentDigest for the specified output.
func (*OutputMetadata) SetGeneratedByBundle ¶ added in v0.18.0
func (o *OutputMetadata) SetGeneratedByBundle(outputName string, generatedByBundle bool) error
SetGeneratedByBundle for the specified output.
func (*OutputMetadata) SetMetadata ¶ added in v0.18.0
func (o *OutputMetadata) SetMetadata(outputName string, metadataKey string, value string) error
SetMetadata for the specified output and key.
type Result ¶
type Result struct { // Id of the result. ID string `json:"id"` // ClaimId associated with the claim that generated the result. ClaimID string `json:"claimId"` // Created timestamp of the result. Created time.Time `json:"created"` // Message communicates the outcome of the operation. Message string `json:"message,omitempty"` // Status of the operation, for example StatusSucceeded. Status string `json:"status"` // OutputMetadata generated by the operation, mapping from the output names to // metadata about the output. OutputMetadata OutputMetadata `json:"outputs,omitempty"` // Custom extension data applicable to a given runtime. Custom interface{} `json:"custom,omitempty"` // contains filtered or unexported fields }
Result tracks the result of an operation on a CNAB installation