mta

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package mta provides a convenient way of exploring the structure of `mta.yaml` file objects such as retrieving a list of resources required by a specific module.

Index

Constants

View Source
const UnmarshalFailsMsg = `the "%s" file is not a valid MTA descriptor`

Variables

This section is empty.

Functions

func AddModule

func AddModule(path string, moduleDataJSON string, marshal func(*MTA) ([]byte, error)) ([]string, error)

AddModule - adds a new module.

func AddResource

func AddResource(path string, resourceDataJSON string, marshal func(*MTA) ([]byte, error)) ([]string, error)

AddResource - adds a new resource.

func CopyFile

func CopyFile(src, dst string, create func(string) (*os.File, error)) (rerr error)

CopyFile - copies a file from the source path to the target path.

func CreateMta

func CreateMta(path string, mtaDataJSON string, mkDirs func(string, os.FileMode) error) error

CreateMta - creates an MTA project.

func DeleteFile

func DeleteFile(path string) error

DeleteFile - deletes the file.

func DeleteMta added in v0.0.8

func DeleteMta(path string) error

DeleteMta - deletes the MTA

func GetMtaHash

func GetMtaHash(path string) (int, bool, error)

GetMtaHash - gets the hashcode of the MTA file.

func GetMtaID added in v0.1.2

func GetMtaID(path string) (string, []string, error)

GetMtaID - gets MTA ID.

func GetParameters added in v1.0.1

func GetParameters(path string, extensions []string) (*map[string]interface{}, []string, error)

getParameters - gets the MTA parameters.

func GetResourceConfig added in v1.0.1

func GetResourceConfig(path string, extensions []string, resourceName string, workspaceDir string) (map[string]interface{}, []string, error)

GetResourceConfig returns the configuration for a resource (its service creation parameters). If both the config and path parameters are defined, the result is merged.

func IsNameUnique

func IsNameUnique(path string, name string) (bool, []string, error)

IsNameUnique - checks if the name already exists as a `module`/`resource`/`provide` name.

func Marshal

func Marshal(omta *MTA) ([]byte, error)

Marshal marshals an MTA object

func Merge

func Merge(mta *MTA, mtaExt *EXT, extFilePath string) error

Merge merges mta object with mta extension object extension properties complement and overwrite mta properties

func ModifyMta

func ModifyMta(path string, modify func() ([]string, error), hashcode int, force bool, isNew bool, mkDirs func(string, os.FileMode) error) (newHashcode int, messages []string, rerr error)

ModifyMta - locks and modifies the "mta.yaml" file.

func RunAndWriteResultAndHash

func RunAndWriteResultAndHash(info string, path string, extensions []string, action func() (interface{}, []string, error)) error

RunAndWriteResultAndHash - logs the info, executes the action, and writes the result and hashcode of the MTA in the path (or an error, if needed) to the output

func RunModifyAndWriteHash

func RunModifyAndWriteHash(info string, path string, force bool, action func() ([]string, error), hashcode int, isNew bool) error

RunModifyAndWriteHash - logs the info, executes the action while locking the MTA file in the path, and writes the result and hashcode (or error, if needed) to the output.

func UpdateBuildParameters added in v0.0.3

func UpdateBuildParameters(path string, buildParamsDataJSON string) ([]string, error)

UpdateBuildParameters - updates the MTA build parameters.

func UpdateModule

func UpdateModule(path string, moduleDataJSON string, marshal func(*MTA) ([]byte, error)) ([]string, error)

UpdateModule updates an existing module according to the module name. If more than one module with this name exists, one of the modules is updated to the existing structure.

func UpdateParameters added in v1.0.1

func UpdateParameters(path string, paramsDataJSON string) ([]string, error)

UpdateParameters - updates the MTA parameters.

func UpdateResource

func UpdateResource(path string, resourceDataJSON string, marshal func(*MTA) ([]byte, error)) ([]string, error)

