definitions

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package definitions provides functions for reading, parsing and converting object's definitions.

Index

Constants

View Source
const APIVersionRegex = `"?apiVersion"?\s*:\s*"?n9`

Variables

View Source
var (
	ErrIoReaderIsNil          = errors.New("io.Reader must no be nil")
	ErrNoFilesMatchingPattern = errors.Errorf(
		"no Nobl9 resource definition files matched the provided path pattern, %s", matchingRulesDisclaimer)
	ErrNoFilesInPath = errors.Errorf("no Nobl9 resource definition files were found under selected path, %s",
		matchingRulesDisclaimer)
	ErrInvalidFile = errors.Errorf("valid Nobl9 resource definition must match against the following regex: '%s'",
		APIVersionRegex)
	ErrInvalidSourceType = errors.New("invalid SourceType provided")
)

Functions

func GetSupportedFileExtensions

func GetSupportedFileExtensions() []string

GetSupportedFileExtensions returns the file extensions which are used to filter out files to be processed.

func Read

func Read(ctx context.Context, annotations MetadataAnnotations, rawSources ...RawSource) ([]sdk.AnyJSONObj, error)

Read resolves the RawSource(s) it receives and calls ReadSources on the resolved Source(s).

func ReadSources

func ReadSources(ctx context.Context, annotations MetadataAnnotations, sources ...*Source) ([]sdk.AnyJSONObj, error)

ReadSources reads from the provided Source(s) based on the SourceType. For SourceTypeInput it will read directly from Source.Reader, otherwise it reads from all the Source.Paths. It calculates a sum for each definition read from Source and won't create duplicates. This allows the user to combine Source(s) with possibly overlapping paths. If the same exact definition is identified with multiple sources, it will choose the first Source path it encounters. If the Source is of type SourceTypeGlobPattern or SourceTypeDirectory and a file does not contain the required APIVersionRegex, it is skipped. However in case of SourceTypeFile, it will thrown ErrInvalidFile error.

Types

type MetadataAnnotations

type MetadataAnnotations struct {
	Organization string
	Project      string
	// When using Read or ReadSources this field is set by these functions,
	// anything here will provided here will be overwritten.
	ManifestSource string
}

MetadataAnnotations defines a set of annotations appended to applied objects definitions. These annotations are only set if the resource definition does not contain them already.

func (MetadataAnnotations) AnnotateObject

func (ma MetadataAnnotations) AnnotateObject(object sdk.AnyJSONObj) (sdk.AnyJSONObj, error)

AnnotateObject annotates an sdk.Kind with additional metadata. If objects does not contain project - default value is added. If value 'metadata.project' in the definition is different from the Project provided in MetadataAnnotations, an error is returned.

type RawSource

type RawSource = string

RawSource may be interpreted as (with interpretation): - file path (SourceTypeFile or SourceTypeDirectory) - glob pattern (SourceTypeGlobPattern) - URL (SourceTypeURL) - input provided via io.Reader, like os.Stdin (SourceTypeInput)

type Source

type Source struct {
	// Type defines how the Source should be read when passed to ReadSources.
	Type SourceType
	// Paths lists all resolved URIs the Source points at.
	Paths []string
	// Reader may be optionally provided with SourceTypeInput for ReadSources to read from the io.Reader.
	Reader io.Reader
	// Raw is the original, unresolved RawSource, an example might be a relative path
	// which was resolved to its absolute form.
	Raw RawSource
}

Source represents a single resource definition source.

func NewInputSource

func NewInputSource(r io.Reader, source RawSource) *Source

NewInputSource creates a special instance of Source with SourceTypeInput. ReadSources will process the Source by reading form the provided io.Reader.

func ResolveSource

func ResolveSource(rawSource RawSource) (src *Source, err error)

ResolveSource attempts to resolve a single RawSource producing a Source instance read to be passed to ReadSources. It interprets the provided URI and associates it with a specific SourceType. If you wish to create a SourceTypeInput Source you should use a separate method: NewInputSource.

func ResolveSources

func ResolveSources(rawSources ...RawSource) ([]*Source, error)

ResolveSources calls ResolveSource on all supplied RawSource(s) and aggregates the resolved Source(s). It fails fast on the first encountered error.

func (Source) String

func (s Source) String() string

type SourceType

type SourceType int
const (
	SourceTypeFile SourceType = iota
	SourceTypeDirectory
	SourceTypeGlobPattern
	SourceTypeURL
	SourceTypeInput
)

func (SourceType) String

func (i SourceType) String() string

Jump to

Keyboard shortcuts

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