This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
/
wrapper.go
118 lines (102 loc) · 4.25 KB
/
wrapper.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package cloudformation
import (
"fmt"
awsCF "github.com/aws/aws-sdk-go/service/cloudformation"
)
// Subset of AWS API calls required by the events task, as a mockable
// interface.
type StackEventer interface {
Open(string, string) string
DescribeStackEvents(*awsCF.DescribeStackEventsInput) (*awsCF.DescribeStackEventsOutput, error)
DescribeStackEventsPages(*awsCF.DescribeStackEventsInput, func(*awsCF.DescribeStackEventsOutput, bool) bool) error
}
// Subset of AWS API calls required by the upsert task, as a mockable
// interface.
type StackUpserter interface {
Open(string, string) string
CreateChangeSet(*awsCF.CreateChangeSetInput) (*awsCF.CreateChangeSetOutput, error)
DeleteChangeSet(*awsCF.DeleteChangeSetInput) (*awsCF.DeleteChangeSetOutput, error)
DeleteStack(*awsCF.DeleteStackInput) (*awsCF.DeleteStackOutput, error)
DescribeChangeSet(*awsCF.DescribeChangeSetInput) (*awsCF.DescribeChangeSetOutput, error)
DescribeStackEvents(*awsCF.DescribeStackEventsInput) (*awsCF.DescribeStackEventsOutput, error)
DescribeStackEventsPages(*awsCF.DescribeStackEventsInput, func(*awsCF.DescribeStackEventsOutput, bool) bool) error
DescribeStacks(*awsCF.DescribeStacksInput) (*awsCF.DescribeStacksOutput, error)
ExecuteChangeSet(*awsCF.ExecuteChangeSetInput) (*awsCF.ExecuteChangeSetOutput, error)
WaitUntilChangeSetCreateComplete(*awsCF.DescribeChangeSetInput) error
}
type StackDeleter interface {
Open(string, string) string
DeleteStack(*awsCF.DeleteStackInput) (*awsCF.DeleteStackOutput, error)
DescribeStackEvents(*awsCF.DescribeStackEventsInput) (*awsCF.DescribeStackEventsOutput, error)
DescribeStackEventsPages(*awsCF.DescribeStackEventsInput, func(*awsCF.DescribeStackEventsOutput, bool) bool) error
DescribeStacks(*awsCF.DescribeStacksInput) (*awsCF.DescribeStacksOutput, error)
}
type Wrapper struct {
client *awsCF.CloudFormation
}
// Placeholder helper so that tasks still using awsCF.CloudFormation directly
// can wrap it to use helpers that have been updated to use interfaces.
func NewWrapper(client *awsCF.CloudFormation) *Wrapper {
return &Wrapper{
client: client,
}
}
func (wr *Wrapper) Open(profile, region string) string {
acctID, cfClient := GetCloudformationClient(profile, region)
wr.client = cfClient
return acctID
}
func (wr *Wrapper) DescribeStackEvents(input *awsCF.DescribeStackEventsInput) (*awsCF.DescribeStackEventsOutput, error) {
if wr.client == nil {
return nil, fmt.Errorf("connection not opened")
}
return wr.client.DescribeStackEvents(input)
}
func (wr *Wrapper) DescribeStackEventsPages(input *awsCF.DescribeStackEventsInput, fn func(*awsCF.DescribeStackEventsOutput, bool) bool) error {
if wr.client == nil {
return fmt.Errorf("connection not opened")
}
return wr.client.DescribeStackEventsPages(input, fn)
}
func (wr *Wrapper) DescribeStacks(in *awsCF.DescribeStacksInput) (*awsCF.DescribeStacksOutput, error) {
if wr.client == nil {
return nil, fmt.Errorf("connection not opened")
}
return wr.client.DescribeStacks(in)
}
func (wr *Wrapper) DeleteStack(in *awsCF.DeleteStackInput) (*awsCF.DeleteStackOutput, error) {
if wr.client == nil {
return nil, fmt.Errorf("connection not opened")
}
return wr.client.DeleteStack(in)
}
func (wr *Wrapper) CreateChangeSet(in *awsCF.CreateChangeSetInput) (*awsCF.CreateChangeSetOutput, error) {
if wr.client == nil {
return nil, fmt.Errorf("connection not opened")
}
return wr.client.CreateChangeSet(in)
}
func (wr *Wrapper) DescribeChangeSet(in *awsCF.DescribeChangeSetInput) (*awsCF.DescribeChangeSetOutput, error) {
if wr.client == nil {
return nil, fmt.Errorf("connection not opened")
}
return wr.client.DescribeChangeSet(in)
}
func (wr *Wrapper) WaitUntilChangeSetCreateComplete(in *awsCF.DescribeChangeSetInput) error {
if wr.client == nil {
return fmt.Errorf("connection not opened")
}
return wr.client.WaitUntilChangeSetCreateComplete(in)
}
func (wr *Wrapper) ExecuteChangeSet(in *awsCF.ExecuteChangeSetInput) (*awsCF.ExecuteChangeSetOutput, error) {
if wr.client == nil {
return nil, fmt.Errorf("connection not opened")
}
return wr.client.ExecuteChangeSet(in)
}
func (wr *Wrapper) DeleteChangeSet(in *awsCF.DeleteChangeSetInput) (*awsCF.DeleteChangeSetOutput, error) {
if wr.client == nil {
return nil, fmt.Errorf("connection not opened")
}
return wr.client.DeleteChangeSet(in)
}