Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1023)

Delta Between Two Patch Sets: juju/conn.go

Issue 6856105: various: use TLS
Left Patch Set: various: use TLS Created 12 years, 4 months ago
Right Patch Set: various: use TLS Created 12 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « environs/ec2/live_test.go ('k') | state/open.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 package juju 1 package juju
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "crypto/sha256" 5 "crypto/sha256"
6 "encoding/hex" 6 "encoding/hex"
7 "fmt" 7 "fmt"
8 "io" 8 "io"
9 "launchpad.net/juju-core/charm" 9 "launchpad.net/juju-core/charm"
10 "launchpad.net/juju-core/environs" 10 "launchpad.net/juju-core/environs"
11 "launchpad.net/juju-core/log" 11 "launchpad.net/juju-core/log"
12 "launchpad.net/juju-core/state" 12 "launchpad.net/juju-core/state"
13 "launchpad.net/juju-core/trivial" 13 "launchpad.net/juju-core/trivial"
14 "net/url" 14 "net/url"
15 "os" 15 "os"
16 "time"
16 ) 17 )
17 18
18 // Conn holds a connection to a juju environment and its 19 // Conn holds a connection to a juju environment and its
19 // associated state. 20 // associated state.
20 type Conn struct { 21 type Conn struct {
21 Environ environs.Environ 22 Environ environs.Environ
22 State *state.State 23 State *state.State
24 }
25
26 var redialStrategy = trivial.AttemptStrategy{
27 Total: 60 * time.Second,
28 Delay: 250 * time.Millisecond,
23 } 29 }
24 30
25 // NewConn returns a new Conn that uses the 31 // NewConn returns a new Conn that uses the
26 // given environment. The environment must have already 32 // given environment. The environment must have already
27 // been bootstrapped. 33 // been bootstrapped.
28 func NewConn(environ environs.Environ) (*Conn, error) { 34 func NewConn(environ environs.Environ) (*Conn, error) {
29 info, err := environ.StateInfo() 35 info, err := environ.StateInfo()
30 if err != nil { 36 if err != nil {
31 return nil, err 37 return nil, err
32 } 38 }
33 password := environ.Config().AdminSecret() 39 password := environ.Config().AdminSecret()
34 if password == "" { 40 if password == "" {
35 return nil, fmt.Errorf("cannot connect without admin-secret") 41 return nil, fmt.Errorf("cannot connect without admin-secret")
36 } 42 }
37 info.Password = password 43 info.Password = password
38 st, err := state.Open(info) 44 st, err := state.Open(info)
39 if err == state.ErrUnauthorized { 45 if err == state.ErrUnauthorized {
40 // We can't connect with the administrator password,; 46 // We can't connect with the administrator password,;
41 // perhaps this was the first connection and the 47 // perhaps this was the first connection and the
42 // password has not been changed yet. 48 // password has not been changed yet.
43 info.Password = trivial.PasswordHash(password) 49 info.Password = trivial.PasswordHash(password)
44 » » st, err = state.Open(info) 50
51 » » // We try for a while because we might succeed in
52 » » // connecting to mongo before the state has been
53 » » // initialized and the initial password set.
54 » » for a := redialStrategy.Start(); a.Next(); {
55 » » » st, err = state.Open(info)
56 » » » if err != state.ErrUnauthorized {
57 » » » » break
58 » » » }
59 » » }
45 if err != nil { 60 if err != nil {
46 return nil, err 61 return nil, err
47 } 62 }
48 if err := st.SetAdminPassword(password); err != nil { 63 if err := st.SetAdminPassword(password); err != nil {
49 return nil, err 64 return nil, err
50 } 65 }
51 } else if err != nil { 66 } else if err != nil {
52 return nil, err 67 return nil, err
53 } 68 }
54 conn := &Conn{ 69 conn := &Conn{
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 261 }
247 if status != state.UnitError { 262 if status != state.UnitError {
248 return fmt.Errorf("unit %q is not in an error state", unit) 263 return fmt.Errorf("unit %q is not in an error state", unit)
249 } 264 }
250 mode := state.ResolvedNoHooks 265 mode := state.ResolvedNoHooks
251 if retryHooks { 266 if retryHooks {
252 mode = state.ResolvedRetryHooks 267 mode = state.ResolvedRetryHooks
253 } 268 }
254 return unit.SetResolved(mode) 269 return unit.SetResolved(mode)
255 } 270 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b