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 2e59532
Show file tree
Hide file tree
Showing 2 changed files with 15 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
ProvideFrom = providers.ProvideFrom
)
12 changes: 12 additions & 0 deletions pkg/providers/interface.go
Expand Up @@ -83,3 +83,15 @@ func Provide(ctx context.Context, audience string) (string, error) {
}
return id, err
}

// ProvideFrom fetches the specified provider
func ProvideFrom(ctx context.Context, provider string) (Interface, error) {
m.Lock()
defer m.Unlock()

p, ok := providers[provider]
if !ok {
return nil, fmt.Errorf("%s is not a valid provider", provider)
}
return p, nil
}

0 comments on commit 2e59532

Please sign in to comment.