resource

package
v0.0.0-...-efc9231 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: AGPL-3.0 Imports: 14 Imported by: 24

Documentation

Overview

Package resources provides core functionality for the "resources" feature in Juju.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsMap

func AsMap(resources []Resource) map[string]Resource

AsMap returns the mapping of resource name to info for each of the given resources.

func DeserializeFingerprint

func DeserializeFingerprint(fpSum []byte) (resource.Fingerprint, error)

DeserializeFingerprint converts the serialized fingerprint back into a Fingerprint. "zero" values are treated appropriately.

func Sort

func Sort(resources []Resource)

Sort sorts the provided resources.

Types

type ApplicationResources

type ApplicationResources struct {
	// Resources are the current version of the resource for the application that
	// resource-get will retrieve.
	Resources []Resource

	// RepositoryResources provides the resource info from the charm
	// store for each of the application's resources. The information from
	// the charm store is current as of the last time the charm store
	// was polled. Each entry here corresponds to the same indexed entry
	// in the Resources field.
	RepositoryResources []resource.Resource

	// UnitResources reports the currently-in-use version of resources for each
	// unit.
	UnitResources []UnitResources
}

ApplicationResources contains the list of resources for the application and all its units.

func (ApplicationResources) Updates

func (sr ApplicationResources) Updates() ([]resource.Resource, error)

Updates returns the list of charm store resources corresponding to the application's resources that are out of date. If there is a charm store resource with a different revision than the one used into the application, it will be returned. Any charm store resources with the same revision number from the corresponding application resources will be filtered out.

type BasicAuthConfig

type BasicAuthConfig struct {
	// Auth is the base64 encoded "username:password" string.
	Auth *Token

	// Username holds the username used to gain access to a non-public image.
	Username string

	// Password holds the password used to gain access to a non-public image.
	Password string
}

BasicAuthConfig contains authorization information for basic auth.

func (BasicAuthConfig) Empty

func (ba BasicAuthConfig) Empty() bool

Empty checks if the auth information is empty.

type Content

type Content struct {
	// Data holds the resource content, ready to be read (once).
	Data io.Reader

	// Size is the byte count of the data.
	Size int64

	// Fingerprint holds the checksum of the data.
	Fingerprint charmresource.Fingerprint
}

Content holds a reader for the content of a resource along with details about that content.

func GenerateContent

func GenerateContent(reader io.ReadSeeker) (Content, error)

GenerateContent returns a new Content for the given data stream.

type DockerImageDetails

type DockerImageDetails struct {
	// RegistryPath holds the path of the Docker image (including host and sha256) in a docker registry.
	RegistryPath string

	ImageRepoDetails
}

DockerImageDetails holds the details for a Docker resource type.

func (DockerImageDetails) IsPrivate

func (did DockerImageDetails) IsPrivate() bool

IsPrivate shows if the image repo is private or not.

type ImageRepoDetails

type ImageRepoDetails struct {
	BasicAuthConfig
	TokenAuthConfig

	// Repository is the namespace of the image repo.
	Repository string

	// ServerAddress is the auth server address.
	ServerAddress string

	// Region is the cloud region.
	Region string
}

ImageRepoDetails contains authorization information for connecting to a Registry.

func (ImageRepoDetails) IsPrivate

func (rid ImageRepoDetails) IsPrivate() bool

IsPrivate checks if the repository detail is private.

type Opened

type Opened struct {
	Resource
	io.ReadCloser
}

Opened provides both the resource info and content.

func (Opened) Close

func (o Opened) Close() error

func (Opened) Content

func (o Opened) Content() Content

Content returns the "content" for the opened resource.

type Opener

type Opener interface {
	// OpenResource returns an opened resource with a reader that will
	// stream the resource content.
	OpenResource(ctx context.Context, name string) (Opened, error)

	// SetResource records that the resource is currently in use.
	SetResourceUsed(ctx context.Context, resName string) error
}

Opener exposes the functionality for opening a resource.

type Resource

type Resource struct {
	resource.Resource

	UUID UUID

	// ApplicationName identifies the application name for the resource
	ApplicationName string

	// RetrievedBy is the name of who added the resource to the controller.
	// The name is a username if the resource is uploaded from the cli
	// by a specific user. If the resource is downloaded from a repository,
	// the ID of the unit which triggered the download is used.
	RetrievedBy string

	// Timestamp indicates when this resource was added to the model in
	// the case of applications or when this resource was loaded by a unit.
	Timestamp time.Time
}

