本文整理汇总了Golang中github.com/juju/juju/environs/config.Config.UnknownAttrs方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.UnknownAttrs方法的具体用法?Golang Config.UnknownAttrs怎么用?Golang Config.UnknownAttrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/environs/config.Config
的用法示例。
在下文中一共展示了Config.UnknownAttrs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: validateConfig
func validateConfig(cfg, old *config.Config) (*environConfig, error) {
// Check for valid changes for the base config values.
if err := config.Validate(cfg, old); err != nil {
return nil, err
}
validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults)
if err != nil {
return nil, err
}
ecfg := &environConfig{cfg, validated}
if vpcID := ecfg.vpcID(); isVPCIDSetButInvalid(vpcID) {
return nil, fmt.Errorf("vpc-id: %q is not a valid AWS VPC ID", vpcID)
} else if !isVPCIDSet(vpcID) && ecfg.forceVPCID() {
return nil, fmt.Errorf("cannot use vpc-id-force without specifying vpc-id as well")
}
if old != nil {
attrs := old.UnknownAttrs()
if vpcID, _ := attrs["vpc-id"].(string); vpcID != ecfg.vpcID() {
return nil, fmt.Errorf("cannot change vpc-id from %q to %q", vpcID, ecfg.vpcID())
}
if forceVPCID, _ := attrs["vpc-id-force"].(bool); forceVPCID != ecfg.forceVPCID() {
return nil, fmt.Errorf("cannot change vpc-id-force from %v to %v", forceVPCID, ecfg.forceVPCID())
}
}
// ssl-hostname-verification cannot be disabled
if !ecfg.SSLHostnameVerification() {
return nil, fmt.Errorf("disabling ssh-hostname-verification is not supported")
}
return ecfg, nil
}
示例2: PrepareForBootstrap
// PrepareForBootstrap is specified in the EnvironProvider interface.
func (prov *azureEnvironProvider) PrepareForBootstrap(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
// Ensure that internal configuration is not specified, and then set
// what we can now. We only need to do this during bootstrap. Validate
// will check for changes later.
unknownAttrs := cfg.UnknownAttrs()
for _, key := range internalConfigAttributes {
if _, ok := unknownAttrs[key]; ok {
return nil, errors.Errorf(`internal config %q must not be specified`, key)
}
}
// Record the UUID that will be used for the controller environment.
cfg, err := cfg.Apply(map[string]interface{}{
configAttrControllerResourceGroup: resourceGroupName(cfg),
})
if err != nil {
return nil, errors.Annotate(err, "recording controller-resource-group")
}
env, err := prov.Open(cfg)
if err != nil {
return nil, errors.Trace(err)
}
if ctx.ShouldVerifyCredentials() {
if err := verifyCredentials(env.(*azureEnviron)); err != nil {
return nil, errors.Trace(err)
}
}
return env, nil
}
示例3: update
// update applies changes from the provided config to the env config.
// Changes to any immutable attributes result in an error.
func (c *environConfig) update(cfg *config.Config) error {
// Validate the updates. newValidConfig does not modify the "known"
// config attributes so it is safe to call Validate here first.
if err := config.Validate(cfg, c.Config); err != nil {
return errors.Trace(err)
}
updates, err := newValidConfig(cfg, configDefaults)
if err != nil {
return errors.Trace(err)
}
// Check that no immutable fields have changed.
attrs := updates.UnknownAttrs()
for _, field := range configImmutableFields {
if attrs[field] != c.attrs[field] {
return errors.Errorf("%s: cannot change from %v to %v", field, c.attrs[field], attrs[field])
}
}
// Apply the updates.
c.Config = cfg
c.attrs = cfg.UnknownAttrs()
return nil
}
示例4: PrepareForBootstrap
func (p manualProvider) PrepareForBootstrap(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
}
cfg, err = cfg.Apply(envConfig.attrs)
if err != nil {
return nil, err
}
envConfig = newEnvironConfig(cfg, envConfig.attrs)
if err := ensureBootstrapUbuntuUser(ctx, envConfig); err != nil {
return nil, err
}
return p.open(envConfig)
}
示例5: SetConfig
// SetConfig is specified in the Environ interface.
func (env *azureEnviron) SetConfig(cfg *config.Config) error {
env.mu.Lock()
defer env.mu.Unlock()
var old *config.Config
if env.config != nil {
old = env.config.Config
}
ecfg, err := validateConfig(cfg, old)
if err != nil {
return err
}
env.config = ecfg
// Initialise clients.
env.compute = compute.NewWithBaseURI(ecfg.endpoint, env.config.subscriptionId)
env.resources = resources.NewWithBaseURI(ecfg.endpoint, env.config.subscriptionId)
env.storage = storage.NewWithBaseURI(ecfg.endpoint, env.config.subscriptionId)
env.network = network.NewWithBaseURI(ecfg.endpoint, env.config.subscriptionId)
clients := map[string]*autorest.Client{
"azure.compute": &env.compute.Client,
"azure.resources": &env.resources.Client,
"azure.storage": &env.storage.Client,
"azure.network": &env.network.Client,
}
if env.provider.config.Sender != nil {
env.config.token.SetSender(env.provider.config.Sender)
}
for id, client := range clients {
client.Authorizer = env.config.token
logger := loggo.GetLogger(id)
if env.provider.config.Sender != nil {
client.Sender = env.provider.config.Sender
}
client.ResponseInspector = tracingRespondDecorator(logger)
client.RequestInspector = tracingPrepareDecorator(logger)
if env.provider.config.RequestInspector != nil {
tracer := client.RequestInspector
inspector := env.provider.config.RequestInspector
client.RequestInspector = func(p autorest.Preparer) autorest.Preparer {
p = tracer(p)
p = inspector(p)
return p
}
}
}
// Invalidate instance types when the location changes.
if old != nil {
oldLocation := old.UnknownAttrs()["location"].(string)
if env.config.location != oldLocation {
env.instanceTypes = nil
}
}
return nil
}
示例6: PrepareForCreateEnvironment
// PrepareForCreateEnvironment is specified in the EnvironProvider interface.
func (p maasEnvironProvider) PrepareForCreateEnvironment(cfg *config.Config) (*config.Config, error) {
attrs := cfg.UnknownAttrs()
oldName, found := attrs["maas-agent-name"]
if found && oldName != "" {
return nil, errAgentNameAlreadySet
}
attrs["maas-agent-name"] = cfg.UUID()
return cfg.Apply(attrs)
}
示例7: SetConfig
func (e *manualEnviron) SetConfig(cfg *config.Config) error {
e.mu.Lock()
defer e.mu.Unlock()
_, err := manualProvider{}.validate(cfg, e.cfg.Config)
if err != nil {
return err
}
e.cfg = newModelConfig(cfg, cfg.UnknownAttrs())
return nil
}
示例8: SecretAttrs
// SecretAttrs is specified in the EnvironProvider interface.
func (prov *azureEnvironProvider) SecretAttrs(cfg *config.Config) (map[string]string, error) {
unknownAttrs := cfg.UnknownAttrs()
secretAttrs := map[string]string{
configAttrAppPassword: unknownAttrs[configAttrAppPassword].(string),
}
if storageAccountKey, ok := unknownAttrs[configAttrStorageAccountKey].(string); ok {
secretAttrs[configAttrStorageAccountKey] = storageAccountKey
}
return secretAttrs, nil
}
示例9: PrepareForBootstrap
// PrepareForBootstrap is specified in the EnvironProvider interface.
func (p manualProvider) PrepareForBootstrap(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
if _, err := p.validate(cfg, nil); err != nil {
return nil, err
}
envConfig := newModelConfig(cfg, cfg.UnknownAttrs())
if err := ensureBootstrapUbuntuUser(ctx, envConfig); err != nil {
return nil, err
}
return p.open(envConfig)
}
示例10: 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
}
// Add MAAS specific defaults.
providerDefaults := make(map[string]interface{})
// Storage.
if _, ok := cfg.StorageDefaultBlockSource(); !ok {
providerDefaults[config.StorageDefaultBlockSourceKey] = maasStorageProviderType
}
if len(providerDefaults) > 0 {
if cfg, err = cfg.Apply(providerDefaults); 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)
}
示例11: Open
func (p manualProvider) Open(cfg *config.Config) (environs.Environ, error) {
_, err := p.validate(cfg, nil)
if err != nil {
return nil, err
}
// validate adds missing manual-specific config attributes
// with their defaults in the result; we don't wnat that in
// Open.
envConfig := newEnvironConfig(cfg, cfg.UnknownAttrs())
return p.open(envConfig)
}
示例12: PrepareForCreateEnvironment
// PrepareForCreateEnvironment is specified in the EnvironProvider interface.
func (p environProvider) PrepareForCreateEnvironment(cfg *config.Config) (*config.Config, error) {
attrs := cfg.UnknownAttrs()
if _, ok := attrs["control-bucket"]; !ok {
uuid, err := utils.NewUUID()
if err != nil {
return nil, errors.Trace(err)
}
attrs["control-bucket"] = fmt.Sprintf("%x", uuid.Raw())
}
return cfg.Apply(attrs)
}
示例13: checkAttrs
func (ts configTestSpec) checkAttrs(c *gc.C, attrs map[string]interface{}, cfg *config.Config) {
for field, expected := range cfg.UnknownAttrs() {
value := attrs[field]
if field == "auth-file" && value != nil {
filename := value.(string)
if filename != "" {
value = interface{}(filepath.Join(ts.rootDir, filename))
}
}
c.Check(value, gc.Equals, expected)
}
}
示例14: validateConfig
func validateConfig(cfg, old *config.Config) (*environConfig, error) {
// Check for valid changes for the base config values.
if err := config.Validate(cfg, old); err != nil {
return nil, err
}
validated, err := cfg.ValidateUnknownAttrs(configFields, configDefaults)
if err != nil {
return nil, err
}
// Add EC2 specific defaults.
providerDefaults := make(map[string]interface{})
// Storage.
if _, ok := cfg.StorageDefaultBlockSource(); !ok {
providerDefaults[config.StorageDefaultBlockSourceKey] = EBS_ProviderType
}
if len(providerDefaults) > 0 {
if cfg, err = cfg.Apply(providerDefaults); err != nil {
return nil, err
}
}
ecfg := &environConfig{cfg, validated}
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 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())
}
}
// ssl-hostname-verification cannot be disabled
if !ecfg.SSLHostnameVerification() {
return nil, fmt.Errorf("disabling ssh-hostname-verification is not supported")
}
return ecfg, nil
}
示例15: PrepareForCreateEnvironment
// PrepareForCreateEnvironment is specified in the EnvironProvider interface.
func (joyentProvider) PrepareForCreateEnvironment(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, errors.Trace(err)
}
attrs["control-dir"] = fmt.Sprintf("%x", uuid.Raw())
}
return cfg.Apply(attrs)
}