Skip to content

Commit 2d2d673

Browse files
authored
remove namespace property from wskprops (#434)
1 parent 23de5a3 commit 2d2d673

File tree

11 files changed

+51
-162
lines changed

11 files changed

+51
-162
lines changed

commands/action.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ func nonNestedError(errorMessage string) error {
939939
}
940940

941941
func actionParseError(cmd *cobra.Command, args []string, err error) error {
942-
whisk.Debug(whisk.DbgError, "parseAction(%s, %s) error: %s\n", cmd, args, err)
942+
whisk.Debug(whisk.DbgError, "parseAction(%s, %s) error: %s\n", cmd.Name(), args, err)
943943

944944
errMsg := wski18n.T(
945945
"Invalid argument(s). {{.required}}",
@@ -1028,7 +1028,7 @@ func actionGetError(entityName string, fetchCode bool, err error) error {
10281028
func handleInvocationError(err error, entityName string) error {
10291029
whisk.Debug(
10301030
whisk.DbgError,
1031-
"Client.Actions.Invoke(%s, %t) error: %s\n",
1031+
"Client.Actions.Invoke(%s) error: %s\n",
10321032
entityName,
10331033
err)
10341034

commands/api.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ var apiCreateCmd = &cobra.Command{
205205
}
206206
api, qname, err = parseApi(cmd, args)
207207
if err != nil {
208-
whisk.Debug(whisk.DbgError, "parseApi(%s, %s) error: %s\n", cmd, args, err)
208+
whisk.Debug(whisk.DbgError, "parseApi(%s, %s) error: %s\n", cmd.Name(), args, err)
209209
errMsg := wski18n.T("Unable to parse api command arguments: {{.err}}",
210210
map[string]interface{}{"err": err})
211211
whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXIT_CODE_ERR_GENERAL,
@@ -653,7 +653,7 @@ func genFilteredList(resultApi *whisk.RetApi, apiPath string, apiVerb string) []
653653
actionName = "/" + opv.XOpenWhisk.Namespace + "/" + opv.XOpenWhisk.ActionName
654654
}
655655
orderInfo = AssignListInfo(actionName, op, apiName, basePath, path, baseUrl+path)
656-
whisk.Debug(whisk.DbgInfo, "Appening to orderInfoArr: %s %s\n", orderInfo.RelPath)
656+
whisk.Debug(whisk.DbgInfo, "Appening to orderInfoArr: %s\n", orderInfo.RelPath)
657657
orderInfoArr = append(orderInfoArr, orderInfo)
658658
}
659659
}
@@ -692,7 +692,7 @@ func genFilteredRow(resultApi *whisk.RetApi, apiPath string, apiVerb string, max
692692
}
693693
orderInfo = AssignRowInfo(actionName[0:min(len(actionName), maxActionNameSize)], op, apiName[0:min(len(apiName), maxApiNameSize)], basePath, path, baseUrl+path)
694694
orderInfo.FmtString = fmtString
695-
whisk.Debug(whisk.DbgInfo, "Appening to orderInfoArr: %s %s\n", orderInfo.RelPath)
695+
whisk.Debug(whisk.DbgInfo, "Appening to orderInfoArr: %s\n", orderInfo.RelPath)
696696
orderInfoArr = append(orderInfoArr, orderInfo)
697697
}
698698
}
@@ -987,15 +987,15 @@ func parseSwaggerApi(configfile string, namespace string) (*whisk.Api, error) {
987987
}
988988

989989
if swaggerObj.BasePath == "" || swaggerObj.SwaggerName == "" || swaggerObj.Info == nil || swaggerObj.Paths == nil {
990-
whisk.Debug(whisk.DbgError, "Swagger file is invalid.\n", configfile, err)
990+
whisk.Debug(whisk.DbgError, "Swagger file is invalid.\n")
991991
errMsg := wski18n.T("Swagger file is invalid (missing basePath, info, paths, or swagger fields)")
992992
whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_GENERAL,
993993
whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
994994
return nil, whiskErr
995995
}
996996

997997
if _, ok := isValidBasepath(swaggerObj.BasePath); !ok {
998-
whisk.Debug(whisk.DbgError, "Swagger file basePath is invalid.\n", configfile, err)
998+
whisk.Debug(whisk.DbgError, "Swagger file basePath is invalid.\n")
999999
errMsg := wski18n.T("Swagger file basePath must start with a leading slash (/)")
10001000
whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_GENERAL,
10011001
whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)

commands/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func SetupClientConfig(cmd *cobra.Command, args []string) error {
4141

4242
// Determine if the parent command will require the API host to be set
4343
apiHostRequired := (cmd.Parent().Name() == "property" && cmd.Name() == "get" && (Flags.property.auth ||
44-
Flags.property.cert || Flags.property.key || Flags.property.apihost || Flags.property.namespace ||
44+
Flags.property.cert || Flags.property.key || Flags.property.apihost ||
4545
Flags.property.apiversion || Flags.property.cliversion)) ||
4646
(cmd.Parent().Name() == "property" && cmd.Name() == "set" && (len(Flags.property.apihostSet) > 0 ||
4747
len(Flags.property.apiversionSet) > 0 || len(Flags.Global.Auth) > 0)) ||

commands/property.go

Lines changed: 25 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -145,38 +145,6 @@ var propertySetCmd = &cobra.Command{
145145
map[string]interface{}{"ok": color.GreenString("ok:"), "version": boldString(apiVersion)}))
146146
}
147147

