Esempio n. 1
0
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)
}
Esempio n. 2
0
	"launchpad.net/gnuflag"

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

// authorizationClient defines the interface of an api client that
// the comand uses to create an authorization macaroon.
type authorizationClient interface {
	// Authorize returns the authorization macaroon for the specified environment,
	// charm url, service name and plan.
	Authorize(environmentUUID, charmURL, serviceName, plan string, visitWebPage func(*url.URL) error) (*macaroon.Macaroon, error)
}

var newAuthorizationClient = func(options ...api.ClientOption) (authorizationClient, error) {
	return api.NewAuthorizationClient(options...)
}

// NewSetPlanCommand returns a new command that is used to set metric credentials for a
// deployed service.
func NewSetPlanCommand() cmd.Command {
	return modelcmd.Wrap(&setPlanCommand{})
}

// setPlanCommand is a command-line tool for setting
// Service.MetricCredential for development & demonstration purposes.
type setPlanCommand struct {
	modelcmd.ModelCommandBase
	rcmd.HttpCommand

	Service string