common

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UUID_PREFIX    = "#"
	WILDCARD       = "*"
	YAML_DELIMITER = "---"
)

Variables

View Source
var (
	ErrInvalidSchema   = errors.New("schema is invalid")
	ErrInvalidYaml     = errors.New("error unmarshaling JSON")
	ErrInvalidVersion  = errors.New("version is invalid")
	ErrInvalidDomain   = errors.New("domain is invalid")
	ErrInvalidProvider = errors.New("provider is invalid")
)

Define base errors for validations

Functions

func AddIdPrefix added in v0.3.0

func AddIdPrefix(id string) string

AddIdPrefix adds the id prefix to the given id

func GetDomain added in v0.2.0

func GetDomain(domain *Domain, ctx context.Context) (types.Domain, error)

Get the domain and providers

func GetProvider added in v0.2.0

func GetProvider(provider *Provider, ctx context.Context) (types.Provider, error)
func IsLulaLink(link oscalTypes_1_1_2.Link) bool

IsLulaLink checks if the link is a lula link

func IsVersionValid added in v0.1.0

func IsVersionValid(versionConstraint string, version string) (bool, error)

Returns version validity

func ReadFileToBytes

func ReadFileToBytes(path string) ([]byte, error)

ReadFileToBytes reads a file to bytes

func SetCwdToFileDir added in v0.2.0

func SetCwdToFileDir(dirPath string) (resetFunc func(), err error)

SetCwdToFileDir takes a path and changes the current working directory to the directory of the path

func TrimIdPrefix added in v0.3.0

func TrimIdPrefix(id string) string

TrimIdPrefix trims the id prefix from the given id

func ValidationFromString added in v0.2.0

func ValidationFromString(raw string) (validation types.LulaValidation, err error)

Converts a raw string to a Validation object (string -> common.Validation -> types.Validation)

Types

type Domain added in v0.2.0

type Domain struct {
	// Type is the type of domain: enum: kubernetes, api
	Type string `json:"type" yaml:"type"`
	// KubernetesSpec is the specification for a Kubernetes domain, required if type is kubernetes
	KubernetesSpec *kube.KubernetesSpec `json:"kubernetes-spec,omitempty" yaml:"kubernetes-spec,omitempty"`
	// ApiSpec is the specification for an API domain, required if type is api
	ApiSpec *api.ApiSpec `json:"api-spec,omitempty" yaml:"api-spec,omitempty"`
}

Domain is a structure that contains the domain type and the corresponding spec

type Metadata added in v0.2.0

type Metadata struct {
	Name string `json:"name" yaml:"name"`
	UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
}

Metadata is a structure that contains the name and uuid of a validation

type Provider added in v0.2.0

type Provider struct {
	Type        string               `json:"type" yaml:"type"`
	OpaSpec     *opa.OpaSpec         `json:"opa-spec,omitempty" yaml:"opa-spec,omitempty"`
	KyvernoSpec *kyverno.KyvernoSpec `json:"kyverno-spec,omitempty" yaml:"kyverno-spec,omitempty"`
}

type Validation added in v0.2.0

type Validation struct {
	LulaVersion string    `json:"lula-version" yaml:"lula-version"`
	Metadata    *Metadata `json:"metadata,omitempty" yaml:"metadata,omitempty"`
	Provider    *Provider `json:"provider,omitempty" yaml:"provider,omitempty"`
	Domain      *Domain   `json:"domain,omitempty" yaml:"domain,omitempty"`
}

Data structures for ingesting validation data

func ReadValidationsFromYaml added in v0.4.0

func ReadValidationsFromYaml(validationBytes []byte) (validations []Validation, err error)

ReadValidationsFromYaml reads a yaml file of validations to an array of validations

func (*Validation) Lint added in v0.4.3

func (validation *Validation) Lint() oscalValidation.ValidationResult

Lint is a convenience method to lint a Validation object

func (*Validation) MarshalYaml added in v0.2.0

func (v *Validation) MarshalYaml() ([]byte, error)

MarshalYaml is a convenience method to marshal a Validation object to a YAML byte array

func (*Validation) ToLulaValidation added in v0.2.0

func (validation *Validation) ToLulaValidation() (lulaValidation types.LulaValidation, err error)

ToLulaValidation converts a Validation object to a LulaValidation object

func (*Validation) ToResource added in v0.3.0

func (v *Validation) ToResource() (resource *oscalTypes_1_1_2.Resource, err error)

ToResource converts a Validation object to a Resource object

func (*Validation) UnmarshalYaml added in v0.2.0

func (v *Validation) UnmarshalYaml(data []byte) error

UnmarshalYaml is a convenience method to unmarshal a Validation object from a YAML byte array

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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