1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
// The plan package contains wireformat structs intended for
5
// subscription service plan management API.
9
"github.com/juju/errors"
10
"github.com/juju/utils"
11
"gopkg.in/juju/names.v2"
14
// Plan structure is used as a wire format to store information on ISV-created
15
// rating plan and charm URLs for which the plan is valid (a subscription
16
// using this plan can be created).
18
URL string `json:"url"` // Name of the rating plan
19
Definition string `json:"plan"` // The rating plan
20
CreatedOn string `json:"created-on"` // When the plan was created - RFC3339 encoded timestamp
23
// AuthorizationRequest defines the struct used to request a plan authorization.
24
type AuthorizationRequest struct {
25
EnvironmentUUID string `json:"env-uuid"` // TODO(cmars): rename to EnvUUID
26
CharmURL string `json:"charm-url"`
27
ServiceName string `json:"service-name"`
28
PlanURL string `json:"plan-url"`
31
// Validate checks the AuthorizationRequest for errors.
32
func (s AuthorizationRequest) Validate() error {
33
if !utils.IsValidUUIDString(s.EnvironmentUUID) {
34
return errors.Errorf("invalid environment UUID: %q", s.EnvironmentUUID)
36
if s.ServiceName == "" {
37
return errors.New("undefined service name")
39
if !names.IsValidApplication(s.ServiceName) {
40
return errors.Errorf("invalid service name: %q", s.ServiceName)
43
return errors.New("undefined charm url")
45
if !names.IsValidCharm(s.CharmURL) {
46
return errors.Errorf("invalid charm url: %q", s.CharmURL)
49
return errors.Errorf("undefined plan url")