本文整理汇总了Golang中launchpad/net/juju-core/environs/config.Config.UnknownAttrs方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.UnknownAttrs方法的具体用法?Golang Config.UnknownAttrs怎么用?Golang Config.UnknownAttrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/juju-core/environs/config.Config
的用法示例。
在下文中一共展示了Config.UnknownAttrs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Validate
func (p *environProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) {
v, err := checker.Coerce(cfg.UnknownAttrs(), nil)
if err != nil {
return nil, err
}
attrs := v.(map[string]interface{})
switch cfg.FirewallMode() {
case config.FwDefault:
attrs["firewall-mode"] = config.FwInstance
case config.FwInstance, config.FwGlobal:
default:
return nil, fmt.Errorf("unsupported firewall mode: %q", cfg.FirewallMode())
}
return cfg.Apply(attrs)
}
示例2: Validate
func (p environProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) {
v, err := configChecker.Coerce(cfg.UnknownAttrs(), nil)
if err != nil {
return nil, err
}
ecfg := &environConfig{cfg, v.(map[string]interface{})}
if ecfg.accessKey() == "" || ecfg.secretKey() == "" {
auth, err := aws.EnvAuth()
if err != nil || ecfg.accessKey() != "" || ecfg.secretKey() != "" {
return nil, fmt.Errorf("environment has no access-key or secret-key")
}
ecfg.attrs["access-key"] = auth.AccessKey
ecfg.attrs["secret-key"] = auth.SecretKey
}
if _, ok := aws.Regions[ecfg.region()]; !ok {
return nil, fmt.Errorf("invalid region name %q", ecfg.region())
}
if _, ok := aws.Regions[ecfg.publicBucketRegion()]; !ok {
return nil, fmt.Errorf("invalid public-bucket-region name %q", ecfg.publicBucketRegion())
}
if old != nil {
attrs := old.UnknownAttrs()
if region, _ := attrs["region"].(string); ecfg.region() != region {
return nil, fmt.Errorf("cannot change region from %q to %q", region, ecfg.region())
}
if bucket, _ := attrs["control-bucket"].(string); ecfg.controlBucket() != bucket {
return nil, fmt.Errorf("cannot change control-bucket from %q to %q", bucket, ecfg.controlBucket())
}
}
switch cfg.FirewallMode() {
case config.FwDefault:
ecfg.attrs["firewall-mode"] = config.FwInstance
case config.FwInstance, config.FwGlobal:
default:
return nil, fmt.Errorf("unsupported firewall mode: %q", cfg.FirewallMode())
}
// ssl-hostname-verification cannot be disabled
if !ecfg.SSLHostnameVerification() {
return nil, fmt.Errorf("disabling ssh-hostname-verification is not supported")
}
return cfg.Apply(ecfg.attrs)
}
示例3: Validate
// Validate ensures that config is a valid configuration for this
// provider like specified in the EnvironProvider interface.
func (prov azureEnvironProvider) Validate(cfg, oldCfg *config.Config) (*config.Config, error) {
// Validate base configuration change before validating Azure specifics.
err := config.Validate(cfg, oldCfg)
if err != nil {
return nil, err
}
validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults)
if err != nil {
return nil, err
}
envCfg := new(azureEnvironConfig)
envCfg.Config = cfg
envCfg.attrs = validated
cert := envCfg.ManagementCertificate()
if cert == "" {
certPath := envCfg.attrs["management-certificate-path"].(string)
pemData, err := ioutil.ReadFile(certPath)
if err != nil {
return nil, fmt.Errorf("invalid management-certificate-path: %s", err)
}
envCfg.attrs["management-certificate"] = string(pemData)
}
delete(envCfg.attrs, "management-certificate-path")
if envCfg.Location() == "" {
return nil, fmt.Errorf("environment has no location; you need to set one. E.g. 'West US'")
}
if envCfg.StorageContainerName() == "" {
return nil, fmt.Errorf("environment has no storage-container-name; auto-creation of storage containers is not yet supported")
}
if (envCfg.PublicStorageAccountName() == "") != (envCfg.PublicStorageContainerName() == "") {
return nil, fmt.Errorf("public-storage-account-name and public-storage-container-name must be specified both or none of them")
}
if oldCfg != nil {
attrs := oldCfg.UnknownAttrs()
if storageContainerName, _ := attrs["storage-container-name"].(string); envCfg.StorageContainerName() != storageContainerName {
return nil, fmt.Errorf("cannot change storage-container-name from %q to %q", storageContainerName, envCfg.StorageContainerName())
}
}
return cfg.Apply(envCfg.attrs)
}
示例4: Validate
func (p environProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) {
// Check for valid changes for the base config values.
if err := config.Validate(cfg, old); err != nil {
return nil, err
}
// Check for deprecated fields and log a warning. We also print to stderr to ensure the user sees the message
// even if they are not running with --debug.
if defaultImageId := cfg.AllAttrs()["default-image-id"]; defaultImageId != nil && defaultImageId.(string) != "" {
msg := fmt.Sprintf(
"config attribute %q (%v) is deprecated and ignored, use simplestreams metadata instead",
"default-image-id", defaultImageId)
log.Warningf(msg)
}
if defaultInstanceType := cfg.AllAttrs()["default-instance-type"]; defaultInstanceType != nil && defaultInstanceType.(string) != "" {
msg := fmt.Sprintf(
"config attribute %q (%v) is deprecated and ignored", "default-instance-type", defaultInstanceType)
log.Warningf(msg)
}
validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults)
if err != nil {
return nil, err
}
ecfg := &environConfig{cfg, validated}
authMode := AuthMode(ecfg.authMode())
switch authMode {
case AuthKeyPair:
case AuthLegacy:
case AuthUserPass:
default:
return nil, fmt.Errorf("invalid authorization mode: %q", authMode)
}
if ecfg.authURL() != "" {
parts, err := url.Parse(ecfg.authURL())
if err != nil || parts.Host == "" || parts.Scheme == "" {
return nil, fmt.Errorf("invalid auth-url value %q", ecfg.authURL())
}
}
cred := identity.CredentialsFromEnv()
format := "required environment variable not set for credentials attribute: %s"
if authMode == AuthUserPass || authMode == AuthLegacy {
if ecfg.username() == "" {
if cred.User == "" {
return nil, fmt.Errorf(format, "User")
}
ecfg.attrs["username"] = cred.User
}
if ecfg.password() == "" {
if cred.Secrets == "" {
return nil, fmt.Errorf(format, "Secrets")
}
ecfg.attrs["password"] = cred.Secrets
}
} else if authMode == AuthKeyPair {
if ecfg.accessKey() == "" {
if cred.User == "" {
return nil, fmt.Errorf(format, "User")
}
ecfg.attrs["access-key"] = cred.User
}
if ecfg.secretKey() == "" {
if cred.Secrets == "" {
return nil, fmt.Errorf(format, "Secrets")
}
ecfg.attrs["secret-key"] = cred.Secrets
}
}
if ecfg.authURL() == "" {
if cred.URL == "" {
return nil, fmt.Errorf(format, "URL")
}
ecfg.attrs["auth-url"] = cred.URL
}
if ecfg.tenantName() == "" {
if cred.TenantName == "" {
return nil, fmt.Errorf(format, "TenantName")
}
ecfg.attrs["tenant-name"] = cred.TenantName
}
if ecfg.region() == "" {
if cred.Region == "" {
return nil, fmt.Errorf(format, "Region")
}
ecfg.attrs["region"] = cred.Region
}
if old != nil {
attrs := old.UnknownAttrs()
if region, _ := attrs["region"].(string); ecfg.region() != region {
return nil, fmt.Errorf("cannot change region from %q to %q", region, ecfg.region())
}
if controlBucket, _ := attrs["control-bucket"].(string); ecfg.controlBucket() != controlBucket {
return nil, fmt.Errorf("cannot change control-bucket from %q to %q", controlBucket, ecfg.controlBucket())
}
}
// Apply the coerced unknown values back into the config.
//.........这里部分代码省略.........