This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
/
events.go
85 lines (73 loc) · 2.03 KB
/
events.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
package tasks
import (
"fmt"
printer "github.com/KablamoOSS/go-cli-printer"
"github.com/KablamoOSS/kombustion/config"
"github.com/KablamoOSS/kombustion/internal/cloudformation"
"github.com/KablamoOSS/kombustion/internal/cloudformation/tasks"
"github.com/KablamoOSS/kombustion/internal/core"
"github.com/KablamoOSS/kombustion/internal/manifest"
"github.com/urfave/cli"
)
// PrintEvents outputs the events of a stack
func PrintEvents(c *cli.Context) {
objectStore := core.NewFilesystemStore(".")
fileName := c.Args().Get(0)
if fileName == "" {
printer.Fatal(
fmt.Errorf("Can't find stack, no source template provided"),
"Add the path to the source template file, or provide use --stack-name",
"https://www.kombustion.io/api/cli/#stacks",
)
}
eventer := &cloudformation.Wrapper{}
printEvents(
objectStore,
eventer,
fileName,
c.String("stack-name"),
c.GlobalString("environment"),
c.GlobalString("region"),
c.String("profile"),
c.GlobalString("manifest-file"),
)
}
func printEvents(
objectStore core.ObjectStore,
eventer cloudformation.StackEventer,
templatePath string,
stackName string,
envName string,
profile string,
region string,
manifestLocation string,
) {
printer.Progress("Kombusting")
manifestFile, err := manifest.GetManifestObject(objectStore, manifestLocation)
if err != nil {
printer.Fatal(err, config.ErrorHelpInfo, "")
}
if region == "" {
// If no region was provided by the cli flag, check for the default in the manifest
if manifestFile.Region != "" {
region = manifestFile.Region
}
}
acctID := eventer.Open(profile, region)
if env, ok := manifestFile.Environments[envName]; ok {
if !env.IsAllowlistedAccount(acctID) {
printer.Fatal(
fmt.Errorf("Account %s is not allowed for environment %s", acctID, envName),
"Use allowlisted account, or add account to environment accounts in kombustion.yaml",
"",
)
}
}
stackName = cloudformation.GetStackName(
manifestFile,
templatePath,
envName,
stackName,
)
tasks.PrintStackEvents(eventer, stackName)
}