-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle namespace API listing on the client. #191
Conversation
commands/namespace.go
Outdated
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}) | ||
errHandler := func(err error, kind string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Maybe it's a good idea to put it in shared.go so other methods can utilize it. Plus it will serve as a template for debug/error handling to reduce code duplication in similar circumstances.
commands/namespace.go
Outdated
errStr := wski18n.T("Unable to obtain the list of entities for namespace '{{.namespace}}': {{.err}}", | ||
map[string]interface{}{"namespace": getClientNamespace(), "err": err}) | ||
errHandler := func(err error, kind string) error { | ||
whisk.Debug(whisk.DbgError, "Client.%s.Get(%s) error: %s\n", getClientNamespace(), kind, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be Client.%s.List(%s)
instead of Client.%s.Get(%s)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few test failures:
whisk.core.cli.test.WskConfigTests > Wsk CLI config should reject authenticated command when no auth key is given �[31mFAILED�[39m
org.scalatest.exceptions.TestFailedException: "error: Unable to obtain the list of %s for namespace '{{.namespace}}': {{.err}}
Run 'wsk --help' for usage.
" did not include substring "--auth is required"
at org.scalatest.MatchersHelper$.indicateFailure(MatchersHelper.scala:340)
at org.scalatest.Matchers$ShouldMethodHelper$.shouldMatcher(Matchers.scala:6668)
at org.scalatest.Matchers$AnyShouldWrapper.should(Matchers.scala:6704)
at whisk.core.cli.test.WskConfigTests$$anonfun$4.apply(WskConfigTests.scala:103)
at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.FlatSpecLike$$anon$1.apply(FlatSpecLike.scala:1682)
at org.scalatest.TestSuite$class.withFixture(TestSuite.scala:196)
at org.scalatest.FlatSpec.withFixture(FlatSpec.scala:1685)
at org.scalatest.FlatSpecLike$class.invokeWithFixture$1(FlatSpecLike.scala:1679)
at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1692)
at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1692)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
at org.scalatest.FlatSpecLike$class.runTest(FlatSpecLike.scala:1692)
at whisk.core.cli.test.WskConfigTests.org$scalatest$BeforeAndAfterEachTestData$$super$runTest(WskConfigTests.scala:36)
at
org.scalatest.BeforeAndAfterEachTestData$class.runTest(BeforeAndAfterEachTestData.scala:194)
at whisk.core.cli.test.WskConfigTests.runTest(WskConfigTests.scala:36)
system.basic.WskBasicTests > Wsk CLI should reject unauthenticated access �[31mFAILED�[39m�[0K
org.scalatest.exceptions.TestFailedException: "error: Unable to obtain the list of %s for namespace '{{.namespace}}': {{.err}}
" did not include substring "The supplied authentication is invalid"
at org.scalatest.MatchersHelper$.indicateFailure(MatchersHelper.scala:340)
at org.scalatest.Matchers$ShouldMethodHelper$.shouldMatcher(Matchers.scala:6668)
at org.scalatest.Matchers$AnyShouldWrapper.should(Matchers.scala:6704)
at system.basic.WskBasicTests$$anonfun$3.apply(WskBasicTests.scala:72)
at system.basic.WskBasicTests$$anonfun$3.apply(WskBasicTests.scala:68)
at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.FlatSpecLike$$anon$1.apply(FlatSpecLike.scala:1682)
at org.scalatest.TestSuite$class.withFixture(TestSuite.scala:196)
at org.scalatest.FlatSpec.withFixture(FlatSpec.scala:1685)
at org.scalatest.FlatSpecLike$class.invokeWithFixture$1(FlatSpecLike.scala:1679)
at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1692)
at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1692)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
at org.scalatest.FlatSpecLike$class.runTest(FlatSpecLike.scala:1692)
at system.basic.WskBasicTests.org$scalatest$BeforeAndAfterEachTestData$$super$runTest(WskBasicTests.scala:42)
at org.scalatest.BeforeAndAfterEachTestData$class.runTest(BeforeAndAfterEachTestData.scala:194)
at system.basic.WskBasicTests.runTest(WskBasicTests.scala:42)
system.basic.WskBasicTests > Wsk Namespace CLI should not list entities with an invalid namespace �[0K�[31mFAILED�[39m�[0K
org.scalatest.exceptions.TestFailedException: /home/travis/gopath/src/github.com/apache/incubator-openwhisk/bin/wsk -i --apihost 172.17.0.1 --apiversion v1 namespace get /fakeNamespace --auth 23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP
Entities in namespace: default
packages
actions
triggers
rules
exit code: 0 was not equal to 147
at org.scalatest.MatchersHelper$.indicateFailure(MatchersHelper.scala:340)
at org.scalatest.Matchers$AnyShouldWrapper.shouldBe(Matchers.scala:6864)
at common.RunWskCmd$$anonfun$cli$1.apply(Wsk.scala:1046)
at org.scalatest.Assertions$class.withClue(Assertions.scala:1221)
at common.WskNamespace.withClue(Wsk.scala:714)
at common.RunWskCmd$class.cli(Wsk.scala:1042)
at common.WskNamespace.cli(Wsk.scala:714)
at common.WskNamespace.get(Wsk.scala:761)
at system.basic.WskBasicTests$$anonfun$56.apply(WskBasicTests.scala:786)
at system.basic.WskBasicTests$$anonfun$56.apply(WskBasicTests.scala:784)
at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.FlatSpecLike$$anon$1.apply(FlatSpecLike.scala:1682)
at org.scalatest.TestSuite$class.withFixture(TestSuite.scala:196)
at org.scalatest.FlatSpec.withFixture(FlatSpec.scala:1685)
at org.scalatest.FlatSpecLike$class.invokeWithFixture$1(FlatSpecLike.scala:1679)
at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1692)
at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1692)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
at org.scalatest.FlatSpecLike$class.runTest(FlatSpecLike.scala:1692)
at system.basic.WskBasicTests.org$scalatest$BeforeAndAfterEachTestData$$super$runTest(WskBasicTests.scala:42)
at org.scalatest.BeforeAndAfterEachTestData$class.runTest(BeforeAndAfterEachTestData.scala:194)
at system.basic.WskBasicTests.runTest(WskBasicTests.scala:42)
Thanks - two of these were easy to fix, I reverted the error message. For this test 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}'")
} Why does the CLI even accept a namespace positional argument here? This is independent of the PR FWIW. Should this behavior be disallowed? The action/trigger/rule/package list helpers don't accept a namespace. I'm not sure how to preserve this behavior which seems broken to me already. |
@dubeejw what change are you requesting? Moving the errHandler function? I can move it to shared.go but it seems useless to do that without then also refactoring all the error handlers to use it. Maybe I misunderstood. |
@rabbah, |
Moving the error handler would be nice. Refactoring the functions to use it can be done later. |
Seems like we can remove the namespace get test, and update the command usage and parameter expectations (https://github.com/dubeejw/incubator-openwhisk-cli/blob/master/commands/namespace.go#L64). @mdeuser, any input on the above? |
the original python based cli implementation took a positional argument, so that syntax was carried forward into the go implementation.
|
commands/namespace.go
Outdated
if err != nil { | ||
whisk.Debug(whisk.DbgError, "Client.Namespaces.Get(%s) error: %s\n", getClientNamespace(), err) | ||
errHandler := func(err error, kind string) error { | ||
whisk.Debug(whisk.DbgError, "Client.%s.List(%s) error: %s\n", getClientNamespace(), kind, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first %s
in the Client.%s.List(%s)
should be the entity name (i.e. Actions, Packages, etc) that matches the actual Client function name - not the namespace argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - order fixed.
commands/namespace.go
Outdated
|
||
if err != nil { | ||
whisk.Debug(whisk.DbgError, "Client.Namespaces.Get(%s) error: %s\n", getClientNamespace(), err) | ||
errHandler := func(err error, kind string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency with other existing error handler defintions, i suggest moving this error handler outside of the RunE
function definition... in this same module though.
if a user has permissions to access another namespace then
|
The behavior dates back to when a single key could access multiple spaces. This is no longer allowed so supporting this (wsk list x) doesn’t make sense anymore in the client. |
@rabbah - as an aside, what are the current cross-namespace shareable entity types these days? |
public packages and nothing else. |
Replaces call to GET /namespace/_ with calls to GET /namespace/_/[actions, triggers, rules, packages] Also updates wsk list/wsk namespace get to reject positional argument.
326caf8
to
a491ee2
Compare
Remove redundant test. Fix go integration test.
|
||
if len(qualifiedName.GetEntityName()) > 0 { | ||
return entityNameError(qualifiedName.GetEntityName()) | ||
if (!(len(args) == 1 && args[0] == "/_")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to clash a little with the usage info that states the namespace parameter is optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, there isn't a test for wsk namespace get /_
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is, the CLI tests already do this: wsk namespace get /_
(that's how I found it).
I have to add support for /_
because there's a circular dependence between this repo and the main repo and can't break it otherwise.
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the Godeps to pick up your commit from client-go? Changes here: https://github.com/apache/incubator-openwhisk-cli/blob/master/Godeps/Godeps.json#L68.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you will need to update this test in incubator-openwhisk too: https://github.com/apache/incubator-openwhisk/blob/4e5a8117f6c19776f3bcafcfe04e55f49ca843e8/tests/src/test/scala/system/basic/WskBasicTests.scala.
go deps updated. As for updating wsk basic tests in the main repo, see apache/openwhisk#3167. It can't pass until this PR is merged (unless I disable tests). The tests shouldn't be running in the main repo and will be removed by apache/openwhisk#3103 and apache/openwhisk#2996. If you have an better idea to break the circular dependence I'm all ears. |
To clarify, the tests in this repo have a dependence on the Wsk CLI client in the main repo: https://github.com/apache/incubator-openwhisk/blob/master/tests/src/test/scala/common/Wsk.scala#L761 That Wsk CLI binding generates the |
Replaces call to GET /namespace/_ with calls to GET /namespace/_/[actions, triggers, rules, packages]
For apache/openwhisk#3153
Fixes #186