azure

package
v0.0.0-...-63a68a9 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBackupFromMatched

func NewBackupFromMatched(matched map[string]Matched, directory string) string

NewBackupFromMatched makes a file backup from the resources in matched to a json file in directory

func String

func String(v string) *string

String converts string v to the string pointer

Types

type ActionExecution

type ActionExecution struct {
	ResourceID string
	RuleName   string
	Actions    []rules.ActionItem
}

ActionExecution stores information about execution of actions of a rule

type BackupEntry

type BackupEntry struct {
	ID   string             `json:"id"`
	Tags map[string]*string `json:"tags"`
}

BackupEntry represents one resource tags backup

type Matched

type Matched struct {
	Resource Resource
	TagRules []rules.Rule
}

Matched represents rules that mathc for a resource

type Resource

type Resource struct {
	Platform      string
	Name          *string
	Region        string
	ID            string
	Kind          *string
	Type          *string
	Tags          map[string]*string
	ResourceGroup *string
}

Resource represents a generic resource with name, region, id, tags and resource group

type ResourceDetails

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

ResourceDetails contains details about an Azure resource

func ParseResourceID

func ParseResourceID(resourceID string) (ResourceDetails, error)

ParseResourceID parses a resource ID into a ResourceDetails struct

type ResourceGroupScanner

type ResourceGroupScanner struct {
	Session         *session.AzureSession
	ResourcesClient *armresources.Client
	GroupsClient    *armresources.ResourceGroupsClient
}

ResourceGroupScanner represents resource group scanner that scans all resources in a resource group

func NewResourceGroupScanner

func NewResourceGroupScanner(s *session.AzureSession) *ResourceGroupScanner

NewResourceGroupScanner creates ResourceGroupScanner with Azure Serssion s

func (ResourceGroupScanner) GetGroups

func (r ResourceGroupScanner) GetGroups() ([]string, error)

GetGroups returns list of resource groups in a subscription

func (ResourceGroupScanner) GetResourceGroupTags

func (r ResourceGroupScanner) GetResourceGroupTags(rg string) (map[string]*string, error)

GetResourceGroupTags returns a map of key value tags of a reource group rg

func (ResourceGroupScanner) GetResources

func (r ResourceGroupScanner) GetResources() ([]Resource, error)

GetResources retruns list of resources in resource group

func (ResourceGroupScanner) GetResourcesByResourceGroup

func (r ResourceGroupScanner) GetResourcesByResourceGroup(rg string) ([]Resource, error)

GetResourcesByResourceGroup returns resources in a resource group rg

func (ResourceGroupScanner) ScanResourceGroup

func (r ResourceGroupScanner) ScanResourceGroup(rg string) []Resource

ScanResourceGroup returns a list of resources and their tags from a resource group rg

type Restorer

type Restorer interface {
	Restore() error
}

Restorer provides interface for restorers

type SameTagDifferentValue

type SameTagDifferentValue struct {
	Resource Resource
	Value    string
}

SameTagDifferentValue reprents a resource with a tag's value

type Scanner

type Scanner interface {
	GetResources() ([]Resource, error)
	GetResourcesByResourceGroup(string) ([]Resource, error)
	GetGroups() ([]string, error)
	GetResourceGroupTags(string) (map[string]*string, error)
}

Scanner represents generic scanner of Azure resource groups

type TagChecker

type TagChecker struct {
	Session *session.AzureSession
}

TagChecker represents an Azure checker

func (TagChecker) CheckSameTagDifferentValue

func (t TagChecker) CheckSameTagDifferentValue(resources []Resource) map[string][]SameTagDifferentValue

CheckSameTagDifferentValue checks if resources in resources are tagged with the same tag but with different values. It returns a map of lists of such resources. The key to the list is tag key. TODO: make this differently

type TagRestorer

type TagRestorer struct {
	Session         *session.AzureSession // session to connect to Azure
	ResourcesClient *armresources.Client  // client to the resources API
	Backup          []BackupEntry         // list of backup entries
}

TagRestorer represents a restorer of Azure tags from backup

func NewRestorerFromFile

func NewRestorerFromFile(filename string, s *session.AzureSession) *TagRestorer

NewRestorerFromFile creates a TagRestorer, which will restore tag backup from filename

func (TagRestorer) Restore

func (t TagRestorer) Restore() error

Restore restores tags from a backup file provided in TagRestorer

type Tagger

type Tagger struct {
	Session *session.AzureSession
	Matched map[string]Matched
	Rules   rules.TagRules // list of rules

	ResourcesClient           *armresources.Client
	VirtualNetworksClient     *armnetwork.VirtualNetworksClient
	StorageClient             *armstorage.AccountsClient
	RedisClient               *armredis.Client
	OperationManagementClient *armoperationsmanagement.SolutionsClient
	// contains filtered or unexported fields
}

Tagger reprents the maing tagging element

func NewTagger

func NewTagger(ruleDef rules.TagRules, session *session.AzureSession) *Tagger

NewTagger creates tagger

func (*Tagger) DryRun

func (t *Tagger) DryRun()

DryRun returns true if the check should be simulated

func (*Tagger) Eval

func (t *Tagger) Eval(data *Resource, p rules.ConditionItem) bool

Eval checks if condition p is satisfied on resource data

func (Tagger) EvaluateRules

func (t Tagger) EvaluateRules(resources []Resource)

EvaluateRules iterates over all rules and resources and checks which conditions are true.

func (*Tagger) Execute

func (t *Tagger) Execute(data *Resource, p rules.ActionItem) error

Execute executes action from p in resource data

func (*Tagger) ExecuteActions

func (t *Tagger) ExecuteActions() ([]ActionExecution, error)

ExecuteActions executes all actions based on definitions of rules. It resturns list of executed actions

func (*Tagger) InitActionMap

func (t *Tagger) InitActionMap()

InitActionMap initializes action map with supported actions

func (*Tagger) InitCondMap

func (t *Tagger) InitCondMap()

InitCondMap initializes conditions map with supported conditions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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