Resource defines a single resource within a Juju model.

Each application will have exactly the same resources associated with it as are defined in the charm's metadata, no more, no less. When associated with the application the resource may have additional information associated with it.

A resource may be a "placeholder", meaning it is only partially populated before an upload (whether local or from the charm store). In that case the following fields are not set:

UUID, Timestamp, RetrievedBy

For "upload" placeholders, the following additional fields are not set:

Fingerprint, Size

func (Resource) IsPlaceholder

func (res Resource) IsPlaceholder() bool

IsPlaceholder indicates if the resource is a "placeholder" (partially populated pending an upload).

func (Resource) RevisionString

func (res Resource) RevisionString() string

RevisionString returns the human-readable revision for the resource.

func (Resource) TimestampGranular

func (res Resource) TimestampGranular() time.Time

TimestampGranular returns the timestamp at a resolution of 1 second.

func (Resource) Validate

func (res Resource) Validate() error

Validate ensures that the spec is valid.

type RetrievedByType

type RetrievedByType string

RetrievedByType indicates what the RetrievedBy name represents.

const (
	Unknown     RetrievedByType = "unknown"
	Application RetrievedByType = "application"
	Unit        RetrievedByType = "unit"
	User        RetrievedByType = "user"
)

func (RetrievedByType) String

func (r RetrievedByType) String() string

type State

type State string

State identifies the resource state in an application

const (
	// StateAvailable represents a resource which will be used by any units at
	// this point in time
	StateAvailable State = "available"

	// StatePotential indicates there is a different revision of the resource
	// available in a repository. Used to let users know a resource can be
	// upgraded.
	StatePotential State = "potential"
)

These are the valid resource states.

func ParseState

func ParseState(value string) (State, error)

ParseState converts the provided string into an State. If it is not a known state then an error is returned.

func (State) String

func (o State) String() string

String returns the printable representation of the state.

func (State) Validate

func (o State) Validate() error

Validate ensures that the state is correct.

type Token

type Token struct {
	// Value is the value of the token.
	Value string

	// ExpiresAt is the unix time in seconds and milliseconds when the authorization token expires.
	ExpiresAt *time.Time
}

Token defines a token value with expiration time.

func NewToken

func NewToken(value string) *Token

NewToken creates a Token.

func (*Token) Content

func (t *Token) Content() string

Content returns the raw content of the token.

func (*Token) Empty

func (t *Token) Empty() bool

Empty checks if the auth information is empty.

type TokenAuthConfig

type TokenAuthConfig struct {
	Email string

	// IdentityToken is used to authenticate the user and get
	// an access token for the registry.
	IdentityToken *Token

	// RegistryToken is a bearer token to be sent to a registry
	RegistryToken *Token
}

TokenAuthConfig contains authorization information for token auth. Juju does not support the docker credential helper because k8s does not support it either. https://kubernetes.io/docs/concepts/containers/images/#configuring-nodes-to-authenticate-to-a-private-registry

func (TokenAuthConfig) Empty

func (ac TokenAuthConfig) Empty() bool

Empty checks if the auth information is empty.

type UUID

type UUID string

UUID represents a resource unique identifier.

func NewUUID

func NewUUID() (UUID, error)

NewUUID is a convince function for generating a new resource uuid.

func ParseUUID

func ParseUUID(value string) (UUID, error)

ParseUUID returns a new UUID from the given string. If the string is not a valid uuid an error satisfying errors.NotValid will be returned.

func (UUID) String

func (u UUID) String() string

String implements the stringer interface for UUID.

func (UUID) Validate

func (u UUID) Validate() error

Validate ensures the consistency of the UUID. If the uuid is invalid an error satisfying errors.NotValid will be returned.

type UnitResources

type UnitResources struct {
	// Name is the name of the unit.
	Name coreunit.Name

	// Resources are the resource versions currently in use by this unit.
	Resources []Resource
}

UnitResources contains the list of resources used by a unit.

Directories

Path Synopsis
Package testing provides helpers for testing with resources.
Package testing provides helpers for testing with resources.

Jump to

Keyboard shortcuts

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