assets

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

Documentation

Overview

Package assets provides the types used by the Alzlib library. It wraps Azure SDK types and provides additional functionality such as versioning and metadata handling for policy set definitions.

Use the constructor functions to create instances of the types defined in this package, such as NewPolicySetDefinition, NewRoleDefinition, and NewPolicySetDefinitions.

Index

Constants

View Source
const (
	// PolicyAssignmentNameMaxLength is the maximum length of a policy assignment name, at MG scope this is 24.
	PolicyAssignmentNameMaxLength = 24
	// PolicyAssignmentDisplayNameMaxLength is the maximum length of a policy assignment display name.
	PolicyAssignmentDisplayNameMaxLength = 128
	// PolicyAssignmentDescriptionMaxLength is the maximum length of a policy assignment description.
	PolicyAssignmentDescriptionMaxLength = 512
)
View Source
const (
	// PolicyDefinitionDisplayNameMaxLength is the maximum length of the display name for a policy definition.
	PolicyDefinitionDisplayNameMaxLength = 128
	// PolicyDefinitionDescriptionMaxLength is the maximum length of the description for a policy definition.
	PolicyDefinitionDescriptionMaxLength = 512
	// PolicyDefinitionNameMaxLength is the maximum length of the name for a policy definition.
	PolicyDefinitionNameMaxLength = 64
)
View Source
const (
	// PolicySetDefinitionDisplayNameMaxLength is the maximum length of the display name for a policy set definition.
	PolicySetDefinitionDisplayNameMaxLength = 128
	// PolicySetDefinitionDescriptionMaxLength is the maximum length of the description for a policy set definition.
	PolicySetDefinitionDescriptionMaxLength = 512
	// PolicySetDefinitionNameMaxLength is the maximum length of the name for a policy set definition.
	PolicySetDefinitionNameMaxLength = 64
)
View Source
const (
	// ExpectedVersionComponents is the number of components expected in a semantic version.
	ExpectedVersionComponents = 3
)

Variables

View Source
var (
	// ErrNoVersionFound is returned when no version is found for a policy.
	ErrNoVersionFound = errors.New("no version found")
)
View Source
var (
	// ErrVersionConstraintInvalid is returned when the version constraint is invalid.
	ErrVersionConstraintInvalid = errors.New("version constraint is invalid")
)

Functions

func NameFromResourceID added in v0.27.0

func NameFromResourceID(resID string) (string, error)

NameFromResourceID returns the name of the resource from a resource ID.

func NewErrPropertyLength added in v0.28.0

func NewErrPropertyLength(propertyName string, minLength, maxLength, actualLength int) error

NewErrPropertyLength creates a new ErrPropertyLength error.

func NewErrPropertyMustNotBeNil added in v0.28.0

func NewErrPropertyMustNotBeNil(propertyName string) error

NewErrPropertyMustNotBeNil creates a new ErrPropertyMustNotBeNil error.

func ResourceTypeFromResourceID added in v0.27.0

func ResourceTypeFromResourceID(resID string) (string, error)

ResourceTypeFromResourceID returns the resource type of the resource from a resource ID.

func ValidatePolicyAssignment added in v0.26.0

func ValidatePolicyAssignment(pa *PolicyAssignment) error

ValidatePolicyAssignment performs validation checks on the policy assignment. To reduce the risk of nil pointer dereferences, it will create empty values for optional fields.

func ValidatePolicyDefinition added in v0.28.0

func ValidatePolicyDefinition(pd *PolicyDefinition) error

ValidatePolicyDefinition performs validation checks on the policy definition. To reduce the risk of nil pointer dereferences, it will create empty values for optional fields.

func ValidatePolicySetDefinition added in v0.27.0

func ValidatePolicySetDefinition(psd *PolicySetDefinition) error

ValidatePolicySetDefinition performs validation checks on the policy set definition. To reduce the risk of nil pointer dereferences, it will create empty values for optional fields.

func ValidateRoleDefinition added in v0.28.0

func ValidateRoleDefinition(rd *RoleDefinition) error

ValidateRoleDefinition checks if the RoleDefinition is valid.

Types

type ErrPropertyLength added in v0.28.0

type ErrPropertyLength struct {
	PropertyName string
	MinLength    int
	MaxLength    int
	ActualLength int
}

