awsutil

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 20 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateService

func CreateService(awsSession *session.Session, regionName string) *ec2.EC2

func CreateSession

func CreateSession(accountProfileName string) (*session.Session, error)

func CreateTagsFromList

func CreateTagsFromList(list []*ec2.Tag) libtags.Tags

func ForEachTarget

func ForEachTarget(targets TargetList, skipList TargetList,
	targetFunc func(awsService *ec2.EC2, accountName, regionName string,
		logger log.Logger),
	logger log.Logger) (int, error)

func GetLocalRegion

func GetLocalRegion() (string, error)

func ListAccountNames

func ListAccountNames() ([]string, error)

func ListAccountNamesWithOptions

func ListAccountNamesWithOptions(options CredentialsOptions) ([]string, error)

func ListRegions

func ListRegions(awsService *ec2.EC2) ([]string, error)

func MakeFilterFromTag

func MakeFilterFromTag(tag libtags.Tag) *ec2.Filter

func MakeFiltersFromTags

func MakeFiltersFromTags(tags libtags.Tags) []*ec2.Filter

Types

type CredentialsOptions

type CredentialsOptions struct {

	// The path of the credentials file.
	// If empty, defaults to to the same location that the LoadCredentials
	// function uses.
	CredentialsPath string

	// The path of the config file.
	// If empty, defaults to the same location that the LoadCredentials
	// function uses.
	ConfigPath string
}

CredentialsOptions contains options for loading credentials

type CredentialsStore

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

CredentialsStore records AWS credentials (IAM users and roles) for multiple accounts. The methods are safe to use concurrently.

func LoadCredentials

func LoadCredentials() (*CredentialsStore, error)

LoadCredentials loads credentials from the aws credentials file and roles from the aws config file which may be used later.

The location of the credentials file is determined using the following rules from highest to lowest precedence 1) -awsCredentialFile command line parameter. 2) AWS_CREDENTIAL_FILE environment variable. 3) ~/.aws/credentials

The location of the config file is determines using the following rules from highest to lowest precedence 2) -awsConfigFile command line parameter 2) AWS_CONFIG_FILE environment variable. 3) ~/.aws/config

func TryLoadCredentials

func TryLoadCredentials() (
	store *CredentialsStore, unloadedAccounts map[string]error, err error)

TryLoadCredentials works like LoadCredentials but attempts to partially load the credentials in the presence of unloadable accounts. If the partial load is successful, unloadableAccounts contains the error encountered for each unloaded account. If partial load is unsuccessful, TryLoadCredentials returns nil, nil, err

func TryLoadCredentialsWithOptions

func TryLoadCredentialsWithOptions(options CredentialsOptions) (
	store *CredentialsStore, unloadedAccounts map[string]error, err error)

TryLoadCredentialsWithOptions works just like TryLoadCredentials but allows caller to specify options for loading the credentials.

func (*CredentialsStore) AccountIdToName

func (cs *CredentialsStore) AccountIdToName(accountId string) string

AccountIdToName will return an account name given an account ID.

func (*CredentialsStore) AccountNameToId

func (cs *CredentialsStore) AccountNameToId(accountName string) string

AccountNameToId will return an account ID given an account name.

func (*CredentialsStore) ForEachEC2Target

func (cs *CredentialsStore) ForEachEC2Target(targets TargetList,
	skipList TargetList,
	targetFunc func(awsService *ec2.EC2, accountName, regionName string,
		logger log.Logger),
	wait bool, logger log.Logger) (int, error)

ForEachEC2Target will iterate over a set of targets ((account,region) tuples) and will launch a goroutine calling targetFunc for each target. The list of targets to iterate over is given by targets and the list of targets to skip is given by skipList. An empty string for .AccountName is expanded to all available accounts and an empty string for .Region is expanded to all regions for an account. The number of goroutines is returned. If wait is true then ForEachTarget will wait for all the goroutines to complete, else it is the responsibility of the caller to wait for the goroutines to complete.

func (*CredentialsStore) ForEachTarget

func (cs *CredentialsStore) ForEachTarget(targets TargetList,
	skipList TargetList,
	targetFunc func(awsSession *session.Session, accountName, regionName string,
		logger log.Logger),
	wait bool, logger log.Logger) (int, error)

ForEachTarget will iterate over a set of targets ((account,region) tuples) and will launch a goroutine calling targetFunc for each target. The list of targets to iterate over is given by targets and the list of targets to skip is given by skipList. An empty string for .AccountName is expanded to all available accounts and an empty string for .Region is expanded to all regions for an account. The number of goroutines is returned. If wait is true then ForEachTarget will wait for all the goroutines to complete, else it is the responsibility of the caller to wait for the goroutines to complete.

func (*CredentialsStore) GetEC2Service

func (cs *CredentialsStore) GetEC2Service(accountName,
	regionName string) *ec2.EC2

GetEC2Service will get an EC2 service handle for an account and region.

func (*CredentialsStore) GetSessionForAccount

func (cs *CredentialsStore) GetSessionForAccount(
	accountName string) *session.Session

GetSessionForAccount will return the session credentials available for an account. The name of the account should be given by accountName. A *session.Session is returned which may be used to bind to AWS services (i.e. EC2).

func (*CredentialsStore) ListAccountsWithCredentials

func (cs *CredentialsStore) ListAccountsWithCredentials() []string

ListAccountsWithCredentials will list all accounts for which credentials are available.

func (*CredentialsStore) ListRegionsForAccount

func (cs *CredentialsStore) ListRegionsForAccount(accountName string) []string

ListRegionsForAccount will return all the regions available to an account.

type Target

type Target struct {
	AccountName string
	Region      string
}

type TargetList

type TargetList []Target

func (*TargetList) Set

func (list *TargetList) Set(value string) error

func (*TargetList) String

func (list *TargetList) String() string

Jump to

Keyboard shortcuts

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