From e6855b46329813425dfdddede6cfed9c8280549d Mon Sep 17 00:00:00 2001 From: pmahindrakar-oss Date: Fri, 21 Jan 2022 14:05:00 +0530 Subject: [PATCH] Added endpoint suffix to service user for pkce token saved in token cache (#264) * Added endpoint suffix to service user for pkce token saved in token cache Signed-off-by: Prafulla Mahindrakar * nits Signed-off-by: Prafulla Mahindrakar --- flytectl/cmd/core/cmd.go | 3 ++- flytectl/cmd/core/cmd_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 flytectl/cmd/core/cmd_test.go diff --git a/flytectl/cmd/core/cmd.go b/flytectl/cmd/core/cmd.go index 54483c5c8f..c1121355fb 100644 --- a/flytectl/cmd/core/cmd.go +++ b/flytectl/cmd/core/cmd.go @@ -58,9 +58,10 @@ func generateCommandFunc(cmdEntry CommandEntry) func(cmd *cobra.Command, args [] return err } + adminCfg := admin.GetConfig(ctx) clientSet, err := admin.ClientSetBuilder().WithConfig(admin.GetConfig(ctx)). WithTokenCache(pkce.TokenCacheKeyringProvider{ - ServiceUser: pkce.KeyRingServiceUser, + ServiceUser: fmt.Sprintf("%s:%s", adminCfg.Endpoint.String(), pkce.KeyRingServiceUser), ServiceName: pkce.KeyRingServiceName, }).Build(ctx) if err != nil { diff --git a/flytectl/cmd/core/cmd_test.go b/flytectl/cmd/core/cmd_test.go new file mode 100644 index 0000000000..f0bab3bc53 --- /dev/null +++ b/flytectl/cmd/core/cmd_test.go @@ -0,0 +1,27 @@ +package cmdcore + +import ( + "context" + "net/url" + "testing" + + "github.com/flyteorg/flyteidl/clients/go/admin" + "github.com/flyteorg/flytestdlib/config" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" +) + +func testCommandFunc(ctx context.Context, args []string, cmdCtx CommandContext) error { + return nil +} + +func TestGenerateCommandFunc(t *testing.T) { + adminCfg := admin.GetConfig(context.Background()) + adminCfg.Endpoint = config.URL{URL: url.URL{Host: "dummyHost"}} + adminCfg.AuthType = admin.AuthTypePkce + rootCmd := &cobra.Command{} + cmdEntry := CommandEntry{CmdFunc: testCommandFunc, ProjectDomainNotRequired: true} + fn := generateCommandFunc(cmdEntry) + assert.Nil(t, fn(rootCmd, []string{})) +}