-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcloudfront.go
59 lines (48 loc) · 1.52 KB
/
cloudfront.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
package interactor
import (
"context"
"github.com/google/wire"
"github.com/nao1215/rainbow/app/domain/service"
"github.com/nao1215/rainbow/app/usecase"
)
// CloudFrontCreatorSet is a set of CloudFrontCreator.
//
//nolint:gochecknoglobals
var CloudFrontCreatorSet = wire.NewSet(
NewCloudFrontCreator,
wire.Struct(new(CloudFrontCreatorOptions), "*"),
wire.Bind(new(usecase.CloudFrontCreator), new(*CloudFrontCreator)),
)
var _ usecase.CloudFrontCreator = (*CloudFrontCreator)(nil)
// CloudFrontCreator is an implementation for CloudFrontCreator.
type CloudFrontCreator struct {
opts *CloudFrontCreatorOptions
}
// CloudFrontCreatorOptions is an option struct for CloudFrontCreator.
type CloudFrontCreatorOptions struct {
service.CloudFrontCreator
service.OAICreator
}
// NewCloudFrontCreator returns a new CloudFrontCreator struct.
func NewCloudFrontCreator(opts *CloudFrontCreatorOptions) *CloudFrontCreator {
return &CloudFrontCreator{
opts: opts,
}
}
// CreateCloudFront creates a CDN.
func (c *CloudFrontCreator) CreateCloudFront(ctx context.Context, input *usecase.CreateCloudFrontInput) (*usecase.CreateCloudFrontOutput, error) {
oaiOutput, err := c.opts.OAICreator.CreateOAI(ctx, &service.OAICreatorInput{})
if err != nil {
return nil, err
}
createCDNOutput, err := c.opts.CloudFrontCreator.CreateCloudFront(ctx, &service.CloudFrontCreatorInput{
Bucket: input.Bucket,
OAIID: oaiOutput.ID,
})
if err != nil {
return nil, err
}
return &usecase.CreateCloudFrontOutput{
Domain: createCDNOutput.Domain,
}, nil
}