aws

package
v0.0.0-...-23a5b11 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 17 Imported by: 0

README

#AWS

aws operations will probably split into it's own library at some point.

Currently there are three main parts of this library

  1. RDS operations which directly operates on instances and clusters This allow us to do the following: 1. Create a snapshot 1. Create a cluster 1. Create an instance
  2. rds Parameter groups which are for parameter groups for database configuration
  3. KMS operations which is purely for copying snapshots right now though that will probably change. This allows us to create a new key in the region we are copying the snapshot to by default. Warning these can persist so you have to be careful with not giving that parameter. (NOTE this warning should move to main readme or tutorial)

Documentation

Index

Constants

View Source
const MaxConcurrentJobs = 3

MaxConcurrentJobs max number of operations to hit AWS with at the same time

Variables

This section is empty.

Functions

func GetClusterParameterGroup

func GetClusterParameterGroup(r state.RDSRestorationStore, i DbInstances) ([]pgstate.ParameterGroup, error)

GetClusterParameterGroup take in restoration store return list of parameter groups associated with a cluster

func GetParameterGroups

func GetParameterGroups(r state.RDSRestorationStore, i DbInstances) ([]pgstate.ParameterGroup, error)

GetParameterGroups get a list of paramter groups

Types

type Client

type Client interface {
	DescribeDBClusters(ctx context.Context, params *rds.DescribeDBClustersInput, optFns ...func(*rds.Options)) (*rds.DescribeDBClustersOutput, error)
	DescribeDBClusterSnapshots(ctx context.Context, params *rds.DescribeDBClusterSnapshotsInput, optFns ...func(*rds.Options)) (*rds.DescribeDBClusterSnapshotsOutput, error)
	DescribeDBInstances(ctx context.Context, input *rds.DescribeDBInstancesInput, optFns ...func(*rds.Options)) (*rds.DescribeDBInstancesOutput, error)
	DescribeDBSnapshots(ctx context.Context, params *rds.DescribeDBSnapshotsInput, optFns ...func(*rds.Options)) (*rds.DescribeDBSnapshotsOutput, error)
	DescribeOptionGroups(ctx context.Context, params *rds.DescribeOptionGroupsInput, optFns ...func(*rds.Options)) (*rds.DescribeOptionGroupsOutput, error)
	CreateDBSubnetGroup(ctx context.Context, params *rds.CreateDBSubnetGroupInput, optFns ...func(*rds.Options)) (*rds.CreateDBSubnetGroupOutput, error)
	CreateDBParameterGroup(ctx context.Context, params *rds.CreateDBParameterGroupInput, optFns ...func(*rds.Options)) (*rds.CreateDBParameterGroupOutput, error)
	CreateDBClusterParameterGroup(ctx context.Context, params *rds.CreateDBClusterParameterGroupInput, optFns ...func(*rds.Options)) (*rds.CreateDBClusterParameterGroupOutput, error)
	CreateOptionGroup(ctx context.Context, params *rds.CreateOptionGroupInput, optFns ...func(*rds.Options)) (*rds.CreateOptionGroupOutput, error)
	CreateDBInstance(ctx context.Context, params *rds.CreateDBInstanceInput, optFns ...func(*rds.Options)) (*rds.CreateDBInstanceOutput, error)
	CreateDBSnapshot(ctx context.Context, params *rds.CreateDBSnapshotInput, optFns ...func(*rds.Options)) (*rds.CreateDBSnapshotOutput, error)
	CreateDBClusterSnapshot(ctx context.Context, params *rds.CreateDBClusterSnapshotInput, optFns ...func(*rds.Options)) (*rds.CreateDBClusterSnapshotOutput, error)
	ModifyDBParameterGroup(ctx context.Context, params *rds.ModifyDBParameterGroupInput, optFns ...func(*rds.Options)) (*rds.ModifyDBParameterGroupOutput, error)
	ModifyOptionGroup(ctx context.Context, params *rds.ModifyOptionGroupInput, optFns ...func(*rds.Options)) (*rds.ModifyOptionGroupOutput, error)
	ModifyDBClusterParameterGroup(ctx context.Context, params *rds.ModifyDBClusterParameterGroupInput, optFns ...func(*rds.Options)) (*rds.ModifyDBClusterParameterGroupOutput, error)
	DescribeDBClusterParameters(ctx context.Context, params *rds.DescribeDBClusterParametersInput, optFns ...func(*rds.Options)) (*rds.DescribeDBClusterParametersOutput, error)
	DescribeDBClusterParameterGroups(ctx context.Context, params *rds.DescribeDBClusterParameterGroupsInput, optFns ...func(*rds.Options)) (*rds.DescribeDBClusterParameterGroupsOutput, error)
	DescribeDBParameters(ctx context.Context, params *rds.DescribeDBParametersInput, optFns ...func(*rds.Options)) (*rds.DescribeDBParametersOutput, error)
	DescribeDBParameterGroups(ctx context.Context, params *rds.DescribeDBParameterGroupsInput, optFns ...func(*rds.Options)) (*rds.DescribeDBParameterGroupsOutput, error)
	CopyDBSnapshot(ctx context.Context, params *rds.CopyDBSnapshotInput, optFns ...func(*rds.Options)) (*rds.CopyDBSnapshotOutput, error)
	CopyDBClusterSnapshot(ctx context.Context, params *rds.CopyDBClusterSnapshotInput, optFns ...func(*rds.Options)) (*rds.CopyDBClusterSnapshotOutput, error)
	RestoreDBClusterFromSnapshot(ctx context.Context, params *rds.RestoreDBClusterFromSnapshotInput, optFns ...func(*rds.Options)) (*rds.RestoreDBClusterFromSnapshotOutput, error)
	RestoreDBInstanceFromDBSnapshot(ctx context.Context, params *rds.RestoreDBInstanceFromDBSnapshotInput, optFns ...func(*rds.Options)) (*rds.RestoreDBInstanceFromDBSnapshotOutput, error)
}

