Skip to content

Commit

Permalink
Add function to explictly request a certain provider (#1837)
Browse files Browse the repository at this point in the history
Signed-off-by: Priya Wadhwa <[email protected]>
  • Loading branch information
priyawadhwa authored May 4, 2022
1 parent d46a3da commit c6ca9a2
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 c6ca9a2

Please sign in to comment.