-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
presenter.go
165 lines (152 loc) · 5.48 KB
/
presenter.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package main
import (
"fmt"
"strconv"
"github.com/aws/aws-sdk-go/service/cloudwatchevents"
)
func displayWhatWillChange(rules []Rule) {
updates := WillUpdateRulesAndTargets(rules)
deletes := WillDeleteRulesAndTargets(rules)
if len(updates) == 0 && len(deletes) == 0 {
fmt.Println("No Changes")
}
if len(updates) > 0 {
fmt.Println("Updates")
for _, r := range updates {
ShowWillUpdateFieldInRule(r)
for _, t := range r.Targets {
if t.NeedUpdate && !t.NeedDelete {
ShowWillUpdateFieldInTarget(t)
}
}
}
}
if len(deletes) > 0 {
fmt.Println("Deletes")
for _, r := range deletes {
ShowWillDeleteRule(r)
for _, t := range r.Targets {
if t.NeedDelete {
ShowWillDeleteTarget(t)
}
}
}
}
}
// WillUpdateRulesAndTargets return will be updated rules and targets
func WillUpdateRulesAndTargets(rules []Rule) []Rule {
u := make([]Rule, 0)
for _, rule := range rules {
if rule.NeedUpdate && !rule.NeedDelete {
u = append(u, rule)
} else {
for _, target := range rule.Targets {
if target.NeedUpdate && !target.NeedDelete {
u = append(u, rule)
break
}
}
}
}
return u
}
// WillDeleteRulesAndTargets return will be deleted rules and targets
func WillDeleteRulesAndTargets(rules []Rule) []Rule {
d := make([]Rule, 0)
for _, rule := range rules {
if rule.NeedDelete {
d = append(d, rule)
} else {
for _, target := range rule.Targets {
if target.NeedDelete {
d = append(d, rule)
break
}
}
}
}
return d
}
// ShowWillUpdateFieldInRule print what will rule changes to stdout
func ShowWillUpdateFieldInRule(rule Rule) {
fmt.Printf("Rule: %s\n", rule.Name)
if !CompareString(&rule.Name, rule.ActualRule.Name) {
fmt.Printf(" Name: %s -> %s\n", NilSafeStr(rule.ActualRule.Name), rule.Name)
}
if !CompareString(&rule.Description, rule.ActualRule.Description) {
fmt.Printf(" Description: %s -> %s\n", NilSafeStr(rule.ActualRule.Description), rule.Description)
}
if !CompareString(&rule.EventPattern, rule.ActualRule.EventPattern) {
fmt.Printf(" EventPattern: %s -> %s\n", NilSafeStr(rule.ActualRule.EventPattern), rule.EventPattern)
}
if !CompareString(&rule.RoleArn, rule.ActualRule.RoleArn) {
fmt.Printf(" RoleArn: %s -> %s\n", NilSafeStr(rule.ActualRule.RoleArn), rule.RoleArn)
}
if !CompareString(&rule.ScheduleExpression, rule.ActualRule.ScheduleExpression) {
fmt.Printf(" ScheduleExpression: %s -> %s\n", NilSafeStr(rule.ActualRule.ScheduleExpression), rule.ScheduleExpression)
}
if !CompareString(&rule.State, rule.ActualRule.State) {
fmt.Printf(" State: %s -> %s\n", NilSafeStr(rule.ActualRule.State), rule.State)
}
}
// ShowWillUpdateFieldInTarget print what will target changes to stdout
func ShowWillUpdateFieldInTarget(target Target) {
fmt.Printf(" Target: %s\n", target.Arn)
if !CompareString(&target.Arn, target.ActualTarget.Arn) {
fmt.Printf(" Arn: %s -> %s\n", NilSafeStr(target.ActualTarget.Arn), target.Arn)
}
if !CompareString(&target.ID, target.ActualTarget.Id) {
fmt.Printf(" ID: %s -> %s\n", NilSafeStr(target.ActualTarget.Id), target.ID)
}
if !CompareString(&target.Input, target.ActualTarget.Input) {
fmt.Printf(" Input: %s -> %s\n", NilSafeStr(target.ActualTarget.Input), target.Input)
}
if !CompareString(&target.InputPath, target.ActualTarget.InputPath) {
fmt.Printf(" InputPath: %s -> %s\n", NilSafeStr(target.ActualTarget.InputPath), target.InputPath)
}
if !CompareString(&target.RoleArn, target.ActualTarget.RoleArn) {
fmt.Printf(" RoleArn: %s -> %s\n", NilSafeStr(target.ActualTarget.RoleArn), target.RoleArn)
}
if !CompareEcsParameters(&target.EcsParameters, target.ActualTarget.EcsParameters) {
fmt.Println(" EcsParameters:")
ShowDiffOfTheEcsParameters(target.ActualTarget.EcsParameters, target.EcsParameters)
}
if !CompareKinesisParameters(&target.KinesisParameters, target.ActualTarget.KinesisParameters) {
fmt.Println(" KinesisParameters:")
ShowDiffOfTheKinesisParameters(target.ActualTarget.KinesisParameters, target.KinesisParameters)
}
}
// ShowDiffOfTheEcsParameters print what will EcsParameters in target changes to stdout
func ShowDiffOfTheEcsParameters(current *cloudwatchevents.EcsParameters, expect EcsParameters) {
var currTaskDefinitionArn, currTaskCount string
if current != nil {
currTaskDefinitionArn = *current.TaskDefinitionArn
currTaskCount = strconv.FormatInt(*current.TaskCount, 10)
}
if !CompareString(&currTaskDefinitionArn, &expect.TaskDefinitionArn) {
fmt.Printf(" TaskDefinitionArn: %s -> %s\n", currTaskDefinitionArn, expect.TaskDefinitionArn)
}
if current != nil && !CompareInt64(current.TaskCount, &expect.TaskCount) {
fmt.Printf(" TaskCount: %s -> %d\n", currTaskCount, expect.TaskCount)
}
}
// ShowDiffOfTheKinesisParameters print what will KinesisParameters in target changes to stdout
func ShowDiffOfTheKinesisParameters(current *cloudwatchevents.KinesisParameters, expect KinesisParameters) {
var currPart string
if current != nil {
currPart = *current.PartitionKeyPath
}
fmt.Printf(" PartitionKeyPath: %s -> %s\n", currPart, expect.PartitionKeyPath)
}
// ShowWillDeleteRule print the rule will delete to stdout
func ShowWillDeleteRule(rule Rule) {
if rule.NeedDelete {
fmt.Printf("Rule: %s this will delete\n", *rule.ActualRule.Name)
} else {
fmt.Printf("Rule: %s\n", rule.Name)
}
}
// ShowWillDeleteTarget print the target will delete to stdout
func ShowWillDeleteTarget(target Target) {
fmt.Printf(" Target: %s this will delete\n", *target.ActualTarget.Id)
}