awsdefault

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: Apache-2.0 Imports: 7 Imported by: 1

README

awsdefault

Build Status Go Report Card Coverage Status

Change Amazon AWS profiles/accounts globally.

This tool sets one of your AWS profiles, configured in your $HOME/.aws/credentials file (see here), to the default profile. Means:

  • adding parameters like --profile=my-profile to the aws cli
  • or changing the environment variable with export AWS_PROFILE=my-profile in every new terminal window

are not required anymore.

Table of Contents

Example Usage

Use either the cli tool

Change the default AWS profile to 'personal'
  • command:
$ awsdefault to personal
Disable/unset the AWS profile

command:

$ awsdefault rm

the complete list of parameters can be found here

Or the UI tool

Linux

awsdefault-gkt3-example1

Note i3block was used as statusbar in this example. You can find the config in the doc folder.

Windows

TODO

Installation

Option 1 — Download binaries

precompiled binaries for Linux, (TODO: Windows and MacOS) are available at the [release] page.

curl 

Option 2 — Compile it

  • for the cli tool, see here
  • for the gtk3-UI, see here

Configure your environment (only first time)

Set the environment variable AWS_PROFILE to default (aws userguide).

Linux

Add the following line to your .xinitrc, .zshrc or .bashrc file:

export AWS_PROFILE=default
Windows

TODO

How it works

The awsdefault (cli or UI) tool creates, changes or deletes the [default] profile section in your AWS credentials file. This default section contains the same aws_access_key_id and aws_secret_access_key as stored in one of the other profile sections. Together with the configured environment variable AWS_PROFILE=default, this approach enables or disables the credentials of the specific AWS profile. In other words, the default profile points to the required profile or will be deleted if no profile is needed.

  • The environment variable
$ env | grep AWS_PROFILE
AWS_PROFILE=default
  • The AWS credentials file — no default was set; default was unset
$ cat ~/.aws/credentials
[live]
aws_access_key_id     = A
aws_secret_access_key = B

[dev]
aws_access_key_id     = C
aws_secret_access_key = D

[personal]
aws_access_key_id     = E
aws_secret_access_key = F
  • The AWS credentials file — default was set to personal (comment was added automatically)
$ cat ~/.aws/credentials
; active_profile=personal
[default]
aws_access_key_id     = E
aws_secret_access_key = F
                         
[live]                   
aws_access_key_id     = A
aws_secret_access_key = B
                         
[dev]                    
aws_access_key_id     = C
aws_secret_access_key = D
                         
[personal]               
aws_access_key_id     = E
aws_secret_access_key = F

License

See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CredentialsFile

type CredentialsFile struct {
	Content *ini.File
	Path    string
}

CredentialsFile stores the content and path of the AWS credentials file

func GetCredentialsFile

func GetCredentialsFile() (*CredentialsFile, error)

GetCredentialsFile reads the AWS credentials file either from the HOME directory or from a path given by the environment variable AWS_SHARED_CREDENTIALS_FILE

func (*CredentialsFile) GetProfileBy added in v0.2.0

func (f *CredentialsFile) GetProfileBy(name string) (*Profile, error)

GetProfileBy returns the profile by a given name

func (*CredentialsFile) GetProfilesNames

func (f *CredentialsFile) GetProfilesNames() (names []string)

GetProfilesNames returns a sorted list of all available profiles inside the AWS credentials file.

func (*CredentialsFile) GetUsedID added in v0.2.0

func (f *CredentialsFile) GetUsedID() (string, error)

GetUsedID returns the AWS_ACCESS_KEY_ID of the profile currently used as default profile.

func (*CredentialsFile) GetUsedKey added in v0.2.0

func (f *CredentialsFile) GetUsedKey() (string, error)

GetUsedKey returns the AWS_SECRET_ACCESS_KEY of the profile currently used as default profile.

func (*CredentialsFile) GetUsedProfileNameAndIndex

func (f *CredentialsFile) GetUsedProfileNameAndIndex() (string, int, error)

GetUsedProfileNameAndIndex returns the name and the index of the profile currently used as default profile.

func (*CredentialsFile) SetDefaultTo

func (f *CredentialsFile) SetDefaultTo(profileName string) error

SetDefaultTo overwrites/creates the default section inside the AWS credentials file. It also adds a comment containing the name of the profile used as current default profile

func (*CredentialsFile) UnSetDefault

func (f *CredentialsFile) UnSetDefault() error

UnSetDefault deletes the default section inside the AWS credentials file.

type Profile

type Profile struct {
	//Name            string `ini:"name"`
	AccessKeyID     string `ini:"aws_access_key_id"`
	SecretAccessKey string `ini:"aws_secret_access_key"`
	SessionToken    string `ini:"aws_session_token,omitempty"`
	Region          string `ini:"region,omitempty"`
	Output          string `ini:"output,omitempty"`
	// contains filtered or unexported fields
}

Profile stored in the AWS shared credentials file consisting of an AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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