You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/10/02 00:07:25 UTC

[GitHub] mdeuser closed pull request #370: Allow API GW access token override

mdeuser closed pull request #370: Allow API GW access token override
URL: https://github.com/apache/incubator-openwhisk-cli/pull/370
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/commands/api.go b/commands/api.go
index 41dd919a..6a992059 100644
--- a/commands/api.go
+++ b/commands/api.go
@@ -57,6 +57,9 @@ var fmtString = "%-30s %7s %20s  %s\n"
 // When set, this overrides the default authkey based api context id
 var ContextId string
 
+// When set, this overrides the default access token used to authenticate with the api gw
+var ApiGwAccessToken string
+
 func IsValidApiVerb(verb string) (error, bool) {
 	// Is the API verb valid?
 	if _, ok := whisk.ApiVerbs[strings.ToUpper(verb)]; !ok {
@@ -1010,15 +1013,21 @@ func getAccessToken() (string, error) {
 	var token string = "DUMMY TOKEN"
 	var err error
 
-	props, err := ReadProps(Properties.PropsFile)
-	if err == nil {
-		if len(props["APIGW_ACCESS_TOKEN"]) > 0 {
-			token = props["APIGW_ACCESS_TOKEN"]
-		}
+	// If the api gw access token override has been set, use it instead of the default
+	whisk.Debug(whisk.DbgInfo, "api gw access token override is '%s'\n", ApiGwAccessToken)
+	if len(ApiGwAccessToken) > 0 {
+		token = ApiGwAccessToken
 	} else {
-		whisk.Debug(whisk.DbgError, "readProps(%s) failed: %s\n", Properties.PropsFile, err)
-		errStr := wski18n.T("Unable to obtain the API Gateway access token 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)
+		props, errprops := ReadProps(Properties.PropsFile)
+		if errprops == nil {
+			if len(props["APIGW_ACCESS_TOKEN"]) > 0 {
+				token = props["APIGW_ACCESS_TOKEN"]
+			}
+		} else {
+			whisk.Debug(whisk.DbgError, "readProps(%s) failed: %s\n", Properties.PropsFile, err)
+			errStr := wski18n.T("Unable to obtain the API Gateway access token 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 token, err


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services