utils

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: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoerceToJsonMap

func CoerceToJsonMap(ymlData InterfaceOrBytes) (model map[string]interface{}, err error)

CoerceToJsonMap takes a yaml byte array and coerces it to a json interface{} This is necessary because the jsonschema library only accepts valid json data types that may not match yaml. Example: yaml allows for DateTimes to be time.Time, but json requires them to be strings This also allows for structs to be passed in, and they will be converted to map[string]interface{}

func CreateFileDirs

func CreateFileDirs(fullPath string) (err error)

CreateFileDirs creates the directories for a file path if they do not exist.

func FindValue

func FindValue(model map[string]interface{}, keys []string) interface{}

Finds the value of a key in a model in a map[string]interface{} given a slice of keys Returns nil if the key is not found or the model type is not supported Internal Recursive function so that the model can keep type safety

func FormatOscalVersion

func FormatOscalVersion(version string) (formattedVersion string)

FormatOscalVersion takes a version string and returns a formatted version string

func FormatTags

func FormatTags(cmdlineTags string) (tagList []string, err error)

formatTags formats Go struct tags.

func GetLatestSupportedVersion

func GetLatestSupportedVersion() string

GetLatestSupportedVersion returns the latest version of the OSCAL schema supported by the go-oscal release

func GetModelType

func GetModelType(model map[string]interface{}) (modelType string, err error)

GetModelType returns the type of the model if the model is valid returns error if more than one model is found or no models are found (consistent with OSCAL spec)

func GetOscalVersionFromMap

func GetOscalVersionFromMap(model map[string]interface{}) (version string, err error)

GetOscalVersionFromMap returns formatted OSCAL version if valid version is passed, returns error if not.

func GetTimestamp

func GetTimestamp() time.Time

func IsJson

func IsJson(path string) (err error)

func IsJsonOrYaml

func IsJsonOrYaml(path string) (err error)

isJsonOrYaml returns error if the file is not a json or yaml file.

func IsValidOscalVersion

func IsValidOscalVersion(version string) error

IsValidOscalVersion returns true if the version is supported, false if not.

func MarshalByExtension

func MarshalByExtension(model interface{}, outputFile string) (bytes []byte, err error)

MarshalByExtension takes a model and marshals it to json or yaml based on the extension of the output file

func RemoveTrailingWhitespace added in v0.3.1

func RemoveTrailingWhitespace(bytes []byte) []byte

RemoveTrailingWhitespace removes trailing whitespace from each line in a byte array. This is useful for removing trailing whitespace from a yaml file before it is marshalled into a struct. Prevents strings from being collapsed into a single line by yaml parser.

func ReplaceOscalVersionInMap

func ReplaceOscalVersionInMap(model map[string]interface{}, version string) (upgradedModel map[string]interface{}, err error)

ReplaceOscalVersionInMap returns the model with the oscal version replaced

func UpdateLastModified

func UpdateLastModified(metadata map[string]interface{})

UpdateLastModified updates the last-modified field in the metadata

func VersionWarning

func VersionWarning(version string) error

VersionWarning returns an warning as an error if there are any known issues with the current version or it isn't the latest.

func WriteOutput

func WriteOutput(output []byte, outputFile string) (err error)

WriteOutput writes to the provided output file or to stdout by default.

Types

type InterfaceOrBytes

type InterfaceOrBytes interface {
	interface{} | []byte
}

InterfaceOrBytes is an interface{} or []byte for generic functions that can support either type

Jump to

Keyboard shortcuts

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