Skip to content

Commit

Permalink
Merge pull request #173 from overmindtech/change-risks-status
Browse files Browse the repository at this point in the history
Use the new GetChangeRisks() API
  • Loading branch information
DavidS-ovm authored Feb 14, 2024
2 parents 1c980e8 + 72e5260 commit 36c8804
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
32 changes: 32 additions & 0 deletions cmd/datamaps/awssource.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 26 additions & 14 deletions cmd/getchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,25 @@ func GetChange(ctx context.Context, ready chan bool) int {
lf["uuid"] = changeUuid.String()

client := AuthenticatedChangesClient(ctx)
var changeRes *connect.Response[sdp.GetChangeResponse]
var riskRes *connect.Response[sdp.GetChangeRisksResponse]
fetch:
for {
// use the variable to avoid shadowing
var err error
changeRes, err = client.GetChange(ctx, &connect.Request[sdp.GetChangeRequest]{
Msg: &sdp.GetChangeRequest{
riskRes, err := client.GetChangeRisks(ctx, &connect.Request[sdp.GetChangeRisksRequest]{
Msg: &sdp.GetChangeRisksRequest{
UUID: changeUuid[:],
},
})
if err != nil {
log.WithContext(ctx).WithError(err).WithFields(log.Fields{
"change-url": viper.GetString("change-url"),
}).Error("failed to get change")
}).Error("failed to get change risks")
return 1
}
log.WithContext(ctx).WithFields(log.Fields{
"change-uuid": uuid.UUID(changeRes.Msg.GetChange().GetMetadata().GetUUID()),
"change-created": changeRes.Msg.GetChange().GetMetadata().GetCreatedAt().AsTime(),
"change-status": changeRes.Msg.GetChange().GetMetadata().GetStatus().String(),
"change-name": changeRes.Msg.GetChange().GetProperties().GetTitle(),
"change-description": changeRes.Msg.GetChange().GetProperties().GetDescription(),
}).Info("found change")

if changeRes.Msg.GetChange().GetMetadata().GetRiskCalculationStatus().GetStatus() == sdp.RiskCalculationStatus_STATUS_INPROGRESS {
log.WithContext(ctx).WithField("status", changeRes.Msg.GetChange().GetMetadata().GetRiskCalculationStatus().GetStatus().String()).Info("waiting for risk calculation")
if riskRes.Msg.GetChangeRiskMetadata().GetRiskCalculationStatus().GetStatus() == sdp.RiskCalculationStatus_STATUS_INPROGRESS {
log.WithContext(ctx).WithField("status", riskRes.Msg.GetChangeRiskMetadata().GetRiskCalculationStatus().GetStatus().String()).Info("waiting for risk calculation")
time.Sleep(10 * time.Second)
// retry
} else {
Expand All @@ -142,6 +135,25 @@ fetch:
}
}

changeRes, err := client.GetChange(ctx, &connect.Request[sdp.GetChangeRequest]{
Msg: &sdp.GetChangeRequest{
UUID: changeUuid[:],
},
})
if err != nil {
log.WithContext(ctx).WithError(err).WithFields(log.Fields{
"change-url": viper.GetString("change-url"),
}).Error("failed to get change")
return 1
}
log.WithContext(ctx).WithFields(log.Fields{
"change-uuid": uuid.UUID(changeRes.Msg.GetChange().GetMetadata().GetUUID()),
"change-created": changeRes.Msg.GetChange().GetMetadata().GetCreatedAt().AsTime(),
"change-status": changeRes.Msg.GetChange().GetMetadata().GetStatus().String(),
"change-name": changeRes.Msg.GetChange().GetProperties().GetTitle(),
"change-description": changeRes.Msg.GetChange().GetProperties().GetDescription(),
}).Info("found change")

switch viper.GetString("format") {
case "json":
b, err := json.MarshalIndent(changeRes.Msg.GetChange().ToMap(), "", " ")
Expand Down Expand Up @@ -286,7 +298,7 @@ fetch:
}
}

for _, risk := range changeRes.Msg.GetChange().GetMetadata().GetRisks() {
for _, risk := range riskRes.Msg.GetChangeRiskMetadata().GetRisks() {
data.Risks = append(data.Risks, TemplateRisk{
SeverityAlt: severity[risk.GetSeverity()].SeverityAlt,
SeverityIcon: severity[risk.GetSeverity()].SeverityIcon,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/hexops/gotextdiff v1.0.3
github.com/jedib0t/go-pretty/v6 v6.5.4
github.com/mattn/go-isatty v0.0.20
github.com/overmindtech/sdp-go v0.63.2
github.com/overmindtech/sdp-go v0.65.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/overmindtech/sdp-go v0.63.2 h1:FSNaGYoeU3pDmNiUn/FiP76wtkGddOPiJrVx65JovKw=
github.com/overmindtech/sdp-go v0.63.2/go.mod h1:9wKdnCDCGKku0T/BeGemk8Uk5Lj9mYVMohxufmN2HVo=
github.com/overmindtech/sdp-go v0.65.0 h1:WX9Ue0adOHB1LYvn4uSlVEWpWBqhVOTfHswo64ws1L0=
github.com/overmindtech/sdp-go v0.65.0/go.mod h1:9wKdnCDCGKku0T/BeGemk8Uk5Lj9mYVMohxufmN2HVo=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
Expand Down

0 comments on commit 36c8804

Please sign in to comment.