@@ -9,6 +9,15 @@ import (
99 "github.com/deis/deis/deisctl/utils"
1010)
1111
12+ // fileKeys define config keys to be read from local files
13+ var fileKeys = []string {
14+ "/deis/platform/sshPrivateKey" ,
15+ "/deis/router/sslCert" ,
16+ "/deis/router/sslKey" }
17+
18+ // b64Keys define config keys to be base64 encoded before stored
19+ var b64Keys = []string {"/deis/platform/sshPrivateKey" }
20+
1221// Config runs the config subcommand
1322func Config (args map [string ]interface {}) error {
1423 return doConfig (args )
@@ -62,25 +71,14 @@ func doConfigSet(client *etcdClient, root string, kvs []string) ([]string, error
6271 for _ , kv := range kvs {
6372
6473 // split k/v from args
65- split := strings .Split (kv , "=" )
66- if len (split ) != 2 {
67- return result , fmt .Errorf ("invalid argument: %v" , kv )
68- }
74+ split := strings .SplitN (kv , "=" , 2 )
6975 k , v := split [0 ], split [1 ]
7076
7177 // prepare path and value
7278 path := root + k
73- var val string
74-
75- // special handling for sshKey
76- if path == "/deis/platform/sshPrivateKey" {
77- b64 , err := readSSHPrivateKey (utils .ResolvePath (v ))
78- if err != nil {
79- return result , err
80- }
81- val = b64
82- } else {
83- val = v
79+ val , err := valueForPath (path , v )
80+ if err != nil {
81+ return result , err
8482 }
8583
8684 // set key/value in etcd
@@ -106,13 +104,31 @@ func doConfigGet(client *etcdClient, root string, keys []string) ([]string, erro
106104 return result , nil
107105}
108106
109- // readSSHPrivateKey reads the key file and returns a base64 encoded string
110- func readSSHPrivateKey (path string ) (string , error ) {
107+ // valueForPath returns the canonical value for a user-defined path and value
108+ func valueForPath (path string , v string ) (string , error ) {
111109
112- bytes , err := ioutil .ReadFile (path )
113- if err != nil {
114- return "" , err
110+ // check if path is part of fileKeys
111+ for _ , p := range fileKeys {
112+
113+ if path == p {
114+
115+ // read value from filesystem
116+ bytes , err := ioutil .ReadFile (utils .ResolvePath (v ))
117+ if err != nil {
118+ return "" , err
119+ }
120+
121+ // see if we should return base64 encoded value
122+ for _ , pp := range b64Keys {
123+ if path == pp {
124+ return base64 .StdEncoding .EncodeToString (bytes ), nil
125+ }
126+ }
127+
128+ return string (bytes ), nil
129+ }
115130 }
116131
117- return base64 .StdEncoding .EncodeToString (bytes ), nil
132+ return v , nil
133+
118134}
0 commit comments