~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/romulus/wireformat/plan/entities.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
// The plan package contains wireformat structs intended for
 
5
// subscription service plan management API.
 
6
package plan
 
7
 
 
8
import (
 
9
        "github.com/juju/errors"
 
10
        "github.com/juju/utils"
 
11
        "gopkg.in/juju/names.v2"
 
12
)
 
13
 
 
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).
 
17
type Plan struct {
 
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
 
21
}
 
22
 
 
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"`
 
29
}
 
30
 
 
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)
 
35
        }
 
36
        if s.ServiceName == "" {
 
37
                return errors.New("undefined service name")
 
38
        }
 
39
        if !names.IsValidApplication(s.ServiceName) {
 
40
                return errors.Errorf("invalid service name: %q", s.ServiceName)
 
41
        }
 
42
        if s.CharmURL == "" {
 
43
                return errors.New("undefined charm url")
 
44
        }
 
45
        if !names.IsValidCharm(s.CharmURL) {
 
46
                return errors.Errorf("invalid charm url: %q", s.CharmURL)
 
47
        }
 
48
        if s.PlanURL == "" {
 
49
                return errors.Errorf("undefined plan url")
 
50
        }
 
51
        return nil
 
52
}