common

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package common contains common functions and types.

It has AWS related functions and types. It also has functions to print the results in different formats.

Package common contains common functions and types.

common defines an important interface that all results must implement. It has AWS related functions and types. It also has functions to print the results in different formats.

Package common contains common functions and types.

It has AWS related functions and types. It also has functions to print the results in different formats.

Package common contains common functions and types.

It has AWS related functions and types. It also has functions to print the results in different formats.

Index

Constants

View Source
const (
	// JSON is the JSON output format.
	JSON = "json"
	// JSONPretty is the pretty JSON output format.
	JSONPretty = "json-pretty"
	// Table is the table output format.
	Table = "table"
)

Variables

View Source
var Bold = toBold

Bold is the function used to bold text.

We use this var to allow tests to mock the function.

Functions

func AwsConfig

func AwsConfig(profile, region string) (aws.Config, error)

AwsConfig returns a AWS config for the specific profile and region.

func FilterAvailabilityZones

func FilterAvailabilityZones(availabilityZones []string, region string) []types.Filter

FilterAvailabilityZones returns a list of types.Filter by availability-zone.

The availabilityZones must be a list of letters that represent the availability zone. For example: "a", "b", "c". The region is used to get the full availability zone name.

func FilterDefault

func FilterDefault(key string, values []string) []types.Filter

FilterDefault returns a list of types.Filter. The key is used as filter Name and the values as Values.

func FilterNames

func FilterNames(names []string) []types.Filter

FilterNames returns a list of types.Filter where the filter Name is tag:Name and the names are the Values.

func FilterTags

func FilterTags(tags []string) []types.Filter

FilterTags returns a list of types.Filter by tag:Key=Value1,Value2,Value3...

func GetAwsProfiles

func GetAwsProfiles() ([]string, error)

GetAwsProfiles returns a list of profiles from the AWS config file.

It is used to get the list of profiles from the AWS config file. The default location is ~/.aws/config.

func IPtoString

func IPtoString(i []net.IP) []string

IPtoString returns a slice of strings from a slice of IPs.

func ParseTags

func ParseTags(tags []string) (map[string][]string, error)

ParseTags receives a slice of strings and returns a map of tags and values.

It expects a string in the format of "key1=value1:value2,key2=value3" and returns a map[string][]string{"key1":{"value1","value2"},"key2":{"value3"}}.

func PrintResults

func PrintResults(w io.Writer, resultsChan <-chan Results, done chan<- bool, output string, showEmpty, showTags bool)

PrintResults prints the results in the given format.

The results are read from the resultsChan channel. The done channel is used to signal that the results were printed. The output is the format of the output. The showEmpty flag indicates if empty results should be shown. The showTags flag indicates if the tags should be shown.

func String

func String(s string) *string

String returns a pointer to a string.

func StringInSlice

func StringInSlice(s string, slice []string) bool

StringInSlice returns true if the string is in the slice.

func StringSliceToString

func StringSliceToString(s []string, sep string) string

StringSliceToString returns a string from a slice of strings.

The separator is the string that will be used to join the strings.

func StringValue

func StringValue(s *string) string

StringValue returns an empty string if the pointer is nil.

func StructToFilters

func StructToFilters(s interface{}) (map[string][]string, error)

StructToFilters returns a map of filters from a struct.

The struct must have the tag "filter" in the fields that should be used as filters.

func TagName

func TagName(tags []types.Tag) string

TagName returns the value of the tag:Name from a slice of types.Tag.

func TagsToMap

func TagsToMap(tags []types.Tag) map[string]string

TagsToMap takes a slice of types.Tag and returns a map of tags and values.

func TerminalSize added in v0.7.3

func TerminalSize() terminalSize

func ValidOutputs added in v0.7.3

func ValidOutputs(o string) (string, bool)

ValidOutputs returns the valid output formats and if the given output is valid.

func WhoAmI added in v0.7.1

func WhoAmI(profile, region string) (string, error)

WhoAmI returns the AWS account ID and error.

The profile and region are used to create the AWS config. The AWS account ID is returned by the STS GetCallerIdentity API. This function is used as workaround to pre-authenticate the AWS config.

Types

type Results

type Results interface {
	Search()
	Len() int
	GetProfile() string
	GetRegion() string
	GetErrors() []string
	GetSortField() string
	GetHeaders() []interface{}
	GetRows() []interface{}
}

Results is an interface that defines the methods that a result must implement.

Jump to

Keyboard shortcuts

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