Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token source for external command #6271

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions flyteidl/clients/go/admin/token_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import (
"context"
"strings"

"github.com/flyteorg/flyte/flyteidl/clients/go/admin/externalprocess"

"golang.org/x/oauth2"
)
Expand Down Expand Up @@ -49,3 +52,19 @@
insecure: insecure,
}
}

type ExternalCommandTokenSource struct {
command []string
}

func (ec *ExternalCommandTokenSource) Token() (*oauth2.Token, error) {
output, err := externalprocess.Execute(ec.command)
if err != nil {
return nil, err
}

Check warning on line 64 in flyteidl/clients/go/admin/token_source.go

View check run for this annotation

Codecov / codecov/patch

flyteidl/clients/go/admin/token_source.go#L63-L64

Added lines #L63 - L64 were not covered by tests
t := &oauth2.Token{
AccessToken: strings.Trim(string(output), "\t \n"),
TokenType: "bearer",
}
return t, nil
}
14 changes: 4 additions & 10 deletions flyteidl/clients/go/admin/token_source_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/flyteorg/flyte/flyteidl/clients/go/admin/cache"
"github.com/flyteorg/flyte/flyteidl/clients/go/admin/deviceflow"
"github.com/flyteorg/flyte/flyteidl/clients/go/admin/externalprocess"
"github.com/flyteorg/flyte/flyteidl/clients/go/admin/pkce"
"github.com/flyteorg/flyte/flyteidl/clients/go/admin/tokenorchestrator"
"github.com/flyteorg/flyte/flyteidl/clients/go/admin/utils"
Expand Down Expand Up @@ -120,15 +119,10 @@ func NewExternalTokenSourceProvider(command []string) (TokenSourceProvider, erro
}

func (e ExternalTokenSourceProvider) GetTokenSource(ctx context.Context) (oauth2.TokenSource, error) {
output, err := externalprocess.Execute(e.command)
if err != nil {
return nil, err
}

return oauth2.StaticTokenSource(&oauth2.Token{
AccessToken: strings.Trim(string(output), "\t \n"),
TokenType: "bearer",
}), nil
// Return a TokenSource that will call out to the external command on each Token()
return &ExternalCommandTokenSource{
command: e.command,
}, nil
}

type PKCETokenSourceProvider struct {
Expand Down
Loading