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

Side by Side Diff: juju/conn.go

Issue 6632049: various: set passwords in state at bootstrap time.
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:
View unified diff | Download patch
OLDNEW
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 ) 8 )
8 9
9 // Conn holds a connection to a juju environment and its 10 // Conn holds a connection to a juju environment and its
10 // associated state. 11 // associated state.
11 type Conn struct { 12 type Conn struct {
12 Environ environs.Environ 13 Environ environs.Environ
13 State *state.State 14 State *state.State
14 } 15 }
15 16
16 // NewConn returns a new Conn that uses the 17 // NewConn returns a new Conn that uses the
17 // given environment. The environment must have already 18 // given environment. The environment must have already
18 // been bootstrapped. 19 // been bootstrapped.
19 func NewConn(environ environs.Environ) (*Conn, error) { 20 func NewConn(environ environs.Environ) (*Conn, error) {
20 info, err := environ.StateInfo() 21 info, err := environ.StateInfo()
21 if err != nil { 22 if err != nil {
22 return nil, err 23 return nil, err
23 } 24 }
25 password := environ.Config().AdminSecret()
26 info.Password = password
24 st, err := state.Open(info) 27 st, err := state.Open(info)
25 » if err != nil { 28 » if err == state.ErrUnauthorized {
29 » » // We can't connect with the administrator password,;
30 » » // perhaps we are 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.
32 » » info.Password = trivial.PasswordHash(password)
33 » » st, err = state.Open(info)
34 » » if err != nil {
35 » » » return nil, err
36 » » }
37 » » if err := st.SetAdminPassword(password); err != nil {
38 » » » return nil, err
39 » » }
niemeyer 2012/10/09 22:35:45 This turned out rather nice.
40 » } else if err != nil {
26 return nil, err 41 return nil, err
27 } 42 }
28 conn := &Conn{ 43 conn := &Conn{
29 Environ: environ, 44 Environ: environ,
30 State: st, 45 State: st,
31 } 46 }
32 if err := conn.updateSecrets(); err != nil { 47 if err := conn.updateSecrets(); err != nil {
33 conn.Close() 48 conn.Close()
34 return nil, fmt.Errorf("unable to push secrets: %v", err) 49 return nil, fmt.Errorf("unable to push secrets: %v", err)
35 } 50 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Environment already has secrets. Won't send again. 87 // Environment already has secrets. Won't send again.
73 return nil 88 return nil
74 } 89 }
75 } 90 }
76 cfg, err = cfg.Apply(secrets) 91 cfg, err = cfg.Apply(secrets)
77 if err != nil { 92 if err != nil {
78 return err 93 return err
79 } 94 }
80 return c.State.SetEnvironConfig(cfg) 95 return c.State.SetEnvironConfig(cfg)
81 } 96 }
OLDNEW

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