本文整理匯總了Golang中github.com/wallyworld/core/environs/config.Config.UnknownAttrs方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.UnknownAttrs方法的具體用法?Golang Config.UnknownAttrs怎麽用?Golang Config.UnknownAttrs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/wallyworld/core/environs/config.Config
的用法示例。
在下文中一共展示了Config.UnknownAttrs方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Prepare
func (p manualProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
if _, ok := cfg.UnknownAttrs()["storage-auth-key"]; !ok {
uuid, err := utils.NewUUID()
if err != nil {
return nil, err
}
cfg, err = cfg.Apply(map[string]interface{}{
"storage-auth-key": uuid.String(),
})
if err != nil {
return nil, err
}
}
if use, ok := cfg.UnknownAttrs()["use-sshstorage"].(bool); ok && !use {
return nil, fmt.Errorf("use-sshstorage must not be specified")
}
envConfig, err := p.validate(cfg, nil)
if err != nil {
return nil, err
}
if err := ensureBootstrapUbuntuUser(ctx, envConfig); err != nil {
return nil, err
}
return p.open(envConfig)
}
示例2: prepareConfig
func prepareConfig(cfg *config.Config) (*config.Config, error) {
// Turn an incomplete config into a valid one, if possible.
attrs := cfg.UnknownAttrs()
if _, ok := attrs["control-dir"]; !ok {
uuid, err := utils.NewUUID()
if err != nil {
return nil, err
}
attrs["control-dir"] = fmt.Sprintf("%x", uuid.Raw())
}
return cfg.Apply(attrs)
}
示例3: Prepare
func (p maasEnvironProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
attrs := cfg.UnknownAttrs()
oldName, found := attrs["maas-agent-name"]
if found && oldName != "" {
return nil, errAgentNameAlreadySet
}
uuid, err := utils.NewUUID()
if err != nil {
return nil, err
}
attrs["maas-agent-name"] = uuid.String()
cfg, err = cfg.Apply(attrs)
if err != nil {
return nil, err
}
return p.Open(cfg)
}
示例4: Open
// Open implements environs.EnvironProvider.Open.
func (environProvider) Open(cfg *config.Config) (environs.Environ, error) {
logger.Infof("opening environment %q", cfg.Name())
if _, ok := cfg.AgentVersion(); !ok {
newCfg, err := cfg.Apply(map[string]interface{}{
"agent-version": version.Current.Number.String(),
})
if err != nil {
return nil, err
}
cfg = newCfg
}
// Set the "namespace" attribute. We do this here, and not in Prepare,
// for backwards compatibility: older versions did not store the namespace
// in config.
if namespace, _ := cfg.UnknownAttrs()["namespace"].(string); namespace == "" {
username := os.Getenv("USER")
if username == "" {
u, err := userCurrent()
if err != nil {
return nil, fmt.Errorf("failed to determine username for namespace: %v", err)
}
username = u.Username
}
var err error
namespace = fmt.Sprintf("%s-%s", username, cfg.Name())
cfg, err = cfg.Apply(map[string]interface{}{"namespace": namespace})
if err != nil {
return nil, fmt.Errorf("failed to create namespace: %v", err)
}
}
// Do the initial validation on the config.
localConfig, err := providerInstance.newConfig(cfg)
if err != nil {
return nil, err
}
if err := VerifyPrerequisites(localConfig.container()); err != nil {
return nil, fmt.Errorf("failed verification of local provider prerequisites: %v", err)
}
environ := &localEnviron{name: cfg.Name()}
if err := environ.SetConfig(cfg); err != nil {
return nil, fmt.Errorf("failure setting config: %v", err)
}
return environ, nil
}
示例5: Validate
func (prov maasEnvironProvider) Validate(cfg, oldCfg *config.Config) (*config.Config, error) {
// Validate base configuration change before validating MAAS specifics.
err := config.Validate(cfg, oldCfg)
if err != nil {
return nil, err
}
validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults)
if err != nil {
return nil, err
}
if oldCfg != nil {
oldAttrs := oldCfg.UnknownAttrs()
validMaasAgentName := false
if oldName, ok := oldAttrs["maas-agent-name"]; !ok || oldName == nil {
// If maas-agent-name was nil (because the config was
// generated pre-1.16.2 the only correct value for it is ""
// See bug #1256179
validMaasAgentName = (validated["maas-agent-name"] == "")
} else {
validMaasAgentName = (validated["maas-agent-name"] == oldName)
}
if !validMaasAgentName {
return nil, fmt.Errorf("cannot change maas-agent-name")
}
}
envCfg := new(maasEnvironConfig)
envCfg.Config = cfg
envCfg.attrs = validated
server := envCfg.maasServer()
serverURL, err := url.Parse(server)
if err != nil || serverURL.Scheme == "" || serverURL.Host == "" {
return nil, fmt.Errorf("malformed maas-server URL '%v': %s", server, err)
}
oauth := envCfg.maasOAuth()
if strings.Count(oauth, ":") != 2 {
return nil, errMalformedMaasOAuth
}
return cfg.Apply(envCfg.attrs)
}