@@ -30,16 +30,16 @@ import (
3030 "github.com/apache/incubator-openwhisk-wskdeploy/parsers"
3131 "github.com/apache/incubator-openwhisk-wskdeploy/utils"
3232 "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
33- "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
3433 "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
34+ "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
3535)
3636
3737const (
38- COMMANDLINE = "wskdeploy command line"
38+ COMMANDLINE = "wskdeploy command line"
3939 DEFAULTVALUE = "default value"
40- WSKPROPS = ".wskprops"
40+ WSKPROPS = ".wskprops"
4141 WHISKPROPERTY = "whisk.properties"
42- INTERINPUT = "interactve input"
42+ INTERINPUT = "interactve input"
4343)
4444
4545type PropertyValue struct {
@@ -67,7 +67,7 @@ var GetCommandLineFlags = func() (string, string, string, string, string) {
6767 return utils .Flags .ApiHost , utils .Flags .Auth , utils .Flags .Namespace , utils .Flags .Key , utils .Flags .Cert
6868}
6969
70- var CreateNewClient = func (config_input * whisk.Config ) (* whisk.Client , error ) {
70+ var CreateNewClient = func (config_input * whisk.Config ) (* whisk.Client , error ) {
7171 var netClient = & http.Client {
7272 Timeout : time .Second * utils .DEFAULT_HTTP_TIMEOUT ,
7373 }
@@ -85,16 +85,16 @@ func NewWhiskConfig(proppath string, deploymentPath string, manifestPath string,
8585 credential := PropertyValue {}
8686 namespace := PropertyValue {}
8787 apiHost := PropertyValue {}
88- key := PropertyValue {}
89- cert := PropertyValue {}
88+ key := PropertyValue {}
89+ cert := PropertyValue {}
9090
9191 // read credentials from command line
9292 apihost , auth , ns , keyfile , certfile := GetCommandLineFlags ()
9393 credential = GetPropertyValue (credential , auth , COMMANDLINE )
9494 namespace = GetPropertyValue (namespace , ns , COMMANDLINE )
9595 apiHost = GetPropertyValue (apiHost , apihost , COMMANDLINE )
96- key = GetPropertyValue (key , keyfile , COMMANDLINE )
97- cert = GetPropertyValue (cert , certfile , COMMANDLINE )
96+ key = GetPropertyValue (key , keyfile , COMMANDLINE )
97+ cert = GetPropertyValue (cert , certfile , COMMANDLINE )
9898
9999 // now, read them from deployment file if not found on command line
100100 if len (credential .Value ) == 0 || len (namespace .Value ) == 0 || len (apiHost .Value ) == 0 {
@@ -138,29 +138,33 @@ func NewWhiskConfig(proppath string, deploymentPath string, manifestPath string,
138138 credential = GetPropertyValue (credential , wskprops .AuthKey , WSKPROPS )
139139 namespace = GetPropertyValue (namespace , wskprops .Namespace , WSKPROPS )
140140 apiHost = GetPropertyValue (apiHost , wskprops .APIHost , WSKPROPS )
141- key = GetPropertyValue (key , wskprops .Key , WSKPROPS )
142- cert = GetPropertyValue (cert , wskprops .Cert , WSKPROPS )
141+ key = GetPropertyValue (key , wskprops .Key , WSKPROPS )
142+ cert = GetPropertyValue (cert , wskprops .Cert , WSKPROPS )
143143
144+ // TODO() see if we can split the following whisk prop logic into a separate function
144145 // now, read credentials from whisk.properties but this is only acceptable within Travis
145146 // whisk.properties will soon be deprecated and should not be used for any production deployment
146147 whiskproperty , _ := GetWskPropFromWhiskProperty (pi )
148+
149+ var warnmsg string
150+
147151 credential = GetPropertyValue (credential , whiskproperty .AuthKey , WHISKPROPERTY )
148152 if credential .Source == WHISKPROPERTY {
149- // TODO() i18n
150- wskprint . PrintlnOpenWhiskWarning ( "The authentication key was retrieved from whisk.properties " +
151- "which will soon be deprecated please do not use it outside of Travis builds." )
153+ warnmsg = wski18n . T ( wski18n . ID_WARN_WHISK_PROPS_DEPRECATED ,
154+ map [ string ] interface {}{ " key" : "authenticaton key" })
155+ wskprint . PrintlnOpenWhiskWarning ( warnmsg )
152156 }
153157 namespace = GetPropertyValue (namespace , whiskproperty .Namespace , WHISKPROPERTY )
154158 if namespace .Source == WHISKPROPERTY {
155- // TODO() i18n
156- wskprint . PrintlnOpenWhiskWarning ( "The namespace was retrieved from whisk.properties " +
157- "which will soon be deprecated please do not use it outside of Travis builds." )
159+ warnmsg = wski18n . T ( wski18n . ID_WARN_WHISK_PROPS_DEPRECATED ,
160+ map [ string ] interface {}{ "key" : " namespace" })
161+ wskprint . PrintlnOpenWhiskWarning ( warnmsg )
158162 }
159163 apiHost = GetPropertyValue (apiHost , whiskproperty .APIHost , WHISKPROPERTY )
160164 if apiHost .Source == WHISKPROPERTY {
161- // TODO() i18n
162- wskprint . PrintlnOpenWhiskWarning ( "The API host was retrieved from whisk.properties " +
163- "which will soon be deprecated please do not use it outside of Travis builds." )
165+ warnmsg = wski18n . T ( wski18n . ID_WARN_WHISK_PROPS_DEPRECATED ,
166+ map [ string ] interface {}{ "key" : " API host" })
167+ wskprint . PrintlnOpenWhiskWarning ( warnmsg )
164168 }
165169
166170 // set namespace to default namespace if not yet found
@@ -169,98 +173,99 @@ func NewWhiskConfig(proppath string, deploymentPath string, manifestPath string,
169173 namespace .Source = DEFAULTVALUE
170174 }
171175
176+ // TODO() See if we can split off the interactive logic into a separate function
172177 // If we still can not find the values we need, check if it is interactive mode.
173178 // If so, we prompt users for the input.
174179 // The namespace is set to a default value at this point if not provided.
175180 if len (apiHost .Value ) == 0 && isInteractive == true {
176- // TODO() i18n
177- host := promptForValue ("\n Please provide the hostname for OpenWhisk [default value is openwhisk.ng.bluemix.net]: " )
181+ host := promptForValue (wski18n .T (wski18n .ID_MSG_PROMPT_APIHOST ))
178182 if host == "" {
179- // TODO() tell caller that we are using this default, look to make a const at top of file
183+ // TODO() programmatically tell caller that we are using this default
184+ // TODO() make this configurable or remove
180185 host = "openwhisk.ng.bluemix.net"
181186 }
182187 apiHost .Value = host
183188 apiHost .Source = INTERINPUT
184189 }
185190
186191 if len (credential .Value ) == 0 && isInteractive == true {
187- // TODO() i18n
188- cred := promptForValue ("\n Please provide an authentication token: " )
192+ cred := promptForValue (wski18n .T (wski18n .ID_MSG_PROMPT_AUTHKEY ))
189193 credential .Value = cred
190194 credential .Source = INTERINPUT
191195
192196 // The namespace is always associated with the credential. Both of them should be picked up from the same source.
193197 if len (namespace .Value ) == 0 || namespace .Value == whisk .DEFAULT_NAMESPACE {
194- // TODO() i18n
195- ns := promptForValue ("\n Please provide a namespace [default value is guest]: " )
198+ tempNamespace := promptForValue (wski18n .T (wski18n .ID_MSG_PROMPT_NAMESPACE ))
196199 source := INTERINPUT
197200
198- if ns == "" {
199- ns = whisk .DEFAULT_NAMESPACE
201+ if tempNamespace == "" {
202+ tempNamespace = whisk .DEFAULT_NAMESPACE
200203 source = DEFAULTVALUE
201204 }
202205
203- namespace .Value = ns
206+ namespace .Value = tempNamespace
204207 namespace .Source = source
205208 }
206209 }
207210
208- mode := true
209- if (len (cert .Value ) != 0 && len (key .Value ) != 0 ) {
210- mode = false
211- }
211+ mode := true
212+ if (len (cert .Value ) != 0 && len (key .Value ) != 0 ) {
213+ mode = false
214+ }
212215
213- clientConfig = & whisk.Config {
216+ clientConfig = & whisk.Config {
214217 AuthToken : credential .Value , //Authtoken
215- Namespace : namespace .Value , //Namespace
218+ Namespace : namespace .Value , //Namespace
216219 Host : apiHost .Value ,
217220 Version : "v1" ,
218- Cert : cert .Value ,
219- Key : key .Value ,
221+ Cert : cert .Value ,
222+ Key : key .Value ,
220223 Insecure : mode , // true if you want to ignore certificate signing
221224 }
222225
226+ // validate we have credential, apihost and namespace
227+ err := validateClientConfig (credential , apiHost , namespace )
228+
229+ return clientConfig , err
230+ }
231+
232+ func validateClientConfig (credential PropertyValue , apiHost PropertyValue , namespace PropertyValue ) (error ) {
233+
234+ // Display error message based upon which config value was missing
223235 if len (credential .Value ) == 0 || len (apiHost .Value ) == 0 || len (namespace .Value ) == 0 {
224- var errStr string
236+ var errmsg string
225237 if len (credential .Value ) == 0 {
226- errStr += wski18n .T ("The authentication key is not configured.\n " )
227- } else {
228- errStr += wski18n .T ("The authenitcation key is set from {{.authsource}}.\n " ,
229- map [string ]interface {}{"authsource" : credential .Source })
238+ errmsg = wski18n .T (wski18n .ID_MSG_CONFIG_MISSING_AUTHKEY )
230239 }
231240
232241 if len (apiHost .Value ) == 0 {
233- errStr += wski18n .T ("The API host is not configured.\n " )
234- } else {
235- errStr += wski18n .T ("The API host is {{.apihost}}, from {{.apisource}}.\n " ,
236- map [string ]interface {}{"apihost" : apiHost .Value , "apisource" : apiHost .Source })
242+ errmsg = wski18n .T (wski18n .ID_MSG_CONFIG_MISSING_APIHOST )
237243 }
238244
239245 if len (namespace .Value ) == 0 {
240- errStr += wski18n .T ("The namespace is not configured.\n " )
241- } else {
242- errStr += wski18n .T ("The namespace is {{.namespace}}, from {{.namespacesource}}.\n " ,
243- map [string ]interface {}{"namespace" : namespace .Value , "namespacesource" : namespace .Source })
244-
246+ errmsg = wski18n .T (wski18n .ID_MSG_CONFIG_MISSING_NAMESPACE )
245247 }
246- whisk . Debug ( whisk . DbgError , errStr )
247- return clientConfig , wskderrors .NewWhiskClientInvalidConfigError (errStr )
248+
249+ return wskderrors .NewWhiskClientInvalidConfigError (errmsg )
248250 }
249251
250- stdout := wski18n .T ("The API host is {{.apihost}}, from {{.apisource}}.\n " ,
251- map [string ]interface {}{"apihost" : apiHost .Value , "apisource" : apiHost .Source })
252- whisk .Debug (whisk .DbgInfo , stdout )
252+ // Show caller what final values we used for credential, apihost and namespace
253+ stdout := wski18n .T (wski18n .ID_MSG_CONFIG_INFO_APIHOST_X_host_X_source_X ,
254+ map [string ]interface {}{"host" : apiHost .Value , "source" : apiHost .Source })
255+ wskprint .PrintOpenWhiskStatus (stdout )
256+
257+ stdout = wski18n .T (wski18n .ID_MSG_CONFIG_INFO_AUTHKEY_X_source_X ,
258+ map [string ]interface {}{"source" : credential .Source })
259+ wskprint .PrintOpenWhiskStatus (stdout )
253260
254- stdout = wski18n .T ("The auth key is set, from {{.authsource}}. \n " ,
255- map [string ]interface {}{"authsource " : credential .Source })
256- whisk . Debug ( whisk . DbgInfo , stdout )
261+ stdout = wski18n .T (wski18n . ID_MSG_CONFIG_INFO_NAMESPACE_X_namespace_X_source_X ,
262+ map [string ]interface {}{"namespace " : namespace . Value , "source" : namespace .Source })
263+ wskprint . PrintOpenWhiskStatus ( stdout )
257264
258- stdout = wski18n .T ("The namespace is {{.namespace}}, from {{.namespacesource}}.\n " ,
259- map [string ]interface {}{"namespace" : namespace .Value , "namespacesource" : namespace .Source })
260- whisk .Debug (whisk .DbgInfo , stdout )
261- return clientConfig , nil
265+ return nil
262266}
263267
268+ // TODO() move into its own package "wskread" and add support for passing in default value
264269var promptForValue = func (msg string ) (string ) {
265270 reader := bufio .NewReader (os .Stdin )
266271 fmt .Print (msg )
0 commit comments