UpdateResource updates an existing resource according to the resource name. If more than one resource with this name exists, one of the resources is updated in the existing structure.

func WriteResult

func WriteResult(result interface{}, messages []string, hashcode int, err error) error

WriteResult - writes the result of an operation to the output in JSON format. If successful, the hashcode and results are written; otherwise an error is displayed.

Types

type EXT

type EXT struct {
	// indicates MTA schema version, using semver.
	SchemaVersion *string `yaml:"_schema-version"`
	// A globally unique ID of this MTA extension. Unlimited string of unicode characters.
	ID string `yaml:"ID"`
	// A non-translatable description of this MTA extension. This is not a text for application users
	Description string `yaml:"description,omitempty"`
	//  a globally unique ID of the MTA or the MTA extension which shall be extended by this descriptor
	Extends string `yaml:"extends"`
	// Application version, using semantic versioning standard
	Version string `yaml:"version,omitempty"`
	// The provider of this extension descriptor
	Provider string `yaml:"provider,omitempty"`
	// list of modules
	Modules []*ModuleExt `yaml:"modules,omitempty"`
	// Resource declarations. Resources can be anything required to run the application which is not provided by the application itself
	Resources []*ResourceExt `yaml:"resources,omitempty"`
	// Parameters can be used to steer the behavior of tools which interpret this descriptor
	Parameters map[string]interface{} `yaml:"parameters,omitempty"`
}

EXT mta extension schema

func UnmarshalExt

func UnmarshalExt(content []byte) (*EXT, error)

UnmarshalExt returns a reference to the EXT object from a byte array.

type ExtensionError added in v1.0.1

type ExtensionError struct {
	FileName string

	IsParseError bool
	// contains filtered or unexported fields
}

func (ExtensionError) Error added in v1.0.1

func (e ExtensionError) Error() string

type Hook added in v0.0.6

type Hook struct {
	// An MTA internal name which can be used for documentation purposes and shown by the deployer.
	Name string `yaml:"name,omitempty" json:"name,omitempty"`
	// Defines the type of action that should be executed by the deployer.
	Type string `yaml:"type,omitempty" json:"type,omitempty"`
	// A list of strings that define the points at which the hook must be executed.
	Phases             []string               `yaml:"phases,omitempty" json:"phases,omitempty"`
	Parameters         map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty"`
	ParametersMetaData map[string]MetaData    `yaml:"parameters-metadata,omitempty" json:"parameters-metadata,omitempty"`
	Requires           []Requires             `yaml:"requires,omitempty" json:"requires,omitempty"`
}

Hook - defined and executed at specific phases of module deployment.

func (*Hook) GetRequiresByName added in v0.0.6

func (hook *Hook) GetRequiresByName(name string) *Requires

GetRequiresByName returns a specific requires by name

type Includes

type Includes struct {
	// A name of an include section. This name will be used by a builder to generate a parameter section in the deployment descriptor
	Name string `yaml:"name,omitempty" json:"name,omitempty"`
	// A path pointing to a file which contains a map of parameters, either in JSON or in YAML format.
	Path string `yaml:"path,omitempty" json:"path,omitempty"`
}

Includes The 'includes' element only relevant for development descriptor, not for deployment descriptor

type MTA

