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:
- Create a cache from an Azure tenant using NewCacheFromAzure.
- Save the cache to a file using Cache.Save.
- Load the cache from the file using NewCache.
- Inject the cache into AlzLib using AlzLib.AddCache.
Index ¶
- type Cache
- func (c *Cache) PolicyDefinitionCount() int
- func (c *Cache) PolicyDefinitionNames() int
- func (c *Cache) PolicyDefinitionVersionsByName(name string) *assets.PolicyDefinitionVersions
- func (c *Cache) PolicyDefinitionVersionsForName(name string) []semver.Version
- func (c *Cache) PolicyDefinitions() map[string]*assets.PolicyDefinitionVersions
- func (c *Cache) PolicySetDefinitionCount() int
- func (c *Cache) PolicySetDefinitionNames() int
- func (c *Cache) PolicySetDefinitionVersionsByName(name string) *assets.PolicySetDefinitionVersions
- func (c *Cache) PolicySetDefinitionVersionsForName(name string) []semver.Version
- func (c *Cache) PolicySetDefinitions() map[string]*assets.PolicySetDefinitionVersions
- func (c *Cache) Save(w io.Writer) error
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 ¶
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 ¶
PolicyDefinitionCount returns the total number of policy definitions in the cache, counting each version separately.
func (*Cache) PolicyDefinitionNames ¶
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 ¶
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 ¶
PolicySetDefinitionCount returns the total number of policy set definitions in the cache, counting each version separately.
func (*Cache) PolicySetDefinitionNames ¶
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 ¶
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.