mapper

package
v0.0.0-...-ed4bd9e Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(logger *logrus.Entry)

SetLogger is used to pass the loger from the main program

Types

type ErrSanityConfig

type ErrSanityConfig struct {
	TagName string
	// contains filtered or unexported fields
}

ErrSanityConfig is returned for the sanity checks in the Mapper

func NewErrSanityConfig

func NewErrSanityConfig(message, tagName string) *ErrSanityConfig

NewErrSanityConfig generates a new ErrSanityNomapping

func (*ErrSanityConfig) Error

func (e *ErrSanityConfig) Error() string

Error just returns the error message, basic error interface implementation

type ErrSanityNoMapping

type ErrSanityNoMapping struct {
	TagName  string
	TagValue string
	// contains filtered or unexported fields
}

ErrSanityNoMapping is returned for the sanity checks in the Mapper

func NewErrSanityNoMapping

func NewErrSanityNoMapping(message, tagName, tagValue string) *ErrSanityNoMapping

NewErrSanityNoMapping generates a new ErrSanityNomapping

func (*ErrSanityNoMapping) Error

func (e *ErrSanityNoMapping) Error() string

Error just returns the error message, basic error interface implementation

type Iface

type Iface interface {
	LoadConfig(io.Reader) error
	StripDefaults(*map[string]string)
	GetMissingDefaults(*map[string]string) *map[string]string
	GetFromTags(*map[string]string) (*map[string]string, error)
	GetFromKey(string, *map[string]string) (*map[string]string, error)
	ValidateTag(string, string) (*TagItem, error)
	MergeMaps(*map[string]string, *map[string]string)

	Retag(*string, *map[string]string, []string, PutTagFn)
}

Iface has been created for testing purposes. It allows to create mocks when testing class that depend on the mapper

type KeyMapper

type KeyMapper struct {
	KeyPattern  string     `json:"pattern"`
	Destination []*TagItem `json:"destination"`
}

KeyMapper makes the relation between an existing key and a list of tags that should be present on that resource. A key is: - the SSH Key name for an ec2 instance - DBClusterIdentifier, DBInstanceIdentifier, DBName, MasterUsername for RDS instances - DBClusterIdentifier, DBName, MasterUsername for RDS clusters

type Mapper

type Mapper struct {
	Iface
	CopyTag          []*TagCopy        `json:"copy_tags,omitempty"`
	TagMap           []*TagMapper      `json:"tags,omitempty"`
	KeyMap           []*KeyMapper      `json:"keys,omitempty"`
	Sanity           []*TagSanity      `json:"sanity,omitempty"`
	DefaultTagValues map[string]string `json:"defaults,omitempty"`
}

Mapper contains the different mappings between attributes and the list of tags that should be present on that resource

func (*Mapper) GetFromKey

func (m *Mapper) GetFromKey(resourceKey string, existingTags *map[string]string) (*map[string]string, error)

GetFromKey retrieves the tags corresponding to the KeyMap configuration except when the tag is already set in existingTags

func (*Mapper) GetFromTags

func (m *Mapper) GetFromTags(existingTags *map[string]string) (*map[string]string, error)

GetFromTags returns all the tags to add or update based on a list of existing tag that exist on the resource.

func (*Mapper) GetMissingDefaults

func (m *Mapper) GetMissingDefaults(existingTags *map[string]string) *map[string]string

GetMissingDefaults returns the tags and their default values for the ones that are missing from the existing tags

func (*Mapper) LoadConfig

func (m *Mapper) LoadConfig(configReader io.Reader) error

LoadConfig loads a json-formatted config into the current Mapper using the given io.Reader

func (*Mapper) MergeMaps

func (m *Mapper) MergeMaps(mainMap, complementary *map[string]string)

MergeMaps adds to mainMap the missing elements that are present in complementary

func (*Mapper) Retag

func (m *Mapper) Retag(resourceID *string, tags *map[string]string, keys []string, setTags PutTagFn)

Retag does the different re-tagging operations and calls the given setTags function

func (*Mapper) StripDefaults

func (m *Mapper) StripDefaults(existingTags *map[string]string)

StripDefaults removes from the existing tags the ones that are set to the default value

func (*Mapper) ValidateTag

func (m *Mapper) ValidateTag(tagName, tagValue string) (*TagItem, error)

ValidateTag operates on the tags map to validates a given tag Sanity configuration element of the Mapper

type MockMapper

type MockMapper struct {
	Iface
	// ResourceTags is used to record which tags have been pushed to the Retag
	// function on which resource since the creation of the object
	ResourceTags map[string]map[string]string
	// ResourceKeys is used to record which keys have been pushed to the
	// Retag function on which resource since the creation of the object
	ResourceKeys map[string][]string
}

MockMapper is used to mock the calls to retag during the tests

func (*MockMapper) Retag

func (m *MockMapper) Retag(resourceID *string, tags *map[string]string, keys []string, setTags PutTagFn)

Retag just records which resource has been called with which tags

type PutTagFn

type PutTagFn func(*string, []*TagItem) error

PutTagFn is used to specify the function structure to pass to the Retag method

type TagCopy

type TagCopy struct {
	Source      []string `json:"sources"`
	Destination string   `json:"destination"`
}

TagCopy specify a list of tags you want to copy the value from if they exist before the sanity of the tag is processed

type TagItem

type TagItem struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

TagItem is a standard AWS tag structure

type TagMapper

type TagMapper struct {
	Source      *TagItem   `json:"source"`
	Destination []*TagItem `json:"destination"`
}

TagMapper makes the relation between an existing tag on a resource and a list of tags that should be present on that resource

type TagSanity

type TagSanity struct {
	TagName   string              `json:"tag_name"`
	Transform map[string][]string `json:"remap"`
}

TagSanity limits the values of a tag to a list of values after remapping the values using the Transform matrix (the key is the acceptable value and the values are the list of values it will be transformed from)

Jump to

Keyboard shortcuts

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