processor

package
v0.29.3 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package processor is used to process the library files and read them into a result struct for Alzlib to use.

Index

Constants

View Source
const (
	PolicyAssignmentFileType       = "alz_policy_assignment"
	PolicyDefinitionFileType       = "alz_policy_definition"
	PolicySetDefinitionFileType    = "alz_policy_set_definition"
	RoleDefinitionFileType         = "alz_role_definition"
	ArchitectureDefinitionFileType = "alz_architecture_definition"
	ArchetypeDefinitionFileType    = "alz_archetype_definition"
	ArchetypeOverrideFileType      = "alz_archetype_override"
	PolicyDefaultValuesFileType    = "alz_policy_default_values"
)

These are the file prefixes for the resource types.

Variables

View Source
var (
	// ArchitectureDefinitionRegex matches architecture definition files.
	ArchitectureDefinitionRegex = regexp.MustCompile(architectureDefinitionSuffix)
	// ArchetypeDefinitionRegex matches archetype definition files.
	ArchetypeDefinitionRegex = regexp.MustCompile(archetypeDefinitionSuffix)
	// ArchetypeOverrideRegex matches archetype override files.
	ArchetypeOverrideRegex = regexp.MustCompile(archetypeOverrideSuffix)
	// PolicyAssignmentRegex matches policy assignment files.
	PolicyAssignmentRegex = regexp.MustCompile(policyAssignmentSuffix)
	// PolicyDefinitionRegex matches policy definition files.
	PolicyDefinitionRegex = regexp.MustCompile(policyDefinitionSuffix)
	// PolicySetDefinitionRegex matches policy set definition files.
	PolicySetDefinitionRegex = regexp.MustCompile(policySetDefinitionSuffix)
	// RoleDefinitionRegex matches role definition files.
	RoleDefinitionRegex = regexp.MustCompile(roleDefinitionSuffix)
	// PolicyDefaultValuesRegex matches policy default values files.
	PolicyDefaultValuesRegex = regexp.MustCompile(policyDefaultValueFileName)
)
View Source
var (
	// ErrResourceAlreadyExists is returned when a resource already exists in the result.
	ErrResourceAlreadyExists = errors.New("resource already exists in the result")

	// ErrNoNameProvided is returned when no name was provided for the resource.
	ErrNoNameProvided = errors.New("no name provided for the resource, cannot process it without a name")

	// ErrUnmarshaling is returned when unmarshaling fails.
	ErrUnmarshaling = errors.New("error converting data from YAML/JSON, please check the file format and content")

	// ErrMultipleDefaultPolicyValuesFileFound is returned when multiple default policy values files are found.
	ErrMultipleDefaultPolicyValuesFileFound = errors.New("multiple default policy values files found, only one is allowed")

	// ErrProcessingFile is returned when there is an error processing the file.
	ErrProcessingFile = errors.New("error processing file, please check the file format and content")
)

Functions

func NewErrNoNameProvided added in v0.27.0

func NewErrNoNameProvided(resourceType string) error

NewErrNoNameProvided creates a new error indicating that no name was provided for the resource.

func NewErrResourceAlreadyExists added in v0.27.0

func NewErrResourceAlreadyExists(resourceType, name string) error

NewErrResourceAlreadyExists creates a new error indicating that a resource already exists in the result.

func NewErrorUnmarshaling added in v0.27.0

func NewErrorUnmarshaling(detail string) error

NewErrorUnmarshaling creates a new error indicating that unmarshaling failed.

Types

type Client added in v0.27.0

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

Client is the client that is used to process the library files.

func NewClient added in v0.27.0

func NewClient(fs fs.FS) *Client

NewClient creates a new Client with the provided filesystem.

func (*Client) Metadata added in v0.27.0

func (client *Client) Metadata() (*LibMetadata, error)

Metadata returns the metadata of the library.

func (*Client) Process added in v0.27.0

func (client *Client) Process(res *Result) error