ErrPropertyLength is an error type that indicates a property has an invalid length.

func (*ErrPropertyLength) Error added in v0.28.0

func (e *ErrPropertyLength) Error() string

Error implements the error interface for type ErrPropertyLength.

type ErrPropertyMustNotBeNil added in v0.28.0

type ErrPropertyMustNotBeNil struct {
	PropertyName string
}

ErrPropertyMustNotBeNil is an error type that indicates a required property is nil.

func (*ErrPropertyMustNotBeNil) Error added in v0.28.0

func (e *ErrPropertyMustNotBeNil) Error() string

Error implements the error interface for type ErrPropertyMustNotBeNil.

type PolicyAssignment

type PolicyAssignment struct {
	armpolicy.Assignment
}

PolicyAssignment represents a policy assignment in Azure. It wraps the armpolicy.Assignment type and provides additional methods for validation and working with policy assignments.

func NewPolicyAssignment

func NewPolicyAssignment(pa armpolicy.Assignment) *PolicyAssignment

NewPolicyAssignment creates a new PolicyAssignment instance from an armpolicy.Assignment. The caller is responsible for ensuring that the policy assignment is valid. Use either the UnmarshalJSON method, or the ValidatePolicyAssignment function to validate the assignment.

func NewPolicyAssignmentValidate added in v0.26.0

func NewPolicyAssignmentValidate(pa armpolicy.Assignment) (*PolicyAssignment, error)

NewPolicyAssignmentValidate creates a new PolicyAssignment instance and validates it.

func (*PolicyAssignment) IdentityType

func (pa *PolicyAssignment) IdentityType() armpolicy.ResourceIdentityType

IdentityType returns the identity type of the policy assignment.

func (*PolicyAssignment) ParameterValueAsString

func (pa *PolicyAssignment) ParameterValueAsString(paramName string) (string, error)

ParameterValueAsString returns the value of a policy assignment parameter. We always expect the value to be a string as it's used in calculating the additional role assignments for policy parameters with the assignPermissions metadata set to true. Therefore the value should be an ARM resourceId.

func (*PolicyAssignment) ReferencedPolicyDefinitionResourceIDAndVersion added in v0.29.0

func (pa *PolicyAssignment) ReferencedPolicyDefinitionResourceIDAndVersion() (*arm.ResourceID, *string, error)

ReferencedPolicyDefinitionResourceIDAndVersion returns the resource ID and version of the policy definition referenced by the policy assignment.

func (*PolicyAssignment) UnmarshalJSON added in v0.26.0

func (pa *PolicyAssignment) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for type PolicyAssignment. It performs validity checks on mandatory fields as well as some validation checks on certain fields.

type PolicyDefinition

type PolicyDefinition struct {
	armpolicy.Definition
}

PolicyDefinition is a wrapper around armpolicy.Definition that provides additional methods to work with policy definitions, such as extracting role definition IDs and managing parameters.

func NewPolicyDefinition

func NewPolicyDefinition(pd armpolicy.Definition) *PolicyDefinition

NewPolicyDefinition creates a new PolicyDefinition from an armpolicy.Definition.

func NewPolicyDefinitionFromVersionValidate added in v0.29.0

func NewPolicyDefinitionFromVersionValidate(pd armpolicy.DefinitionVersion) (*PolicyDefinition, error)

NewPolicyDefinitionFromVersionValidate creates a new PolicyDefinition instance from a versioned policy definition.

func NewPolicyDefinitionValidate added in v0.28.0

func NewPolicyDefinitionValidate(pd armpolicy.Definition) (*PolicyDefinition, error)

NewPolicyDefinitionValidate creates a new PolicyDefinition instance and validates it.

func (*PolicyDefinition) AssignPermissionsParameterNames

func (pd *PolicyDefinition) AssignPermissionsParameterNames() ([]string, error)

AssignPermissionsParameterNames returns a list of parameter names that have the AssignPermissions metadata field set to true in the policy definition.

func (*PolicyDefinition) GetName added in v0.29.0

func (pd *PolicyDefinition) GetName() *string

GetName returns the name of the policy definition version.

func (*PolicyDefinition) GetVersion added in v0.29.0

func (pd *PolicyDefinition) GetVersion() *string

GetVersion returns the version of the policy definition, if it exists. If the version is not set, it returns nil.

