Repository: GoogleCloudPlatform/terraform-validator
Pull request #724 (2022-05-25 20:35:06)

Revert "Add user agent parameter to ReadPlannedAssets()"
Reverts GoogleCloudPlatform/terraform-validator#718


Patch:
diff --git a/cmd/convert.go b/cmd/convert.go
index 83c1c8da..a7b04b39 100644
--- a/cmd/convert.go
+++ b/cmd/convert.go
@@ -17,11 +17,9 @@ package cmd
 import (
 	"context"
 	"encoding/json"
-	"fmt"
 	"os"
 
 	"github.com/GoogleCloudPlatform/terraform-validator/tfgcv"
-	"github.com/GoogleCloudPlatform/terraform-validator/version"
 	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
 	"go.uber.org/zap"
@@ -98,8 +96,7 @@ func (o *convertOptions) run(plan string) error {
 	ancestryCache := map[string]string{
 		o.project: o.ancestry,
 	}
-	userAgent := fmt.Sprintf("config-validator-tf/%s", version.BuildVersion())
-	assets, err := o.readPlannedAssets(ctx, plan, o.project, ancestryCache, o.offline, false, o.rootOptions.errorLogger, userAgent)
+	assets, err := o.readPlannedAssets(ctx, plan, o.project, ancestryCache, o.offline, false, o.rootOptions.errorLogger)
 	if err != nil {
 		if errors.Cause(err) == tfgcv.ErrParsingProviderProject {
 			return errors.New("unable to parse provider project, please use --project flag")
diff --git a/cmd/validate.go b/cmd/validate.go
index 33758fcb..cb48fb75 100644
--- a/cmd/validate.go
+++ b/cmd/validate.go
@@ -24,7 +24,6 @@ import (
 	"github.com/GoogleCloudPlatform/config-validator/pkg/api/validator"
 	"github.com/GoogleCloudPlatform/terraform-validator/converters/google"
 	"github.com/GoogleCloudPlatform/terraform-validator/tfgcv"
-	"github.com/GoogleCloudPlatform/terraform-validator/version"
 	"github.com/golang/protobuf/jsonpb"
 	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
@@ -116,8 +115,7 @@ func (o *validateOptions) run(plan string) error {
 		ancestryCache := map[string]string{
 			o.project: o.ancestry,
 		}
-		userAgent := fmt.Sprintf("config-validator-tf/%s", version.BuildVersion())
-		assets, err = o.readPlannedAssets(ctx, plan, o.project, ancestryCache, o.offline, false, o.rootOptions.errorLogger, userAgent)
+		assets, err = o.readPlannedAssets(ctx, plan, o.project, ancestryCache, o.offline, false, o.rootOptions.errorLogger)
 		if err != nil {
 			if errors.Cause(err) == tfgcv.ErrParsingProviderProject {
 				return errors.New("unable to parse provider project, please use --project flag")
diff --git a/tfgcv/planned_assets.go b/tfgcv/planned_assets.go
index 4b5332ca..99da7d10 100644
--- a/tfgcv/planned_assets.go
+++ b/tfgcv/planned_assets.go
@@ -30,7 +30,7 @@ import (
 	"go.uber.org/zap"
 )
 
-type ReadPlannedAssetsFunc func(ctx context.Context, path, project string, ancestry map[string]string, offline, convertUnchanged bool, errorLogger *zap.Logger, userAgent string) ([]google.Asset, error)
+type ReadPlannedAssetsFunc func(ctx context.Context, path, project string, ancestry map[string]string, offline, convertUnchanged bool, errorLogger *zap.Logger) ([]google.Asset, error)
 
 // ReadPlannedAssets extracts CAI assets from a terraform plan file.
 // If ancestry path is provided, it assumes the project is in that path rather
@@ -39,8 +39,8 @@ type ReadPlannedAssetsFunc func(ctx context.Context, path, project string, ances
 // are also reported in the output, otherwise only resources that are going to
 // be changed are reported.
 // It ignores non-supported resources.
-func ReadPlannedAssets(ctx context.Context, path, project string, ancestry map[string]string, offline, convertUnchanged bool, errorLogger *zap.Logger, userAgent string) ([]google.Asset, error) {
-	converter, err := newConverter(ctx, path, project, ancestry, offline, convertUnchanged, errorLogger, userAgent)
+func ReadPlannedAssets(ctx context.Context, path, project string, ancestry map[string]string, offline, convertUnchanged bool, errorLogger *zap.Logger) ([]google.Asset, error) {
+	converter, err := newConverter(ctx, path, project, ancestry, offline, convertUnchanged, errorLogger)
 	if err != nil {
 		return nil, err
 	}
@@ -63,8 +63,8 @@ func ReadPlannedAssets(ctx context.Context, path, project string, ancestry map[s
 	return converter.Assets(), nil
 }
 
-func newConverter(ctx context.Context, path, project string, ancestry map[string]string, offline, convertUnchanged bool, errorLogger *zap.Logger, userAgent string) (*google.Converter, error) {
-	cfg, err := resources.GetConfig(ctx, project, offline, userAgent)
+func newConverter(ctx context.Context, path, project string, ancestry map[string]string, offline, convertUnchanged bool, errorLogger *zap.Logger) (*google.Converter, error) {
+	cfg, err := resources.GetConfig(ctx, project, offline)
 	if err != nil {
 		return nil, errors.Wrap(err, "building google configuration")
 	}


Test patch:
diff --git a/cmd/convert_test.go b/cmd/convert_test.go
index e4b116c3..54e7db9e 100644
--- a/cmd/convert_test.go
+++ b/cmd/convert_test.go
@@ -36,7 +36,7 @@ func testAssets() []google.Asset {
 	}
 }
 
-func MockReadPlannedAssets(ctx context.Context, path, project string, ancestry map[string]string, offline, convertUnchanged bool, errorLogger *zap.Logger, userAgent string) ([]google.Asset, error) {
+func MockReadPlannedAssets(ctx context.Context, path, project string, ancestry map[string]string, offline, convertUnchanged bool, errorLogger *zap.Logger) ([]google.Asset, error) {
 	return testAssets(), nil
 }
 
diff --git a/converters/google/convert_test.go b/converters/google/convert_test.go
index 4ab832b5..a8f1dd54 100644
--- a/converters/google/convert_test.go
+++ b/converters/google/convert_test.go
@@ -34,7 +34,7 @@ func newTestConverter(convertUnchanged bool) (*Converter, error) {
 	ctx := context.Background()
 	project := testProject
 	offline := true
-	cfg, err := resources.GetConfig(ctx, project, offline, "")
+	cfg, err := resources.GetConfig(ctx, project, offline)
 	if err != nil {
 		return nil, errors.Wrap(err, "constructing configuration")
 	}
diff --git a/tfgcv/planned_assets_test.go b/tfgcv/planned_assets_test.go
index 38caa7e7..d6fc3a55 100644
--- a/tfgcv/planned_assets_test.go
+++ b/tfgcv/planned_assets_test.go
@@ -80,7 +80,7 @@ func TestReadPlannedAssets(t *testing.T) {
 			ancestryCache := map[string]string{
 				tt.args.project: tt.args.ancestry,
 			}
-			got, err := ReadPlannedAssets(ctx, testFile, tt.args.project, ancestryCache, offline, tt.args.convertUnchanged, zap.NewExample(), "")
+			got, err := ReadPlannedAssets(ctx, testFile, tt.args.project, ancestryCache, offline, tt.args.convertUnchanged, zap.NewExample())
 			if (err != nil) != tt.wantErr {
 				t.Errorf("ReadPlannedAssets() error = %v, wantErr %v", err, tt.wantErr)
 				return