type MTA struct {
	// indicates MTA schema version, using semver.
	SchemaVersion *string `yaml:"_schema-version" json:"_schema-version"`
	// A globally unique ID of this MTA. Unlimited string of unicode characters.
	ID string `yaml:"ID" json:"ID"`
	// A non-translatable description of this MTA. This is not a text for application users
	Description string `yaml:"description,omitempty" json:"description,omitempty"`
	// Application version, using semantic versioning standard
	Version string `yaml:"version,omitempty" json:"version,omitempty"`
	// The provider or vendor of this software
	Provider string `yaml:"provider,omitempty" json:"provider,omitempty"`
	// A copyright statement from the provider
	Copyright string `yaml:"copyright,omitempty" json:"copyright,omitempty"`
	// list of modules
	Modules []*Module `yaml:"modules,omitempty" json:"modules,omitempty"`
	// Module type declarations
	ModuleTypes []*ModuleTypes `yaml:"module-types,omitempty" json:"module-types,omitempty"`
	// Resource declarations. Resources can be anything required to run the application which is not provided by the application itself
	Resources []*Resource `yaml:"resources,omitempty" json:"resources,omitempty"`
	// Resource type declarations
	ResourceTypes []*ResourceTypes `yaml:"resource-types,omitempty" json:"resource-types,omitempty"`
	// Parameters can be used to steer the behavior of tools which interpret this descriptor
	Parameters         map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty"`
	ParametersMetaData map[string]MetaData    `yaml:"parameters-metadata,omitempty" json:"parameters-metadata,omitempty"`
	// Experimental - use for pre/post hook
	BuildParams *ProjectBuild `yaml:"build-parameters,omitempty" json:"build-parameters,omitempty"`
}

MTA mta schema, the schema will contain the latest mta schema version and all the previous version will be as subset of the latest Todo - Add the missing properties to support the latest 3.2 version

func GetMtaFromFile added in v1.0.1

func GetMtaFromFile(path string, extensions []string, returnMergeError bool) (mta *MTA, messages []string, err error)

func GetMtaFromFileWithStrict added in v1.0.8

func GetMtaFromFileWithStrict(path string, extensions []string, returnMergeError bool, strict bool) (mta *MTA, messages []string, err error)

func Unmarshal

func Unmarshal(content []byte) (*MTA, error)

Unmarshal returns a reference to the MTA object from a byte array.

func (*MTA) GetModuleByName

func (mta *MTA) GetModuleByName(name string) (*Module, error)

GetModuleByName returns a specific module by name.

func (*MTA) GetModules

func (mta *MTA) GetModules() []*Module

GetModules returns a list of MTA modules.

func (*MTA) GetResourceByName

func (mta *MTA) GetResourceByName(name string) *Resource

GetResourceByName returns a specific resource by name.

func (*MTA) GetResources

func (mta *MTA) GetResources() []*Resource

GetResources returns list of MTA resources.

type MetaData added in v0.0.6

type MetaData struct {
	// If set to true, the value can be overwritten by an extension descriptor.
	OverWritable *bool `yaml:"overwritable,omitempty" json:"overwritable,omitempty"`
	// If set to false, a value must be present in the final deployment configuration.
	Optional *bool `yaml:"optional,omitempty" json:"optional,omitempty"`
	// An interface with which a UI-tool can query for possible parameter names together with the expected datatypes and default values.
	Datatype interface{} `yaml:"datatype,omitempty" json:"datatype,omitempty"`
	// Indicate sensitive information to a UI-tool which it can use, e.g., for masking a value
	Sensitive bool `yaml:"sensitive,omitempty" json:"sensitive,omitempty"`
}

MetaData - The properties-metadata and the parameters-metadata structure

func (*MetaData) UnmarshalYAML added in v0.0.6

func (meta *MetaData) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML unmarshals a MetaData object, setting default values for fields not in the source

type Module

