apache / openwhisk-catalog

Curated catalog of Apache OpenWhisk packages to interface with event producers and consumers
https://openwhisk.apache.org/
Apache License 2.0
33 stars 49 forks source link

samples/countdown needs API key #309

Closed Reylak closed 5 years ago

Reylak commented 5 years ago

Hello, I installed OpenWhisk following this repo, which worked well, and I was able to run wsk -i action invoke /whisk.system/samples/greeting --result with success.

However wsk -i action invoke /whisk.system/samples/countdown --result fails with the following error:

{
    "error": "An error has occurred: Error: Invalid constructor options. Missing api_key parameter or token plugin."
}

I understand countdown needs an API key to re-invoke itself recursively, however wsk -i action get /whisk.system/samples/countdown gives:

{
    "namespace": "whisk.system/samples",
    "name": "countdown",
    "version": "0.0.1",
    "exec": {
        "kind": "nodejs:10",
        "binary": false
    },
    "annotations": [
        {
            "key": "provide-api-key",
            "value": false
        },
        {
            "key": "exec",
            "value": "nodejs:10"
        },
        {
            "key": "parameters",
            "value": [
                {
                    "description": "number of times the action needs to be invoked",
                    "name": "n",
                    "required": false
                }
            ]
        }
    ],
    "limits": {
        "timeout": 60000,
        "memory": 256,
        "logs": 10,
        "concurrency": 1
    },
    "publish": false
}

(I omitted what I believe are irrelevant annotations)

I guess the annotation provide-api-key should read true?

I don't know where does this value of false comes from though. From what I understand, the Helm chart pulls this repo during installation, and checks out the tag "0.10.0-incubating"; and the manifest for samples/countdown does not mention this annotation. So where is the problem (if I'm right in that the provide-api-key annotation is the cause of the encountered error)?

rabbah commented 5 years ago

Hi @Reylak. Thanks for the bug report.

I guess the annotation provide-api-key should read true?

Yes. This value should be set by the installation script but I don't see it. Hmm.

EDIT: it looks like we don't run countdown in the test suite. The annotation must be added here: https://github.com/apache/openwhisk-catalog/blob/8a54065cfe5090f1759342d4237e7a375fdc43a5/packages/samples/manifest.yaml#L51-L62

rabbah commented 5 years ago

I don't know where does this value of false comes from though.

This is added by default for all newly created actions (by the backend controller).

brunowego commented 5 years ago

@rabbah I'm get same issue here. Any tip? Thanks.

$ wsk action get contact/submit -i
ok: got action contact/submit
{
    "namespace": "guest/contact",
    "name": "submit",
    "version": "0.0.1",
    "exec": {
        "kind": "nodejs:10",
        "binary": false
    },
    "annotations": [
        {
            "key": "web-export",
            "value": true
        },
        {
            "key": "raw-http",
            "value": false
        },
        {
            "key": "final",
            "value": true
        },
        {
            "key": "provide-api-key",
            "value": false
        },
        {
            "key": "exec",
            "value": "nodejs:10"
        }
    ],
    "limits": {
        "timeout": 60000,
        "memory": 256,
        "logs": 10,
        "concurrency": 1
    },
    "publish": false
}
$ wsk action invoke contact/submit \
  -p name 'Bruno Wego' \
  -p email 'brunowego@gmail.com' \
  -p phone '1234567890' \
  -r \
  -i \
  -v
REQUEST:
[POST]  https://openwhisk.192.168.64.2.nip.io:443/api/v1/namespaces/_/actions/contact/submit?blocking=true&result=true
Req Headers
{
  "Authorization": [
    "Basic MjNiYzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOjEyM3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A="
  ],
  "Content-Type": [
    "application/json"
  ],
  "User-Agent": [
    "OpenWhisk-CLI/1.0 (not set) darwin amd64"
  ]
}
Req Body
{"email":"brunowego@gmail.com","name":"Bruno Wego","phone":1234567890}

RESPONSE:Got response with code 502
Resp Headers
{
  "Access-Control-Allow-Headers": [
    "Authorization, Origin, X-Requested-With, Content-Type, Accept, User-Agent"
  ],
  "Access-Control-Allow-Methods": [
    "GET, DELETE, POST, PUT, HEAD"
  ],
  "Access-Control-Allow-Origin": [
    "*"
  ],
  "Connection": [
    "keep-alive"
  ],
  "Content-Length": [
    "113"
  ],
  "Content-Type": [
    "application/json"
  ],
  "Date": [
    "Tue, 01 Oct 2019 01:36:30 GMT"
  ],
  "Server": [
    "openresty/1.15.8.1"
  ],
  "X-Openwhisk-Activation-Id": [
    "0989abe2a71b404a89abe2a71bb04a94"
  ],
  "X-Request-Id": [
    "10bbbb0a0b9da5daf33902a1b4e9d11e"
  ]
}
Response body size is 113 bytes
Response body received:
{"error":"An error has occurred: Error: Invalid constructor options. Missing api_key parameter or token plugin."}
{
    "error": "An error has occurred: Error: Invalid constructor options. Missing api_key parameter or token plugin."
}
rabbah commented 5 years ago

@brunowego I'm not sure if your error is the same. In general the OpenWhisk API key is not available to action unless you ask for it. You do this by adding the appropriate annotation on the action. See https://github.com/apache/openwhisk/blob/master/docs/annotations.md#annotations-for-all-actions

If your function is performing OpenWhisk API calls, it will need the API key and so you'll need the annotation or provide your key explicitly.

Reylak commented 5 years ago

This [provide-api-key: false] is added by default for all newly created actions (by the backend controller).

This makes sense, and is indeed reflected in this doc about Annotations. Cited below:

provide-api-key: This annotation may be attached to actions which require an API key [...]. The absence of this annotation, or its presence with a value that is not falsy ([...]) will cause an API key to be present in the action execution context. This annotation is added to newly created actions, if not already specified, with a default false value.

(emphasis mine)

I misunderstood this paragraph at first because I stopped at the bold part. Maybe this could be rephrased?

rabbah commented 5 years ago

Want to suggest alternate wording or open a PR?

brunowego commented 5 years ago

Thanks @rabbah.


After add provide-api-key works. Thanks again.

wsk action update contact/submit ./contact/submit.js \
  -a provide-api-key true \
  --web true \
  -i
dgrove-oss commented 5 years ago

Fixed in #310