func (*PolicyDefinition) NormalizedRoleDefinitionResourceIDs added in v0.27.0

func (pd *PolicyDefinition) NormalizedRoleDefinitionResourceIDs() ([]string, error)

NormalizedRoleDefinitionResourceIDs returns a list of normalized role definition IDs from the policy definition. Normalized IDs are those without the management group portion, e.g.: /providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionId}.

func (*PolicyDefinition) Parameter added in v0.18.1

Parameter returns the parameter with the given name from the policy definition.

func (*PolicyDefinition) ParameterIsOptional added in v0.19.1

func (pd *PolicyDefinition) ParameterIsOptional(name string) (bool, error)

ParameterIsOptional checks if the parameter with the given name is optional in the policy definition.

func (*PolicyDefinition) RoleDefinitionResourceIDs added in v0.27.0

func (pd *PolicyDefinition) RoleDefinitionResourceIDs() ([]string, error)

RoleDefinitionResourceIDs returns the role definition ids referenced in a policy definition if they exist. We marshall the policyRule as JSON and then unmarshal into a custom type.

func (*PolicyDefinition) SetAssignPermissionsOnParameter added in v0.25.0

func (pd *PolicyDefinition) SetAssignPermissionsOnParameter(parameterName string)

SetAssignPermissionsOnParameter sets the AssignPermissions metadata field to true for the parameter with the given name.

func (*PolicyDefinition) UnmarshalJSON added in v0.28.0

func (pd *PolicyDefinition) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for type PolicySetDefinition. It performs validity checks on mandatory fields as well as some validation checks on certain fields.

func (*PolicyDefinition) UnsetAssignPermissionsOnParameter added in v0.25.0

func (pd *PolicyDefinition) UnsetAssignPermissionsOnParameter(parameterName string)

UnsetAssignPermissionsOnParameter removes the AssignPermissions metadata field for the parameter with the given name.

type PolicyDefinitionVersions added in v0.26.0

type PolicyDefinitionVersions = VersionedPolicyCollection[*PolicyDefinition]

PolicyDefinitionVersions is a type alias for the generic collection.

func NewPolicyDefinitionVersions added in v0.26.0

func NewPolicyDefinitionVersions() *PolicyDefinitionVersions

NewPolicyDefinitionVersions creates a collection of PolicyDefinition.

type PolicySetDefinition

type PolicySetDefinition struct {
	armpolicy.SetDefinition
}

PolicySetDefinition represents a policy set definition and embeds the armpolicy.SetDefinition struct.

func NewPolicySetDefinition

func NewPolicySetDefinition(psd armpolicy.SetDefinition) *PolicySetDefinition

NewPolicySetDefinition creates a new PolicySetDefinition from an armpolicy.SetDefinition.

func NewPolicySetDefinitionFromVersionValidate added in v0.29.0

func NewPolicySetDefinitionFromVersionValidate(psd armpolicy.SetDefinitionVersion) (*PolicySetDefinition, error)

NewPolicySetDefinitionFromVersionValidate creates a new PolicySetDefinitionVersion instance and validates it.

func NewPolicySetDefinitionValidate added in v0.28.0

func NewPolicySetDefinitionValidate(psd armpolicy.SetDefinition) (*PolicySetDefinition, error)

NewPolicySetDefinitionValidate creates a new PolicySetDefinition instance and validates it.

func (*PolicySetDefinition) GetName added in v0.29.0

func (psd *PolicySetDefinition) GetName() *string

GetName returns the name of the policy definition version.

func (*PolicySetDefinition) GetVersion added in v0.29.0

func (psd *PolicySetDefinition) GetVersion() *string

GetVersion returns the version of the policy definition, if it exists. If the version is not set, it returns nil.

func (*PolicySetDefinition) Parameter added in v0.19.0

Parameter returns the parameter definition for the given name.

func (*PolicySetDefinition) PolicyDefinitionReferences

func (psd *PolicySetDefinition) PolicyDefinitionReferences() []*armpolicy.DefinitionReference

PolicyDefinitionReferences returns the policy definition references for the policy set definition.

func (*PolicySetDefinition) ReferencedPolicyDefinitionNames

func (psd *PolicySetDefinition) ReferencedPolicyDefinitionNames() ([]string, error)

ReferencedPolicyDefinitionNames returns the names of the policy definitions referenced by the policy set definition.

