core

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 10 Imported by: 88

Documentation

Index

Constants

View Source
const (
	ExposedCommandServiceAccountCreate = "service-account-create"
	ExposedCommandServiceAccountRemove = "service-account-remove"
	ExposedCommandBackupConsumer       = "backup-consumer"
	ExposedCommandPreBackup            = "pre-backup"
	ExposedCommandPostBackup           = "post-backup"
	ExposedCommandPostUpgrade          = "post-upgrade"
	ExposedCommandPreUpgrade           = "pre-upgrade"
	ExposedCommandUpgradeNotification  = "upgrade-notification"
)

Names for ExposedCommands correspond with actual dogu descriptor instance values. Do not change because these come with side effects.

View Source
const (
	DependencyTypeDogu    = "dogu"
	DependencyTypeClient  = "client"
	DependencyTypePackage = "package"
)

Contains the different kind of types supported by dogu dependencies

Variables

View Source
var GetLogger = func() logrus.FieldLogger { return logrus.StandardLogger() }

GetLogger is an alias function to provide a different logger for the core.

Functions

func ContainsDoguWithName

func ContainsDoguWithName(dogus []*Dogu, name string) bool

ContainsDoguWithName checks if a dogu is contained in a slice by comparing the full name (including namespace)

func GetContentOfFile

func GetContentOfFile(path string) (string, error)

GetContentOfFile all content of the file at the given path and returns it as string

func GetNamespace

func GetNamespace(fullDoguName string) string

GetNamespace returns a dogu's namespace.

func GetSimpleDoguName

func GetSimpleDoguName(fullDoguName string) string

GetSimpleDoguName returns the dogu name without its namespace.

func PrintDogus

func PrintDogus(dogus []*Dogu, ns bool)

PrintDogus prints out dogu name, version, display name and description in a table

func ReadDoguFromFile

func ReadDoguFromFile(filePath string) (*Dogu, DoguApiVersion, error)

ReadDoguFromFile reads a single dogu from a file and returns it along with a dogu API version.

func ReadDoguFromString

func ReadDoguFromString(content string) (*Dogu, DoguApiVersion, error)

ReadDoguFromString reads a dogu from a string and returns it along with a dogu API version.

func ReadDogusFromFile

func ReadDogusFromFile(filePath string) ([]*Dogu, DoguApiVersion, error)

ReadDogusFromFile reads all dogus from a given file and returns them along with a their dogu API version.

func ReadDogusFromString

func ReadDogusFromString(content string) ([]*Dogu, DoguApiVersion, error)

ReadDogusFromString reads multiple dogus from a string and returns them along with a dogu API version.

func WriteDoguToFile

func WriteDoguToFile(filePath string, dogu *Dogu) error

WriteDoguToFile writes the dogu to the given file. Uses the default format (first registered).

func WriteDoguToFileWithFormat

func WriteDoguToFileWithFormat(filePath string, dogu *Dogu, formatProvider DoguFormatProvider) error

WriteDoguToFileWithFormat writes the dogu to the given file using a specified format.

func WriteDoguToString

func WriteDoguToString(dogu *Dogu) (string, error)

WriteDoguToString writes the dogu and return the string representation of the specified format.

func WriteDogusToFile

func WriteDogusToFile(filePath string, dogus []*Dogu) error

WriteDogusToFile writes all dogus to the given file. Uses the default format (first registered).

func WriteDogusToFileWithFormat

func WriteDogusToFileWithFormat(filePath string, dogus []*Dogu, formatProvider DoguFormatProvider) error

WriteDogusToFileWithFormat writes all dogus to the given file using a specified format.

func WriteDogusToString

func WriteDogusToString(dogus []*Dogu) (string, error)

WriteDogusToString writes all dogus and return the string representation of the specified format.

Types

type ByDoguVersion

type ByDoguVersion []*Dogu

ByDoguVersion implements sort.Interface for []Dogu to Dogus by their versions

func (ByDoguVersion) Len

func (doguVersions ByDoguVersion) Len() int

Len is the number of elements in the collection.

func (ByDoguVersion) Less

func (doguVersions ByDoguVersion) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (ByDoguVersion) Swap

func (doguVersions ByDoguVersion) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type ByVersion

