From e5257034be31cf4f91c43355778f01a04775a746 Mon Sep 17 00:00:00 2001 From: Michael Golowka <72365+pcman312@users.noreply.github.com> Date: Mon, 27 Apr 2020 14:18:04 -0600 Subject: [PATCH] Add and to read endpoint --- plugin/path_config.go | 7 +++++++ plugin/path_config_test.go | 27 +++++++++++---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/plugin/path_config.go b/plugin/path_config.go index 28d3b23d..4bf8f258 100644 --- a/plugin/path_config.go +++ b/plugin/path_config.go @@ -125,6 +125,13 @@ func (b *GcpAuthBackend) pathConfigRead(ctx context.Context, req *logical.Reques resp["project_id"] = v } + if v := config.IAMAliasType; v != "" { + resp["iam_alias"] = v + } + if v := config.GCEAliasType; v != "" { + resp["gce_alias"] = v + } + return &logical.Response{ Data: resp, }, nil diff --git a/plugin/path_config_test.go b/plugin/path_config_test.go index 55fa3a41..a74c0b33 100644 --- a/plugin/path_config_test.go +++ b/plugin/path_config_test.go @@ -51,6 +51,8 @@ func TestBackend_PathConfigRead(t *testing.T) { PrivateKey: "key", ProjectId: "project", }, + IAMAliasType: defaultIAMAlias, + GCEAliasType: defaultGCEAlias, }) if err != nil { t.Fatal(err) @@ -68,24 +70,17 @@ func TestBackend_PathConfigRead(t *testing.T) { t.Fatal(err) } - if v, exp := resp.Data["client_email"].(string), "user@test.com"; v != exp { - t.Errorf("expected %q to be %q", v, exp) - } - - if v, exp := resp.Data["client_id"].(string), "user"; v != exp { - t.Errorf("expected %q to be %q", v, exp) - } - - if v, exp := resp.Data["private_key_id"].(string), "key_id"; v != exp { - t.Errorf("expected %q to be %q", v, exp) - } - - if v, exp := resp.Data["project_id"].(string), "project"; v != exp { - t.Errorf("expected %q to be %q", v, exp) + expectedData := map[string]interface{}{ + "client_email": "user@test.com", + "client_id": "user", + "private_key_id": "key_id", + "project_id": "project", + "iam_alias": defaultIAMAlias, + "gce_alias": defaultGCEAlias, } - if v, ok := resp.Data["private_key"]; ok { - t.Errorf("expected %q to be missing", v) + if !reflect.DeepEqual(resp.Data, expectedData) { + t.Fatalf("Actual: %#v\nExpected: %#v", resp.Data, expectedData) } }) }