cache

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cache provides a cache for built-in Azure policy definitions and policy set definitions. It can be used to avoid repeated Azure API calls during AlzLib initialization.

The typical workflow is:

  1. Create a cache from an Azure tenant using NewCacheFromAzure.
  2. Save the cache to a file using Cache.Save.
  3. Load the cache from the file using NewCache.
  4. Inject the cache into AlzLib using AlzLib.AddCache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache stores built-in Azure policy definitions and policy set definitions. It is used to pre-populate AlzLib's internal maps to avoid Azure API calls.

func NewCache

func NewCache(r io.Reader) (*Cache, error)

NewCache deserializes a cache from the given reader. The reader should contain JSON data previously written by Cache.Save. Definitions are not validated on load because Azure built-in definitions may not comply with documented property constraints.

func NewCacheFromAzure

func NewCacheFromAzure(ctx context.Context, client *armpolicy.ClientFactory, logger *slog.Logger) (*Cache, error)

NewCacheFromAzure scans an Azure tenant for all built-in policy definitions and policy set definitions and returns a populated Cache. The client factory must be configured with appropriate credentials. If logger is nil, no log output is produced.

func NewCacheFromDefinitions

func NewCacheFromDefinitions(
	pds map[string]*assets.PolicyDefinitionVersions,
	psds map[string]*assets.PolicySetDefinitionVersions,
) *Cache

NewCacheFromDefinitions creates a Cache from pre-loaded policy definition and policy set definition version collections. This is useful when callers want to generate a cache that is tailored to their specific use case — for example, after calling [alzlib.AlzLib.GetDefinitionsFromAzure] to load only the definitions referenced by a particular library.

The supplied maps are shallow-copied: the keys are copied but the value pointers are shared. Callers should not modify the values after creating the cache.

func (*Cache) PolicyDefinitionCount

func (c *Cache) PolicyDefinitionCount() int

PolicyDefinitionCount returns the total number of policy definitions in the cache, counting each version separately.

func (*Cache) PolicyDefinitionNames

func (c *Cache) PolicyDefinitionNames() int

PolicyDefinitionNames returns the number of unique policy definition names in the cache.

func (*Cache) PolicyDefinitionVersionsByName

func (c *Cache) PolicyDefinitionVersionsByName(name string) *assets.PolicyDefinitionVersions

PolicyDefinitionVersionsByName returns the policy definition versions for the given name, or nil if not found.

func (*Cache) PolicyDefinitionVersionsForName

func (c *Cache) PolicyDefinitionVersionsForName(name string) []semver.Version

PolicyDefinitionVersionsForName returns all semver versions for a given policy definition name.

func (*Cache) PolicyDefinitions

func (c *Cache) PolicyDefinitions() map[string]*assets.PolicyDefinitionVersions

PolicyDefinitions returns a shallow copy of the cached policy definition version collections map.

func (*Cache) PolicySetDefinitionCount

func (c *Cache) PolicySetDefinitionCount() int

PolicySetDefinitionCount returns the total number of policy set definitions in the cache, counting each version separately.

func (*Cache) PolicySetDefinitionNames

func (c *Cache) PolicySetDefinitionNames() int

PolicySetDefinitionNames returns the number of unique policy set definition names in the cache.

func (*Cache) PolicySetDefinitionVersionsByName

func (c *Cache) PolicySetDefinitionVersionsByName(name string) *assets.PolicySetDefinitionVersions

PolicySetDefinitionVersionsByName returns the policy set definition versions for the given name, or nil if not found.

func (*Cache) PolicySetDefinitionVersionsForName

func (c *Cache) PolicySetDefinitionVersionsForName(name string) []semver.Version

PolicySetDefinitionVersionsForName returns all semver versions for a given policy set definition name.

func (*Cache) PolicySetDefinitions

func (c *Cache) PolicySetDefinitions() map[string]*assets.PolicySetDefinitionVersions

PolicySetDefinitions returns a shallow copy of the cached policy set definition version collections map.

func (*Cache) Save

func (c *Cache) Save(w io.Writer) error

Save serializes the cache to the given writer as JSON.

Jump to

Keyboard shortcuts

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