當前位置: 首頁>>代碼示例>>Golang>>正文


Golang EnvironProvider.CredentialSchemas方法代碼示例

本文整理匯總了Golang中github.com/juju/juju/environs.EnvironProvider.CredentialSchemas方法的典型用法代碼示例。如果您正苦於以下問題:Golang EnvironProvider.CredentialSchemas方法的具體用法?Golang EnvironProvider.CredentialSchemas怎麽用?Golang EnvironProvider.CredentialSchemas使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/juju/juju/environs.EnvironProvider的用法示例。


在下文中一共展示了EnvironProvider.CredentialSchemas方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例2: 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

示例3: 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


注:本文中的github.com/juju/juju/environs.EnvironProvider.CredentialSchemas方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。