opencontrol

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: CC0-1.0 Imports: 5 Imported by: 0

README

opencontrol.yaml README

opencontrol.yaml is a configuration file that describes the makeup of a system. It describes the components it directly uses as well as any dependent systems / components.

In order to support backwards comparability, we version the configuration file with a field named: schema_version.

The version is expressed in a string format using semantic versioning.

Adding a new schema version.

When adding a new schema version. (in this example we will add v2.0.0

  • Create a new numbered version folder under the versions folder.

    • e.g. mkdir versions/2.0.0/.
    • Make the package name for the go files schema.
    • Ensure there is a function that implements this prototype: func (s *Schema) Parse(data []byte) error
  • In parse.go

    • Create a new Schema Version variable for clean code sake.
      • e.g. SchemaV2_0_0 = semver.Version{2, 0, 0, nil, nil}
    • In the switch case, add a new case for 2.0.0 that calls ParseV2_0_0
    	case SchemaV2_0_0.Equals(v):
    		schema, parseError = parser.ParseV2_0_0(data)
    
  • Add a new ParseV2_0_0 function to the parser/parser.go file.

    • It should satisfy the func (p Parser) ParseVX_Y_Z(data []byte) (base.OpenControl, error) { prototype.
    • Alias the import so that you can easily refer to the particular version.
    import (
      v1_0_0 "github.com/opencontrol/compliance-masonry/pkg/lib/opencontrol/versions/1.0.0"
      v2_0_0 "github.com/opencontrol/compliance-masonry/pkg/lib/opencontrol/versions/1.0.0"
    )
    
    • Now it should call the parse function that your schema version has.
    config := v2_0_0.Schema{}
    config.Parse(data)
    

Documentation

Index

Constants

View Source
const (
	// ErrMalformedBaseYamlPrefix is just the prefix to the error message for when the program is unable to parse
	// data into the base yaml struct.
	ErrMalformedBaseYamlPrefix = "Unable to parse yaml data"
)

Variables

View Source
var (
	// SchemaV1_0_0 is the semantic versioning representation in object form for version 1.0.0
	SchemaV1_0_0 = semver.Version{Major: 1, Minor: 0, Patch: 0, Pre: nil, Build: nil}
)

Functions

This section is empty.

Types

type Base

type Base struct {
	// SchemaVersion contains the schema version.
	SchemaVersion string `yaml:"schema_version"`
}

Base is the common struct that all schemas must have.

func (Base) GetSchemaVersion

func (b Base) GetSchemaVersion() string

GetSchemaVersion is a simple getter function of the schema version.

type SchemaParser

type SchemaParser interface {
	Parse(data []byte) (common.OpenControl, error)
}

SchemaParser is a generic interface that knows how parse different schema_versions.

type YAMLParser

type YAMLParser struct{}

YAMLParser is the concrete implementation of parsing different schema versions in YAML format.

func (YAMLParser) Parse

func (parser YAMLParser) Parse(data []byte) (common.OpenControl, error)

Parse will try to parse the data and determine which specific version of schema to further parse.

Directories

Path Synopsis
versions

Jump to

Keyboard shortcuts

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