You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by du...@apache.org on 2018/09/18 20:56:54 UTC

[incubator-openwhisk-cli] branch master updated: allow api context override (#367)

This is an automated email from the ASF dual-hosted git repository.

dubeejw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new e01606d  allow api context override (#367)
e01606d is described below

commit e01606d4b4b9b45fd72ae2cc8bbb37c0ae2b8597
Author: Mark Deuser <md...@us.ibm.com>
AuthorDate: Tue Sep 18 16:56:47 2018 -0400

    allow api context override (#367)
    
    * allow api context override
---
 commands/api.go | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/commands/api.go b/commands/api.go
index c7b4157..41dd919 100644
--- a/commands/api.go
+++ b/commands/api.go
@@ -54,6 +54,9 @@ var apiCmd = &cobra.Command{
 
 var fmtString = "%-30s %7s %20s  %s\n"
 
+// When set, this overrides the default authkey based api context id
+var ContextId string
+
 func IsValidApiVerb(verb string) (error, bool) {
 	// Is the API verb valid?
 	if _, ok := whisk.ApiVerbs[strings.ToUpper(verb)]; !ok {
@@ -1025,19 +1028,24 @@ func getUserContextId() (string, error) {
 	var guid string
 	var err error
 
-	props, err := ReadProps(Properties.PropsFile)
-	if err == nil {
-		if len(props["AUTH"]) > 0 {
-			guid = strings.Split(props["AUTH"], ":")[0]
+	// If the context id override has been set, use it instead of the default
+	if len(ContextId) > 0 {
+		guid = ContextId
+	} else {
+		props, errprops := ReadProps(Properties.PropsFile)
+		if errprops == nil {
+			if len(props["AUTH"]) > 0 {
+				guid = strings.Split(props["AUTH"], ":")[0]
+			} else {
+				whisk.Debug(whisk.DbgError, "AUTH property not set in properties file: '%s'\n", Properties.PropsFile)
+				errStr := wski18n.T("Authorization key is not configured (--auth is required)")
+				err = whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
+			}
 		} else {
-			whisk.Debug(whisk.DbgError, "AUTH property not set in properties file: '%s'\n", Properties.PropsFile)
-			errStr := wski18n.T("Authorization key is not configured (--auth is required)")
+			whisk.Debug(whisk.DbgError, "readProps(%s) failed: %s\n", Properties.PropsFile, err)
+			errStr := wski18n.T("Unable to obtain the auth key from the properties file: {{.err}}", map[string]interface{}{"err": err})
 			err = whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
 		}
-	} else {
-		whisk.Debug(whisk.DbgError, "readProps(%s) failed: %s\n", Properties.PropsFile, err)
-		errStr := wski18n.T("Unable to obtain the auth key from the properties file: {{.err}}", map[string]interface{}{"err": err})
-		err = whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
 	}
 
 	return guid, err