~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/api/interface.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import (
7
7
        "time"
8
8
 
 
9
        "github.com/juju/errors"
9
10
        "github.com/juju/names"
 
11
        "github.com/juju/version"
10
12
        "gopkg.in/macaroon-bakery.v1/httpbakery"
 
13
        "gopkg.in/macaroon.v1"
11
14
 
12
15
        "github.com/juju/juju/api/addresser"
13
16
        "github.com/juju/juju/api/agent"
27
30
        "github.com/juju/juju/api/upgrader"
28
31
        "github.com/juju/juju/network"
29
32
        "github.com/juju/juju/rpc"
30
 
        "github.com/juju/juju/version"
31
33
)
32
34
 
33
35
// Info encapsulates information about a server holding juju state and
50
52
        // ...but this block of fields is all about the authentication mechanism
51
53
        // to use after connecting -- if any -- and should probably be extracted.
52
54
 
53
 
        // UseMacaroons, when true, enables macaroon-based login and ignores
54
 
        // the provided username and password.
55
 
        UseMacaroons bool `yaml:"use-macaroons,omitempty"`
 
55
        // SkipLogin, if true, skips the Login call on connection. It is an
 
56
        // error to set Tag, Password, or Macaroons if SkipLogin is true.
 
57
        SkipLogin bool `yaml:"-"`
56
58
 
57
59
        // Tag holds the name of the entity that is connecting.
58
60
        // If this is nil, and the password is empty, no login attempt will be made.
63
65
        // Password holds the password for the administrator or connecting entity.
64
66
        Password string
65
67
 
 
68
        // Macaroons holds a slice of macaroon.Slice that may be used to
 
69
        // authenticate with the API server.
 
70
        Macaroons []macaroon.Slice `yaml:",omitempty"`
 
71
 
66
72
        // Nonce holds the nonce used when provisioning the machine. Used
67
73
        // only by the machine agent.
68
74
        Nonce string `yaml:",omitempty"`
69
75
}
70
76
 
 
77
// Validate validates the API info.
 
78
func (info *Info) Validate() error {
 
79
        if len(info.Addrs) == 0 {
 
80
                return errors.NotValidf("missing addresses")
 
81
        }
 
82
        if info.CACert == "" {
 
83
                return errors.NotValidf("missing CA certificate")
 
84
        }
 
85
        if info.SkipLogin {
 
86
                if info.Tag != nil {
 
87
                        return errors.NotValidf("specifying Tag and SkipLogin")
 
88
                }
 
89
                if info.Password != "" {
 
90
                        return errors.NotValidf("specifying Password and SkipLogin")
 
91
                }
 
92
                if len(info.Macaroons) > 0 {
 
93
                        return errors.NotValidf("specifying Macaroons and SkipLogin")
 
94
                }
 
95
        }
 
96
        return nil
 
97
}
 
98
 
71
99
// DialOpts holds configuration parameters that control the
72
100
// Dialing behavior when connecting to a controller.
73
101
type DialOpts struct {
125
153
 
126
154
        // These are a bit off -- ServerVersion is apparently not known until after
127
155
        // Login()? Maybe evidence of need for a separate AuthenticatedConnection..?
128
 
        Login(name names.Tag, password, nonce string) error
 
156
        Login(name names.Tag, password, nonce string, ms []macaroon.Slice) error
129
157
        ServerVersion() (version.Number, bool)
130
158
 
131
159
        // APICaller provides the facility to make API calls directly.