launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #15331
[Merge] lp:~jtv/juju-core/mpv-secret-attrs into lp:~maas-maintainers/juju-core/maas-provider-skeleton
Jeroen T. Vermeulen has proposed merging lp:~jtv/juju-core/mpv-secret-attrs into lp:~maas-maintainers/juju-core/maas-provider-skeleton.
Commit message:
Implement EnvironProvider.SecretAttrs.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~jtv/juju-core/mpv-secret-attrs/+merge/152698
Yes, this was largely cargo-culted. It's not clear to me what sense it makes to return the secret portion of something, as opposed to giving you either the whole thing or only the part that may be seen publicly. But this is what the interface wants, and what the other providers implement.
Jeroen
--
https://code.launchpad.net/~jtv/juju-core/mpv-secret-attrs/+merge/152698
Your team MAAS Maintainers is requested to review the proposed merge of lp:~jtv/juju-core/mpv-secret-attrs into lp:~maas-maintainers/juju-core/maas-provider-skeleton.
=== modified file 'environs/maas/environprovider.go'
--- environs/maas/environprovider.go 2013-03-07 09:26:55 +0000
+++ environs/maas/environprovider.go 2013-03-11 15:14:22 +0000
@@ -28,8 +28,14 @@
}
// SecretAttrs is specified in the EnvironProvider interface.
-func (*maasEnvironProvider) SecretAttrs(*config.Config) (map[string]interface{}, error) {
- panic("Not implemented.")
+func (prov *maasEnvironProvider) SecretAttrs(cfg *config.Config) (map[string]interface{}, error) {
+ secretAttrs := make(map[string]interface{})
+ maasCfg, err := prov.newConfig(cfg)
+ if err != nil {
+ return nil, err
+ }
+ secretAttrs["maas-oauth"] = maasCfg.MAASOAuth()
+ return secretAttrs, nil
}
// PublicAddress is specified in the EnvironProvider interface.
=== added file 'environs/maas/environprovider_test.go'
--- environs/maas/environprovider_test.go 1970-01-01 00:00:00 +0000
+++ environs/maas/environprovider_test.go 2013-03-11 15:14:22 +0000
@@ -0,0 +1,40 @@
+package maas
+
+import (
+ . "launchpad.net/gocheck"
+ "launchpad.net/juju-core/environs/config"
+ "sort"
+)
+
+type EnvironProviderSuite struct {
+ ProviderSuite
+}
+
+var _ = Suite(new(EnvironProviderSuite))
+
+// Return (in lexicographical order) the keys in a map of the given type.
+func getMapKeys(original map[string]interface{}) []string {
+ keys := make([]string, 0)
+ for k, _ := range original {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+ return keys
+}
+
+func (suite *EnvironProviderSuite) TestSecretAttrsReturnsSensitiveMAASAttributes(c *C) {
+ attrs := map[string]interface{}{
+ "maas-oauth": "a:b:c",
+ "maas-server": "http://maas.example.com/maas/api/1.0/",
+ "name": "wheee",
+ "type": "maas",
+ }
+ config, err := config.New(attrs)
+ c.Assert(err, IsNil)
+
+ secretAttrs, err := suite.environ.Provider().SecretAttrs(config)
+ c.Assert(err, IsNil)
+
+ c.Check(getMapKeys(secretAttrs), DeepEquals, []string{"maas-oauth"})
+ c.Check(secretAttrs["maas-oauth"], Equals, attrs["maas-oauth"])
+}