aws

package
v6.0.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package aws provides a simplified interface for various AWS services.

Index

Constants

View Source
const (
	// MetadataKMSARN represents the key for KMS ARN metadata.
	MetadataKMSARN = "x-kms-arn"
	// MetadataEncryptionAlgorithm represents the key for encryption algorithm metadata.
	MetadataEncryptionAlgorithm = "x-encryption-algorithm"
	// MetadataContentKey represents the key for content key metadata.
	MetadataContentKey = "x-content-key"
	// EncryptionAlgorithmAESGCM represents the AES GCM encryption algorithm.
	EncryptionAlgorithmAESGCM = "AES-GCM-256"
)

Variables

View Source
var DefaultMaxMessages int64 = 10

DefaultMaxMessages is the default maximum number of messages.

View Source
var ErrTooManyMessageToDelete = fmt.Errorf("too many messages in receiptHandlerMap (should be less than 10)")

ErrTooManyMessageToDelete is an error indicating too many messages to delete.

Functions

func GetDefaultAWSConfig

func GetDefaultAWSConfig() *aws.Config

GetDefaultAWSConfig retrieves the default AWS configuration.

func GetQueueURL

func GetQueueURL(ctx context.Context, logger log.Log, queueName string, sqsClient *sqs.Client) (*string, error)

GetQueueURL returns the URL of the queue with the given name.

func NewKMSClientWithConfig

func NewKMSClientWithConfig(awsConfig aws.Config) *kms.Client

NewKMSClientWithConfig creates a new KMS client with the provided AWS configuration.

func NewS3ClientWithConfig

func NewS3ClientWithConfig(awsConfig aws.Config) *s3.Client

NewS3ClientWithConfig creates a new S3 client with the provided AWS configuration.

func NewSNSClientWithConfig

func NewSNSClientWithConfig(awsConfig *aws.Config) *sns.Client

NewSNSClientWithConfig creates a new SNS client with the provided AWS configuration.

func NewSQSClientWithConfig

func NewSQSClientWithConfig(awsConfig aws.Config) *sqs.Client

NewSQSClientWithConfig creates a new SQS client with the provided AWS configuration.

func NewSecretManagerClientWithSession

func NewSecretManagerClientWithSession(awsConfig aws.Config) *secretsmanager.Client

NewSecretManagerClientWithSession creates a new Secrets Manager client with the provided AWS configuration.

func SetDefaultAWSConfig

func SetDefaultAWSConfig(defaultConfig aws.Config, t Tracer)

SetDefaultAWSConfig sets the default AWS configuration and applies tracing if provided.

Types

type BatchQueueMessage

type BatchQueueMessage struct {
	ID                     *string
	Message                *utils.Message
	Attribute              map[string]interface{}
	MessageDeduplicationID *string
	MessageGroupID         *string
}

BatchQueueMessage represents a message to be sent in a batch to SQS.

type KMS

type KMS struct {
	*kms.Client
	// contains filtered or unexported fields
}

KMS provides an interface to interact with AWS Key Management Service (KMS).

func GetDefaultKMSClient

func GetDefaultKMSClient(logger log.Log, keyArn string) *KMS

GetDefaultKMSClient retrieves the default KMS client using the provided logger and key ARN.

func NewKMSClient

func NewKMSClient(logger log.Log, client *kms.Client, keyArn string) *KMS

NewKMSClient creates a new KMS client with the provided logger, client, and key ARN.

func (*KMS) Decrypt

func (k *KMS) Decrypt(ctx context.Context, cipherBlob []byte) (plainText []byte, err error)

Decrypt decrypts the ciphertext using the KMS client and returns the plaintext.

func (*KMS) Encrypt

func (k *KMS) Encrypt(ctx context.Context, plainText []byte) (cipherBlob []byte, err error)

Encrypt encrypts the plaintext using the KMS client and returns the ciphertext.

type PIITempFile

type PIITempFile struct {
	Request     *v4.PresignedHTTPRequest `json:"req"`
	ExpiresAt   time.Time                `json:"expiresAt"`
	ContentType *string                  `json:"contentType"`
}

PIITempFile contains information about a temporary presigned URL for a file.

type S3

type S3 struct {
	*s3.Client
	*s3.PresignClient
	// contains filtered or unexported fields
}

S3 provides an interface for interacting with AWS Simple Storage Service (S3).

func GetDefaultS3Client

func GetDefaultS3Client(logger log.Log) *S3

GetDefaultS3Client retrieves the default S3 client using the provided logger.

func NewS3Client

func NewS3Client(client *s3.Client, logger log.Log) *S3

