awsutils

package
v0.0.0-...-5328375 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetSecret = func(secretKey, region string) (secret string) {
	sess, err := session.NewSession()
	if err != nil {

		log.Println(err.Error())
		return
	}
	svc := secretsmanager.New(sess,
		aws.NewConfig().WithRegion(region))
	input := &secretsmanager.GetSecretValueInput{
		SecretId: aws.String(secretKey),
	}

	result, err := svc.GetSecretValue(input)

	if err != nil {
		if aerr, ok := err.(awserr.Error); ok {
			switch aerr.Code() {
			case secretsmanager.ErrCodeDecryptionFailure:

				log.Println(secretsmanager.ErrCodeDecryptionFailure, aerr.Error())

			case secretsmanager.ErrCodeInternalServiceError:

				log.Println(secretsmanager.ErrCodeInternalServiceError, aerr.Error())

			case secretsmanager.ErrCodeInvalidParameterException:

				log.Println(secretsmanager.ErrCodeInvalidParameterException, aerr.Error())

			case secretsmanager.ErrCodeInvalidRequestException:

				log.Println(secretsmanager.ErrCodeInvalidRequestException, aerr.Error())

			case secretsmanager.ErrCodeResourceNotFoundException:

				log.Println(secretsmanager.ErrCodeResourceNotFoundException, aerr.Error())
			}
		} else {
			log.Println(err.Error())
		}
		return
	}

	var secretString string
	if result.SecretString != nil {
		secretString = *result.SecretString
	} else {
		decodedBinarySecretBytes := make([]byte, base64.StdEncoding.DecodedLen(len(result.SecretBinary)))
		_, err := base64.StdEncoding.Decode(decodedBinarySecretBytes, result.SecretBinary)
		if err != nil {
			log.Println("Base64 Decode Error:", err)
			return
		}
	}
	return secretString
}

Functions

This section is empty.

Types

type AwsUtils

type AwsUtils interface {
	GetNewSession(config config.AWSConfig) (*session.Session, error)
}

type AwsUtilsImpl

type AwsUtilsImpl struct{}

func NewAwsUtils

func NewAwsUtils() *AwsUtilsImpl

func (*AwsUtilsImpl) GetNewSession

func (au *AwsUtilsImpl) GetNewSession(config config.AWSConfig) (*session.Session, error)

type MockAwsUtils

type MockAwsUtils struct {
	GetNewSessionfunc func(config config.AWSConfig) (*session.Session, error)
}

func (*MockAwsUtils) GetNewSession

func (mau *MockAwsUtils) GetNewSession(config config.AWSConfig) (*session.Session, error)

Jump to

Keyboard shortcuts

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