本文整理匯總了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")
}
}
}
示例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)
}
示例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)
}