• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang environs.EnvironProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/juju/juju/environs.EnvironProvider的典型用法代码示例。如果您正苦于以下问题:Golang EnvironProvider类的具体用法?Golang EnvironProvider怎么用?Golang EnvironProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了EnvironProvider类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: openEnviron

func openEnviron(
	c *gc.C,
	provider environs.EnvironProvider,
	sender *azuretesting.Senders,
	attrs ...testing.Attrs,
) environs.Environ {
	// Opening the environment should not incur network communication,
	// so we don't set s.sender until after opening.
	cfg := makeTestModelConfig(c, attrs...)
	env, err := provider.Open(environs.OpenParams{
		Cloud:  fakeCloudSpec(),
		Config: cfg,
	})
	c.Assert(err, jc.ErrorIsNil)

	// Force an explicit refresh of the access token, so it isn't done
	// implicitly during the tests.
	*sender = azuretesting.Senders{
		discoverAuthSender(),
		tokenRefreshSender(),
	}
	err = azure.ForceTokenRefresh(env)
	c.Assert(err, jc.ErrorIsNil)
	return env
}
开发者ID:bac,项目名称:juju,代码行数:25,代码来源:environ_test.go


示例2: prepareForBootstrap

func prepareForBootstrap(
	c *gc.C,
	ctx environs.BootstrapContext,
	provider environs.EnvironProvider,
	sender *azuretesting.Senders,
	attrs ...testing.Attrs,
) environs.Environ {
	// Opening the environment should not incur network communication,
	// so we don't set s.sender until after opening.
	cfg, err := provider.PrepareConfig(environs.PrepareConfigParams{
		Config: makeTestModelConfig(c, attrs...),
		Cloud:  fakeCloudSpec(),
	})
	c.Assert(err, jc.ErrorIsNil)

	env, err := provider.Open(environs.OpenParams{
		Cloud:  fakeCloudSpec(),
		Config: cfg,
	})
	c.Assert(err, jc.ErrorIsNil)

	*sender = azuretesting.Senders{
		discoverAuthSender(),
		tokenRefreshSender(),
	}
	err = env.PrepareForBootstrap(ctx)
	c.Assert(err, jc.ErrorIsNil)
	return env
}
开发者ID:bac,项目名称:juju,代码行数:29,代码来源:environ_test.go


示例3: AssertProviderCredentialsValid

