-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinfo.go
More file actions
146 lines (111 loc) · 3.03 KB
/
info.go
File metadata and controls
146 lines (111 loc) · 3.03 KB
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
package assembly
import (
"fmt"
"strings"
"time"
"github.com/molecule-man/stack-assembly/awscf"
"github.com/molecule-man/stack-assembly/cli"
"github.com/molecule-man/stack-assembly/conf"
)
func (sa SA) colorizedStatus(status string) string {
switch {
case strings.HasSuffix(status, "COMPLETE"):
return sa.cli.Color.Success(status)
case strings.HasSuffix(status, "IN_PROGRESS"):
return sa.cli.Color.Neutral(status)
case strings.Contains(status, "ROLLBACK"), strings.Contains(status, "FAILED"):
return sa.cli.Color.Fail(status)
}
return status
}
func (sa SA) sprintEvent(e awscf.StackEvent) string {
return fmt.Sprintf("%s\t%s\t%s\t%s", e.ResourceType, sa.colorizedStatus(e.Status), e.LogicalResourceID, e.StatusReason)
}
func (sa SA) Info(stack *awscf.Stack) error {
exists, err := stack.Exists()
if err != nil {
return err
}
if !exists {
return nil
}
info, err := stack.Info()
if err != nil {
return err
}
sa.printStackDetails(stack.Name, info)
sa.printResources(stack)
sa.printParameters(info)
sa.printOutputs(info)
sa.printEvents(stack)
sa.cli.Print("")
return nil
}
func (sa SA) InfoAll(cfg conf.Config) error {
ss, err := cfg.StackConfigsSortedByExecOrder()
if err != nil {
return err
}
for _, s := range ss {
err = sa.InfoAll(s)
if err != nil {
return err
}
}
if cfg.Name == "" {
return nil
}
return sa.Info(cfg.Stack())
}
func (sa SA) printStackDetails(name string, info awscf.StackInfo) {
sa.cli.Print("######################################")
sa.cli.Print(fmt.Sprintf("STACK:\t%s", name))
sa.cli.Print(fmt.Sprintf("STATUS:\t%s %s", sa.colorizedStatus(info.Status()), info.StatusDescription()))
sa.cli.Print("")
}
func (sa SA) printResources(stack *awscf.Stack) {
resources, err := stack.Resources()
MustSucceed(err)
sa.cli.Print("==== RESOURCES ====")
w := cli.NewColWriter(sa.cli.Writer, " ")
for _, res := range resources {
fields := []string{res.LogicalID, sa.colorizedStatus(res.Status), res.PhysicalID}
fmt.Fprintln(w, strings.Join(fields, "\t"))
}
MustSucceed(w.Flush())
sa.cli.Print("")
}
func (sa SA) printOutputs(info awscf.StackInfo) {
sa.cli.Print("==== OUTPUTS ====")
w := cli.NewColWriter(sa.cli.Writer, " ")
for _, out := range info.Outputs() {
fmt.Fprintln(w, strings.Join([]string{out.Key, out.Value, out.ExportName}, "\t"))
}
MustSucceed(w.Flush())
sa.cli.Print("")
}
func (sa SA) printParameters(info awscf.StackInfo) {
sa.cli.Print("==== PARAMETERS ====")
w := cli.NewColWriter(sa.cli.Writer, " ")
info.Parameters()
for _, kv := range info.Parameters() {
fmt.Fprintf(w, "%s:\t%s\n", kv.Key, kv.Val)
}
MustSucceed(w.Flush())
sa.cli.Print("")
}
func (sa SA) printEvents(stack *awscf.Stack) {
events, err := stack.Events()
MustSucceed(err)
w := cli.NewColWriter(sa.cli.Writer, " ")
sa.cli.Print("==== EVENTS ====")
limit := 10
if len(events) < limit {
limit = len(events)
}
for _, e := range events[:limit] {
fmt.Fprintf(w, "[%s]\t%s\n", e.Timestamp.Format(time.RFC3339), sa.sprintEvent(e))
}
MustSucceed(w.Flush())
sa.cli.Print("")
}