148-
if namespace := Flags.property.namespaceSet; len(namespace) > 0 {
149-
namespaces, _, err := Client.Namespaces.List()
150-
if err != nil {
151-
whisk.Debug(whisk.DbgError, "Client.Namespaces.List() failed: %s\n", err)
152-
errStr := fmt.Sprintf(
153-
wski18n.T("Authenticated user does not have namespace '{{.name}}'; set command failed: {{.err}}",
154-
map[string]interface{}{"name": namespace, "err": err}))
155-
werr = whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
156-
} else {
157-
whisk.Debug(whisk.DbgInfo, "Validating namespace '%s' is in user namespace list %#v\n", namespace, namespaces)
158-
var validNamespace bool
159-
for _, ns := range namespaces {
160-
if ns.Name == namespace {
161-
whisk.Debug(whisk.DbgInfo, "Namespace '%s' is valid\n", namespace)
162-
validNamespace = true
163-
}
164-
}
165-
if !validNamespace {
166-
whisk.Debug(whisk.DbgError, "Namespace '%s' is not in the list of entitled namespaces\n", namespace)
167-
errStr := fmt.Sprintf(
168-
wski18n.T("Namespace '{{.name}}' is not in the list of entitled namespaces",
169-
map[string]interface{}{"name": namespace}))
170-
werr = whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
171-
} else {
172-
props["NAMESPACE"] = namespace
173-
okMsg += fmt.Sprintf(
174-
wski18n.T("{{.ok}} whisk namespace set to {{.name}}\n",
175-
map[string]interface{}{"ok": color.GreenString("ok:"), "name": boldString(namespace)}))
176-
}
177-
}
178-
}
179-
180148
err = WriteProps(Properties.PropsFile, props)
181149
if err != nil {
182150
whisk.Debug(whisk.DbgError, "writeProps(%s, %#v) failed: %s\n", Properties.PropsFile, props, err)
@@ -236,21 +204,6 @@ var propertyUnsetCmd = &cobra.Command{
236204
map[string]interface{}{"ok": color.GreenString("ok:")}))
237205
}
238206

