service/vendor/github.com/aliyun/credentials-go/credentials/provider_chain.go

33 lines
640 B
Go
Raw Permalink Normal View History

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")
}