-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
s3.go
98 lines (83 loc) · 2.54 KB
/
s3.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Package interactor contains the implementations of usecases.
package interactor
import (
"context"
"github.com/google/wire"
"github.com/nao1215/rainbow/app/domain/service"
"github.com/nao1215/rainbow/app/usecase"
)
// S3bucketCreatorSet is a provider set for S3BucketCreator.
//
//nolint:gochecknoglobals
var S3bucketCreatorSet = wire.NewSet(
NewS3BucketCreator,
wire.Bind(new(usecase.S3BucketCreator), new(*S3BucketCreator)),
)
var _ usecase.S3BucketCreator = (*S3BucketCreator)(nil)
// S3BucketCreator implements the S3BucketCreator interface.
type S3BucketCreator struct {
service.S3BucketCreator
}
// NewS3BucketCreator creates a new S3BucketCreator.
func NewS3BucketCreator(c service.S3BucketCreator) *S3BucketCreator {
return &S3BucketCreator{
S3BucketCreator: c,
}
}
// CreateBucket creates a new S3 bucket.
func (s *S3BucketCreator) CreateBucket(ctx context.Context, input *usecase.S3BucketCreatorInput) (*usecase.S3BucketCreatorOutput, error) {
if err := input.Bucket.Validate(); err != nil {
return nil, err
}
if err := input.Region.Validate(); err != nil {
return nil, err
}
in := service.S3BucketCreatorInput{
Bucket: input.Bucket,
Region: input.Region,
}
if _, err := s.S3BucketCreator.CreateBucket(ctx, &in); err != nil {
return nil, err
}
return &usecase.S3BucketCreatorOutput{}, nil
}
// S3bucketListerSet is a provider set for S3BucketLister.
//
//nolint:gochecknoglobals
var S3bucketListerSet = wire.NewSet(
NewS3BucketLister,
wire.Bind(new(usecase.S3BucketLister), new(*S3BucketLister)),
)
var _ usecase.S3BucketLister = (*S3BucketLister)(nil)
// S3BucketLister implements the S3BucketLister interface.
type S3BucketLister struct {
service.S3BucketLister
service.S3BucketLocationGetter
}
// NewS3BucketLister creates a new S3BucketLister.
func NewS3BucketLister(l service.S3BucketLister, g service.S3BucketLocationGetter) *S3BucketLister {
return &S3BucketLister{
S3BucketLister: l,
S3BucketLocationGetter: g,
}
}
// ListBuckets lists the buckets.
func (s *S3BucketLister) ListBuckets(ctx context.Context, _ *usecase.S3BucketListerInput) (*usecase.S3BucketListerOutput, error) {
out, err := s.S3BucketLister.ListBuckets(ctx, &service.S3BucketListerInput{})
if err != nil {
return nil, err
}
for i, b := range out.Buckets {
in := service.S3BucketLocationGetterInput{
Bucket: b.Bucket,
}
o, err := s.S3BucketLocationGetter.GetBucketLocation(ctx, &in)
if err != nil {
return nil, err
}
out.Buckets[i].Region = o.Region
}
return &usecase.S3BucketListerOutput{
Buckets: out.Buckets,
}, nil
}