From 28980aab05a40b2d139807801f23fff728205e7a Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Tue, 18 Jul 2023 19:58:02 +0000 Subject: [PATCH 1/3] Fixed `SEARCH` -> `LIST` conversion Not sure why this was like this. `SEARCH` is correct --- cmd/datamaps/awssource.go | 24 ++++++++++++------------ extractmaps.go | 7 +------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/cmd/datamaps/awssource.go b/cmd/datamaps/awssource.go index bde94178..b8da5600 100644 --- a/cmd/datamaps/awssource.go +++ b/cmd/datamaps/awssource.go @@ -8,7 +8,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_alb_listener": { { Type: "elbv2-listener", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "arn", Scope: "*", }, @@ -16,7 +16,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_alb_listener_rule": { { Type: "elbv2-rule", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "arn", Scope: "*", }, @@ -128,7 +128,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_ecs_service": { { Type: "ecs-service", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "arn", Scope: "*", }, @@ -184,7 +184,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_eks_addon": { { Type: "eks-addon", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "arn", Scope: "*", }, @@ -200,7 +200,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_eks_fargate_profile": { { Type: "eks-fargate-profile", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "arn", Scope: "*", }, @@ -208,7 +208,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_eks_node_group": { { Type: "eks-nodegroup", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "arn", Scope: "*", }, @@ -248,7 +248,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_iam_policy": { { Type: "iam-policy", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "arn", Scope: "*", }, @@ -264,7 +264,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_iam_role_policy_attachment": { { Type: "iam-policy", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "policy_arn", Scope: "*", }, @@ -308,7 +308,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_iam_user_policy_attachment": { { Type: "iam-policy", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "policy_arn", Scope: "*", }, @@ -378,7 +378,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_lambda_layer_version": { { Type: "lambda-layer-version", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "arn", Scope: "*", }, @@ -402,7 +402,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_lb_listener": { { Type: "elbv2-listener", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "arn", Scope: "*", }, @@ -410,7 +410,7 @@ var AwssourceData = map[string][]TfMapData{ "aws_lb_listener_rule": { { Type: "elbv2-rule", - Method: sdp.QueryMethod_LIST, + Method: sdp.QueryMethod_SEARCH, QueryField: "arn", Scope: "*", }, diff --git a/extractmaps.go b/extractmaps.go index 526a7a79..8f9686c3 100644 --- a/extractmaps.go +++ b/extractmaps.go @@ -124,12 +124,7 @@ func dataFromFiles(path string) map[string][]map[string]string { data["query-field"] = qSplit[1] data["scope"] = parsed["terraformScope"].(string) - switch parsed["terraformMethod"].(string) { - case "GET": - data["method"] = "GET" - case "SEARCH": - data["method"] = "LIST" - } + data["method"] = parsed["terraformMethod"].(string) result[data["query-type"]] = append(result[data["query-type"]], data) } From 47e7e805e7b6877611da091180f29f0b2f5958c2 Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Tue, 18 Jul 2023 19:58:14 +0000 Subject: [PATCH 2/3] Remove unused config file logic --- cmd/root.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 96386775..6a0a115d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,7 +23,6 @@ import ( "google.golang.org/protobuf/types/known/durationpb" ) -var cfgFile string var logLevel string var minStatusInterval = durationpb.New(250 * time.Millisecond) @@ -188,7 +187,6 @@ func init() { cobra.OnInitialize(initConfig) // General Config - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is redacted.yaml)") rootCmd.PersistentFlags().StringVar(&logLevel, "log", "info", "Set the log level. Valid values: panic, fatal, error, warn, info, debug, trace") // api endpoint @@ -249,17 +247,8 @@ func init() { // initConfig reads in config file and ENV variables if set. func initConfig() { - viper.SetConfigFile(cfgFile) - replacer := strings.NewReplacer("-", "_") viper.SetEnvKeyReplacer(replacer) viper.AutomaticEnv() // read in environment variables that match - - // If a config file is found, read it in. - if err := viper.ReadInConfig(); err == nil { - log.Infof("Using config file: %v", viper.ConfigFileUsed()) - } else { - log.WithFields(log.Fields{"err": err}).Errorf("Error reading config file") - } } From 62a26c0eb82be653ed82ba0e7d419acbec8f8772 Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Tue, 18 Jul 2023 19:58:41 +0000 Subject: [PATCH 3/3] Use correct url No clue how this was working before --- cmd/submitplan.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/submitplan.go b/cmd/submitplan.go index 503c3778..0ef7ea5c 100644 --- a/cmd/submitplan.go +++ b/cmd/submitplan.go @@ -216,7 +216,7 @@ func SubmitPlan(signals chan os.Signal, ready chan bool) int { } log.WithContext(ctx).WithFields(lf).WithField("item_count", len(queries)).Info("identifying items") - c, _, err := websocket.Dial(ctx, viper.GetString("url"), options) + c, _, err := websocket.Dial(ctx, viper.GetString("gateway-url"), options) if err != nil { log.WithContext(ctx).WithFields(lf).WithError(err).Error("Failed to connect to overmind API") return 1 @@ -236,6 +236,16 @@ func SubmitPlan(signals chan os.Signal, ready chan bool) int { }, } err = wspb.Write(ctx, c, &req) + + if err == nil { + log.WithContext(ctx).WithFields(log.Fields{ + "scope": q.Scope, + "type": q.Type, + "query": q.Query, + "method": q.Method.String(), + "uuid": q.ParseUuid().String(), + }).Trace("Started query") + } if err != nil { log.WithContext(ctx).WithFields(lf).WithError(err).WithField("req", &req).Error("Failed to send request") continue