utils

package
v0.2.0-rc2 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 10 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,
}

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 AwsConfigFile

func AwsConfigFile(accountName string, region string) string

Marshalls data into a string used for the aws credentials file

func AwsConfigFileCredentialsProcessV1 added in v0.2.0

func AwsConfigFileCredentialsProcessV1(accountName string, region string) string

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

func AwsConfigFileRead

func AwsConfigFileRead() string

Reads the aws config file

func AwsCredentialsFile

func AwsCredentialsFile(accountName string, accessKeyID string, secretAccessKey string, sessionToken string) string

Marshalls data into a string used for the aws credentials file

func AwsCredsFileRead

func AwsCredsFileRead() string

Reads the aws credentials file

func AwsReplaceBlock

func AwsReplaceBlock(file string, accountName string) string

Removes from a file all text in between two indentificators (accountName)

func AwsSingleReplaceBlock added in v0.1.5

func AwsSingleReplaceBlock(file string, accountName string) string

Returns only the text entry which statisfies the accountName

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) string

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 GeneralParams

func CommandExists

func CommandExists(command string)

Check if a command exists

func ConfigFileResultString

func ConfigFileResultString(profile string, field string) interface{}

Parses letme-config file and returns one field at a time

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 int64, 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 GetCurrentContext added in v0.2.0

func GetCurrentContext() string

func GetHomeDirectory

func GetHomeDirectory() string

Gets the user $HOME directory

func GetLatestRequestedTime added in v0.1.5

func GetLatestRequestedTime(content string) string

Return the latest requested time from a block of text

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() string

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 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 GeneralParams

type GeneralParams struct {
	Aws_source_profile        string
	Aws_source_profile_region string `toml:"aws_source_profile_region,omitempty"`
	Dynamodb_table            string
	Mfa_arn                   string `toml:"mfa_arn,omitempty"`
	Session_name              string
	Session_duration          int64 `toml:"session_duration,omitempty"`
}

Struct which represents the config-file keys

type UserSettings

type UserSettings struct {
	ActiveContext string `json:"activeContext"`
}

UserSettings represents the structure of the .letme-usersettings file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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