utils

package
v0.0.0-...-7043925 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Running    InstanceState = "running"
	Stopped                  = "stopped"
	Terminated               = "terminated"
)

Variables

This section is empty.

Functions

func CheckIfResourcesYAMLExistsAndReturnPath

func CheckIfResourcesYAMLExistsAndReturnPath() (bool, string)

func CreateSockV5erDirectory

func CreateSockV5erDirectory() string

func GetExternalIP

func GetExternalIP() (string, error)

func ReadFileContent

func ReadFileContent(filepath string) ([]byte, error)

func StartWorker

func StartWorker()

func ToMap

func ToMap(a *AWSResource) map[string]string

func WriteFileContent

func WriteFileContent(filepath string, fileContent []byte) error

Types

type AWSRepository

type AWSRepository struct {
	Client          *ec2.Client
	Region          string
	KeyPairId       string
	SecurityGroupID string

	Ec2InstanceId string
	InstanceIP    string
	KeyPairKey    string
	// contains filtered or unexported fields
}

func (*AWSRepository) CheckIfInstanceExists

func (repo *AWSRepository) CheckIfInstanceExists(instanceID string) (bool, error)

func (*AWSRepository) CheckIfInstanceIsInState

func (repo *AWSRepository) CheckIfInstanceIsInState(instanceId string, state InstanceState) bool

func (*AWSRepository) CreateEC2Instance

func (repo *AWSRepository) CreateEC2Instance() (string, error)

func (*AWSRepository) CreateKeyPair

func (repo *AWSRepository) CreateKeyPair() error

func (*AWSRepository) CreateResources

func (repo *AWSRepository) CreateResources(region string, s *Settings, tracker *ResourceTracker) error

func (*AWSRepository) CreateSecurityGroup

func (repo *AWSRepository) CreateSecurityGroup() error

func (*AWSRepository) DeleteKeyPair

func (repo *AWSRepository) DeleteKeyPair(keyPairId string) error

func (*AWSRepository) DeleteResources

func (repo *AWSRepository) DeleteResources(region string, s *Settings, tracker *ResourceTracker) error

func (*AWSRepository) DeleteSecurityGroup

func (repo *AWSRepository) DeleteSecurityGroup(securityGroupId string) error

func (*AWSRepository) GetDefaultVPC

func (repo *AWSRepository) GetDefaultVPC() error

func (*AWSRepository) GetHostIP

func (repo *AWSRepository) GetHostIP() string

func (*AWSRepository) GetPrivateKey

func (repo *AWSRepository) GetPrivateKey() []byte

func (*AWSRepository) GetRegions

func (repo *AWSRepository) GetRegions(s *Settings) []map[string]string

func (*AWSRepository) Initialize

func (repo *AWSRepository) Initialize(s *Settings) error

func (*AWSRepository) PrepareResourcesForDeletion

func (repo *AWSRepository) PrepareResourcesForDeletion(resource map[string]string)

func (*AWSRepository) SetRegion

func (repo *AWSRepository) SetRegion(region string, s *Settings) error

func (*AWSRepository) TerminateEC2Instance

func (repo *AWSRepository) TerminateEC2Instance(instanceId string) error

func (*AWSRepository) UpdateTracker

func (repo *AWSRepository) UpdateTracker(resources map[string]string, op TrackingOp, tracker *ResourceTracker)

func (*AWSRepository) WaitUntilInstanceIsActive

func (repo *AWSRepository) WaitUntilInstanceIsActive(instanceId string) bool

func (*AWSRepository) WaitUntilInstanceIsTerminated

func (repo *AWSRepository) WaitUntilInstanceIsTerminated(instanceId string) bool

type AWSResource

type AWSResource struct {
	Region          string `yaml:"region"`
	InstanceId      string `yaml:"instanceId"`
	SecurityGroupId string `yaml:"securityGroupId"`
	KeyPairId       string `yaml:"keyPairId"`
}