type Module struct {
	// An MTA internal module name. Names need to be unique within the MTA scope
	Name string `yaml:"name" json:"name"`
	// a globally unique type ID. Deployment tools will interpret this type ID
	Type string `yaml:"type" json:"type"`
	// a non-translatable description of this module. This is not a text for application users
	Description string `yaml:"description,omitempty" json:"description,omitempty"`
	// A file path which identifies the location of module artifacts.
	Path string `yaml:"path,omitempty" json:"path,omitempty"`
	// Provided property values can be accessed by "~{<name-of-provides-section>/<provided-property-name>}". Such expressions can be part of an arbitrary string
	Properties         map[string]interface{} `yaml:"properties,omitempty" json:"properties,omitempty"`
	PropertiesMetaData map[string]MetaData    `yaml:"properties-metadata,omitempty" json:"properties-metadata,omitempty"`
	// THE 'includes' ELEMENT IS ONLY RELEVANT FOR DEVELOPMENT DESCRIPTORS (PRIO TO BUILD), NOT FOR DEPLOYMENT DESCRIPTORS!
	Includes []Includes `yaml:"includes,omitempty" json:"includes,omitempty"`
	// list of names either matching a resource name or a name provided by another module within the same MTA
	Requires []Requires `yaml:"requires,omitempty" json:"requires,omitempty"`
	// List of provided names (MTA internal)to which properties (= configuration data) can be attached
	Provides []Provides `yaml:"provides,omitempty" json:"provides,omitempty"`
	// Parameters can be used to steer the behavior of tools which interpret this descriptor. Parameters are not made available to the module at runtime
	Parameters         map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty"`
	ParametersMetaData map[string]MetaData    `yaml:"parameters-metadata,omitempty" json:"parameters-metadata,omitempty"`
	// Build-parameters are specifically steering the behavior of build tools.
	BuildParams map[string]interface{} `yaml:"build-parameters,omitempty" json:"build-parameters,omitempty"`
	// A list containing the names of the modules that must be deployed prior to this one.
	DeployedAfter []string `yaml:"deployed-after,omitempty" json:"deployed-after,omitempty"`
	// Defined and executed at specific phases of module deployment.
	Hooks []Hook `yaml:"hooks,omitempty" json:"hooks,omitempty"`
}

Module - modules section.

func GetModules

func GetModules(path string, extensions []string) ([]*Module, []string, error)

GetModules - gets all modules.

func (*Module) GetHookByName added in v0.0.6

func (module *Module) GetHookByName(name string) *Hook

GetHookByName returns a specific hook by name

func (*Module) GetProvidesByName added in v0.0.6

func (module *Module) GetProvidesByName(name string) *Provides

GetProvidesByName returns a specific provide by name

func (*Module) GetRequiresByName added in v0.0.6

func (module *Module) GetRequiresByName(name string) *Requires

GetRequiresByName returns a specific requires by name

type ModuleExt

type ModuleExt struct {
	// An MTA internal module name. Names need to be unique within the MTA scope
	Name string
	// Provided property values can be accessed by "~{<name-of-provides-section>/<provided-property-name>}". Such expressions can be part of an arbitrary string
	Properties map[string]interface{} `yaml:"properties,omitempty"`
	// THE 'includes' ELEMENT IS ONLY RELEVANT FOR DEVELOPMENT DESCRIPTORS (PRIO TO BUILD), NOT FOR DEPLOYMENT DESCRIPTORS!
	Includes []Includes `yaml:"includes,omitempty"`
	// list of names either matching a resource name or a name provided by another module within the same MTA
	Requires []Requires `yaml:"requires,omitempty"`
	// List of provided names (MTA internal)to which properties (= configuration data) can be attached
	Provides []Provides `yaml:"provides,omitempty"`
	// Parameters can be used to steer the behavior of tools which interpret this descriptor. Parameters are not made available to the module at runtime
	Parameters map[string]interface{} `yaml:"parameters,omitempty"`
	// Build-parameters are specifically steering the behavior of build tools.
	BuildParams map[string]interface{} `yaml:"build-parameters,omitempty"`
	// Defined and executed at specific phases of module deployment.
	Hooks []Hook `yaml:"hooks,omitempty" json:"hooks,omitempty"`
}

ModuleExt - modules section in MTA extension

type ModuleTypes

