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{})) +}