This repository has been archived by the owner on Sep 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
fails.go
76 lines (58 loc) · 1.73 KB
/
fails.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
package client
import (
"encoding/json"
"fmt"
"time"
"github.com/coinbase/odin/aws"
"github.com/coinbase/step/bifrost"
"github.com/coinbase/step/execution"
"github.com/coinbase/step/utils/to"
)
// Release is the Data Structure passed between Client to Deployer
type FailedRelease struct {
// Useful information from AWS
AwsAccountID *string `json:"aws_account_id,omitempty"`
AwsRegion *string `json:"aws_region,omitempty"`
ProjectName *string `json:"project_name,omitempty"`
ConfigName *string `json:"config_name,omitempty"`
// Where the previous Catch Error should be located
Error *bifrost.ReleaseError `json:"error,omitempty"`
}
// List the recent failures and their causes
func Failures(step_fn *string) error {
region, accountID := to.RegionAccount()
deployerARN := to.StepArn(region, accountID, step_fn)
awsc := &aws.ClientsStr{}
return failures(awsc.SFNClient(nil, nil, nil), deployerARN)
}
func failures(sfnc aws.SFNAPI, arn *string) error {
execs, err := execution.ExecutionsAfter(sfnc, arn, to.Strp("FAILED"), time.Now().Add((-3*24)*time.Hour))
if err != nil {
return err
}
for _, e := range execs {
sd, err := e.GetStateDetails(sfnc)
if err != nil {
return err
}
release := FailedRelease{}
if err := json.Unmarshal([]byte(*sd.LastOutput), &release); err != nil {
j, _ := to.PrettyJSON(*sd.LastOutput)
fmt.Println(j)
continue
}
cause := ""
err_json := map[string]string{}
if release.Error != nil {
err = json.Unmarshal([]byte(*release.Error.Cause), &err_json)
if err != nil {
fmt.Println(err)
cause = *release.Error.Cause
} else {
cause = err_json["errorMessage"]
}
}
fmt.Println(fmt.Printf("%v -- %v -- %q", *sd.LastStateName, *e.Name, cause))
}
return nil
}