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

Delta Between Two Patch Sets: juju/conn.go

Issue 6632049: various: set passwords in state at bootstrap time.
Left Patch Set: various: set passwords in state at bootstrap time. Created 12 years, 5 months ago
Right Patch Set: various: set passwords in state at bootstrap time. Created 12 years, 5 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « environs/interface.go ('k') | juju/conn_test.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
1 package juju 1 package juju
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "launchpad.net/juju-core/environs" 5 "launchpad.net/juju-core/environs"
6 "launchpad.net/juju-core/state" 6 "launchpad.net/juju-core/state"
7 "launchpad.net/juju-core/trivial" 7 "launchpad.net/juju-core/trivial"
8 ) 8 )
9 9
10 // Conn holds a connection to a juju environment and its 10 // Conn holds a connection to a juju environment and its
11 // associated state. 11 // associated state.
12 type Conn struct { 12 type Conn struct {
13 Environ environs.Environ 13 Environ environs.Environ
14 State *state.State 14 State *state.State
15 } 15 }
16 16
17 // NewConn returns a new Conn that uses the 17 // NewConn returns a new Conn that uses the
18 // given environment. The environment must have already 18 // given environment. The environment must have already
19 // been bootstrapped. 19 // been bootstrapped.
20 func NewConn(environ environs.Environ) (*Conn, error) { 20 func NewConn(environ environs.Environ) (*Conn, error) {
21 info, err := environ.StateInfo() 21 info, err := environ.StateInfo()
22 if err != nil { 22 if err != nil {
23 return nil, err 23 return nil, err
24 } 24 }
25 password := environ.Config().AdminSecret() 25 password := environ.Config().AdminSecret()
26 info.Password = password 26 info.Password = password
27 st, err := state.Open(info) 27 st, err := state.Open(info)
28 if err == state.ErrUnauthorized { 28 if err == state.ErrUnauthorized {
29 // We can't connect with the administrator password,; 29 // We can't connect with the administrator password,;
30 » » // perhaps we are the first connection and the 30 » » // perhaps this was the first connection and the
niemeyer 2012/10/09 22:35:45 s/we are/this was/
rog 2012/10/11 10:51:13 Done.
31 // password has not been changed yet. 31 // password has not been changed yet.
32 info.Password = trivial.PasswordHash(password) 32 info.Password = trivial.PasswordHash(password)
33 st, err = state.Open(info) 33 st, err = state.Open(info)
34 if err != nil { 34 if err != nil {
35 return nil, err 35 return nil, err
36 } 36 }
37 if err := st.SetAdminPassword(password); err != nil { 37 if err := st.SetAdminPassword(password); err != nil {
38 return nil, err 38 return nil, err
39 } 39 }
niemeyer 2012/10/09 22:35:45 This turned out rather nice.
40 } else if err != nil { 40 } else if err != nil {
41 return nil, err 41 return nil, err
42 } 42 }
43 conn := &Conn{ 43 conn := &Conn{
44 Environ: environ, 44 Environ: environ,
45 State: st, 45 State: st,
46 } 46 }
47 if err := conn.updateSecrets(); err != nil { 47 if err := conn.updateSecrets(); err != nil {
48 conn.Close() 48 conn.Close()
49 return nil, fmt.Errorf("unable to push secrets: %v", err) 49 return nil, fmt.Errorf("unable to push secrets: %v", err)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // Environment already has secrets. Won't send again. 87 // Environment already has secrets. Won't send again.
88 return nil 88 return nil
89 } 89 }
90 } 90 }
91 cfg, err = cfg.Apply(secrets) 91 cfg, err = cfg.Apply(secrets)
92 if err != nil { 92 if err != nil {
93 return err 93 return err
94 } 94 }
95 return c.State.SetEnvironConfig(cfg) 95 return c.State.SetEnvironConfig(cfg)
96 } 96 }
LEFTRIGHT

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