type ByVersion []Version

ByVersion implements sort.Interface for []Version to sort versions

func (ByVersion) Len

func (versions ByVersion) Len() int

Len is the number of elements in the collection.

func (ByVersion) Less

func (versions ByVersion) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (ByVersion) Swap

func (versions ByVersion) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type ConfigurationField

type ConfigurationField struct {
	// Name contains the name of the key. It must not be empty. It must not contain leading or trailing slashes "/", but
	// it may contain directory keys delimited with slashes within the name.
	Name string
	// Description should mention the context and purpose of the config field in human readable format.
	Description string
	// Optional allows to have this config field unset.
	Optional bool
	// Encrypted marks this config field to contain a sensitive value that will be encrypted with the dogu's private key.
	Encrypted bool
	// Global marks this config field to contain a value that is available for all dogus.
	Global bool
	// Default defines a default value that may be evaluated if no value was configured, or the vallue is empty or even invalid.
	Default string
	// Validation configures a Validator that will be used to validate this config field.
	Validation ValidationDescriptor
}

ConfigurationField describes a field of the dogu configuration which is stored in the registry.

type Credentials

type Credentials struct {
	Username string
	Password string
}

Credentials for a remote system

type Dependency

type Dependency struct {
	Type    string `json:"type"`
	Name    string `json:"name"`
	Version string `json:"version"`
}

Dependency contains the dependencies of the application and all their necessary information.

type Dogu

type Dogu struct {
	Name                 string
	Version              string
	DisplayName          string
	Description          string
	Category             string
	Tags                 []string
	URL                  string
	Image                string
	ExposedPorts         []ExposedPort
	ExposedCommands      []ExposedCommand
	Volumes              []Volume
	HealthCheck          HealthCheck // deprecated use HealthChecks
	HealthChecks         []HealthCheck
	ServiceAccounts      []ServiceAccount
	Privileged           bool
	Configuration        []ConfigurationField
	Properties           Properties
	EnvironmentVariables []EnvironmentVariable
	Dependencies         []Dependency
	OptionalDependencies []Dependency
}

Dogu defines an application for the CES. A dogu defines the image and meta information for the resulting container.

func SortDogusByDependency

func SortDogusByDependency(dogus []*Dogu) []*Dogu

SortDogusByDependency takes an unsorted slice of Dogu structs and returns a slice of Dogus ordered by the importance of their dependencies descending, that is: the most needed dogu will be the first element.

func SortDogusByInvertedDependency

func SortDogusByInvertedDependency(dogus []*Dogu) []*Dogu

SortDogusByInvertedDependency takes an unsorted slice of Dogu structs and returns a new slice of Dogus ordered by the importance of their dependencies ascending, that is: the most independent dogu will be the first element.

func SortDogusByName

func SortDogusByName(dogus []*Dogu) []*Dogu

SortDogusByName takes an unsorted slice of Dogus and returns an copy of the slice ordered by the full name of the dogu

func (*Dogu) CreateV1Copy

func (d *Dogu) CreateV1Copy() DoguV1

CreateV1Copy converts this dogu object into a deep-copied DoguV1 object (for legacy reasons).

func (*Dogu) DependsOn

func (d *Dogu) DependsOn(name string) bool

DependsOn returns true if the dogu has a hard dependency to the given dogu

func (*Dogu) GetAllDependenciesOfType

func (d *Dogu) GetAllDependenciesOfType(dependencyType string) []Dependency

GetAllDependenciesOfType returns all dependencies in accordance to the given dependency type.

func (*Dogu) GetDependenciesOfType

func (d *Dogu) GetDependenciesOfType(dependencyType string) []Dependency

GetDependenciesOfType returns all dependencies in accordance to the given dependency type.

func (*Dogu) GetEnvironmentVariables

func (d *Dogu) GetEnvironmentVariables() []EnvironmentVariable

GetEnvironmentVariables returns environment variables formatted as array of key value objects

func (*Dogu) GetEnvironmentVariablesAsStringArray

func (d *Dogu) GetEnvironmentVariablesAsStringArray() []string

GetEnvironmentVariablesAsStringArray returns environment variables formatted as string array

func (*Dogu) GetExposedCommand

