-
Notifications
You must be signed in to change notification settings - Fork 4
/
provider.go
94 lines (73 loc) · 2.16 KB
/
provider.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
package aws
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/aws/aws-sdk-go/service/codebuild"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/aws/aws-sdk-go/service/s3"
)
type AwsCloud struct {
DeploymentName string
Region, SettingBucket string
Access, Secret, Token string
}
func (p *AwsCloud) config() *aws.Config {
config := &aws.Config{}
if p.Region != "" {
config.Region = aws.String(p.Region)
}
return config
}
func (p *AwsCloud) cloudformation() *cloudformation.CloudFormation {
return cloudformation.New(session.New(), p.config())
}
func (p *AwsCloud) dynamodb() *dynamodb.DynamoDB {
return dynamodb.New(session.New(), p.config())
}
func (p *AwsCloud) s3() *s3.S3 {
return s3.New(session.New(), p.config())
}
func (p *AwsCloud) codebuild() *codebuild.CodeBuild {
return codebuild.New(session.New(), p.config())
}
func (p *AwsCloud) cloudwatchlogs() *cloudwatchlogs.CloudWatchLogs {
return cloudwatchlogs.New(session.New(), p.config())
}
func (p *AwsCloud) ecr() *ecr.ECR {
return ecr.New(session.New(), p.config())
}
func (p *AwsCloud) describeStack(name string) (*cloudformation.Stack, error) {
if name == "" {
name = p.DeploymentName
}
out, err := p.cloudformation().DescribeStacks(&cloudformation.DescribeStacksInput{
StackName: aws.String(name),
})
if err != nil {
return nil, err
}
for _, s := range out.Stacks {
if s.StackName != nil && *s.StackName == name {
return s, nil
}
}
return nil, fmt.Errorf("No stack found by name: %s", name)
}
func (p *AwsCloud) describeStacks(input *cloudformation.DescribeStacksInput) ([]*cloudformation.Stack, error) {
out, err := p.cloudformation().DescribeStacks(input)
if err != nil {
return nil, err
}
return out.Stacks, nil
}
func (p *AwsCloud) describeStackEvents(input *cloudformation.DescribeStackEventsInput) (*cloudformation.DescribeStackEventsOutput, error) {
res, err := p.cloudformation().DescribeStackEvents(input)
if err != nil {
return nil, err
}
return res, nil
}