本文整理汇总了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)
}