Client is used for mocking the AWS RDS instance for testing

type CreateClusterFromStackInput

type CreateClusterFromStackInput struct {
	S             *stack.Stack
	ClusterName   *string
	DBSubnetGroup *string

	VpcID   *string
	Ingress []PassedIPs
	Egress  []PassedIPs
	// contains filtered or unexported fields
}

CreateClusterFromStackInput creates a stack all inputs required

type CreateInstanceFromStackInput

type CreateInstanceFromStackInput struct {
	Stack         *stack.Stack
	DBName        *string
	DBSubnetGroup *string

	VpcID   *string
	Ingress []PassedIPs
	Egress  []PassedIPs
	// contains filtered or unexported fields
}

CreateInstanceFromStackInput input for creating a stack

type CreateSGInput

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

CreateSGInput input for the create SG function

type DbInstances

type DbInstances struct {
	RdsClient Client
}

DbInstances holds our RDS client that allows for operations in AWS

func Init

func Init(region string) DbInstances

Init creates an RDS Client

func (*DbInstances) CopyClusterSnaphot

func (instances *DbInstances) CopyClusterSnaphot(originalSnapshotName string, newSnapshotName string, sourceRegion string, kmsKey string) (
	*types.DBClusterSnapshot, error)

CopyClusterSnaphot see CopySnapshot now for a Cluster

func (*DbInstances) CopySnapshot

func (instances *DbInstances) CopySnapshot(originalSnapshotName string, newSnapshotName string, sourceRegion string, KmsKey string) (
	*types.DBSnapshot, error)

CopySnapshot copies a snapshot to a new region note it needs to run from the destination region so it needs a different client then CreateSnapshot!

func (*DbInstances) CreateClusterFromStack

func (instances *DbInstances) CreateClusterFromStack(c CreateClusterFromStackInput) error

CreateClusterFromStack creates an RDS cluster from a stack

func (*DbInstances) CreateClusterParameterGroup

func (instances *DbInstances) CreateClusterParameterGroup(p *types.DBClusterParameterGroup) (*rds.CreateDBClusterParameterGroupOutput, error)

CreateClusterParameterGroup creates a pararmeter group for a DB instance

func (*DbInstances) CreateClusterSnapshot

func (instances *DbInstances) CreateClusterSnapshot(clusterName string, snapshotName string) (*types.DBClusterSnapshot, error)

CreateClusterSnapshot so it turns out AWS is annoying and makes us create snapshots seperatly for clusters and instaces how fun!

func (*DbInstances) CreateDBSubnetGroup

func (instances *DbInstances) CreateDBSubnetGroup(name string, description string, subnets []string) (*rds.CreateDBSubnetGroupOutput, error)

CreateDBSubnetGroup creates a subnet group to allow for the creation of databases

func (*DbInstances) CreateInstanceFromStack

