validation

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 6

Documentation

Index

Constants

View Source
const (
	NON_SCHEMA_ERROR_ABSOLUTE_KEYWORD_LOCATION = "non-schema-error"
)

Variables

This section is empty.

Functions

func Flatten added in v0.6.0

func Flatten(outputUnit *jsonschema.OutputUnit) []*jsonschema.OutputUnit

Flatten function to collect all OutputUnits into a slice

func GetNonSchemaError added in v0.6.0

func GetNonSchemaError(result *ValidationResult) error

GetNonSchemaError extracts the system validation error If the result is not a system validation error or if there are no errors, return nil

func IsNonSchemaValidationError added in v0.6.0

func IsNonSchemaValidationError(result *ValidationResult) bool

IsNonSchemaValidationError checks if the result is a system validation error

func WriteValidationResult

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

WriteValidationResult writes a ValidationResult to a file

func WriteValidationResults added in v0.4.3

func WriteValidationResults(validationResults []ValidationResult, outputFile string) (err error)

WriteValidationResults writes a slice of ValidationResults to a file

Types

type ValidationParams added in v0.6.0

type ValidationParams struct {
	// This is the name of the model to validate (used for documentation and error reporting purposes) (required)
	ModelType string `json:"model-type,omitempty" yaml:"model-type,omitempty"`
	// This is the reference of the model to validate (does not have to be a url, used for documentation and error reporting purposes) (optional)
	ModelPath string `json:"model-path,omitempty" yaml:"model-path,omitempty"`
	// This is the version of the model to validate against (for example, 1.0.0) (optional)
	ModelVersion string `json:"model-version,omitempty" yaml:"model-version,omitempty"`
	// Must be a json map (map[string]interface{}) (required)
	ModelData map[string]interface{} `json:"model-data,omitempty" yaml:"model-data,omitempty"`
	// This is the reference of the schema to validate against (does not have to be a url, used for documentation and error reporting purposes) (required)
	SchemaPath string `json:"schema-path,omitempty" yaml:"schema-path,omitempty"`
	// Must be a json map (map[string]interface{}) (required)
	SchemaData map[string]interface{} `json:"schema-data,omitempty" yaml:"schema-data,omitempty"`
	// This is the version of the schema to validate against (for example, 1.0.0) (optional)
	SchemaVersion string `json:"schema-version,omitempty" yaml:"schema-version,omitempty"`
}

type ValidationResponse

type ValidationResponse struct {
	Validator Validator
	// Parsed validation result
	Result ValidationResult
	// Non-failing go-oscal warnings (ie: deprecated fields, newer schema versions, etc)
	Warnings []string
	// Unparsed Failing validation errors from the jsonschema library
	JsonSchemaError *jsonschema.ValidationError
}

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 is true if the validation result is valid
	Valid bool `json:"valid" yaml:"valid"`
	// TimeStamp is the time the validation result was created
	TimeStamp time.Time `json:"timeStamp" yaml:"timeStamp"`
	// Errors is a slice of ValidatorErrors
	Errors []ValidatorError `json:"errors,omitempty" yaml:"errors,omitempty"`
	// Metadata is the metadata of the validation result
	Metadata ValidationResultMetadata `json:"metadata" yaml:"metadata"`
}

func NewNonSchemaValidationError added in v0.6.0

func NewNonSchemaValidationError(err error, params *ValidationParams) *ValidationResult

NewNonSchemaValidationError creates a system validation error

func NewValidationResult

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

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

func NewValidationResultFromParams added in v0.6.0

func NewValidationResultFromParams(params *ValidationParams, valErrs []ValidatorError) *ValidationResult

NewValidationResultFromParams creates a new validation result from the params

func ValidateFromParams added in v0.6.0

func ValidateFromParams(params *ValidationParams) (*ValidationResult, error)

ValidateFromParams validates a model against a schema using the given `ValidationParams`

type ValidationResultMetadata

type ValidationResultMetadata struct {
	// DocumentPath is the path to the document
	DocumentPath string `json:"documentPath,omitempty" yaml:"documentPath,omitempty"`
	// DocumentType is the type of the document
	DocumentType string `json:"documentType,omitempty" yaml:"documentType,omitempty"`
	// DocumentVersion is the version of the document
	DocumentVersion string `json:"documentVersion,omitempty" yaml:"documentVersion,omitempty"`
	// SchemaVersion is the version of the schema
	SchemaVersion string `json:"schemaVersion,omitempty" yaml:"schemaVersion,omitempty"`
}

func NewValidationResultMetadataFromParams added in v0.6.0

func NewValidationResultMetadataFromParams(params *ValidationParams) ValidationResultMetadata

NewValidationResultMetadataFromParams creates a new validation result metadata from the params

type Validator

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

func NewValidator

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

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

func NewValidatorDesiredVersion

func NewValidatorDesiredVersion(oscalDoc model.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) GetValidationParams added in v0.6.0

func (v *Validator) GetValidationParams() (*ValidationParams, error)

GetValidationParams returns the validation params for the validator.

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 is the location of the keyword in the schema for failing value
	KeywordLocation string `json:"keywordLocation" yaml:"keywordLocation"`
	// AbsoluteKeywordLocation is the absolute location of the keyword in the schema for failing value
	AbsoluteKeywordLocation string `json:"absoluteKeywordLocation" yaml:"absoluteKeywordLocation"`
	// InstanceLocation is the location of the instance in the document
	InstanceLocation string `json:"instanceLocation" yaml:"instanceLocation"`
	// Error is the error message
	Error string `json:"error" yaml:"error"`
	// FailedValue is the value of the key that failed validation
	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{}, detailedOutputUnit *jsonschema.OutputUnit) (validationErrors []ValidatorError)

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

Jump to

Keyboard shortcuts

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