From 35bb8fe50463f8f50a97f6099d178691dcdffb3b Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Tue, 13 Feb 2024 10:23:32 +0100 Subject: [PATCH 1/3] Use the new GetChangeRisks() API --- cmd/getchange.go | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/cmd/getchange.go b/cmd/getchange.go index e596f14d..a3be68f3 100644 --- a/cmd/getchange.go +++ b/cmd/getchange.go @@ -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 { @@ -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(), "", " ") @@ -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, From 36917fbabcd6abf3ce4a7f91a5ed755ad55c79e4 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Tue, 13 Feb 2024 10:24:34 +0100 Subject: [PATCH 2/3] Update datasources --- cmd/datamaps/awssource.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cmd/datamaps/awssource.go b/cmd/datamaps/awssource.go index 3a02cdc9..f5432c0a 100644 --- a/cmd/datamaps/awssource.go +++ b/cmd/datamaps/awssource.go @@ -205,6 +205,30 @@ var AwssourceData = map[string][]TfMapData{ Scope: "*", }, }, + "aws_dx_hosted_connection": { + { + Type: "directconnect-hosted-connection", + Method: sdp.QueryMethod_GET, + QueryField: "id", + Scope: "*", + }, + }, + "aws_dx_lag": { + { + Type: "directconnect-lag", + Method: sdp.QueryMethod_GET, + QueryField: "id", + Scope: "*", + }, + }, + "aws_dx_location": { + { + Type: "directconnect-location", + Method: sdp.QueryMethod_GET, + QueryField: "location_code", + Scope: "*", + }, + }, "aws_dx_private_virtual_interface": { { Type: "directconnect-virtual-interface", @@ -221,6 +245,14 @@ var AwssourceData = map[string][]TfMapData{ Scope: "*", }, }, + "aws_dx_router_configuration": { + { + Type: "directconnect-router-configuration", + Method: sdp.QueryMethod_GET, + QueryField: "virtual_interface_id", + Scope: "*", + }, + }, "aws_dx_transit_virtual_interface": { { Type: "directconnect-virtual-interface", From 72e5260c34f3256a4c71b9e88d919a0f1e54e142 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Tue, 13 Feb 2024 10:25:02 +0100 Subject: [PATCH 3/3] Update sdp-go --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c819e0d5..5ff9820c 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index a62631e4..cda43b08 100644 --- a/go.sum +++ b/go.sum @@ -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=