// AssertProviderCredentialsValid asserts that the given provider is
// able to validate the given authentication type and credential
// attributes; and that removing any one of the attributes will cause
// the validation to fail.
func AssertProviderCredentialsValid(c *gc.C, p environs.EnvironProvider, authType cloud.AuthType, attrs map[string]string) {
	schema, ok := p.CredentialSchemas()[authType]
	c.Assert(ok, jc.IsTrue, gc.Commentf("missing schema for %q auth-type", authType))
	validate := func(attrs map[string]string) error {
		_, err := schema.Finalize(attrs, func(string) ([]byte, error) {
			return nil, errors.NotSupportedf("reading files")
		})
		return err
	}

	err := validate(attrs)
	c.Assert(err, jc.ErrorIsNil)

	for excludedKey := range attrs {
		field, _ := schema.Attribute(excludedKey)
		if field.Optional {
			continue
		}
		reducedAttrs := make(map[string]string)
		for key, value := range attrs {
			if key != excludedKey {
				reducedAttrs[key] = value
			}
		}
		err := validate(reducedAttrs)
		if field.FileAttr != "" {
			c.Assert(err, gc.ErrorMatches, fmt.Sprintf(
				`either %q or %q must be specified`, excludedKey, field.FileAttr),
			)
		} else {
			c.Assert(err, gc.ErrorMatches, excludedKey+": expected string, got nothing")
		}
	}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:38,代码来源:credentials.go


示例4: prepareForBootstrap

func prepareForBootstrap(
	c *gc.C,
	ctx environs.BootstrapContext,
	provider environs.EnvironProvider,
	sender *azuretesting.Senders,
	attrs ...testing.Attrs,
) environs.Environ {
	// Opening the environment should not incur network communication,
	// so we don't set s.sender until after opening.
	cfg := makeTestModelConfig(c, attrs...)
	cfg, err := cfg.Remove([]string{"controller-resource-group"})
	c.Assert(err, jc.ErrorIsNil)
	*sender = azuretesting.Senders{tokenRefreshSender()}
	cfg, err = provider.BootstrapConfig(environs.BootstrapConfigParams{
		Config:               cfg,
		CloudRegion:          "westus",
		CloudEndpoint:        "https://management.azure.com",
		CloudStorageEndpoint: "https://core.windows.net",
		Credentials:          fakeUserPassCredential(),
	})
	c.Assert(err, jc.ErrorIsNil)
	env, err := provider.PrepareForBootstrap(ctx, cfg)
	c.Assert(err, jc.ErrorIsNil)
	return env
}
开发者ID:makyo,项目名称:juju,代码行数:25,代码来源:environ_test.go


示例5: AssertProviderAuthTypes

// AssertProviderAuthTypes asserts that the given provider has credential
// schemas for exactly the specified set of authentication types.
func AssertProviderAuthTypes(c *gc.C, p environs.EnvironProvider, expectedAuthTypes ...cloud.AuthType) {
	var authTypes []cloud.AuthType
	for authType := range p.CredentialSchemas() {
		authTypes = append(authTypes, authType)
	}
	c.Assert(authTypes, jc.SameContents, expectedAuthTypes)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:9,代码来源:credentials.go


示例6: AssertProviderCredentialsAttributesHidden

// AssertProviderCredentialsAttributesHidden asserts that the provider
// credentials schema for the given provider and authentication type
// marks the specified attributes (and only those attributes) as being
// hidden.
func AssertProviderCredentialsAttributesHidden(c *gc.C, p environs.EnvironProvider, authType cloud.AuthType, expectedHidden ...string) {
	var hidden []string
	schema, ok := p.CredentialSchemas()[authType]
	c.Assert(ok, jc.IsTrue, gc.Commentf("missing schema for %q auth-type", authType))
	for _, field := range schema {
		if field.Hidden {
			hidden = append(hidden, field.Name)
		}
	}
	c.Assert(hidden, jc.SameContents, expectedHidden)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:15,代码来源:credentials.go


示例7: prepareForBootstrap

func prepareForBootstrap(
	c *gc.C,
	ctx environs.BootstrapContext,
	provider environs.EnvironProvider,
	sender *azuretesting.Senders,
	attrs ...testing.Attrs,
) environs.Environ {
	// Opening the environment should not incur network communication,
	// so we don't set s.sender until after opening.
	cfg := makeTestModelConfig(c, attrs...)
	cfg, err := cfg.Remove([]string{"controller-resource-group"})
	c.Assert(err, jc.ErrorIsNil)
	*sender = azuretesting.Senders{tokenRefreshSender()}
	env, err := provider.PrepareForBootstrap(ctx, cfg)
	c.Assert(err, jc.ErrorIsNil)
	return env
}
开发者ID:pmatulis,项目名称:juju,代码行数:17,代码来源:environ_test.go


示例8: finalizeConfig

// finalizeConfig creates the config object from attributes,
// and calls EnvironProvider.PrepareConfig.
func finalizeConfig(
	provider environs.EnvironProvider,
	cloud environs.CloudSpec,
	attrs map[string]interface{},
) (*config.Config, error) {
	cfg, err := config.New(config.UseDefaults, attrs)
	if err != nil {
		return nil, errors.Annotate(err, "creating config from values failed")
	}
	cfg, err = provider.PrepareConfig(environs.PrepareConfigParams{
		Cloud:  cloud,
		Config: cfg,
	})
	if err != nil {
		return nil, errors.Annotate(err, "provider config preparation failed")
	}
	cfg, err = provider.Validate(cfg, nil)
	if err != nil {
		return nil, errors.Annotate(err, "provider config validation failed")
	}
	return cfg, nil
}
开发者ID:bac,项目名称:juju,代码行数:24,代码来源:createmodel.go


示例9: prepare

func prepare(
	ctx environs.BootstrapContext,
	p environs.EnvironProvider,
	args PrepareParams,
) (environs.Environ, prepareDetails, error) {
	var details prepareDetails

	cfg, err := config.New(config.NoDefaults, args.ModelConfig)
	if err != nil {
		return nil, details, errors.Trace(err)
	}

	cfg, err = p.PrepareConfig(environs.PrepareConfigParams{args.Cloud, cfg})
	if err != nil {
		return nil, details, errors.Trace(err)
	}
	env, err := p.Open(environs.OpenParams{
		Cloud:  args.Cloud,
		Config: cfg,
	})
	if err != nil {
		return nil, details, errors.Trace(err)
	}
	if err := env.PrepareForBootstrap(ctx); err != nil {
		return nil, details, errors.Trace(err)
	}

	// We store the base configuration only; we don't want the
	// default attributes, generated secrets/certificates, or
	// UUIDs stored in the bootstrap config. Make a copy, so
	// we don't disturb the caller's config map.
	details.Config = make(map[string]interface{})
	for k, v := range args.ModelConfig {
		details.Config[k] = v
	}
	delete(details.Config, config.UUIDKey)

	// TODO(axw) change signature of CACert() to not return a bool.
	// It's no longer possible to have a controller config without
	// a CA certificate.
	caCert, ok := args.ControllerConfig.CACert()
	if !ok {
		return nil, details, errors.New("controller config is missing CA certificate")
	}

	// We want to store attributes describing how a controller has been configured.
	// These do not include the CACert or UUID since they will be replaced with new
	// values when/if we need to use this configuration.
	details.ControllerConfig = make(controller.Config)
	for k, v := range args.ControllerConfig {
		if k == controller.CACertKey || k == controller.ControllerUUIDKey {
			continue
		}
		details.ControllerConfig[k] = v
	}
	for k, v := range args.ControllerConfig {
		if k == controller.CACertKey || k == controller.ControllerUUIDKey {
			continue
		}
		details.ControllerConfig[k] = v
	}
	details.CACert = caCert
	details.ControllerUUID = args.ControllerConfig.ControllerUUID()
	details.ControllerModelUUID = args.ModelConfig[config.UUIDKey].(string)
	details.User = environs.AdminUser
	details.Password = args.AdminSecret
	details.LastKnownAccess = string(permission.SuperuserAccess)
	details.ModelUUID = cfg.UUID()
	details.ControllerDetails.Cloud = args.Cloud.Name
	details.ControllerDetails.CloudRegion = args.Cloud.Region
	details.BootstrapConfig.CloudType = args.Cloud.Type
	details.BootstrapConfig.Cloud = args.Cloud.Name
	details.BootstrapConfig.CloudRegion = args.Cloud.Region
	details.CloudEndpoint = args.Cloud.Endpoint
	details.CloudIdentityEndpoint = args.Cloud.IdentityEndpoint
	details.CloudStorageEndpoint = args.Cloud.StorageEndpoint
	details.Credential = args.CredentialName

	return env, details, nil
}
开发者ID:bac,项目名称:juju,代码行数:80,代码来源:prepare.go



注:本文中的github.com/juju/juju/environs.EnvironProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang environs.NetworkingEnviron类代码示例发布时间:2022-05-23
下一篇:
Golang environs.Environ类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap