Documentation ¶
Overview ¶
Package definitions provides functions for reading, parsing and converting object's definitions.
Index ¶
- Constants
- Variables
- func Decode(data []byte) ([]manifest.Object, error)
- func DecodeSingle[T manifest.Object](data []byte) (object T, err error)
- func GetSupportedFileExtensions() []string
- func Read(ctx context.Context, rawSources ...RawSource) ([]manifest.Object, error)
- func ReadSources(ctx context.Context, sources ...*Source) ([]manifest.Object, error)
- type RawSource
- type Source
- type SourceType
Constants ¶
const APIVersionRegex = `"?apiVersion"?\s*:\s*"?n9`
Variables ¶
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") ErrSourceTypeReaderPath = errors.New("SourceTypeReader Source may define at most a single Source.Path") )
var ErrNoDefinitionsFound = errors.New("no definitions in input")
Functions ¶
func Decode ¶ added in v0.28.0
Decode reads objects from the provided bytes slice. It detects if the input is in JSON (manifest.RawObjectFormatJSON) or YAML (manifest.RawObjectFormatYAML format.
func DecodeSingle ¶ added in v0.28.0
DecodeSingle returns a single, concrete object implementing manifest.Object. It expects exactly one object in the decoded byte slice.
func GetSupportedFileExtensions ¶
func GetSupportedFileExtensions() []string
GetSupportedFileExtensions returns the file extensions which are used to filter out files to be processed.
func Read ¶
Read resolves the RawSource(s) it receives and calls ReadSources on the resolved Source(s).
func ReadSources ¶
ReadSources reads from the provided Source(s) based on the SourceType. For SourceTypeReader 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 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 (SourceTypeReader)
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 SourceTypeReader 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 NewReaderSource ¶ added in v0.28.0
NewReaderSource creates a special instance of Source with SourceTypeReader. ReadSources will process the Source by reading form the provided io.Reader.
func ResolveSource ¶
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 SourceTypeReader Source you should use a separate method: NewReaderSource.
func ResolveSources ¶
ResolveSources calls ResolveSource on all supplied RawSource(s) and aggregates the resolved Source(s). It fails fast on the first encountered error.
type SourceType ¶
type SourceType int
const ( SourceTypeFile SourceType = iota SourceTypeDirectory SourceTypeGlobPattern SourceTypeURL SourceTypeReader )
func (SourceType) String ¶
func (i SourceType) String() string