amicache

package
v2.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2019 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultStateTag = "state"

DefaultStateTag is the default tag-key for determining AMI state.

Variables

This section is empty.

Functions

func SortByState

func SortByState(state string, images []Image)

SortByState sorts by taking the CreationDate attribute, converting it to UNIX epoch, and adds it to the weighted value of the status tag. It sorts from newest to oldest AMIs.

Types

type Cache

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

Cache manages the images polled from AWS.

func New

func New(svc stsiface.STSAPI, roleName string, ownerIDs []string, options ...Option) *Cache

New returns a Cache with sensible defaults if none are provided.

func (*Cache) CollectLaunchPermissions

func (c *Cache) CollectLaunchPermissions() bool

CollectLaunchPermissions returns whether the cache is storing launch permission data for each AMI.

func (*Cache) FilterImages

func (c *Cache) FilterImages(region string, filter *Filter) ([]Image, error)

FilterImages returns a filtered set of cached images from the provided region.

func (*Cache) Images

func (c *Cache) Images(region string) ([]Image, error)

Images returns the cached images from the provided region.

func (*Cache) Regions

func (c *Cache) Regions() []string

Regions returns the list of AWS regions being cached.

func (*Cache) Run

func (c *Cache) Run(ctx context.Context, warmed chan struct{}) error

Run starts the cache and keeps it up to date. It closes warmed after the first cache update completes.

func (*Cache) StateTag

func (c *Cache) StateTag() string

StateTag returns the name of the tag used to determine an AMI's state.

func (*Cache) Stop

func (c *Cache) Stop()

Stop stops the cache.

type Filter

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

Filter is used to filter Image objects.

func NewFilter

func NewFilter(filters ...Filterer) *Filter

NewFilter creates a new Filter.

func (*Filter) Apply

func (f *Filter) Apply(images []Image) []Image

Apply returns the filtered images.

type FilterFunc

type FilterFunc func([]Image) []Image

The FilterFunc type is an adapter to allow the use of ordinary functions as filter handlers. If f is a function with the appropriate signature, FilterFunc(f) is a Filterer object that calls f.

func FilterByImageID

func FilterByImageID(ids ...string) FilterFunc

FilterByImageID returns images with matching AMI ids.

func FilterByLaunchPermission

func FilterByLaunchPermission(id string) FilterFunc

FilterByLaunchPermission returns images that have the account id in its launch permissions.

func FilterByOwnerID

func FilterByOwnerID(id string) FilterFunc

FilterByOwnerID returns only the images owned by the provided owner ID.

func FilterByTags

func FilterByTags(tags map[string][]string) FilterFunc

FilterByTags returns images with matching tags.

func (FilterFunc) Filter

func (f FilterFunc) Filter(images []Image) []Image

Filter implements the Filterer interface.

type Filterer

type Filterer interface {
	Filter([]Image) []Image
}

Filterer is an interface used to apply specified filters on a slice of Image objects.

type Image

type Image struct {
	Image   *ec2.Image
	OwnerID string
	Region  string
	// contains filtered or unexported fields
}

Image represents an Amazon Machine Image.

func NewImage

func NewImage(image *ec2.Image, ownerID, region string, perms []string) Image

NewImage returns a new Image from the provided ec2.Image and region.

func (*Image) Tag

func (i *Image) Tag(key string) string

Tag returns the value of the provided tag key. An empty string is returned if there is no matching key.

func (*Image) Tags

func (i *Image) Tags() map[string]string

Tags is a convenience function that returns ec2.Image.Tags as a map[string]string

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is the option interface. It has private methods to prevent its use from outside of this package.

func CollectLaunchPermissions

func CollectLaunchPermissions(collect bool) Option

CollectLaunchPermissions determines if launch permissions should be collected for each AMI.

func HTTPClient

func HTTPClient(client *http.Client) Option

HTTPClient sets the http.Client used for communicating with the AWS APIs.

func Logger

func Logger(logger log.Logger) Option

Logger sets the go-kit logger.

func MaxConcurrentRequests

func MaxConcurrentRequests(max int) Option

MaxConcurrentRequests sets the maximum number of concurrent DescribeImageAttributes API requests for a given Owner.

This is used to control RequestLimitExceed errors. http://docs.aws.amazon.com/AWSEC2/latest/APIReference/query-api-troubleshooting.html#api-request-rate

func MaxRequestRetries

func MaxRequestRetries(max int) Option

MaxRequestRetries sets the maximum number of retries for the DescribeImageAttributes API request for a given AMI.

This is used to control RequestLimitExceed errors. http://docs.aws.amazon.com/AWSEC2/latest/APIReference/query-api-troubleshooting.html#api-request-rate

func Regions

func Regions(regions ...string) Option

Regions sets the AWS standard regions that will be polled for AMIs.

func StateTag

func StateTag(tag string) Option

StateTag sets the tag-key used to determine the state of an AMI.

func TTL

func TTL(ttl time.Duration) Option

TTL sets the duration between cache updates.

func TagFilter

func TagFilter(tag string) Option

TagFilter sets the tag-key used to filter the results of ec2:DescribeImages. The value is irrelevant, only the existence of the tag is required.

Jump to

Keyboard shortcuts

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