func (*PolicySetDefinition) UnmarshalJSON added in v0.27.0

func (psd *PolicySetDefinition) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for type PolicySetDefinition. It performs validity checks on mandatory fields as well as some validation checks on certain fields.

type PolicySetDefinitionVersions added in v0.26.0

type PolicySetDefinitionVersions = VersionedPolicyCollection[*PolicySetDefinition]

PolicySetDefinitionVersions represents a version collection of a policy set definitions.

func NewPolicySetDefinitionVersions added in v0.26.0

func NewPolicySetDefinitionVersions() *PolicySetDefinitionVersions

NewPolicySetDefinitionVersions creates a collection of PolicySetDefinition.

type RoleDefinition

type RoleDefinition struct {
	armauthorization.RoleDefinition
}

RoleDefinition is a wrapper around armauthorization.RoleDefinition to provide additional methods or properties if needed.

func NewRoleDefinition

func NewRoleDefinition(rd armauthorization.RoleDefinition) *RoleDefinition

NewRoleDefinition creates a new RoleDefinition from an armauthorization.RoleDefinition.

func NewRoleDefinitionValidate added in v0.28.0

func NewRoleDefinitionValidate(rd armauthorization.RoleDefinition) (*RoleDefinition, error)

NewRoleDefinitionValidate creates a new RoleDefinition instance and validates it.

func (*RoleDefinition) UnmarshalJSON added in v0.28.0

func (rd *RoleDefinition) UnmarshalJSON(data []byte) error

UnmarshalJSON customizes the JSON unmarshaling for RoleDefinition.

type Versioned added in v0.26.0

type Versioned interface {
	VersionedTypes
	GetVersion() *string
	GetName() *string
}

Versioned is an interface for versioned policy types.

type VersionedPolicyCollection added in v0.26.0

type VersionedPolicyCollection[T Versioned] struct {
	// contains filtered or unexported fields
}

VersionedPolicyCollection is a generic collection of versioned policies.

func (*VersionedPolicyCollection[T]) Add added in v0.26.0

func (c *VersionedPolicyCollection[T]) Add(add T, overwrite bool) error

Add adds a new version to the collection.

func (*VersionedPolicyCollection[T]) AllVersions added in v0.29.0

func (c *VersionedPolicyCollection[T]) AllVersions() iter.Seq[T]

AllVersions returns an iterator over all versions in the collection.

func (*VersionedPolicyCollection[T]) Exists added in v0.29.0

func (c *VersionedPolicyCollection[T]) Exists(version *string) bool

Exists checks if a version or versionless definition exists in the collection. If version is nil, it checks for the existence of a versionless definition. You must supply a exact semver version string to check for a specific version. If you want to supply a version constraint, use GetVersion instead.

func (*VersionedPolicyCollection[T]) GetVersion added in v0.26.0

func (c *VersionedPolicyCollection[T]) GetVersion(constraintStr *string) (T, error)

GetVersion returns a policy version based on the provided constraint string. If the constraint string is nil, it returns the versionless definition if it exists. If the constraint string is nil and no versionless definition exists, it returns the latest version.

func (*VersionedPolicyCollection[T]) GetVersionStrict added in v0.29.0

func (c *VersionedPolicyCollection[T]) GetVersionStrict(ver *string) (T, error)

GetVersionStrict returns a policy version based on the exact version string. If the version string is nil, it returns the versionless definition if it exists. If the version string is nil and no versionless definition exists it returns the exact match, or an error if no exact match exists.

func (*VersionedPolicyCollection[T]) Upsert added in v0.29.0

func (c *VersionedPolicyCollection[T]) Upsert(in *VersionedPolicyCollection[T], overwrite bool) error

Upsert merges another VersionedPolicyCollection into this one. If overwrite is true, existing versions will be overwritten. If overwrite is false, an error will be returned if a version already exists.

func (*VersionedPolicyCollection[T]) Versions added in v0.29.0

func (c *VersionedPolicyCollection[T]) Versions() []semver.Version

Versions returns a sorted list of all versions in the collection.

type VersionedTypes added in v0.26.0

type VersionedTypes interface {
	*PolicyDefinition | *PolicySetDefinition
}

VersionedTypes is a type constraint for versioned policy types.

Jump to

Keyboard shortcuts

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