func (instances *DbInstances) CreateInstanceFromStack(c CreateInstanceFromStackInput) error

CreateInstanceFromStack creates an RDS instance from a stack object

func (*DbInstances) CreateParameterGroup

func (instances *DbInstances) CreateParameterGroup(p *types.DBParameterGroup) (*rds.CreateDBParameterGroupOutput, error)

CreateParameterGroup creates a pararmeter group for a DB instance

func (*DbInstances) CreateSnapshot

func (instances *DbInstances) CreateSnapshot(instanceName string, snapshotName string) (
	*types.DBSnapshot, error)

CreateSnapshot creates an AWS snapshot :instanceName - name of the database we want to backup :snapShotName name of the backup we are creating

func (*DbInstances) GetCluster

func (instances *DbInstances) GetCluster(clusterName string) (*types.DBCluster, error)

GetCluster describes an RDS cluster

func (*DbInstances) GetClusterParameterGroup

func (instances *DbInstances) GetClusterParameterGroup(ParameterGroupName string) (
	*types.DBClusterParameterGroup, error)

GetClusterParameterGroup get the cluster parameter group so we can make a new one in a new region or you know store it for restoration (actually we won't need to do that cause the data is stored on the snapshot :P)

func (*DbInstances) GetClusterSnapshotARN

func (instances *DbInstances) GetClusterSnapshotARN(name string, marker *string) (*string, error)

GetClusterSnapshotARN get's the cluster snapshot arn from snapshot name

func (*DbInstances) GetClusterSnapshotStatus

func (instances *DbInstances) GetClusterSnapshotStatus(name string) (*string, error)

GetClusterSnapshotStatus get the status for a cluster snapshot the way AWS divides snapshots is annoying

func (*DbInstances) GetInstance

func (instances *DbInstances) GetInstance(instanceName string) (
	*types.DBInstance, error)

GetInstance describes an RDS instance and returns it's output

func (*DbInstances) GetInstanceSnapshotARN

func (instances *DbInstances) GetInstanceSnapshotARN(name string, marker *string) (*string, error)

GetInstanceSnapshotARN get the arn for an instance snapshot

func (*DbInstances) GetInstanceSnapshotPercentage

func (instances *DbInstances) GetInstanceSnapshotPercentage(name string) (*int32, error)

GetInstanceSnapshotPercentage get the status for an instance snapshot

func (*DbInstances) GetInstanceSnapshotStatus

func (instances *DbInstances) GetInstanceSnapshotStatus(name string) (*string, error)

GetInstanceSnapshotStatus get the status for an instance snapshot

func (*DbInstances) GetInstancesFromCluster

func (instances *DbInstances) GetInstancesFromCluster(c *types.DBCluster) ([]types.DBInstance, error)

GetInstancesFromCluster get's the instaces associated with a database cluster

func (*DbInstances) GetOptionGroup

func (instances *DbInstances) GetOptionGroup(OptionGroupName string) (*types.OptionGroup, error)

GetOptionGroup get option group by name

func (*DbInstances) GetParameterGroup

func (instances *DbInstances) GetParameterGroup(parameterGroupName string) (
	*types.DBParameterGroup, error)

GetParameterGroup we will use this for moving custom parameter groups

func (*DbInstances) GetParametersForClusterParameterGroup

func (instances *DbInstances) GetParametersForClusterParameterGroup(ParameterGroupName string) (*[]types.Parameter, error)

GetParametersForClusterParameterGroup returns parameters for a cluster group

func (*DbInstances) GetParametersForGroup

func (instances *DbInstances) GetParametersForGroup(ParameterGroupName string) (*[]types.Parameter, error)

GetParametersForGroup returns the parameters for a parameter group

func (*DbInstances) GetSnapshotARN

func (instances *DbInstances) GetSnapshotARN(name string, cluster bool) (*string, error)

GetSnapshotARN get's the snapshot ARN from the snapshot name

func (*DbInstances) ModifyClusterParameterGroup

func (instances *DbInstances) ModifyClusterParameterGroup(pg string, parameters []types.Parameter) error

ModifyClusterParameterGroup adds all the parameters to a db cluster parameter group

func (*DbInstances) ModifyOptionGroup

func (instances *DbInstances) ModifyOptionGroup(OptionGroupName string, Include []types.OptionConfiguration) error

ModifyOptionGroup modifies the option group

func (*DbInstances) ModifyParameterGroup

func (instances *DbInstances) ModifyParameterGroup(pg string, parameters []types.Parameter) error

ModifyParameterGroup adds all the parameters to a db parameter group

func (*DbInstances) RestoreInstanceForCluster

func (instances *DbInstances) RestoreInstanceForCluster(input rds.CreateDBInstanceInput) (*rds.CreateDBInstanceOutput, error)

RestoreInstanceForCluster our cluster has no instances by default it need's instances to be usable this makes them exist

func (*DbInstances) RestoreOptionGroup

func (instances *DbInstances) RestoreOptionGroup(EngineName string, MajorEngineVersion string, OptionGroupName string, Description string) (
	*rds.CreateOptionGroupOutput, error)

RestoreOptionGroup creates the option group for our database this is very optional

func (*DbInstances) RestoreSnapshotCluster

RestoreSnapshotCluster takes a snapshot turns it into a DB Cluster fun fact the cluster won't be ready from just this there will be no instances

func (*DbInstances) RestoreSnapshotInstance

RestoreSnapshotInstance restores a single db instance from a snapshot

type EC2Instances

type EC2Instances struct {
	Client Ec2Client
}

EC2Instances is the struct to hold our ec2 client

func InitEc2

func InitEc2(region string) EC2Instances

InitEc2 creates an EC2 client

func (*EC2Instances) CreateSG

CreateSG creates a new security group

func (*EC2Instances) DescribeSG

func (c *EC2Instances) DescribeSG(sgIds string) (*ec2.DescribeSecurityGroupsOutput, error)

DescribeSG describes a security group

func (*EC2Instances) GetSubnet

func (c *EC2Instances) GetSubnet(subnetID string) (*ec2.DescribeSubnetsOutput, error)

func (*EC2Instances) GetSubnets

func (c *EC2Instances) GetSubnets(sgIds []string) (*ec2.DescribeSubnetsOutput, error)

func (*EC2Instances) SGEgress

func (*EC2Instances) SGIngress

SGIngress updates a security group with ingress ips

type Ec2Client

type Ec2Client interface {
	CreateSecurityGroup(ctx context.Context, params *ec2.CreateSecurityGroupInput, optFns ...func(*ec2.Options)) (*ec2.CreateSecurityGroupOutput, error)
	AuthorizeSecurityGroupEgress(ctx context.Context, params *ec2.AuthorizeSecurityGroupEgressInput, optFns ...func(*ec2.Options)) (*ec2.AuthorizeSecurityGroupEgressOutput, error)
	DescribeSecurityGroups(ctx context.Context, params *ec2.DescribeSecurityGroupsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeSecurityGroupsOutput, error)
	AuthorizeSecurityGroupIngress(ctx context.Context, params *ec2.AuthorizeSecurityGroupIngressInput, optFns ...func(*ec2.Options)) (*ec2.AuthorizeSecurityGroupIngressOutput, error)
	DescribeSubnets(ctx context.Context, params *ec2.DescribeSubnetsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeSubnetsOutput, error)
}

Ec2Client allows mocking of the ec2 client

type KmsClient

type KmsClient interface {
	CreateKey(ctx context.Context, params *kms.CreateKeyInput, optFns ...func(*kms.Options)) (*kms.CreateKeyOutput, error)
}

KmsClient type for mocks

type KmsConfig

type KmsConfig struct {
	Description *string
	Multiregion *bool
	Policy      *string
}

KmsConfig descripes our KmsConfig and they way it works

type KmsOperations

type KmsOperations struct {
	Client KmsClient
}

KmsOperations struct with the KmsClient

func InitKms

func InitKms(region string) KmsOperations

InitKms creates a KMS client

func (KmsOperations) CreateKMSKey

func (k KmsOperations) CreateKMSKey(cfg *KmsConfig) (*types.KeyMetadata, error)

CreateKMSKey creates a new KMS key for multiregion deploys

type PassedIPs

type PassedIPs struct {
	Port        int
	Permissions string
	Protocol    string
	Description string
	Type        string
}

PassedIPs allows us to update our sg we need to transform this to an SGInput

func (PassedIPs) CreateSgInput

func (p PassedIPs) CreateSgInput(SGID *string) SGInput

CreateSgInput this only hanldes TCP and IPv4 right now this is a stub while I think of how to do it better

type SGInput

type SGInput struct {
	SGId          *string
	IPPermissions []types.IpPermission
	Rules         []state.SGRuleStorage
}

SGInput input for updating security group

Jump to

Keyboard shortcuts

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