NewS3Client creates a new S3 client with the provided client and logger.

func (*S3) GetFile

func (s *S3) GetFile(ctx context.Context, s3Bucket, s3Key, localFilePath string) error

GetFile downloads an object from S3 to the specified local file path.

func (*S3) GetObject

func (s *S3) GetObject(ctx context.Context, s3Bucket, s3Key string) (*s3.GetObjectOutput, error)

GetObject retrieves an object from S3 and returns the response.

func (*S3) PresignGetObject

func (s *S3) PresignGetObject(ctx context.Context, s3Bucket, s3Key string, expireTimeInSeconds int64) (*v4.PresignedHTTPRequest, error)

PresignGetObject creates a presigned URL for downloading an object from S3.

func (*S3) PresignPutObject

func (s *S3) PresignPutObject(ctx context.Context, s3Bucket, s3Key string, expireTimeInSeconds int64) (*v4.PresignedHTTPRequest, error)

PresignPutObject creates a presigned URL for uploading an object to S3.

func (*S3) PutFile

func (s *S3) PutFile(ctx context.Context, s3Bucket, s3Key, localFilePath string) (*s3.PutObjectOutput, error)

PutFile uploads a file to S3 using the provided local file path and returns the response.

func (*S3) PutObject

func (s *S3) PutObject(ctx context.Context, s3Bucket, s3Key string, body io.Reader, mimeType string, metadata map[string]string) (*s3.PutObjectOutput, error)

PutObject uploads an object to S3 and returns the response.

type S3Crypto

type S3Crypto struct {
	*S3
	// contains filtered or unexported fields
}

S3Crypto extends S3 with client-side object encryption.

func GetDefaultS3CryptoClient

func GetDefaultS3CryptoClient(logger log.Log, keyArn string) *S3Crypto

GetDefaultS3CryptoClient retrieves the default S3 Crypto client using the provided logger and KMS key ARN.

func NewS3CryptoClient

func NewS3CryptoClient(s3Client *S3, kms *KMS, logger log.Log) *S3Crypto

NewS3CryptoClient creates a new S3 Crypto client with the provided S3 client, KMS client, and logger.

func (*S3Crypto) GetFile

func (s *S3Crypto) GetFile(ctx context.Context, s3Bucket, s3Key, localFilePath string) error

GetFile retrieves an encrypted file from S3, decrypts its content, and writes it to a local file specified by the localFilePath argument. It takes a context, S3 bucket name, S3 object key, and local file path as input. If an error occurs during retrieval, decryption, or file writing, it returns an error.

func (*S3Crypto) GetFileCache

func (s *S3Crypto) GetFileCache(ctx context.Context, s3Bucket, s3Key, tempPathPart string) (*PIITempFile, error)

GetFileCache retrieves an encrypted file from S3, creates a temporary presigned URL for it, and caches the URL for future use. It returns a PIITempFile object containing the presigned URL information and other metadata. It takes a context, S3 bucket name, S3 object key, and a string for generating a unique part of the temporary path as input. If an error occurs during retrieval or URL generation, it returns an error.

func (*S3Crypto) GetObject

func (s *S3Crypto) GetObject(ctx context.Context, s3Bucket, s3Key string) ([]byte, error)

GetObject retrieves an encrypted object from S3 and decrypts its content. It takes a context, S3 bucket name, and S3 object key as input and returns the decrypted content of the object as a byte slice. If an error occurs during retrieval or decryption, it returns an error.

func (*S3Crypto) PutFile

func (s *S3Crypto) PutFile(ctx context.Context, s3Bucket, s3Key, localFilePath string) error

PutFile uploads an encrypted file to S3.

func (*S3Crypto) PutObject

func (s *S3Crypto) PutObject(ctx context.Context, s3Bucket, s3Key string, body io.Reader, mimeType string) error

PutObject uploads an encrypted object to S3.

type SNS

type SNS struct {
	*sns.Client
	// contains filtered or unexported fields
}

SNS provides methods to interact with AWS Simple Notification Service (SNS).

func GetDefaultSNSClient

func GetDefaultSNSClient(logger log.Log) *SNS

GetDefaultSNSClient returns the default SNS client using the provided logger.

func NewSNSClient

func NewSNSClient(logger log.Log, client *sns.Client) *SNS

NewSNSClient creates a new SNS instance with the provided logger and SNS client.

func (*SNS) GenerateAttribute

func (s *SNS) GenerateAttribute(ctx context.Context, attribute map[string]interface{}) map[string]types.MessageAttributeValue