239-
if Flags.property.namespace {
240-
delete(props, "NAMESPACE")
241-
okMsg += fmt.Sprintf(
242-
wski18n.T("{{.ok}} whisk namespace unset",
243-
map[string]interface{}{"ok": color.GreenString("ok:")}))
244-
if len(DefaultNamespace) > 0 {
245-
okMsg += fmt.Sprintf(
246-
wski18n.T("; the default value of {{.default}} will be used.\n",
247-
map[string]interface{}{"default": boldString(DefaultNamespace)}))
248-
} else {
249-
okMsg += fmt.Sprint(
250-
wski18n.T("; there is no default value that can be used.\n"))
251-
}
252-
}
253-
254207
if Flags.property.apihost {
255208
delete(props, "APIHOST")
256209
okMsg += fmt.Sprintf(
@@ -305,8 +258,8 @@ var propertyGetCmd = &cobra.Command{
305258
case "raw":
306259
outputFormat = "raw"
307260
break
308-
//case "json": For future implementation
309-
//case "yaml": For future implementation
261+
//case "json": For future implementation
262+
//case "yaml": For future implementation
310263
default:
311264
errStr := fmt.Sprintf(
312265
wski18n.T("Supported output format are std|raw"))
@@ -323,6 +276,7 @@ var propertyGetCmd = &cobra.Command{
323276
Flags.property.apihost || Flags.property.apibuildno) {
324277
Flags.property.all = true
325278
}
279+
326280
if Flags.property.all {
327281
// Currently with all only standard output format is supported.
328282
if outputFormat != "std" {
@@ -332,14 +286,23 @@ var propertyGetCmd = &cobra.Command{
332286
return werr
333287
}
334288

289+
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayAPIHost), boldString(Properties.APIHost))
290+
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayAuth), boldString(Properties.Auth))
291+
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayNamespace), boldString(getNamespace()))
335292
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayCert), boldString(Properties.Cert))
336293
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayKey), boldString(Properties.Key))
337-
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayAuth), boldString(Properties.Auth))
338-
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayAPIHost), boldString(Properties.APIHost))
339294
fmt.Fprintf(color.Output, "%s\t%s\n", wski18n.T(propDisplayAPIVersion), boldString(Properties.APIVersion))
340-
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayNamespace), boldString(Properties.Namespace))
341295
fmt.Fprintf(color.Output, "%s\t%s\n", wski18n.T(propDisplayCLIVersion), boldString(Properties.CLIVersion))
342296
} else {
297+
if Flags.property.apihost {
298+
printProperty(Properties.APIHost, propDisplayAPIHost, outputFormat)
299+
}
300+
if Flags.property.auth {
301+
printProperty(Properties.Auth, propDisplayAuth, outputFormat)
302+
}
303+
if Flags.property.namespace {
304+
printProperty(getNamespace(), propDisplayNamespace, outputFormat)
305+
}
343306
if Flags.property.cert {
344307
printProperty(Properties.Cert, propDisplayCert, outputFormat)
345308
}
@@ -349,18 +312,9 @@ var propertyGetCmd = &cobra.Command{
349312
if Flags.property.cliversion {
350313
printProperty(Properties.CLIVersion, propDisplayCLIVersion, outputFormat, "%s\t%s\n")
351314
}
352-
if Flags.property.apihost {
353-
printProperty(Properties.APIHost, propDisplayAPIHost, outputFormat)
354-
}
355-
if Flags.property.auth {
356-
printProperty(Properties.Auth, propDisplayAuth, outputFormat)
357-
}
358315
if Flags.property.apiversion {
359316
printProperty(Properties.APIVersion, propDisplayAPIVersion, outputFormat, "%s\t%s\n")
360317
}
361-
if Flags.property.namespace {
362-
printProperty(Properties.Namespace, propDisplayNamespace, outputFormat)
363-
}
364318
}
365319

366320
if Flags.property.all || Flags.property.apibuild || Flags.property.apibuildno {
@@ -418,15 +372,12 @@ func init() {
418372
propertySetCmd.Flags().StringVar(&Flags.Global.Key, "key", "", wski18n.T(propDisplayKey))
419373
propertySetCmd.Flags().StringVar(&Flags.property.apihostSet, "apihost", "", wski18n.T("whisk API `HOST`"))
420374
propertySetCmd.Flags().StringVar(&Flags.property.apiversionSet, "apiversion", "", wski18n.T("whisk API `VERSION`"))
421-
propertySetCmd.Flags().StringVar(&Flags.property.namespaceSet, "namespace", "", wski18n.T("whisk `NAMESPACE`"))
422375

423376
propertyUnsetCmd.Flags().BoolVar(&Flags.property.cert, "cert", false, wski18n.T(propDisplayCert))
424377
propertyUnsetCmd.Flags().BoolVar(&Flags.property.key, "key", false, wski18n.T(propDisplayKey))
425378
propertyUnsetCmd.Flags().BoolVar(&Flags.property.auth, "auth", false, wski18n.T("authorization key"))
426379
propertyUnsetCmd.Flags().BoolVar(&Flags.property.apihost, "apihost", false, wski18n.T(propDisplayAPIHost))
427380
propertyUnsetCmd.Flags().BoolVar(&Flags.property.apiversion, "apiversion", false, wski18n.T(propDisplayAPIVersion))
428-
propertyUnsetCmd.Flags().BoolVar(&Flags.property.namespace, "namespace", false, wski18n.T(propDisplayNamespace))
429-
430381
}
431382

432383
func SetDefaultProperties() {
@@ -527,14 +478,6 @@ func loadProperties() error {
527478
Properties.APIHost = apiHost
528479
}
529480

530-
if namespace, hasProp := props["NAMESPACE"]; hasProp && len(namespace) > 0 {
531-
Properties.Namespace = namespace
532-
}
533-
534-
if namespace := os.Getenv("WHISK_NAMESPACE"); len(namespace) > 0 {
535-
Properties.Namespace = namespace
536-
}
537-
538481
return nil
539482
}
540483

@@ -561,13 +504,6 @@ func parseConfigFlags(cmd *cobra.Command, args []string) error {
561504
}
562505
}
563506

564-
if namespace := Flags.property.namespaceSet; len(namespace) > 0 {
565-
Properties.Namespace = namespace
566-
if Client != nil {
567-
Client.Config.Namespace = namespace
568-
}
569-
}
570-
571507
if apiVersion := Flags.Global.Apiversion; len(apiVersion) > 0 {
572508
Properties.APIVersion = apiVersion
573509
if Client != nil {
@@ -619,3 +555,13 @@ func printProperty(propertyName string, displayText string, formatType string, f
619555
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(displayText), boldString(propertyName))
620556
}
621557
}
558+
559+
func getNamespace() string {
560+
var namespaces, _, err = Client.Namespaces.List()
561+
whisk.Debug(whisk.DbgError, "Client.Namespaces.List() failed: %s\n", err)
562+
if err != nil {
563+
return "_"
564+
} else {
565+
return namespaces[0].Name
566+
}
567+
}

commands/sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var sdkInstallCmd = &cobra.Command{
8686
} else {
8787
err = WskCmd.GenBashCompletionFile(BASH_AUTOCOMPLETE_FILENAME)
8888
if err != nil {
89-
whisk.Debug(whisk.DbgError, "GenBashCompletionFile('%s`) error: \n", BASH_AUTOCOMPLETE_FILENAME, err)
89+
whisk.Debug(whisk.DbgError, "GenBashCompletionFile('%s`) error: %s\n", BASH_AUTOCOMPLETE_FILENAME, err)
9090
errStr := wski18n.T("Unable to generate '{{.name}}': {{.err}}",
9191
map[string]interface{}{"name": BASH_AUTOCOMPLETE_FILENAME, "err": err})
9292
werr := whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)

commands/trigger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func createOrUpdate(Client *whisk.Client, fqn *QualifiedName, trigger *whisk.Tri
8383
_, _, err := Client.Triggers.Insert(trigger, overwrite)
8484

8585
if err != nil {
86-
whisk.Debug(whisk.DbgError, "Client.Triggers.Insert(%+v, %s) failed: %s\n", trigger, overwrite, err)
86+
whisk.Debug(whisk.DbgError, "Client.Triggers.Insert(%+v, %t) failed: %s\n", trigger, overwrite, err)
8787
var errStr string
8888
if !overwrite {
8989
errStr = wski18n.T("Unable to create trigger '{{.name}}': {{.err}}",

commands/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func getParameters(params []string, keyValueFormat bool, annotation bool) interf
7575

7676
parameters, err = getJSONFromStrings(params, keyValueFormat)
7777
if err != nil {
78-
whisk.Debug(whisk.DbgError, "getJSONFromStrings(%#v, %s) failed: %s\n", params, keyValueFormat, err)
78+
whisk.Debug(whisk.DbgError, "getJSONFromStrings(%#v, %t) failed: %s\n", params, keyValueFormat, err)
7979
var errStr string
8080

8181
if !annotation {

tests/src/integration/command_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestShowAPIVersion(t *testing.T) {
8282
// Test case to verify the default namespace _.
8383
func TestDefaultNamespace(t *testing.T) {
8484
common.CreateFile(tmpProp)
85-
common.WriteFile(tmpProp, []string{"NAMESPACE="})
85+
common.WriteFile(tmpProp, []string{"APIHOST=xyz"})
8686

8787
os.Setenv("WSK_CONFIG_FILE", tmpProp)
8888
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
@@ -101,7 +101,7 @@ func TestValidateDefaultProperties(t *testing.T) {
101101
os.Setenv("WSK_CONFIG_FILE", tmpProp)
102102
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
103103

104-
stdout, err := wsk.RunCommand("property", "unset", "--auth", "--apihost", "--apiversion", "--namespace")
104+
stdout, err := wsk.RunCommand("property", "unset", "--auth", "--apihost", "--apiversion")
105105
assert.Equal(t, nil, err, "The command property unset failed to run.")
106106
outputString := string(stdout)
107107
assert.Contains(t, outputString, "ok: whisk auth unset",
@@ -110,8 +110,6 @@ func TestValidateDefaultProperties(t *testing.T) {
110110
"The output of the command does not contain \"ok: whisk API host unset\".")
111111
assert.Contains(t, outputString, "ok: whisk API version unset",
112112
"The output of the command does not contain \"ok: whisk API version unset\".")
113-
assert.Contains(t, outputString, "ok: whisk namespace unset",
114-
"The output of the command does not contain \"ok: whisk namespace unset\".")
115113

116114
stdout, err = wsk.RunCommand("property", "get", "--auth")
117115
assert.Equal(t, nil, err, "The command property get --auth failed to run.")
@@ -123,11 +121,6 @@ func TestValidateDefaultProperties(t *testing.T) {
123121
assert.Equal(t, common.PropDisplayAPIHost, common.RemoveRedundentSpaces(string(stdout)),
124122
"The output of the command does not equal to "+common.PropDisplayAPIHost)
125123

126-
stdout, err = wsk.RunCommand("property", "get", "--namespace")
127-
assert.Equal(t, nil, err, "The command property get --namespace failed to run.")
128-
assert.Equal(t, common.PropDisplayNamespace+" _", common.RemoveRedundentSpaces(string(stdout)),
129-
"The output of the command does not equal to "+common.PropDisplayNamespace+" _")
130-
131124
common.DeleteFile(tmpProp)
132125
}
133126

tests/src/integration/integration_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package tests
2222
import (
2323
"fmt"
2424
"os"
25-
"strings"
2625
"testing"
2726

2827
"github.com/apache/incubator-openwhisk-cli/tests/src/integration/common"
@@ -331,29 +330,23 @@ func initInvalidArgs() {
331330
var wsk *common.Wsk = common.NewWsk()
332331
var tmpProp = common.GetRepoPath() + "/wskprops.tmp"
333332

334-
// Test case to set apihost, auth, and namespace.
333+
// Test case to set apihost and auth.
335334
func TestSetAPIHostAuthNamespace(t *testing.T) {
336335
common.CreateFile(tmpProp)
337336
common.WriteFile(tmpProp, []string{})
338337

339338
os.Setenv("WSK_CONFIG_FILE", tmpProp)
340339
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
341340

342-
namespace, _ := wsk.ListNamespaces()
343-
namespaces := strings.Split(strings.TrimSpace(string(namespace)), "\n")
344-
expectedNamespace := string(namespaces[len(namespaces)-1])
345341
fmt.Println(wsk.Wskprops.APIHost)
346342
if wsk.Wskprops.APIHost != "" && wsk.Wskprops.AuthKey != "" {
347-
stdout, err := wsk.RunCommand("property", "set", "--apihost", wsk.Wskprops.APIHost,
348-
"--auth", wsk.Wskprops.AuthKey, "--namespace", expectedNamespace)
343+
stdout, err := wsk.RunCommand("property", "set", "--apihost", wsk.Wskprops.APIHost, "--auth", wsk.Wskprops.AuthKey)
349344
ouputString := string(stdout)
350-
assert.Equal(t, nil, err, "The command property set --apihost --auth --namespace failed to run.")
345+
assert.Equal(t, nil, err, "The command property set --apihost --auth failed to run.")
351346
assert.Contains(t, ouputString, "ok: whisk auth set. Run 'wsk property get --auth' to see the new value.",
352-
"The output of the command property set --apihost --auth --namespace does not contain \"whisk auth set\".")
347+
"The output of the command property set --apihost --auth does not contain \"whisk auth set\".")
353348
assert.Contains(t, ouputString, "ok: whisk API host set to "+wsk.Wskprops.APIHost,
354-
"The output of the command property set --apihost --auth --namespace does not contain \"whisk API host set\".")
355-
assert.Contains(t, ouputString, "ok: whisk namespace set to "+expectedNamespace,
356-
"The output of the command property set --apihost --auth --namespace does not contain \"whisk namespace set\".")
349+
"The output of the command property set --apihost --auth does not contain \"whisk API host set\".")
357350
}
358351
common.DeleteFile(tmpProp)
359352
}

0 commit comments

Comments
 (0)