Process reads the library files and processes them into a Result. Pass in a pointer to a Result struct to store the processed data, create a new *Result with NewResult().

type LibArchetype

type LibArchetype struct {
	Name                 string             `json:"name"                   yaml:"name"`
	PolicyAssignments    mapset.Set[string] `json:"policy_assignments"     yaml:"policy_assignments"`
	PolicyDefinitions    mapset.Set[string] `json:"policy_definitions"     yaml:"policy_definitions"`
	PolicySetDefinitions mapset.Set[string] `json:"policy_set_definitions" yaml:"policy_set_definitions"`
	RoleDefinitions      mapset.Set[string] `json:"role_definitions"       yaml:"role_definitions"`
}

LibArchetype represents an archetype definition file, it used to construct the Archetype struct and is then added to the AlzLib struct.

func (*LibArchetype) UnmarshalJSON

func (la *LibArchetype) UnmarshalJSON(data []byte) error

UnmarshalJSON creates a LibArchetype from the supplied JSON bytes.

func (*LibArchetype) UnmarshalYAML

func (la *LibArchetype) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML creates a LibArchetype from the supplied JSON bytes.

type LibArchetypeOverride

type LibArchetypeOverride struct {
	Name                         string             `json:"name" yaml:"name"`
	BaseArchetype                string             `json:"base_archetype" yaml:"base_archetype"`
	PolicyAssignmentsToAdd       mapset.Set[string] `json:"policy_assignments_to_add" yaml:"policy_assignments_to_add"`
	PolicyAssignmentsToRemove    mapset.Set[string] `json:"policy_assignments_to_remove" yaml:"policy_assignments_to_remove"` //nolint:lll
	PolicyDefinitionsToAdd       mapset.Set[string] `json:"policy_definitions_to_add" yaml:"policy_definitions_to_add"`
	PolicyDefinitionsToRemove    mapset.Set[string] `json:"policy_definitions_to_remove" yaml:"policy_definitions_to_remove"`         //nolint:lll
	PolicySetDefinitionsToAdd    mapset.Set[string] `json:"policy_set_definitions_to_add" yaml:"policy_set_definitions_to_add"`       //nolint:lll
	PolicySetDefinitionsToRemove mapset.Set[string] `json:"policy_set_definitions_to_remove" yaml:"policy_set_definitions_to_remove"` //nolint:lll
	RoleDefinitionsToAdd         mapset.Set[string] `json:"role_definitions_to_add" yaml:"role_definitions_to_add"`
	RoleDefinitionsToRemove      mapset.Set[string] `json:"role_definitions_to_remove" yaml:"role_definitions_to_remove"`
}

LibArchetypeOverride represents an archetype override definition file, it used to construct generate a new Archetype struct from an existing full archetype and is then added to the AlzLib struct.

func (*LibArchetypeOverride) UnmarshalJSON

func (lao *LibArchetypeOverride) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for LibArchetypeOverride.

func (*LibArchetypeOverride) UnmarshalYAML

func (lao *LibArchetypeOverride) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface for LibArchetypeOverride.

type LibArchitecture

type LibArchitecture struct {
	Name             string                           `json:"name"              yaml:"name"`
	ManagementGroups []LibArchitectureManagementGroup `json:"management_groups" yaml:"management_groups"`
}

LibArchitecture represents a management group hierarchy in the library.

func (*LibArchitecture) UnmarshalJSON

func (la *LibArchitecture) UnmarshalJSON(data []byte) error

UnmarshalJSON creates a LibArchitecture from the supplied JSON bytes.

func (*LibArchitecture) UnmarshalYAML

func (la *LibArchitecture) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML creates a LibArchitecture from the supplied JSON bytes.

type LibArchitectureManagementGroup

type LibArchitectureManagementGroup struct {
	ID          string             `json:"id"           yaml:"id"`
	DisplayName string             `json:"display_name" yaml:"display_name"`
	Archetypes  mapset.Set[string] `json:"archetypes"   yaml:"archetypes"`
	ParentID    *string            `json:"parent_id"    yaml:"parent_id"`
	Exists      bool               `json:"exists"       yaml:"exists"`
}

