mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-04-20 07:25:51 -04:00
add DeleteObject to S3 client
This commit is contained in:
parent
04e87973ec
commit
002779ac96
@ -27,6 +27,7 @@ type awsS3ClientAPI interface {
|
||||
GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
|
||||
PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
|
||||
CreateBucket(ctx context.Context, params *s3.CreateBucketInput, optFns ...func(*s3.Options)) (*s3.CreateBucketOutput, error)
|
||||
DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
|
||||
}
|
||||
|
||||
// Storage is an implementation of the Storage interface, storing keys in AWS S3 buckets.
|
||||
@ -76,6 +77,17 @@ func (s *Storage) Get(ctx context.Context, keyID string) ([]byte, error) {
|
||||
return io.ReadAll(output.Body)
|
||||
}
|
||||
|
||||
func (s *Storage) Delete(ctx context.Context, keyID string) error {
|
||||
deleteObjectInput := &s3.DeleteObjectInput{
|
||||
Bucket: &s.bucketID,
|
||||
Key: &keyID,
|
||||
}
|
||||
if _, err := s.client.DeleteObject(ctx, deleteObjectInput); err != nil {
|
||||
return fmt.Errorf("deleting DEK from storage: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Put saves a DEK to AWS S3 Storage by key ID.
|
||||
func (s *Storage) Put(ctx context.Context, keyID string, data []byte) error {
|
||||
putObjectInput := &s3.PutObjectInput{
|
||||
|
@ -43,6 +43,10 @@ func (s *stubAWSS3StorageClient) PutObject(_ context.Context, params *s3.PutObje
|
||||
return &s3.PutObjectOutput{}, s.putObjectErr
|
||||
}
|
||||
|
||||
func (s *stubAWSS3StorageClient) DeleteObject(_ context.Context, _ *s3.DeleteObjectInput, _ ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) {
|
||||
return &s3.DeleteObjectOutput{}, nil
|
||||
}
|
||||
|
||||
func (s *stubAWSS3StorageClient) CreateBucket(_ context.Context, _ *s3.CreateBucketInput, _ ...func(*s3.Options)) (*s3.CreateBucketOutput, error) {
|
||||
s.createBucketCalled = true
|
||||
return &s3.CreateBucketOutput{}, s.createBucketErr
|
||||
|
Loading…
x
Reference in New Issue
Block a user