Skip to content

Commit

Permalink
Add function to explictly request a certain provider
Browse files Browse the repository at this point in the history
Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
  • Loading branch information
priyawadhwa committed May 4, 2022
1 parent d46a3da commit 43d4fc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/providers/all/all.go
Expand Up @@ -27,6 +27,7 @@ import (

// Alias these methods, so that folks can import this to get all providers.
var (
Enabled = providers.Enabled
Provide = providers.Provide
Enabled = providers.Enabled
Provide = providers.Provide
ExplicitProvide = providers.ExplicitProvide
)
15 changes: 15 additions & 0 deletions pkg/providers/interface.go
Expand Up @@ -83,3 +83,18 @@ func Provide(ctx context.Context, audience string) (string, error) {
}
return id, err
}

// ExplicitProvide fetches an OIDC token from the specified provider
func ExplicitProvide(ctx context.Context, audience, provider string) (string, error) {
m.Lock()
defer m.Unlock()

p, ok := providers[provider]
if !ok {
return "", fmt.Errorf("%s is not a valid provider", provider)
}
if !p.Enabled(ctx) {
return "", fmt.Errorf("provider %s is not enabled, check providers.Enabled() before providers.ExplicitProvide()", provider)
}
return p.Provide(ctx, audience)
}

0 comments on commit 43d4fc7

Please sign in to comment.