GenerateAttribute generates SNS message attributes based on the provided map. It extracts correlation parameters from the context and includes them in the message attributes.

func (*SNS) Publish

func (s *SNS) Publish(ctx context.Context, topicArn, subject *string, payload *utils.Message, attributes map[string]interface{}) (*sns.PublishOutput, error)

Publish publishes a message to the specified SNS topic. It returns the publish output and an error if the operation fails.

type SQS

type SQS struct {
	*sqs.Client
	// contains filtered or unexported fields
}

SQS provides methods to interact with AWS Simple Queue Service (SQS).

func GetDefaultSQSClient

func GetDefaultSQSClient(logger log.Log, queueURL string) *SQS

GetDefaultSQSClient returns the default SQS client using the provided logger and queue URL.

func NewSQSClient

func NewSQSClient(logger log.Log, client *sqs.Client, queueURL string) *SQS

NewSQSClient creates a new SQS instance with the provided logger, SQS client, and queue URL.

func (*SQS) DeleteMessage

func (s *SQS) DeleteMessage(ctx context.Context, receiptHandler *string) (*sqs.DeleteMessageOutput, error)

DeleteMessage deletes a message from the SQS queue.

func (*SQS) DeleteMessageBatch

func (s *SQS) DeleteMessageBatch(ctx context.Context, receiptHandlerMap map[string]*string) (*sqs.DeleteMessageBatchOutput, error)

DeleteMessageBatch deletes multiple messages from the SQS queue.

func (*SQS) GenerateAttribute

func (s *SQS) GenerateAttribute(ctx context.Context, attribute map[string]interface{}) map[string]types.MessageAttributeValue

GenerateAttribute generates message attributes from the given attribute map.

func (*SQS) IsFIFO

func (s *SQS) IsFIFO() bool

IsFIFO checks if the SQS queue is FIFO.

func (*SQS) ReceiveMessage

func (s *SQS) ReceiveMessage(ctx context.Context, timeoutInSeconds int32, maxNumberOfMessages int32, waitTimeInSeconds int32) (*sqs.ReceiveMessageOutput, error)

ReceiveMessage receives messages from the SQS queue.

func (*SQS) SendMessage

func (s *SQS) SendMessage(ctx context.Context, message *utils.Message, attribute map[string]interface{}, delayInSeconds int32) (*sqs.SendMessageOutput, error)

SendMessage sends a message to the SQS queue with optional attributes and delay.

func (*SQS) SendMessageBatch

func (s *SQS) SendMessageBatch(ctx context.Context, messageList []*BatchQueueMessage, delayInSeconds int32) (*sqs.SendMessageBatchOutput, error)

SendMessageBatch sends multiple messages in a batch to the SQS queue.

func (*SQS) SendMessageFIFO

func (s *SQS) SendMessageFIFO(ctx context.Context, message *utils.Message, attribute map[string]interface{}, delayInSeconds int32, messageDeduplicationID, messageGroupID *string) (*sqs.SendMessageOutput, error)

SendMessageFIFO sends a message to the FIFO SQS queue with optional attributes, delay, and deduplication/group ID.

type SecretManager

type SecretManager struct {
	*secretsmanager.Client
	// contains filtered or unexported fields
}

SecretManager provides methods to interact with AWS Secrets Manager service.

func GetDefaultSecretManagerClient

func GetDefaultSecretManagerClient(logger log.Log) *SecretManager

GetDefaultSecretManagerClient returns the default Secrets Manager client using the provided logger.

func NewSecretManagerClient

func NewSecretManagerClient(logger log.Log, client *secretsmanager.Client) *SecretManager

NewSecretManagerClient creates a new SecretManager instance with the provided logger and Secrets Manager client.

func (*SecretManager) GetSecretMap

func (s *SecretManager) GetSecretMap(ctx context.Context, secretArn string) (map[string]interface{}, error)

GetSecretMap retrieves the secret value associated with the provided secret ARN as a map[string]interface{}. It unmarshals the secret value JSON string into a map. It returns the secret data as a map or an error if the retrieval or unmarshalling fails.

func (*SecretManager) GetSecretString

func (s *SecretManager) GetSecretString(ctx context.Context, secretArn string) (*string, error)

GetSecretString retrieves the secret value associated with the provided secret ARN. If the secret is cached and the cache is not expired, it returns the cached secret. Otherwise, it fetches the secret from AWS Secrets Manager and caches it. It returns the secret value as a string or an error if the retrieval fails.

type Tracer

type Tracer interface {
	AWS(*aws.Config)
}

Tracer is an interface for tracing AWS configurations.

Jump to

Keyboard shortcuts

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