type ModuleTypes struct {
	// An MTA internal name of the module type. Can be specified in the 'type' element of modules
	Name string `yaml:"name,omitempty" json:"name,omitempty"`
	// The name of the extended type. Can be another resource type defined in this descriptor or one of the default types supported by the deployer
	Extends string `yaml:"extends,omitempty" json:"extends,omitempty"`
	// Properties inherited by all resources of this type
	Properties         map[string]interface{} `yaml:"properties,omitempty" json:"properties,omitempty"`
	PropertiesMetaData map[string]MetaData    `yaml:"properties-metadata,omitempty" json:"properties-metadata,omitempty"`
	// Parameters inherited by all resources of this type
	Parameters         map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty"`
	ParametersMetaData map[string]MetaData    `yaml:"parameters-metadata,omitempty" json:"parameters-metadata,omitempty"`
}

ModuleTypes module types declarations

type ProjectBuild

type ProjectBuild struct {
	BeforeAll []ProjectBuilder `yaml:"before-all,omitempty" json:"before-all,omitempty"`
	AfterAll  []ProjectBuilder `yaml:"after-all,omitempty" json:"after-all,omitempty"`
}

ProjectBuild - experimental use for pre/post build hook

func GetBuildParameters added in v1.0.1

func GetBuildParameters(path string, extensions []string) (*ProjectBuild, []string, error)

getBuildParameters - gets the MTA build parameters.

type ProjectBuilder

type ProjectBuilder struct {
	Builder  string   `yaml:"builder,omitempty" json:"builder,omitempty"`
	Timeout  string   `yaml:"timeout,omitempty" json:"timeout,omitempty"`
	Commands []string `yaml:"commands,omitempty" json:"commands,omitempty"`
}

ProjectBuilder - project builder descriptor

type Provides

type Provides struct {
	Name string `yaml:"name,omitempty" json:"name,omitempty"`
	// Indicates, that the provided properties shall be made publicly available by the deployer
	Public bool `yaml:"public,omitempty" json:"public,omitempty"`
	// property names and values make up the configuration data which is to be provided to requiring modules at runtime
	Properties         map[string]interface{} `yaml:"properties,omitempty" json:"properties,omitempty"`
	PropertiesMetaData map[string]MetaData    `yaml:"properties-metadata,omitempty" json:"properties-metadata,omitempty"`
}

Provides List of provided names to which properties (configs data) can be attached.

type Requires

type Requires struct {
	// an MTA internal name which must match either a provided name, a resource name, or a module name within the same MTA
	Name string `yaml:"name,omitempty" json:"name,omitempty"`
	// A group name which shall be use by a deployer to group properties for lookup by a module runtime.
	Group string `yaml:"group,omitempty" json:"group,omitempty"`
	// All required and found configuration data sets will be assembled into a JSON array and provided to the module by the lookup name as specified by the value of 'list'
	List string `yaml:"list,omitempty" json:"list,omitempty"`
	// Provided property values can be accessed by "~{<provided-property-name>}". Such expressions can be part of an arbitrary string
	Properties         map[string]interface{} `yaml:"properties,omitempty" json:"properties,omitempty"`
	PropertiesMetaData map[string]MetaData    `yaml:"properties-metadata,omitempty" json:"properties-metadata,omitempty"`
	// Parameters can be used to influence the behavior of tools which interpret this descriptor. Parameters are not made available to requiring modules at runtime
	Parameters         map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty"`
	ParametersMetaData map[string]MetaData    `yaml:"parameters-metadata,omitempty" json:"parameters-metadata,omitempty"`
	// THE 'includes' ELEMENT IS ONLY RELEVANT FOR DEVELOPMENT DESCRIPTORS (PRIO TO BUILD), NOT FOR DEPLOYMENT DESCRIPTORS!
	Includes []Includes `yaml:"includes,omitempty" json:"includes,omitempty"`
}

Requires list of names either matching a resource name or a name provided by another module within the same MTA.

type Resource

