-
Notifications
You must be signed in to change notification settings - Fork 597
/
express.go
44 lines (36 loc) · 1.18 KB
/
express.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package customizations
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
internalauthsmithy "github.com/aws/aws-sdk-go-v2/internal/auth/smithy"
"github.com/aws/smithy-go"
"github.com/aws/smithy-go/auth"
)
// S3ExpressCredentialsProvider retrieves credentials for the S3Express storage
// class.
type S3ExpressCredentialsProvider interface {
Retrieve(ctx context.Context, bucket string) (aws.Credentials, error)
}
// ExpressIdentityResolver retrieves identity for the S3Express storage class.
type ExpressIdentityResolver struct {
Provider S3ExpressCredentialsProvider
}
var _ (auth.IdentityResolver) = (*ExpressIdentityResolver)(nil)
// GetIdentity retrieves AWS credentials using the underlying provider.
func (v *ExpressIdentityResolver) GetIdentity(ctx context.Context, props smithy.Properties) (
auth.Identity, error,
) {
bucket, ok := GetIdentityPropertiesBucket(&props)
if !ok {
bucket = GetBucket(ctx)
}
if bucket == "" {
return nil, fmt.Errorf("bucket name is missing")
}
creds, err := v.Provider.Retrieve(ctx, bucket)
if err != nil {
return nil, fmt.Errorf("get credentials: %v", err)
}
return &internalauthsmithy.CredentialsAdapter{Credentials: creds}, nil
}