Documentation
¶
Overview ¶
Package session provides AWS session management and DynamoDB client configuration
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
CredentialsProvider aws.CredentialsProvider
Region string
Endpoint string
// KMSKeyARN is required when using theorydb:"encrypted" fields.
// TableTheory does not manage KMS keys; callers must provide a valid key ARN.
KMSKeyARN string
KMSClient KMSClient `json:"-" yaml:"-"`
EncryptionRand io.Reader `json:"-" yaml:"-"`
Now func() time.Time `json:"-" yaml:"-"`
AWSConfigOptions []func(*config.LoadOptions) error
DynamoDBOptions []func(*dynamodb.Options)
MaxRetries int
DefaultRCU int64
DefaultWCU int64
AutoMigrate bool
EnableMetrics bool
}
Config holds the configuration for TableTheory
type DynamoDBAPI ¶
type DynamoDBAPI interface {
CreateTable(ctx context.Context, params *dynamodb.CreateTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.CreateTableOutput, error)
CreateBackup(ctx context.Context, params *dynamodb.CreateBackupInput, optFns ...func(*dynamodb.Options)) (*dynamodb.CreateBackupOutput, error)
DescribeTable(ctx context.Context, params *dynamodb.DescribeTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DescribeTableOutput, error)
DeleteTable(ctx context.Context, params *dynamodb.DeleteTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DeleteTableOutput, error)
ListTables(ctx context.Context, params *dynamodb.ListTablesInput, optFns ...func(*dynamodb.Options)) (*dynamodb.ListTablesOutput, error)
UpdateTable(ctx context.Context, params *dynamodb.UpdateTableInput, optFns ...func(*dynamodb.Options)) (*dynamodb.UpdateTableOutput, error)
UpdateTimeToLive(ctx context.Context, params *dynamodb.UpdateTimeToLiveInput, optFns ...func(*dynamodb.Options)) (*dynamodb.UpdateTimeToLiveOutput, error)
GetItem(ctx context.Context, params *dynamodb.GetItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.GetItemOutput, error)
PutItem(ctx context.Context, params *dynamodb.PutItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error)
DeleteItem(ctx context.Context, params *dynamodb.DeleteItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.DeleteItemOutput, error)
Query(ctx context.Context, params *dynamodb.QueryInput, optFns ...func(*dynamodb.Options)) (*dynamodb.QueryOutput, error)
Scan(ctx context.Context, params *dynamodb.ScanInput, optFns ...func(*dynamodb.Options)) (*dynamodb.ScanOutput, error)
UpdateItem(ctx context.Context, params *dynamodb.UpdateItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.UpdateItemOutput, error)
BatchGetItem(ctx context.Context, params *dynamodb.BatchGetItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.BatchGetItemOutput, error)
BatchWriteItem(ctx context.Context, params *dynamodb.BatchWriteItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.BatchWriteItemOutput, error)
TransactWriteItems(ctx context.Context, params *dynamodb.TransactWriteItemsInput, optFns ...func(*dynamodb.Options)) (*dynamodb.TransactWriteItemsOutput, error)
TransactGetItems(ctx context.Context, params *dynamodb.TransactGetItemsInput, optFns ...func(*dynamodb.Options)) (*dynamodb.TransactGetItemsOutput, error)
}
DynamoDBAPI is the DynamoDB client seam TableTheory uses internally.
It is intentionally the AWS SDK v2 operation shape, so tests can inject a deterministic local fake while production callers continue to use *dynamodb.Client through NewSession/New.
type KMSClient ¶
type KMSClient interface {
GenerateDataKey(ctx context.Context, params *kms.GenerateDataKeyInput, optFns ...func(*kms.Options)) (*kms.GenerateDataKeyOutput, error)
Decrypt(ctx context.Context, params *kms.DecryptInput, optFns ...func(*kms.Options)) (*kms.DecryptOutput, error)
}
KMSClient is the minimal AWS KMS surface TableTheory needs for attribute encryption. Providing this enables deterministic tests without real AWS KMS calls.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session manages the AWS session and DynamoDB client
func NewSession ¶
NewSession creates a new session with the given configuration
func NewSessionWithClient ¶
func NewSessionWithClient(cfg *Config, client DynamoDBAPI) (*Session, error)
NewSessionWithClient creates a session backed by an injected DynamoDBAPI. It does not create a DynamoDB client or contact AWS for DynamoDB setup.
When encrypted fields are used without Config.KMSClient, KMS is built from the session's AWS config. Because this constructor never contacts AWS, it carries the caller's Config.CredentialsProvider and Config.AWSConfigOptions into that config so KMS requests can authenticate. If KMSKeyARN is set without a KMSClient and without a CredentialsProvider or AWSConfigOptions, construction fails with ErrEncryptionNotConfigured instead of silently discarding credentials and building a KMS client that cannot authenticate.
func (*Session) API ¶
func (s *Session) API() (DynamoDBAPI, error)
API returns the configured DynamoDB operation seam.