validation

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 9 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteValidationResult

func WriteValidationResult(validationResult ValidationResult, outputFile string) (err error)

WriteValidationResult writes a ValidationResult to a file

Types

type ValidationResponse

type ValidationResponse struct {
	Validator Validator
	Result    ValidationResult
	Warnings  []string
}

func ValidationCommand

func ValidationCommand(inputFile string) (validationResponse ValidationResponse, err error)

ValidationCommand validates an OSCAL document Returns a ValidationResponse and an error

type ValidationResult

type ValidationResult struct {
	Valid     bool                     `json:"valid" yaml:"valid"`
	TimeStamp time.Time                `json:"timeStamp" yaml:"timeStamp"`
	Errors    []ValidatorError         `json:"errors,omitempty" yaml:"errors,omitempty"`
	Metadata  ValidationResultMetadata `json:"metadata" yaml:"metadata"`
}

func NewValidationResult

func NewValidationResult(validator *Validator, errors []ValidatorError) ValidationResult

NewValidationResult creates a new ValidationResult from a Validator and a slice of ValidatorErrors

type ValidationResultMetadata

type ValidationResultMetadata struct {
	DocumentPath    string `json:"documentPath,omitempty" yaml:"documentPath,omitempty"`
	DocumentType    string `json:"documentType,omitempty" yaml:"documentType,omitempty"`
	DocumentVersion string `json:"documentVersion,omitempty" yaml:"documentVersion,omitempty"`
	SchemaVersion   string `json:"schemaVersion,omitempty" yaml:"schemaVersion,omitempty"`
}

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

func NewValidator

func NewValidator(oscalDoc utils.InterfaceOrBytes) (validator Validator, err error)

NewValidator returns a validator with the models version of the schema.

func NewValidatorDesiredVersion

func NewValidatorDesiredVersion(oscalDoc utils.InterfaceOrBytes, desiredVersion string) (validator Validator, err error)

NewValidatorDesiredVersion returns a validator with the desired version of the schema.

func (*Validator) GetDocumentPath

func (v *Validator) GetDocumentPath() string

GetDocumentPath returns the path of the document being validated.

func (*Validator) GetJsonModel

func (v *Validator) GetJsonModel() map[string]interface{}

GetJsonModel returns the model being validated.

func (*Validator) GetModelType

func (v *Validator) GetModelType() string

GetModelType returns the type of the model being validated.

func (*Validator) GetSchemaVersion

func (v *Validator) GetSchemaVersion() string

GetSchemaVersion returns the version of the schema used to validate the model.

func (*Validator) GetValidationResult

func (v *Validator) GetValidationResult() (ValidationResult, error)

GetValidationResult returns a ValidationResult. If the validation has not been run, an error is returned.

func (*Validator) IsLatestOscalVersion

func (v *Validator) IsLatestOscalVersion() (bool, error)

IsLatestOscalVersion returns true if the model is the latest version of the OSCAL schema.

func (*Validator) SetDocumentPath

func (v *Validator) SetDocumentPath(documentPath string)

SetDocumentPath sets the path of the document being validated.

func (*Validator) Validate

func (v *Validator) Validate() error

Validate validates the model against the schema.

type ValidatorError

type ValidatorError struct {
	KeywordLocation         string      `json:"keywordLocation" yaml:"keywordLocation"`
	AbsoluteKeywordLocation string      `json:"absoluteKeywordLocation" yaml:"absoluteKeywordLocation"`
	InstanceLocation        string      `json:"instanceLocation" yaml:"instanceLocation"`
	Error                   string      `json:"error" yaml:"error"`
	FailedValue             interface{} `json:"failedValue,omitempty" yaml:"failedValue,omitempty"`
}

Extension of the jsonschema.BasicError struct to include the failed value if the failed value is a map or slice, it will be omitted

func ExtractErrors

func ExtractErrors(originalObject map[string]interface{}, validationError jsonschema.Basic) (validationErrors []ValidatorError)

Creates a []ValidatorError from a jsonschema.Basic The jsonschema.Basic contains the errors from the validation

Jump to

Keyboard shortcuts

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