dubee closed pull request #367: allow api context override
URL: https://github.com/apache/incubator-openwhisk-cli/pull/367
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 c7b41576..41dd919a 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
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services