Skip to content

Commit

Permalink
allow api context override (#367)
Browse files Browse the repository at this point in the history
* allow api context override
  • Loading branch information
mdeuser authored and dubee committed Sep 18, 2018
1 parent bb1b635 commit e01606d
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions commands/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e01606d

Please sign in to comment.