func (s *cloudSuite) TestCloud(c *gc.C) { apiCaller := basetesting.APICallerFunc( func(objType string, version int, id, request string, a, result interface{}, ) error { c.Check(objType, gc.Equals, "Cloud") c.Check(id, gc.Equals, "") c.Check(request, gc.Equals, "Cloud") c.Check(a, jc.DeepEquals, params.Entities{ Entities: []params.Entity{{Tag: "cloud-foo"}}, }) c.Assert(result, gc.FitsTypeOf, ¶ms.CloudResults{}) results := result.(*params.CloudResults) results.Results = append(results.Results, params.CloudResult{ Cloud: ¶ms.Cloud{ Type: "dummy", AuthTypes: []string{"empty", "userpass"}, Regions: []params.CloudRegion{{Name: "nether", Endpoint: "endpoint"}}, }, }) return nil }, ) client := cloudapi.NewClient(apiCaller) result, err := client.Cloud(names.NewCloudTag("foo")) c.Assert(err, jc.ErrorIsNil) c.Assert(result, jc.DeepEquals, cloud.Cloud{ Type: "dummy", AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType}, Regions: []cloud.Region{{Name: "nether", Endpoint: "endpoint"}}, }) }
func (s *cloudSuite) TestRevokeCredential(c *gc.C) { var called bool apiCaller := basetesting.APICallerFunc( func(objType string, version int, id, request string, a, result interface{}, ) error { c.Check(objType, gc.Equals, "Cloud") c.Check(id, gc.Equals, "") c.Check(request, gc.Equals, "RevokeCredentials") c.Assert(result, gc.FitsTypeOf, ¶ms.ErrorResults{}) c.Assert(a, jc.DeepEquals, params.Entities{Entities: []params.Entity{{ Tag: "cloudcred-foo_bob_bar", }}}) *result.(*params.ErrorResults) = params.ErrorResults{ Results: []params.ErrorResult{{}}, } called = true return nil }, ) client := cloudapi.NewClient(apiCaller) tag := names.NewCloudCredentialTag("foo/bob/bar") err := client.RevokeCredential(tag) c.Assert(err, jc.ErrorIsNil) c.Assert(called, jc.IsTrue) }
func (s *cloudSuite) TestUserCredentials(c *gc.C) { apiCaller := basetesting.APICallerFunc( func(objType string, version int, id, request string, a, result interface{}, ) error { c.Check(objType, gc.Equals, "Cloud") c.Check(id, gc.Equals, "") c.Check(request, gc.Equals, "UserCredentials") c.Assert(result, gc.FitsTypeOf, ¶ms.StringsResults{}) c.Assert(a, jc.DeepEquals, params.UserClouds{UserClouds: []params.UserCloud{{ UserTag: "user-bob", CloudTag: "cloud-foo", }}}) *result.(*params.StringsResults) = params.StringsResults{ Results: []params.StringsResult{{ Result: []string{ "cloudcred-foo_bob_one", "cloudcred-foo_bob_two", }, }}, } return nil }, ) client := cloudapi.NewClient(apiCaller) result, err := client.UserCredentials(names.NewUserTag("bob"), names.NewCloudTag("foo")) c.Assert(err, jc.ErrorIsNil) c.Assert(result, jc.SameContents, []names.CloudCredentialTag{ names.NewCloudCredentialTag("foo/bob/one"), names.NewCloudCredentialTag("foo/bob/two"), }) }
func (c *updateCredentialCommand) getAPI() (credentialAPI, error) { if c.api != nil { return c.api, nil } api, err := c.NewAPIRoot() if err != nil { return nil, errors.Annotate(err, "opening API connection") } return apicloud.NewClient(api), nil }
// NewAddModelCommand returns a command to add a model. func NewAddModelCommand() cmd.Command { return modelcmd.WrapController(&addModelCommand{ newAddModelAPI: func(caller base.APICallCloser) AddModelAPI { return modelmanager.NewClient(caller) }, newCloudAPI: func(caller base.APICallCloser) CloudAPI { return cloudapi.NewClient(caller) }, }) }
func (s *cloudSuite) TestCredentials(c *gc.C) { apiCaller := basetesting.APICallerFunc( func(objType string, version int, id, request string, a, result interface{}, ) error { c.Check(objType, gc.Equals, "Cloud") c.Check(id, gc.Equals, "") c.Check(request, gc.Equals, "Credential") c.Assert(result, gc.FitsTypeOf, ¶ms.CloudCredentialResults{}) c.Assert(a, jc.DeepEquals, params.Entities{Entities: []params.Entity{{ Tag: "cloudcred-foo_bob_bar", }}}) *result.(*params.CloudCredentialResults) = params.CloudCredentialResults{ Results: []params.CloudCredentialResult{ { Result: ¶ms.CloudCredential{ AuthType: "userpass", Attributes: map[string]string{"username": "******"}, Redacted: []string{"password"}, }, }, { Result: ¶ms.CloudCredential{ AuthType: "userpass", Attributes: map[string]string{"username": "******"}, Redacted: []string{"password"}, }, }, }, } return nil }, ) client := cloudapi.NewClient(apiCaller) tag := names.NewCloudCredentialTag("foo/bob/bar") result, err := client.Credentials(tag) c.Assert(err, jc.ErrorIsNil) c.Assert(result, jc.DeepEquals, []params.CloudCredentialResult{ { Result: ¶ms.CloudCredential{ AuthType: "userpass", Attributes: map[string]string{"username": "******"}, Redacted: []string{"password"}, }, }, { Result: ¶ms.CloudCredential{ AuthType: "userpass", Attributes: map[string]string{"username": "******"}, Redacted: []string{"password"}, }, }, }) }
// NewDefaultsCommand wraps defaultsCommand with sane model settings. func NewDefaultsCommand() cmd.Command { defaultsCmd := &defaultsCommand{ newCloudAPI: func(caller base.APICallCloser) cloudAPI { return cloudapi.NewClient(caller) }, newDefaultsAPI: func(caller base.APICallCloser) defaultsCommandAPI { return modelmanager.NewClient(caller) }, } defaultsCmd.newAPIRoot = defaultsCmd.NewAPIRoot return modelcmd.WrapController(defaultsCmd) }
func (s *cloudSuite) TestClouds(c *gc.C) { apiCaller := basetesting.APICallerFunc( func(objType string, version int, id, request string, a, result_ interface{}, ) error { c.Check(objType, gc.Equals, "Cloud") c.Check(id, gc.Equals, "") c.Check(request, gc.Equals, "Clouds") c.Check(a, gc.IsNil) c.Assert(result_, gc.FitsTypeOf, ¶ms.CloudsResult{}) result := result_.(*params.CloudsResult) result.Clouds = map[string]params.Cloud{ "cloud-foo": { Type: "bar", }, "cloud-baz": { Type: "qux", AuthTypes: []string{"empty", "userpass"}, Regions: []params.CloudRegion{{Name: "nether", Endpoint: "endpoint"}}, }, } return nil }, ) client := cloudapi.NewClient(apiCaller) clouds, err := client.Clouds() c.Assert(err, jc.ErrorIsNil) c.Assert(clouds, jc.DeepEquals, map[names.CloudTag]cloud.Cloud{ names.NewCloudTag("foo"): { Type: "bar", }, names.NewCloudTag("baz"): { Type: "qux", AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType}, Regions: []cloud.Region{{Name: "nether", Endpoint: "endpoint"}}, }, }) }
func (s *cloudSuite) TestUpdateCredentials(c *gc.C) { var called bool apiCaller := basetesting.APICallerFunc( func(objType string, version int, id, request string, a, result interface{}, ) error { c.Check(objType, gc.Equals, "Cloud") c.Check(id, gc.Equals, "") c.Check(request, gc.Equals, "UpdateCredentials") c.Assert(result, gc.FitsTypeOf, ¶ms.ErrorResults{}) c.Assert(a, jc.DeepEquals, params.UpdateCloudCredentials{Credentials: []params.UpdateCloudCredential{{ Tag: "cloudcred-foo_bob_bar", Credential: params.CloudCredential{ AuthType: "userpass", Attributes: map[string]string{ "username": "******", "password": "******", }, }, }}}) *result.(*params.ErrorResults) = params.ErrorResults{ Results: []params.ErrorResult{{}}, } called = true return nil }, ) client := cloudapi.NewClient(apiCaller) tag := names.NewCloudCredentialTag("foo/bob/bar") err := client.UpdateCredential(tag, cloud.NewCredential(cloud.UserPassAuthType, map[string]string{ "username": "******", "password": "******", })) c.Assert(err, jc.ErrorIsNil) c.Assert(called, jc.IsTrue) }
func (s *cloudSuite) TestDefaultCloud(c *gc.C) { apiCaller := basetesting.APICallerFunc( func(objType string, version int, id, request string, a, result interface{}, ) error { c.Check(objType, gc.Equals, "Cloud") c.Check(id, gc.Equals, "") c.Check(request, gc.Equals, "DefaultCloud") c.Assert(result, gc.FitsTypeOf, ¶ms.StringResult{}) results := result.(*params.StringResult) results.Result = "cloud-foo" return nil }, ) client := cloudapi.NewClient(apiCaller) result, err := client.DefaultCloud() c.Assert(err, jc.ErrorIsNil) c.Assert(result, jc.DeepEquals, names.NewCloudTag("foo")) }
func (s *CloudAPISuite) SetUpTest(c *gc.C) { s.JujuConnSuite.SetUpTest(c) s.client = apicloud.NewClient(s.OpenControllerAPI(c)) }