代码拉取完成,页面将自动刷新
package amazonec2
import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
)
type awsCredentials interface {
Credentials() *credentials.Credentials
}
type ProviderFactory interface {
NewStaticProvider(id, secret, token string) credentials.Provider
}
type defaultAWSCredentials struct {
AccessKey string
SecretKey string
SessionToken string
providerFactory ProviderFactory
fallbackProvider awsCredentials
}
func NewAWSCredentials(id, secret, token string) *defaultAWSCredentials {
creds := defaultAWSCredentials{
AccessKey: id,
SecretKey: secret,
SessionToken: token,
fallbackProvider: &AwsDefaultCredentialsProvider{},
providerFactory: &defaultProviderFactory{},
}
return &creds
}
func (c *defaultAWSCredentials) Credentials() *credentials.Credentials {
providers := []credentials.Provider{}
if c.AccessKey != "" && c.SecretKey != "" {
providers = append(providers, c.providerFactory.NewStaticProvider(c.AccessKey, c.SecretKey, c.SessionToken))
}
if c.fallbackProvider != nil {
fallbackCreds, err := c.fallbackProvider.Credentials().Get()
if err == nil {
providers = append(providers, &credentials.StaticProvider{Value: fallbackCreds})
}
}
return credentials.NewChainCredentials(providers)
}
type AwsDefaultCredentialsProvider struct{}
func (c *AwsDefaultCredentialsProvider) Credentials() *credentials.Credentials {
return session.New().Config.Credentials
}
type defaultProviderFactory struct{}
func (c *defaultProviderFactory) NewStaticProvider(id, secret, token string) credentials.Provider {
return &credentials.StaticProvider{Value: credentials.Value{
AccessKeyID: id,
SecretAccessKey: secret,
SessionToken: token,
}}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。