2023-12-21 22:17:40 +08:00
|
|
|
package credentials
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type providerChain struct {
|
|
|
|
Providers []Provider
|
|
|
|
}
|
|
|
|
|
2024-04-26 10:46:37 +08:00
|
|
|
var defaultproviders = []Provider{providerEnv, providerOIDC, providerProfile, providerInstance}
|
2023-12-21 22:17:40 +08:00
|
|
|
var defaultChain = newProviderChain(defaultproviders)
|
|
|
|
|
|
|
|
func newProviderChain(providers []Provider) Provider {
|
|
|
|
return &providerChain{
|
|
|
|
Providers: providers,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *providerChain) resolve() (*Config, error) {
|
|
|
|
for _, provider := range p.Providers {
|
|
|
|
config, err := provider.resolve()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if config == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return config, err
|
|
|
|
}
|
|
|
|
return nil, errors.New("No credential found")
|
|
|
|
|
|
|
|
}
|