OLD | NEW |
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // APIServerDetails returns the details needed to run an API server. | 87 // APIServerDetails returns the details needed to run an API server. |
88 APIServerDetails() (port int, cert, key []byte) | 88 APIServerDetails() (port int, cert, key []byte) |
89 | 89 |
90 // Value returns the value associated with the key, or an empty string i
f | 90 // Value returns the value associated with the key, or an empty string i
f |
91 // the key is not found. | 91 // the key is not found. |
92 Value(key string) string | 92 Value(key string) string |
93 | 93 |
94 // SetValue updates the value for the specified key. | 94 // SetValue updates the value for the specified key. |
95 SetValue(key, value string) | 95 SetValue(key, value string) |
96 | 96 |
| 97 // StatePort specifies the TCP port that will be used |
| 98 // by the MongoDB server if one is running on this machine. |
| 99 StatePort() int |
| 100 |
97 StateInitializer | 101 StateInitializer |
98 } | 102 } |
99 | 103 |
100 // Ensure that the configInternal struct implements the Config interface. | 104 // Ensure that the configInternal struct implements the Config interface. |
101 var _ Config = (*configInternal)(nil) | 105 var _ Config = (*configInternal)(nil) |
102 | 106 |
103 // The configMutex should be locked before any writing to disk during the | 107 // The configMutex should be locked before any writing to disk during the |
104 // write commands, and unlocked when the writing is complete. This process | 108 // write commands, and unlocked when the writing is complete. This process |
105 // wide lock should stop any unintended concurrent writes. This may happen | 109 // wide lock should stop any unintended concurrent writes. This may happen |
106 // when multiple go-routines may be adding things to the agent config, and | 110 // when multiple go-routines may be adding things to the agent config, and |
(...skipping 18 matching lines...) Expand all Loading... |
125 tag string | 129 tag string |
126 nonce string | 130 nonce string |
127 caCert []byte | 131 caCert []byte |
128 stateDetails *connectionDetails | 132 stateDetails *connectionDetails |
129 apiDetails *connectionDetails | 133 apiDetails *connectionDetails |
130 oldPassword string | 134 oldPassword string |
131 stateServerCert []byte | 135 stateServerCert []byte |
132 stateServerKey []byte | 136 stateServerKey []byte |
133 apiPort int | 137 apiPort int |
134 values map[string]string | 138 values map[string]string |
| 139 statePort int |
135 } | 140 } |
136 | 141 |
137 type AgentConfigParams struct { | 142 type AgentConfigParams struct { |
138 DataDir string | 143 DataDir string |
139 Tag string | 144 Tag string |
140 Password string | 145 Password string |
141 Nonce string | 146 Nonce string |
142 StateAddresses []string | 147 StateAddresses []string |
143 APIAddresses []string | 148 APIAddresses []string |
144 CACert []byte | 149 CACert []byte |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 return nil, requiredError("state server key") | 212 return nil, requiredError("state server key") |
208 } | 213 } |
209 config0, err := NewAgentConfig(params.AgentConfigParams) | 214 config0, err := NewAgentConfig(params.AgentConfigParams) |
210 if err != nil { | 215 if err != nil { |
211 return nil, err | 216 return nil, err |
212 } | 217 } |
213 config := config0.(*configInternal) | 218 config := config0.(*configInternal) |
214 config.stateServerCert = params.StateServerCert | 219 config.stateServerCert = params.StateServerCert |
215 config.stateServerKey = params.StateServerKey | 220 config.stateServerKey = params.StateServerKey |
216 config.apiPort = params.APIPort | 221 config.apiPort = params.APIPort |
| 222 config.statePort = params.StatePort |
217 return config, nil | 223 return config, nil |
218 } | 224 } |
219 | 225 |
220 // Dir returns the agent-specific data directory. | 226 // Dir returns the agent-specific data directory. |
221 func Dir(dataDir, agentName string) string { | 227 func Dir(dataDir, agentName string) string { |
222 return path.Join(dataDir, "agents", agentName) | 228 return path.Join(dataDir, "agents", agentName) |
223 } | 229 } |
224 | 230 |
225 // ReadConf reads configuration data for the given | 231 // ReadConf reads configuration data for the given |
226 // entity from the given data directory. | 232 // entity from the given data directory. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } | 319 } |
314 | 320 |
315 func (c *configInternal) Tag() string { | 321 func (c *configInternal) Tag() string { |
316 return c.tag | 322 return c.tag |
317 } | 323 } |
318 | 324 |
319 func (c *configInternal) Dir() string { | 325 func (c *configInternal) Dir() string { |
320 return Dir(c.dataDir, c.tag) | 326 return Dir(c.dataDir, c.tag) |
321 } | 327 } |
322 | 328 |
| 329 func (c *configInternal) StatePort() int { |
| 330 return c.statePort |
| 331 } |
| 332 |
323 func (c *configInternal) check() error { | 333 func (c *configInternal) check() error { |
324 if c.stateDetails == nil && c.apiDetails == nil { | 334 if c.stateDetails == nil && c.apiDetails == nil { |
325 return requiredError("state or API addresses") | 335 return requiredError("state or API addresses") |
326 } | 336 } |
327 if c.stateDetails != nil { | 337 if c.stateDetails != nil { |
328 if err := checkAddrs(c.stateDetails.addresses, "state server add
ress"); err != nil { | 338 if err := checkAddrs(c.stateDetails.addresses, "state server add
ress"); err != nil { |
329 return err | 339 return err |
330 } | 340 } |
331 } | 341 } |
332 if c.apiDetails != nil { | 342 if c.apiDetails != nil { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 } | 452 } |
443 // TODO(rog) remove this fallback behaviour when | 453 // TODO(rog) remove this fallback behaviour when |
444 // all initial connections are via the API. | 454 // all initial connections are via the API. |
445 if !errors.IsUnauthorizedError(err) { | 455 if !errors.IsUnauthorizedError(err) { |
446 return nil, err | 456 return nil, err |
447 } | 457 } |
448 } | 458 } |
449 info.Password = c.oldPassword | 459 info.Password = c.oldPassword |
450 return state.Open(&info, state.DefaultDialOpts()) | 460 return state.Open(&info, state.DefaultDialOpts()) |
451 } | 461 } |
OLD | NEW |