func (d *Dogu) GetExposedCommand(commandName string) *ExposedCommand

GetExposedCommand returns a ExposedCommand for a given command name if it exists. Otherwise it returns nil. To test if a dogu has a command with a given command name use the HasExposedCommand method:

if dogu.HasExposedCommand(commandName) { doSomething() }

func (*Dogu) GetFullName

func (d *Dogu) GetFullName() string

GetFullName returns the name of the dogu including its namespace

func (*Dogu) GetImageName

func (d *Dogu) GetImageName() string

GetImageName returns the name of the docker image

func (*Dogu) GetNamespace

func (d *Dogu) GetNamespace() string

GetNamespace returns the namespace of the dogu without the name

func (*Dogu) GetOptionalDependenciesOfType

func (d *Dogu) GetOptionalDependenciesOfType(dependencyType string) []Dependency

GetOptionalDependenciesOfType returns all optional dependencies in accordance to the given dependency type.

func (*Dogu) GetRegistryServerURI

func (d *Dogu) GetRegistryServerURI() string

GetRegistryServerURI returns the name of the docker registry which is used by this dogu

func (*Dogu) GetSimpleName

func (d *Dogu) GetSimpleName() string

GetSimpleName returns the name of the dogu without the namespace

func (*Dogu) GetVersion

func (d *Dogu) GetVersion() (Version, error)

GetVersion parses the dogu version and returns a struct which can be used to compare versions

func (*Dogu) HasExposedCommand

func (d *Dogu) HasExposedCommand(commandName string) bool

HasExposedCommand checks if the dogu is a provider of a given command name. Example see constants like ExposedCommandServiceAccountCreate

func (*Dogu) IsEqualTo

func (d *Dogu) IsEqualTo(otherDogu *Dogu) (bool, error)

IsEqualTo returns true if the other dogu has the same name and version.

func (*Dogu) IsNewerThan

func (d *Dogu) IsNewerThan(otherDogu *Dogu) (bool, error)

IsNewerThan returns true if the other dogu has the same name and has a higher version

type DoguApiVersion

type DoguApiVersion int

DoguApiVersion contains the Dog API version as integer starting with 1 (which is deprecated).

const (
	DoguApiVersionUnknown DoguApiVersion = 0
	DoguApiV1             DoguApiVersion = 1
	DoguApiV2             DoguApiVersion = 2
)

type DoguFormatHandler

type DoguFormatHandler struct {
	Providers []DoguFormatProvider
}

DoguFormatHandler is responsible for reading and writing dogus in different formats.

func (*DoguFormatHandler) GetFormatProviders

func (d *DoguFormatHandler) GetFormatProviders() []DoguFormatProvider

GetFormatProviders returns the list or registered format providers.

func (*DoguFormatHandler) RegisterFormatProvider

func (d *DoguFormatHandler) RegisterFormatProvider(provider DoguFormatProvider)

RegisterFormatProvider adds a new dogu format provider to the format manager.

type DoguFormatProvider

type DoguFormatProvider interface {
	// ReadDoguFromString reads a dogu from the given filePath and returns an instance of a dogu.
	ReadDoguFromString(content string) (*Dogu, error)
	// ReadDogusFromString reads multiple dogus from the given filePath and returns a slice of dogu instances.
	ReadDogusFromString(content string) ([]*Dogu, error)
	// WriteDoguToString converts the given dogu to string representation and returns it.
	WriteDoguToString(dogu *Dogu) (string, error)
	// WriteDogusToString converts the given dogus to string representation and returns it.
	WriteDogusToString(dogu []*Dogu) (string, error)
	// GetVersion returns the api version which is used for this format provider.
	GetVersion() DoguApiVersion
}

type DoguJsonV1FormatProvider

type DoguJsonV1FormatProvider struct{}

DoguJsonV1FormatProvider provides methods to format Dogu results compatible to v1 API.

func (*DoguJsonV1FormatProvider) GetVersion

func (d *DoguJsonV1FormatProvider) GetVersion() DoguApiVersion

GetVersion returns DoguApiV1 for this implementation.

func (*DoguJsonV1FormatProvider) ReadDoguFromString

func (d *DoguJsonV1FormatProvider) ReadDoguFromString(content string) (*Dogu, error)

