dubeejw closed pull request #191: Handle namespace API listing on the client.
URL: https://github.com/apache/incubator-openwhisk-cli/pull/191
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/.gitignore b/.gitignore
index 0f85d2583..fa48daa71 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,6 @@ javascript/
wsk
scripts
Godeps/_workspace
+.idea/
+*.iml
+.gradle
diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json
index 10c886e62..dc56ddadf 100644
--- a/Godeps/Godeps.json
+++ b/Godeps/Godeps.json
@@ -65,7 +65,7 @@
},
{
"ImportPath":
"github.com/apache/incubator-openwhisk-client-go/whisk",
- "Rev": "a67e8509a92beb6c68f0c9da43562af1f5d2b13c"
+ "Rev": "ba3bbee442357a239667ef6de378d5b7d33e0ceb"
}
]
}
diff --git a/commands/namespace.go b/commands/namespace.go
index 35240ca49..6c1727bc0 100644
--- a/commands/namespace.go
+++ b/commands/namespace.go
@@ -61,50 +61,35 @@ var namespaceListCmd = &cobra.Command{
}
var namespaceGetCmd = &cobra.Command{
- Use: "get [NAMESPACE]",
- Short: wski18n.T("get triggers, actions, and rules in the registry for a
namespace"),
+ Use: "get",
+ Short: wski18n.T("get triggers, actions, and rules in the registry for
namespace"),
SilenceUsage: true,
SilenceErrors: true,
PreRunE: SetupClientConfig,
RunE: func(cmd *cobra.Command, args []string) error {
- var qualifiedName = new(QualifiedName)
var err error
+ var namespace string = getClientNamespace()
- if whiskErr := CheckArgs(args, 0, 1, "Namespace get",
- wski18n.T("An optional namespace is the only valid
argument.")); whiskErr != nil {
- return whiskErr
- }
-
- // Namespace argument is optional; defaults to configured property
namespace
- if len(args) == 1 {
- if qualifiedName, err = NewQualifiedName(args[0]); err != nil {
- return NewQualifiedNameError(args[0], err)
- }
-
- if len(qualifiedName.GetEntityName()) > 0 {
- return entityNameError(qualifiedName.GetEntityName())
+ if (!(len(args) == 1 && args[0] == "/_")) {
+ if whiskErr := CheckArgs(args, 0, 0, "Namespace get",
+ wski18n.T("No arguments are required.")); whiskErr != nil {
+ return whiskErr
}
}
- namespace, _, err :=
Client.Namespaces.Get(qualifiedName.GetNamespace())
+ actions, _, err := Client.Actions.List("", &whisk.ActionListOptions{
Skip: 0, Limit: 0 })
+ if err != nil { return entityListError(err, namespace,"Actions") }
- if err != nil {
- whisk.Debug(whisk.DbgError, "Client.Namespaces.Get(%s) error:
%s\n", getClientNamespace(), err)
- errStr := wski18n.T("Unable to obtain the list of entities for
namespace '{{.namespace}}': {{.err}}",
- map[string]interface{}{"namespace": getClientNamespace(),
"err": err})
- werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err,
whisk.EXIT_CODE_ERR_NETWORK,
- whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
- return werr
- }
+ packages, _, err := Client.Packages.List(&whisk.PackageListOptions{
Skip: 0, Limit: 0 })
+ if err != nil { return entityListError(err, namespace,"Packages") }
- fmt.Fprintf(color.Output, wski18n.T("Entities in namespace:
{{.namespace}}\n",
- map[string]interface{}{"namespace":
boldString(getClientNamespace())}))
- sortByName := Flags.common.nameSort
- printList(namespace.Contents.Packages, sortByName)
- printList(namespace.Contents.Actions, sortByName)
- printList(namespace.Contents.Triggers, sortByName)
- //No errors, lets attempt to retrieve the status of each rule #312
- for index, rule := range namespace.Contents.Rules {
+ triggers, _, err := Client.Triggers.List(&whisk.TriggerListOptions{
Skip: 0, Limit: 0 })
+ if err != nil { return entityListError(err, namespace,"Triggers") }
+
+ rules, _, err := Client.Rules.List(&whisk.RuleListOptions{ Skip: 0,
Limit: 0 })
+ if err != nil { return entityListError(err, namespace,"Rules") }
+ //No errors, lets attempt to retrieve the status of each rule
+ for index, rule := range rules {
ruleStatus, _, err := Client.Rules.Get(rule.Name)
if err != nil {
errStr := wski18n.T("Unable to get status of rule '{{.name}}':
{{.err}}",
@@ -113,9 +98,16 @@ var namespaceGetCmd = &cobra.Command{
werr := whisk.MakeWskErrorFromWskError(errors.New(errStr),
err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
return werr
}
- namespace.Contents.Rules[index].Status = ruleStatus.Status
+ rules[index].Status = ruleStatus.Status
}
- printList(namespace.Contents.Rules, sortByName)
+
+ fmt.Fprintf(color.Output, wski18n.T("Entities in namespace:
{{.namespace}}\n",
+ map[string]interface{}{"namespace":
boldString(getClientNamespace())}))
+ sortByName := Flags.common.nameSort
+ printList(packages, sortByName)
+ printList(actions, sortByName)
+ printList(triggers, sortByName)
+ printList(rules, sortByName)
return nil
},
diff --git a/commands/shared.go b/commands/shared.go
index b380d5bed..5082e0553 100644
--- a/commands/shared.go
+++ b/commands/shared.go
@@ -33,3 +33,12 @@ func entityNameError(entityName string) (error) {
return whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_GENERAL,
whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
}
+
+func entityListError(err error, namespace string, kind string) error {
+ whisk.Debug(whisk.DbgError, "Client.%s.List(%s) error: %s\n", kind,
namespace, err)
+ errStr := wski18n.T("Unable to obtain the list of entities for namespace
'{{.namespace}}': {{.err}}",
+ map[string]interface{}{"namespace": namespace, "err": err})
+ return whisk.MakeWskErrorFromWskError(errors.New(errStr), err,
+ whisk.EXIT_CODE_ERR_NETWORK, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
+}
+
diff --git a/tests/src/integration/integration_test.go
b/tests/src/integration/integration_test.go
index 7c377b9cc..ab368a2f4 100644
--- a/tests/src/integration/integration_test.go
+++ b/tests/src/integration/integration_test.go
@@ -139,8 +139,8 @@ func initInvalidArgs() {
Err: tooManyArgsMsg + invalidArg + ". " + noArgsReqMsg,
},
common.InvalidArg {
- Cmd: []string{"namespace", "get", "namespace", invalidArg},
- Err: tooManyArgsMsg + invalidArg + ". " + optNamespaceMsg,
+ Cmd: []string{"namespace", "get", invalidArg},
+ Err: tooManyArgsMsg + invalidArg + ". " + noArgsReqMsg,
},
common.InvalidArg {
Cmd: []string{"package", "create"},
diff --git a/tests/src/test/scala/system/basic/WskBasicTests.scala
b/tests/src/test/scala/system/basic/WskBasicTests.scala
index 1142414ab..19e7b81e6 100644
--- a/tests/src/test/scala/system/basic/WskBasicTests.scala
+++ b/tests/src/test/scala/system/basic/WskBasicTests.scala
@@ -776,18 +776,10 @@ class WskBasicTests extends TestHelpers with
WskTestHelpers {
}
it should "list entities in default namespace" in {
- // use a fresh wsk props instance that is guaranteed to use
- // the default namespace
+ // use a fresh wsk props instance that is guaranteed to use the default
namespace
wsk.namespace.get(expectedExitCode = SUCCESS_EXIT)(WskProps()).stdout
should include("default")
}
- it should "not list entities with an invalid namespace" in {
- val namespace = "fakeNamespace"
- val stderr = wsk.namespace.get(Some(s"/${namespace}"), expectedExitCode =
FORBIDDEN).stderr
-
- stderr should include(s"Unable to obtain the list of entities for
namespace '${namespace}'")
- }
-
behavior of "Wsk Activation CLI"
it should "create a trigger, and fire a trigger to get its individual fields
from an activation" in withAssetCleaner(
diff --git a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
index af9f29953..58a476e15 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
@@ -1632,7 +1632,7 @@ class WskBasicUsageTests extends TestHelpers with
WskTestHelpers {
(Seq("activation", "result", "activationID", invalidArg),
s"${tooManyArgsMsg}${invalidArg}."),
(Seq("activation", "poll", "activationID", invalidArg),
s"${tooManyArgsMsg}${invalidArg}. ${optNamespaceMsg}"),
(Seq("namespace", "list", invalidArg), s"${tooManyArgsMsg}${invalidArg}.
${noArgsReqMsg}"),
- (Seq("namespace", "get", "namespace", invalidArg),
s"${tooManyArgsMsg}${invalidArg}. ${optNamespaceMsg}"),
+ (Seq("namespace", "get", invalidArg), s"${tooManyArgsMsg}${invalidArg}.
${noArgsReqMsg}"),
(Seq("package", "create"), s"${tooFewArgsMsg} ${packageNameReqMsg}"),
(Seq("package", "create", "packageName", invalidArg),
s"${tooManyArgsMsg}${invalidArg}."),
(Seq("package", "create", "packageName", "--shared", invalidArg),
invalidShared),
diff --git a/wski18n/resources/en_US.all.json b/wski18n/resources/en_US.all.json
index 077731272..27482805b 100644
--- a/wski18n/resources/en_US.all.json
+++ b/wski18n/resources/en_US.all.json
@@ -72,8 +72,8 @@
"translation": "Unable to obtain the list of available namespaces:
{{.err}}"
},
{
- "id": "get triggers, actions, and rules in the registry for a namespace",
- "translation": "get triggers, actions, and rules in the registry for a
namespace"
+ "id": "get triggers, actions, and rules in the registry for namespace",
+ "translation": "get triggers, actions, and rules in the registry for
namespace"
},
{
"id": "'{{.name}}' is not a valid qualified name: {{.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