utils

package
v0.0.0-...-d0fd1eb Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RegionMap = []string{"us-east-1", "us-east-2", "us-west-1", "us-west-2", "ca-central-1", "eu-west-1", "eu-central-1", "eu-west-2", "ap-northeast-1", "ap-northeast-2", "ap-southeast-1", "ap-southeast-2", "ap-south-1", "sa-east-1"}
)

Functions

func AssumeRoleWithInstance

func AssumeRoleWithInstance(account AccountInfo, region string) (*session.Session, error)

Assumes the role of the given arn with the instance profile and returns a session into the account associated with the arn

func AssumeRoleWithProfile

func AssumeRoleWithProfile(account AccountInfo, region string) *session.Session

Assumes the role of the specified profile

func CreateFile

func CreateFile(name string) (file *os.File, err error)

CreateFile will create a file with a given name It will check to ensure that it does not overwrite a file with the same name

func GenPassword

func GenPassword(n int) string

Will generate a password with length of n using a custom random password generator

func GetAccountId

func GetAccountId(sess *session.Session) (string, error)

GetAccountId will get the account ID for the profile currently in use for the session

func LoadConfigFile

func LoadConfigFile()

This is a helper func to load the ~/.aws/config file

func LogAll

func LogAll(args ...interface{})

Helper function to print to stdout and the log file

func MakeDir

func MakeDir(path string)

This will create a new directory with the given path relative to where the script was run from

func OpenSession

func OpenSession(profile string, region string) *session.Session

func PrettyPrintJson

func PrettyPrintJson(input interface{})

Will take in a struct and print with pretty json

func ReadFile

func ReadFile(path string) ([]string, error)

ReadFile will open a file, and return a string slice with each line as a string

Types

type AccountInfo

type AccountInfo struct {
	AccountId  string
	Arn        string // only required if AccessType is instanceassume
	ExternalId string
	AccessType string
	Profile    string
}

If AccessType is role, then the Profile needs to be configured in your shared config file ~/.aws/config to use have the assume role config setup Example:

[profile <profile name>] role_arn = arn:aws:iam::123456789012:role/<role name> source_profile = <source profile in ~/.aws/credentials> region = us-east-1 output = json

If AccessType is profile, then it will just use the profile in your shared credential file ~/.aws/credentials

func BuildAccountsSlice

func BuildAccountsSlice(profilesFile string, accessType string) ([]AccountInfo, error)

func (AccountInfo) GetSession

func (account AccountInfo) GetSession(region string) (*session.Session, error)

func (AccountInfo) SetAccountId

func (account AccountInfo) SetAccountId() error

type ELBIPInfo

type ELBIPInfo struct {
	SourceIP         string
	SourceIPCount    int
	SourceIPLocation string
	SourceIPGeoInfo  GeoIpInfo
}

type ELBLogInfo

type ELBLogInfo []ELBIPInfo

func ParseELBLog

func ParseELBLog(path string, geo bool) (ELBLogInfo, error)

ParseELBLog will parse an elb log file and return the relevant details Will also check the Geo location of the IP if "geo" is true

type Ec2Options

type Ec2Options struct {
	Tags []string
}

type GeoIpInfo

type GeoIpInfo struct {
	Country   string
	State     string
	City      string
	Latitude  string
	Longitude string
}

func GetIPGeoLocation

func GetIPGeoLocation(ip string) (GeoIpInfo, error)

GetIPGeoLocation will use api.hackertarget.com to find the location of an IP

type Sessioninfo

type Sessioninfo struct {
	Sess    *session.Session
	Region  string
	Account string
}

Jump to

Keyboard shortcuts

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