ReadDoguFromString reads a dogu from a string and returns the API v1 representation.

func (*DoguJsonV1FormatProvider) ReadDogusFromString

func (d *DoguJsonV1FormatProvider) ReadDogusFromString(content string) ([]*Dogu, error)

ReadDogusFromString reads multiple dogus from a string and returns the API v1 representation.

func (*DoguJsonV1FormatProvider) WriteDoguToString

func (d *DoguJsonV1FormatProvider) WriteDoguToString(doguV2 *Dogu) (string, error)

WriteDoguToString receives a single dogu and returns the API v1 representation.

func (*DoguJsonV1FormatProvider) WriteDogusToString

func (d *DoguJsonV1FormatProvider) WriteDogusToString(doguV2List []*Dogu) (string, error)

WriteDogusToString receives a list of dogus and returns the API v1 representation.

type DoguJsonV2FormatProvider

type DoguJsonV2FormatProvider struct{}

DoguJsonV2FormatProvider provides methods to format Dogu results compatible to v2 API.

func (*DoguJsonV2FormatProvider) GetVersion

func (d *DoguJsonV2FormatProvider) GetVersion() DoguApiVersion

GetVersion returns DoguApiV2 for this implementation.

func (*DoguJsonV2FormatProvider) ReadDoguFromString

func (d *DoguJsonV2FormatProvider) ReadDoguFromString(content string) (*Dogu, error)

ReadDoguFromString reads a dogu from a string and returns the API v2 representation.

func (*DoguJsonV2FormatProvider) ReadDogusFromString

func (d *DoguJsonV2FormatProvider) ReadDogusFromString(content string) ([]*Dogu, error)

ReadDogusFromString reads multiple dogus from a string and returns the API v2 representation.

func (*DoguJsonV2FormatProvider) WriteDoguToString

func (d *DoguJsonV2FormatProvider) WriteDoguToString(dogu *Dogu) (string, error)

WriteDoguToString receives a single dogu and returns the API v2 representation.

func (*DoguJsonV2FormatProvider) WriteDogusToString

func (d *DoguJsonV2FormatProvider) WriteDogusToString(dogu []*Dogu) (string, error)

WriteDogusToString receives a list of dogus and returns the API v2 representation.

type DoguV1 deprecated

type DoguV1 struct {
	Name                 string
	Version              string
	DisplayName          string
	Description          string
	Category             string
	Tags                 []string
	URL                  string
	Image                string
	ExposedPorts         []ExposedPort
	ExposedCommands      []ExposedCommand
	Volumes              []Volume
	HealthCheck          HealthCheck // deprecated use HealthChecks
	HealthChecks         []HealthCheck
	ServiceAccounts      []ServiceAccount
	Privileged           bool
	Configuration        []ConfigurationField
	Properties           Properties
	EnvironmentVariables []EnvironmentVariable
	Dependencies         []string
	OptionalDependencies []string
}

DoguV1 defines an application for the CES. A dogu defines the image and meta information for the resulting container.

Deprecated: This schema is deprecated as it does not contain advanced expressions for dependencies. Please use core.DoguV2 instead.

func (*DoguV1) CreateV2Copy

func (d *DoguV1) CreateV2Copy() Dogu

CreateV2Copy creates a deep DoguV2 copy from an existing DoguV1 object.

type EnvironmentVariable

type EnvironmentVariable struct {
	Key   string
	Value string
}

EnvironmentVariable struct represents custom parameters that can change the behaviour of a dogu build process

func (EnvironmentVariable) String

func (env EnvironmentVariable) String() string

String returns a string representation of this EnvironmentVariable

type ExposedCommand

type ExposedCommand struct {
	Name        string
	Description string
	Command     string
}

ExposedCommand struct represents a command which can be executed inside the dogu

type ExposedPort

type ExposedPort struct {
	// Type contains the protocol type over which the container communicates (f. i. 'tcp').
	Type string
	// Container contains the mapped port on side of the container.
	Container int
	// Host contains the mapped port on side of the host.
	Host int
}

ExposedPort struct is used to define ports which are exported to the host

func (*ExposedPort) GetType

func (ep *ExposedPort) GetType() string

GetType returns type of expose port, the default is tcp