type Resource struct {
	Name string `yaml:"name,omitempty" json:"name,omitempty"`
	// A type of a resource. This type is interpreted by and must be known to the deployer. Resources can be untyped
	Type string `yaml:"type,omitempty" json:"type,omitempty"`
	// A non-translatable description of this resource. This is not a text for application users
	Description string `yaml:"description,omitempty" json:"description,omitempty"`
	// Parameters can be used to influence the behavior of tools which interpret this descriptor. Parameters are not made available to requiring modules at runtime
	Parameters         map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty"`
	ParametersMetaData map[string]MetaData    `yaml:"parameters-metadata,omitempty" json:"parameters-metadata,omitempty"`
	// property names and values make up the configuration data which is to be provided to requiring modules at runtime
	Properties         map[string]interface{} `yaml:"properties,omitempty" json:"properties,omitempty"`
	PropertiesMetaData map[string]MetaData    `yaml:"properties-metadata,omitempty" json:"properties-metadata,omitempty"`
	// THE 'includes' ELEMENT IS ONLY RELEVANT FOR DEVELOPMENT DESCRIPTORS (PRIO TO BUILD), NOT FOR DEPLOYMENT DESCRIPTORS!
	Includes []Includes `yaml:"includes,omitempty" json:"includes,omitempty"`
	// A resource can be declared to be optional, if the MTA can compensate for its non-existence
	Optional bool `yaml:"optional,omitempty" json:"optional,omitempty"`
	// If a resource is declared to be active, it is allocated and bound according to declared requirements
	Active *bool `yaml:"active,omitempty" json:"active,omitempty"`
	// A list containing the names of the resources that must be processed prior to this one.
	ProcessedAfter []string `yaml:"processed-after,omitempty" json:"processed-after,omitempty"`
	// list of names either matching a resource name or a name provided by another module within the same MTA
	Requires []Requires `yaml:"requires,omitempty" json:"requires,omitempty"`
}

Resource can be anything required to run the application which is not provided by the application itself.

func GetResources

func GetResources(path string, extensions []string) ([]*Resource, []string, error)

GetResources - gets all resources.

func (*Resource) GetRequiresByName added in v0.0.6

func (resource *Resource) GetRequiresByName(name string) *Requires

GetRequiresByName returns a specific requires by name

type ResourceExt

type ResourceExt struct {
	Name string
	// A type of a resource. This type is interpreted by and must be known to the deployer. Resources can be untyped
	Parameters map[string]interface{} `yaml:"parameters,omitempty"`
	// property names and values make up the configuration data which is to be provided to requiring modules at runtime
	Properties map[string]interface{} `yaml:"properties,omitempty"`
	// If a resource is declared to be active, it is allocated and bound according to declared requirements
	Active *bool `yaml:"active,omitempty"`
	// list of names either matching a resource name or a name provided by another module within the same MTA
	Requires []Requires `yaml:"requires,omitempty" json:"requires,omitempty"`
}

ResourceExt - can be anything required to run the application which is not provided by the application itself.

type ResourceTypes

type ResourceTypes struct {
	// An MTA internal name of the module type. Can be specified in the 'type' element of modules
	Name string `yaml:"name,omitempty" json:"name,omitempty"`
	// The name of the extended type. Can be another resource type defined in this descriptor or one of the default types supported by the deployer
	Extends string `yaml:"extends,omitempty" json:"extends,omitempty"`
	// Properties inherited by all resources of this type
	Properties         map[string]interface{} `yaml:"properties,omitempty" json:"properties,omitempty"`
	PropertiesMetaData map[string]MetaData    `yaml:"properties-metadata,omitempty" json:"properties-metadata,omitempty"`
	// Parameters inherited by all resources of this type
	Parameters         map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty"`
	ParametersMetaData map[string]MetaData    `yaml:"parameters-metadata,omitempty" json:"parameters-metadata,omitempty"`
}

ResourceTypes resources type declarations

Jump to

Keyboard shortcuts

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