Skip to content

Commit

Permalink
Added endpoint suffix to service user for pkce token saved in token c…
Browse files Browse the repository at this point in the history
…ache (#264)

* Added endpoint suffix to service user for pkce token saved in token cache

Signed-off-by: Prafulla Mahindrakar <[email protected]>

* nits

Signed-off-by: Prafulla Mahindrakar <[email protected]>
  • Loading branch information
pmahindrakar-oss authored Jan 21, 2022
1 parent dec585d commit e6855b4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flytectl/cmd/core/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions flytectl/cmd/core/cmd_test.go
Original file line number Diff line number Diff line change
@@ -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{}))
}

0 comments on commit e6855b4

Please sign in to comment.