type HealthCheck

type HealthCheck struct {
	Type       string            // health check type tcp or state
	State      string            // expected state for state health check, default is ready
	Port       int               // port for tcp state check
	Path       string            // path for http check
	Parameters map[string]string // key value pairs for check specific parameters
}

HealthCheck struct will be used to do readyness and health checks for the final container

type Properties

type Properties map[string]string

Properties describes generic properties of the dogu.

type ProxySettings

type ProxySettings struct {
	Enabled  bool
	Server   string `json:",omitempty"`
	Port     int    `json:",omitempty"`
	Username string `json:",omitempty"`
	Password string `json:",omitempty"`
}

ProxySettings contains the settings for http proxy

func (ProxySettings) CreateURL

func (proxy ProxySettings) CreateURL() string

CreateURL creates a proxy http url

type Registry

type Registry struct {
	Type      string   `validate:"eq=etcd"`
	Endpoints []string `validate:"required,min=1"`
}

Registry contains Cloudogu EcoSystem registration details.

type Remote

type Remote struct {
	Endpoint               string `validate:"url"`
	AuthenticationEndpoint string `validate:"omitempty,url"`
	URLSchema              string `json:"urlSchema,omitempty" validate:"omitempty,oneof=default index"`
	CacheDir               string `validate:"required"`
	ProxySettings          ProxySettings
	AnonymousAccess        bool `json:",omitempty"`
	Insecure               bool `json:",omitempty"`
}

Remote contains dogu registry configuration details.

type ServiceAccount

type ServiceAccount struct {
	Type   string
	Params []string
}

ServiceAccount struct can be used to get access to a other dogu.

type ValidationDescriptor

type ValidationDescriptor struct {
	// Type contains the name of the config value validator.
	Type string
	// Values may contain values that aid the selected validator. It is up to the selected validator whether this field is mandatory, optional, or unused.
	Values []string
}

ValidationDescriptor describes how to determine if a config value is valid.

type Version

type Version struct {
	Raw   string
	Major int
	Minor int
	Patch int
	Nano  int
	Extra int
}

Version struct can be used to extract single parts of a version number or to compare version with each other. The version struct can with four or less digits, plus an extra version which is divided by a hyphen. For example: 4.0.7.11-3 => 4 Major, 0 Minor, 7 Patch, 11 Nano, 3 Extra

func ParseVersion

func ParseVersion(raw string) (Version, error)

ParseVersion parses a raw version string and returns a Version struct

func (*Version) IsEqualTo

func (v *Version) IsEqualTo(o Version) bool

IsEqualTo returns true if this version is equal to the given version parameter, otherwise false.

func (*Version) IsNewerOrEqualThan

func (v *Version) IsNewerOrEqualThan(o Version) bool

IsNewerOrEqualThan returns true if this version is newer than the given version parameter

func (*Version) IsNewerThan

func (v *Version) IsNewerThan(o Version) bool

IsNewerThan returns true if this version is newer than the given version parameter

func (*Version) IsOlderOrEqualThan

func (v *Version) IsOlderOrEqualThan(o Version) bool

IsOlderOrEqualThan returns true if this version is older or equal than the given version parameter

func (*Version) IsOlderThan

func (v *Version) IsOlderThan(o Version) bool

IsOlderThan returns true if this version is older than the given version parameter

type VersionComparator

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

VersionComparator is responsible to compare versions and to check defined constraints.

func ParseVersionComparator

func ParseVersionComparator(raw string) (VersionComparator, error)

ParseVersionComparator creates a new version comparator by parsing a raw version string.

func (VersionComparator) Allows

func (v VersionComparator) Allows(version Version) (bool, error)

Allows check whether the given version fulfills the requirements for the version comparator.

type Volume

type Volume struct {
	Name        string
	Path        string
	Owner       string
	Group       string
	NeedsBackup bool
}

Volume is the volume struct of a dogu and will be used to define docker volumes

func (*Volume) UnmarshalJSON

func (v *Volume) UnmarshalJSON(data []byte) error

UnmarshalJSON sets the default value for NeedsBackup. We are preventing an infinite loop by using a local Alias type to call json.Unmarshal again

Jump to

Keyboard shortcuts

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