LEFT | RIGHT |
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package agent | 4 package agent |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "path" | 8 "path" |
9 "regexp" | 9 "regexp" |
10 "sync" | 10 "sync" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // CACert returns the CA certificate that is used to validate the state
or | 59 // CACert returns the CA certificate that is used to validate the state
or |
60 // API servier's certificate. | 60 // API servier's certificate. |
61 CACert() []byte | 61 CACert() []byte |
62 | 62 |
63 // OpenAPI tries to connect to an API end-point. If a non-empty | 63 // OpenAPI tries to connect to an API end-point. If a non-empty |
64 // newPassword is returned, OpenAPI will have written the configuration | 64 // newPassword is returned, OpenAPI will have written the configuration |
65 // with the new password; the caller should set the connecting entity's | 65 // with the new password; the caller should set the connecting entity's |
66 // password accordingly. | 66 // password accordingly. |
67 OpenAPI(dialOpts api.DialOpts) (st *api.State, newPassword string, err e
rror) | 67 OpenAPI(dialOpts api.DialOpts) (st *api.State, newPassword string, err e
rror) |
68 | 68 |
69 » //APIAddresses returns the addresses needed to connect to the api server | 69 » // APIAddresses returns the addresses needed to connect to the api serve
r |
70 » APIAddresses() []string | 70 » APIAddresses() ([]string, error) |
71 | 71 |
72 // OpenState tries to open a direct connection to the state database usi
ng | 72 // OpenState tries to open a direct connection to the state database usi
ng |
73 // the given Conf. | 73 // the given Conf. |
74 OpenState() (*state.State, error) | 74 OpenState() (*state.State, error) |
75 | 75 |
76 // Write writes the agent configuration. | 76 // Write writes the agent configuration. |
77 Write() error | 77 Write() error |
78 | 78 |
79 // WriteCommands returns shell commands to write the agent configuration
. | 79 // WriteCommands returns shell commands to write the agent configuration
. |
80 // It returns an error if the configuration does not have all the right | 80 // It returns an error if the configuration does not have all the right |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 delete(c.values, key) | 295 delete(c.values, key) |
296 } else { | 296 } else { |
297 c.values[key] = value | 297 c.values[key] = value |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 func (c *configInternal) APIServerDetails() (port int, cert, key []byte) { | 301 func (c *configInternal) APIServerDetails() (port int, cert, key []byte) { |
302 return c.apiPort, c.stateServerCert, c.stateServerKey | 302 return c.apiPort, c.stateServerCert, c.stateServerKey |
303 } | 303 } |
304 | 304 |
305 func (c *configInternal) APIAddresses() []string { | 305 func (c *configInternal) APIAddresses() ([]string, error) { |
306 » return c.apiDetails.addresses | 306 » if c.apiDetails == nil { |
| 307 » » return []string{}, fmt.Errorf("No apidetails in config") |
| 308 » } |
| 309 » return append([]string{}, c.apiDetails.addresses...), nil |
307 } | 310 } |
308 | 311 |
309 func (c *configInternal) Tag() string { | 312 func (c *configInternal) Tag() string { |
310 return c.tag | 313 return c.tag |
311 } | 314 } |
312 | 315 |
313 func (c *configInternal) Dir() string { | 316 func (c *configInternal) Dir() string { |
314 return Dir(c.dataDir, c.tag) | 317 return Dir(c.dataDir, c.tag) |
315 } | 318 } |
316 | 319 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 } | 439 } |
437 // TODO(rog) remove this fallback behaviour when | 440 // TODO(rog) remove this fallback behaviour when |
438 // all initial connections are via the API. | 441 // all initial connections are via the API. |
439 if !errors.IsUnauthorizedError(err) { | 442 if !errors.IsUnauthorizedError(err) { |
440 return nil, err | 443 return nil, err |
441 } | 444 } |
442 } | 445 } |
443 info.Password = c.oldPassword | 446 info.Password = c.oldPassword |
444 return state.Open(&info, state.DefaultDialOpts()) | 447 return state.Open(&info, state.DefaultDialOpts()) |
445 } | 448 } |
LEFT | RIGHT |