LibArchitectureManagementGroup represents a management group in the library.

type LibDefaultPolicyValueAssignments

type LibDefaultPolicyValueAssignments struct {
	PolicyAssignmentName string   `json:"policy_assignment_name" yaml:"policy_assignment_name"`
	ParameterNames       []string `json:"parameter_names"        yaml:"parameter_names"`
}

LibDefaultPolicyValueAssignments represents the policy assignments for a default value.

type LibDefaultPolicyValues

type LibDefaultPolicyValues struct {
	Defaults []LibDefaultPolicyValuesDefaults `json:"defaults" yaml:"defaults"`
}

LibDefaultPolicyValues represents the top level value that allow a single value to be mapped into different assignments.

type LibDefaultPolicyValuesDefaults

type LibDefaultPolicyValuesDefaults struct {
	DefaultName       string                             `json:"default_name"          yaml:"default_name"`
	Description       string                             `json:"description,omitempty" yaml:"description"`
	PolicyAssignments []LibDefaultPolicyValueAssignments `json:"policy_assignments"    yaml:"policy_assignments"`
}

LibDefaultPolicyValuesDefaults represents the default policy values that allow a single value to be mapped into different assignments.

type LibMetadata

type LibMetadata struct {
	Name        string `json:"name"         yaml:"name"`         // The name of the library member
	DisplayName string `json:"display_name" yaml:"display_name"` // The display name of the library member
	Description string `json:"description"  yaml:"description"`  // The description of the library member
	// The dependencies of the library member in the format of "path/tag", e.g. "platform/alz/2024.03.0
	Dependencies []LibMetadataDependency `json:"dependencies" yaml:"dependencies"`
	// The relative path to the library member, e.g. "platform/alz"
	Path string `json:"path" yaml:"path"`
}

LibMetadata represents the metadata of a library member in the ALZ Library.

type LibMetadataDependency

type LibMetadataDependency struct {
	// The relative path to the library member within the ALZ Library, e.g. "platform/alz"
	Path string `json:"path"       yaml:"path"`
	Ref  string `json:"ref"        yaml:"ref"` // The calver tag of the library member, e.g. "2024.03.0"
	// The custom URL (go-getter path) of the library member, used when the library member is not in the ALZ Library
	CustomURL string `json:"custom_url" yaml:"custom_url"`
}

LibMetadataDependency represents a dependency of a library member. Use either Path + Ref or CustomUrl.

type Result

type Result struct {
	PolicyDefinitions      map[string]*assets.PolicyDefinitionVersions
	PolicySetDefinitions   map[string]*assets.PolicySetDefinitionVersions
	PolicyAssignments      map[string]*assets.PolicyAssignment
	RoleDefinitions        map[string]*assets.RoleDefinition
	LibArchetypes          map[string]*LibArchetype
	LibArchetypeOverrides  map[string]*LibArchetypeOverride
	LibDefaultPolicyValues map[string]*LibDefaultPolicyValuesDefaults
	LibArchitectures       map[string]*LibArchitecture
	Metadata               *LibMetadata
	// contains filtered or unexported fields
}

Result is the structure that gets built by scanning the library files.

func NewResult

func NewResult() *Result

NewResult creates a new Result struct with initialized maps for each resource type.

type Unmarshaler added in v0.29.0

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

Unmarshaler is a struct that unmarshals data based on the file extension.

func NewUnmarshaler added in v0.29.0

func NewUnmarshaler(data []byte, ext string) Unmarshaler

NewUnmarshaler creates a new Unmarshaler.

func (Unmarshaler) Unmarshal added in v0.29.0

func (u Unmarshaler) Unmarshal(dst any) error

Unmarshal unmarshals the data into the provided destination based on the file extension.

Jump to

Keyboard shortcuts

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