示例#1
0
func (c *setPlanCommand) requestMetricCredentials() ([]byte, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	jclient := service.NewClient(root)
	envUUID := jclient.ModelUUID()
	charmURL, err := jclient.GetCharmURL(c.Service)
	if err != nil {
		return nil, errors.Trace(err)
	}

	hc, err := c.NewClient()
	if err != nil {
		return nil, errors.Trace(err)
	}
	client, err := newAuthorizationClient(api.HTTPClient(hc))
	if err != nil {
		return nil, errors.Trace(err)
	}
	m, err := client.Authorize(envUUID, charmURL.String(), c.Service, c.Plan, httpbakery.OpenWebBrowser)
	if err != nil {
		return nil, errors.Trace(err)
	}
	ms := macaroon.Slice{m}
	return json.Marshal(ms)
}
示例#2
0
文件: api_test.go 项目: juju/romulus
func (s *clientSuite) SetUpTest(c *gc.C) {
	s.httpClient = &mockHttpClient{}

	client, err := api.NewClient(api.HTTPClient(s.httpClient))
	c.Assert(err, jc.ErrorIsNil)
	s.client = client

}
示例#3
0
文件: api_test.go 项目: juju/romulus
func (s *clientSuite) TestAuthorize(c *gc.C) {
	envUUID := utils.MustNewUUID()
	charmURL := "cs:trusty/test-charm-0"
	service := "test-charm"
	plan := utils.MustNewUUID()

	m, err := macaroon.New(nil, "", "")
	c.Assert(err, jc.ErrorIsNil)
	data, err := json.Marshal(m)
	c.Assert(err, jc.ErrorIsNil)

	httpClient := &mockHttpClient{}
	httpClient.status = http.StatusOK
	httpClient.body = data
	authClient, err := api.NewAuthorizationClient(api.HTTPClient(httpClient))
	c.Assert(err, jc.ErrorIsNil)
	_, err = authClient.Authorize(envUUID.String(), charmURL, service, plan.String(), nil)
	c.Assert(err, jc.ErrorIsNil)
}
示例#4
0
文件: api_test.go 项目: juju/romulus
func (s *clientSuite) TestBaseURL(c *gc.C) {
	client, err := api.NewClient(api.HTTPClient(s.httpClient), api.BaseURL("https://example.com"))
	c.Assert(err, jc.ErrorIsNil)

	s.httpClient.status = http.StatusNotFound
	_, err = client.GetAssociatedPlans("bob/uptime")
	c.Assert(err, gc.ErrorMatches, `failed to retrieve associated plans: received http response:  - code "Not Found"`)
	s.httpClient.CheckCall(c, 0, "Do", "https://example.com/charm?charm-url=bob%2Fuptime")
	s.httpClient.ResetCalls()

	m, err := macaroon.New(nil, "", "")
	c.Assert(err, jc.ErrorIsNil)
	data, err := json.Marshal(m)
	c.Assert(err, jc.ErrorIsNil)

	s.httpClient.status = http.StatusOK
	s.httpClient.body = data
	_, err = client.Authorize(utils.MustNewUUID().String(), "cs:trusty/test-charm-0", "test-charm", utils.MustNewUUID().String(), nil)
	c.Assert(err, jc.ErrorIsNil)
	s.httpClient.CheckCall(c, 0, "DoWithBody", "https://example.com/plan/authorize")
}
示例#5
0
func (c *setPlanCommand) requestMetricCredentials(client *application.Client, ctx *cmd.Context) ([]byte, error) {
	envUUID := client.ModelUUID()
	charmURL, err := client.GetCharmURL(c.Application)
	if err != nil {
		return nil, errors.Trace(err)
	}

	hc, err := c.BakeryClient()
	if err != nil {
		return nil, errors.Trace(err)
	}
	authClient, err := newAuthorizationClient(api.HTTPClient(hc))
	if err != nil {
		return nil, errors.Trace(err)
	}
	m, err := authClient.Authorize(envUUID, charmURL.String(), c.Application, c.Plan, hc.VisitWebPage)
	if err != nil {
		return nil, errors.Trace(err)
	}
	ms := macaroon.Slice{m}
	return json.Marshal(ms)
}
示例#6
0
	"gopkg.in/yaml.v2"
	"launchpad.net/gnuflag"

	api "github.com/juju/romulus/api/plan"
	rcmd "github.com/juju/romulus/cmd"
	wireformat "github.com/juju/romulus/wireformat/plan"
)

// apiClient defines the interface of the plan api client need by this command.
type apiClient interface {
	// GetAssociatedPlans returns the plans associated with the charm.
	GetAssociatedPlans(charmURL string) ([]wireformat.Plan, error)
}

var newClient = func(client *httpbakery.Client) (apiClient, error) {
	return api.NewClient(api.HTTPClient(client))
}

const listPlansDoc = `
List plans available for the specified charm.

Examples:
    juju plans cs:webapp
`

// ListPlansCommand retrieves plans that are available for the specified charm
type ListPlansCommand struct {
	modelcmd.JujuCommandBase

	out      cmd.Output
	CharmURL string