@@ -54,6 +54,9 @@ var apiCmd = &cobra.Command{
5454
5555var fmtString = "%-30s %7s %20s %s\n "
5656
57+ // When set, this overrides the default authkey based api context id
58+ var ContextId string
59+
5760func IsValidApiVerb (verb string ) (error , bool ) {
5861 // Is the API verb valid?
5962 if _ , ok := whisk .ApiVerbs [strings .ToUpper (verb )]; ! ok {
@@ -1025,19 +1028,24 @@ func getUserContextId() (string, error) {
10251028 var guid string
10261029 var err error
10271030
1028- props , err := ReadProps (Properties .PropsFile )
1029- if err == nil {
1030- if len (props ["AUTH" ]) > 0 {
1031- guid = strings .Split (props ["AUTH" ], ":" )[0 ]
1031+ // If the context id override has been set, use it instead of the default
1032+ if len (ContextId ) > 0 {
1033+ guid = ContextId
1034+ } else {
1035+ props , errprops := ReadProps (Properties .PropsFile )
1036+ if errprops == nil {
1037+ if len (props ["AUTH" ]) > 0 {
1038+ guid = strings .Split (props ["AUTH" ], ":" )[0 ]
1039+ } else {
1040+ whisk .Debug (whisk .DbgError , "AUTH property not set in properties file: '%s'\n " , Properties .PropsFile )
1041+ errStr := wski18n .T ("Authorization key is not configured (--auth is required)" )
1042+ err = whisk .MakeWskError (errors .New (errStr ), whisk .EXIT_CODE_ERR_GENERAL , whisk .DISPLAY_MSG , whisk .NO_DISPLAY_USAGE )
1043+ }
10321044 } else {
1033- whisk .Debug (whisk .DbgError , "AUTH property not set in properties file: '%s' \n " , Properties .PropsFile )
1034- errStr := wski18n .T ("Authorization key is not configured (--auth is required)" )
1045+ whisk .Debug (whisk .DbgError , "readProps(%s) failed: %s \n " , Properties .PropsFile , err )
1046+ errStr := wski18n .T ("Unable to obtain the auth key from the properties file: {{.err}}" , map [ string ] interface {}{ "err" : err } )
10351047 err = whisk .MakeWskError (errors .New (errStr ), whisk .EXIT_CODE_ERR_GENERAL , whisk .DISPLAY_MSG , whisk .NO_DISPLAY_USAGE )
10361048 }
1037- } else {
1038- whisk .Debug (whisk .DbgError , "readProps(%s) failed: %s\n " , Properties .PropsFile , err )
1039- errStr := wski18n .T ("Unable to obtain the auth key from the properties file: {{.err}}" , map [string ]interface {}{"err" : err })
1040- err = whisk .MakeWskError (errors .New (errStr ), whisk .EXIT_CODE_ERR_GENERAL , whisk .DISPLAY_MSG , whisk .NO_DISPLAY_USAGE )
10411049 }
10421050
10431051 return guid , err
0 commit comments