func FromAWSRepository

func FromAWSRepository(a *AWSRepository) *AWSResource

func FromMap

func FromMap(resourceMap map[string]string) *AWSResource

type CloudProvider

type CloudProvider interface {
	Initialize(s *Settings) error
	GetRegions(s *Settings) []map[string]string
	CreateResources(region string, s *Settings, tracker *ResourceTracker) error
	DeleteResources(region string, s *Settings, tracker *ResourceTracker) error
	PrepareResourcesForDeletion(resources map[string]string)
	UpdateTracker(resources map[string]string, op TrackingOp, tracker *ResourceTracker)
	GetHostIP() string
	GetPrivateKey() []byte
}

func NewAWSProvider

func NewAWSProvider() CloudProvider

type ConfigFileData

type ConfigFileData struct{}

func (*ConfigFileData) Read

func (s *ConfigFileData) Read() *Settings

type ENVData

type ENVData struct{}

func (*ENVData) Read

func (s *ENVData) Read() *Settings

type GeoHelper

type GeoHelper struct {
	Settings *Settings
}

func (*GeoHelper) FindCountry

func (h *GeoHelper) FindCountry(ep string) (string, error)

func (*GeoHelper) GetCountryShortName

func (h *GeoHelper) GetCountryShortName(country string) string

func (*GeoHelper) GetIP

func (h *GeoHelper) GetIP(ep string) (string, error)

type IP2LocationFinder

type IP2LocationFinder interface {
	GetIP(string) (string, error)
	FindCountry(string) (string, error)
}

type InstanceState

type InstanceState string

type Reader

type Reader interface {
	Read() *Settings
}

type ResourceTracker

type ResourceTracker struct {
	// contains filtered or unexported fields
}

func GetNewTracker

func GetNewTracker(trackerFilepath string) *ResourceTracker

func (*ResourceTracker) AddAWSResource

func (rt *ResourceTracker) AddAWSResource(resource *AWSResource)

func (*ResourceTracker) GetResources

func (rt *ResourceTracker) GetResources() *[]AWSResource

func (*ResourceTracker) ReadResourcesFile

func (rt *ResourceTracker) ReadResourcesFile() error

func (*ResourceTracker) RemoveAWSResource

func (rt *ResourceTracker) RemoveAWSResource(resource *AWSResource)

func (*ResourceTracker) WriteResourcesFile

func (rt *ResourceTracker) WriteResourcesFile() error

type SSHConfig

type SSHConfig struct {
	PrivateKey         []byte
	KnownHostsFilepath string
	SSHHost            string
	SSHPort            string
	SSHUsername        string
	SocksV5IP          string
	SocksV5Port        string
}

func (*SSHConfig) GetNewSSHSession

func (config *SSHConfig) GetNewSSHSession() (*ssh.Session, error)

func (*SSHConfig) IssueCommandsViaSSH

func (config *SSHConfig) IssueCommandsViaSSH(session *ssh.Session, commandsToExecute []string)

func (*SSHConfig) StartSocksV5Server

func (config *SSHConfig) StartSocksV5Server()

type Settings

type Settings struct {
	AccessKeyId       string
	SecretKey         string
	SocksV5Host       string
	SocksV5Port       string
	GeoLocationFile   string
	PrivateKeyPath    string
	SSHKnownHostsPath string
	SSHUserName       string
	SSHPort           string
	TrackingFilepath  string
}

type SockV5erResources

type SockV5erResources struct {
	Version      string        `yaml:"version"`
	Generator    string        `yaml:"generator"`
	AWSResources []AWSResource `yaml:"awsResources"`
}

type SocksV5Er

type SocksV5Er struct {
	// contains filtered or unexported fields
}

type TrackingOp

type TrackingOp int
const (
	Add TrackingOp = iota
	Remove
)

Jump to

Keyboard shortcuts

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