aws

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACCESS_TOKEN_FILE    = "-token.json"
	AWS_TOKEN_PATH       = ".aws/sso/cache/"
	DEFAULT_ACCESS_TOKEN = "access-token.json"
)
View Source
const LastUsageLocation = "/.aws/sso/cache/last-usage.json"

Variables

View Source
var (
	ErrMoreThanOneLocation   = errors.New("too many configuration locations provided")
	ErrStartURLCannotBeEmpty = errors.New("start URL cannot be empty")
)
View Source
var (
	AwsRegions = []string{
		"us-east-2",
		"us-east-1",
		"us-west-1",
		"us-west-2",
		"af-south-1",
		"ap-east-1",
		"ap-south-1",
		"ap-northeast-3",
		"ap-northeast-2",
		"ap-southeast-1",
		"ap-southeast-2",
		"ap-northeast-1",
		"ca-central-1",
		"eu-central-1",
		"eu-west-1",
		"eu-west-2",
		"eu-south-1",
		"eu-west-3",
		"eu-north-1",
		"me-south-1",
		"sa-east-1",
		"us-gov-east-1",
		"us-gov-west-1",
		"cn-north-1",
		"cn-northwest-1",
	}

	ErrEmptyResponse  = errors.New("an empty response was returned")
	ErrRegionInvalid  = errors.New("the provided region is invalid")
	ErrRegionNotFound = errors.New("could not find a region in the system")
)
View Source
var ErrAccountNotFound = errors.New("account provided couldn't be found")
View Source
var ErrFileNotFound = errors.New("the provided file could not be found")

Functions

func ClientInfoFileDestination

func ClientInfoFileDestination(configDir ...string) (string, error)

ClientInfoFileDestination finds local AWS configuration settings. Users can optionally input their own home directory location.

func CurrentProfile added in v1.0.3

func CurrentProfile() string

func GetAWSConfigSections added in v1.0.3

func GetAWSConfigSections(filename string) ([]string, error)

func GetAWSProfileName added in v1.0.3

func GetAWSProfileName(profile string) string

func GetAWSProfiles added in v1.0.3

func GetAWSProfiles() ([]string, error)

func GetAccessToken

func GetAccessToken() string

func GetAndSaveRoleCredentials

func GetAndSaveRoleCredentials(ctx context.Context, cfg *aws.Config, accountID, roleName, accessToken *string, accountName, region string) (string, error)

func GetCallerIdentity

func GetCallerIdentity(ctx context.Context, cfg *aws.Config) (*sts.GetCallerIdentityOutput, error)

Gather sts caller identity

func GetClusterInfo

func GetClusterInfo(ctx context.Context, cfg *aws.Config, cluster string) (*eks.DescribeClusterOutput, error)

Get cluster information for provided cluster

func GetClusters

func GetClusters(ctx context.Context, cfg *aws.Config) ([]string, error)

Returns a list of the clusters in the environment

func GetECRRegistryName

func GetECRRegistryName(ctx context.Context, cfg *aws.Config) (string, error)

Returns the name of the ECR registry for the AWS environment

func GetECRToken

func GetECRToken(ctx context.Context, cfg *aws.Config) (string, string, error)

Gather an ECR authentication token and return token, proxy endpoint

func GetRegion

func GetRegion() (string, error)

Returns the region in precedence of environment region, config region and finally default region.

func GetRoleCredentials

func GetRoleCredentials(ctx context.Context, cfg *aws.Config, accountID, roleName, accessToken *string) (*sso.GetRoleCredentialsOutput, error)

func GetURL

func GetURL() (string, error)

func IsLocalConfig added in v1.0.3

func IsLocalConfig(profile string) (bool, error)

func IsProfileConfigured added in v1.0.3

func IsProfileConfigured() bool

IsProfileConfigured returns true if profile is configured, false otherwise.

func Logout

func Logout(ctx context.Context, cfg *aws.Config, accessToken string) error

func PrintClusterInfo

func PrintClusterInfo(ctx context.Context, cfg *aws.Config, cluster string, out io.Writer) error

func RetrieveAccountInformation

func RetrieveAccountInformation(ctx context.Context, cfg *aws.Config, accessToken, acctID *string) (*types.AccountInfo, error)

func RetrieveRoleInfo

func RetrieveRoleInfo(ctx context.Context, cfg *aws.Config, accountID, accessToken *string) (types.RoleInfo, error)

func RetrieveToken

func RetrieveToken(ctx context.Context, cfg *aws.Config, clientInfo *ClientInformation) error

func SaveUsageInformation

func SaveUsageInformation(accountInfo *types.AccountInfo, roleInfo *types.RoleInfo) error

func WriteAWSConfigFile

func WriteAWSConfigFile(profile, region, output string) error

func WriteAWSCredentialsFile

func WriteAWSCredentialsFile(profile string, credentials *sso.GetRoleCredentialsOutput) error

Types

type ClientInformation

type ClientInformation struct {
	AccessTokenExpiresAt    time.Time
	AccessToken             string
	ClientId                string
	ClientSecret            string
	ClientSecretExpiresAt   string
	DeviceCode              string
	VerificationUriComplete string
	StartUrl                string
}

func GatherClientInformation

func GatherClientInformation(ctx context.Context, cfg *aws.Config, startUrl string, b browser.Browser, refresh bool) (*ClientInformation, error)

Attempts to gather current client information. If it doesn't exist, creates new information for the client

func ReadClientInformation

func ReadClientInformation(file string) (*ClientInformation, error)

Will attempt to read in client information given a file location

func RegisterClient

func RegisterClient(ctx context.Context, cfg *aws.Config, startUrl string, b browser.Browser) (*ClientInformation, error)

Registers a client with AWS OIDC and return the client information

func (*ClientInformation) IsExpired

func (c *ClientInformation) IsExpired() bool

Checks to see if the ClientInformation AccessTokenExpiresAt is past the current time

type CredentialsFileTemplate

type CredentialsFileTemplate struct {
	AwsAccessKeyId     string `ini:"aws_access_key_id,omitempty"`
	AwsSecretAccessKey string `ini:"aws_secret_access_key,omitempty"`
	AwsSessionToken    string `ini:"aws_session_token,omitempty"`
	CredentialProcess  string `ini:"credential_process,omitempty"`
	Output             string `ini:"output,omitempty"`
	Region             string `ini:"region,omitempty"`
}

type LastUsageInformation

type LastUsageInformation struct {
	AccountId   string `json:"account_id"`
	AccountName string `json:"account_name"`
	Role        string `json:"role"`
}

Jump to

Keyboard shortcuts

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