bundle

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright 2021 Cloud Privacy Labs, LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bundle

type Bundle struct {
	Base         string                 `json:"base" yaml:"base"`
	Spreadsheets []SpreadsheetReference `json:"spreadsheets" yaml:"spreadsheets"`
	JSONSchemas  []JSONSchema           `json:"jsonSchemas" yaml:"jsonSchemas"`
	Variants     map[string]*Variant    `json:"variants" yaml:"variants"`

	// Layers, keyed by layer ID
	Layers map[string]*ls.Layer
	// contains filtered or unexported fields
}

Bundle defines type names for variants so references can be resolved

func LoadBundle

func LoadBundle(base string, bundleLoader func(parentBundle, loadBundle string) (Bundle, error)) (Bundle, error)

LoadBundle loads a bundle and all the bundles it includes. The bundleLoader is called with the parent bundle name, and the next bundle to load. Parent bundle name can be empty, which means, that is the first bundle to load.

func NewBundleFromVariants

func NewBundleFromVariants(variantMap map[string]*ls.Layer) Bundle

NewBundleFromVariants creates a new bundle from the given variants

func (*Bundle) Add

func (bundle *Bundle) Add(ctx *ls.Context, typeName string, schema *ls.Layer, overlays ...*ls.Layer) (*ls.Layer, error)

Add a new variant to the bundle. The typeName must be unique. If empty, schema type will be used. If there are overlays, the variant will be built using the schema as the base, so caller must create a clone if necessary.

func (*Bundle) Build

func (bundle *Bundle) Build(ctx *ls.Context, spreadsheetLoader func(*ls.Context, string) ([][][]string, error), jsonLoader func(*ls.Context, string) (io.ReadCloser, error), layerLoader func(*ls.Context, string) (*ls.Layer, error)) error

Build collects all parts of a bundle and builds the layers

func (*Bundle) GetCachedLayers

func (bundle *Bundle) GetCachedLayers() map[string]*ls.Layer

func (*Bundle) GetLayer

func (bundle *Bundle) GetLayer(ctx *ls.Context, variant string) (*ls.Layer, error)

GetLayer returns the layer for the given variant. Returns nil if not found. Panics if bundle is not initialized

func (*Bundle) LoadSchema

func (bundle *Bundle) LoadSchema(variant string) (*ls.Layer, error)

func (*Bundle) Merge

func (b *Bundle) Merge(bundle Bundle)

Merge bundle into b

type JSONSchema

type JSONSchema struct {
	// NAme of the JSON schema. This name is passed to the json schema
	// loader to load the schema
	Name string `json:"name" yaml:"name"`

	// The ID of the JSON schema. This ID will be used to reference to
	// this schema within the bundle
	ID string `json:"id" yaml:"id"`

	// JSON schema overlays. These overlays are also JSON schemas
	Overlays []string `json:"overlays" yaml:"overlays"`
}

A JSONSchema is a reference to a JSON schema document, with optional overlays. The JSON schema is loaded, and combined with the specified overlays. Then, it is made available to the bundle using the ID

func (JSONSchema) Load

func (sch JSONSchema) Load(ctx *ls.Context, loader func(*ls.Context, string) (io.ReadCloser, error)) (jsonom.Node, error)

type JSONSchemaReference

type JSONSchemaReference struct {
	// Refer to a layer by ID. Layer can be imported as a spreadsheet
	LayerID string `json:"layerId" yaml:"layerId" bson:"layerId"`
	// This is the reference to the JSON schema defined in the bundle, with an optional fragment
	Ref       string `json:"ref" yaml:"ref" bson:"ref"`
	Namespace string `json:"namespace" yaml:"namespace" bson:"namespace"`
}

func (JSONSchemaReference) GetSchemaBase

func (j JSONSchemaReference) GetSchemaBase() string

GetSchemaBase returns the JSON schema base name, without the fragment

type SchemaRef

type SchemaRef struct {
	Schema     string               `json:"schema,omitempty" yaml:"schema,omitempty"`
	LayerID    string               `json:"layerId,omitempty" yaml:"layerId,omitempty"`
	JSONSchema *JSONSchemaReference `json:"jsonSchema" yaml:"jsonSchema"`
	// contains filtered or unexported fields
}

func (*SchemaRef) Merge

func (ref *SchemaRef) Merge(b SchemaRef)

Merge resets b with ref if ref is nonempty

type SpreadsheetReference

type SpreadsheetReference struct {
	Name    string             `json:"name" yaml:"name"`
	Spec    *csv.CSVImportSpec `json:"spec" yaml:"spec"`
	Context []interface{}      `json:"context" yaml:"context"`
}

func (SpreadsheetReference) Import

func (s SpreadsheetReference) Import(ctx *ls.Context, sheetReader func(*ls.Context, string) ([][][]string, error)) (map[string]*ls.Layer, error)

type Variant

type Variant struct {
	SchemaRef `yaml:",inline"`
	Overlays  []SchemaRef `json:"overlays" yaml:"overlays"`
}

Variant combines a schema and overlays

func (*Variant) Merge

func (variant *Variant) Merge(b Variant)

Merge variant into b

Jump to

Keyboard shortcuts

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