utils

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExpectedKeys = map[string]bool{
	"aws_source_profile":        true,
	"aws_source_profile_region": true,
	"dynamodb_table":            true,
	"mfa_arn":                   true,
	"session_name":              true,
	"session_duration":          true,
	"tags":                      true,
}

Expected keys in letme-config file

View Source
var MandatoryKeys = []string{
	"aws_source_profile",
	"aws_source_profile_region",
	"dynamodb_table",
}

Mandatory keys in letme-config file

Functions

func AssumeRole added in v0.2.0

func AssumeRole(letmeContext *LetmeContext, cfg aws.Config, inlineTokenMfa string, account *DynamoDbAccountConfig, renew bool, localCredentialProcessFlagV1 bool, authMethod string) (ProfileCredential, ProfileConfig)

func AssumeRoleChained added in v0.2.0

func AssumeRoleChained(letmeContext *LetmeContext, cfg aws.Config, inlineTokenMfa string, account *DynamoDbAccountConfig, renew bool, localCredentialProcessFlagV1 bool, authMethod string) (ProfileCredential, ProfileConfig)

func AwsConfigFileCredentialsProcessV1 added in v0.2.0

func AwsConfigFileCredentialsProcessV1(accountName string, region string)

Marshalls data into a string used for the aws config file but with the v1 output protocol

func AwsConfigFileReadV2 added in v0.2.0

func AwsConfigFileReadV2() *ini.File

func AwsCredsFileReadV2 added in v0.2.0

func AwsCredsFileReadV2() *ini.File

func CacheFileExists

func CacheFileExists() bool

Checks if the .letme-cache file exists, this file is not supported starting from versions 0.2.0 and above

func CheckAccountAvailability added in v0.2.0

func CheckAccountAvailability(accountName string) bool

Compare the current local time with the expiry field in the .letme-db file. If current time has not yet surpassed expiry time, return true. Else, return false indicating new credentials need to be requested.

func CheckAccountLocally added in v0.1.5

func CheckAccountLocally(account string) map[string]bool

Check if an account is present on the local aws credentials/config files

func CheckAndReturnError

func CheckAndReturnError(err error)

Checks the error, if the error contains a message, stop the execution and show the error to the user

func CheckConfigFile

func CheckConfigFile(path string) bool

Verify if the config-file respects the struct LetmeContext

func CommandExists

func CommandExists(command string)

Check if a command exists

func CredentialsProcessOutput added in v0.2.0

func CredentialsProcessOutput(accessKeyID string, secretAccessKey string, sessionToken string, expirationTime time.Time) string

Return aws credentials following the credentials_process standard https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sourcing-external.html

func DatabaseFile added in v0.2.0

func DatabaseFile(accountName string, sessionDuration int32, v1Credentials string, authMethod string)

Create a file which stores the last time when credentials where requested. Then query if the account exists, if not, it will create its first entry.

func GetAvalaibleContexts added in v0.2.0

func GetAvalaibleContexts() []string

func GetCurrentContext added in v0.2.0

func GetCurrentContext() string

func GetHomeDirectory

func GetHomeDirectory() string

Gets the user $HOME directory

func LetmeConfigCreate added in v0.2.0

func LetmeConfigCreate()

func LetmeConfigRead added in v0.2.0

func LetmeConfigRead() *ini.File

func ListJsonOutput added in v0.2.1

func ListJsonOutput(accountList []DynamoDbAccountConfig)

func ListTextOutput added in v0.2.1

func ListTextOutput(accountList []DynamoDbAccountConfig)

func LoadAwsConfig added in v0.2.0

func LoadAwsConfig(profileName string, profileConfig ProfileConfig)

func LoadAwsCredentials added in v0.2.0

func LoadAwsCredentials(profileName string, profileCredential ProfileCredential)

func NewContext added in v0.2.0

func NewContext(context string)

func RemoveAccountFromDatabaseFile added in v0.2.0

func RemoveAccountFromDatabaseFile(accountName string)

Remove an account from the database file

func ReturnAccountCredentials added in v0.2.0

func ReturnAccountCredentials(accountName string) map[string]string

Check if the account to retrieve stored credentials exist, if true, return the credentials to stdout

func TemplateConfigFile

func TemplateConfigFile(stdout bool)

Marshalls data into a toml file (config-file)

func UpdateContext added in v0.2.0

func UpdateContext(context string)

Create the .letme-usersettings file which holds the current context and more

Types

type Account added in v0.2.0

type Account struct {
	Account Dataset `json:"account"`
}

type AccountItem added in v0.2.1

type AccountItem struct {
	Name   string `json:"name"`
	Region string `json:"region"`
}

type AccountItems added in v0.2.1

type AccountItems struct {
	Items []AccountItem `json:"items"`
}

type Context added in v0.2.0

type Context struct {
	ActiveContext string `ini:"active_context"`
}

type CredentialsProcess added in v0.2.0

type CredentialsProcess struct {
	Version         int
	AccessKeyId     string
	SecretAccessKey string
	SessionToken    string
	Expiration      time.Time
}

Struct which states the credential process output for the v1 protocol

type Dataset added in v0.2.0

type Dataset struct {
	Name          string `json:"name"`
	LastRequest   int64  `json:"lastRequest"`
	Expiry        int64  `json:"expiry"`
	AuthMethod    string `json:"authMethod"`
	V1Credentials string `json:"v1Credentials,omitempty"`
}

type DynamoDbAccountConfig added in v0.2.0

type DynamoDbAccountConfig struct {
	Name   string   `dynamodbav:"name"`
	Region []string `dynamodbav:"region"`
	Role   []string `dynamodbav:"role"`
	Tags   []string `dynamodbav:"tags"`
}

func GetAccount added in v0.2.0

func GetAccount(awsDynamoDbTable string, cfg aws.Config, profileName string) *DynamoDbAccountConfig

func GetTableData added in v0.2.1

func GetTableData(awsDynamoDbTable string, tags []string, cfg aws.Config) (resp []DynamoDbAccountConfig)

type LetmeContext added in v0.2.0

type LetmeContext struct {
	AwsSourceProfile       string   `ini:"aws_source_profile"`
	AwsSourceProfileRegion string   `ini:"aws_source_profile_region"`
	AwsDynamoDbTable       string   `ini:"dynamodb_table"`
	AwsMfaArn              string   `ini:"mfa_arn"`
	AwsSessionName         string   `ini:"session_name"`
	AwsSessionDuration     int32    `ini:"session_duration"`
	Tags                   []string `ini:"tags"`
}

func GetContextData added in v0.2.0

func GetContextData(context string) *LetmeContext

type ProfileConfig added in v0.2.0

type ProfileConfig struct {
	Output string `ini:"output"`
	Region string `ini:"region"`
}

type ProfileCredential added in v0.2.0

type ProfileCredential struct {
	AccessKey    string `ini:"aws_access_key_id"`
	SecretKey    string `ini:"aws_secret_access_key"`
	SessionToken string `ini:"aws_session_token"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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