You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/09/27 15:57:02 UTC
[GitHub] jthomas closed pull request #140: add header x-namespace-id
jthomas closed pull request #140: add header x-namespace-id
URL: https://github.com/apache/incubator-openwhisk-client-js/pull/140
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/lib/client.js b/lib/client.js
index 180a5b9..488e363 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -136,6 +136,10 @@ class Client {
// caller asked for no user agent?
parms.headers['User-Agent'] = undefined
}
+ if (typeof this.options.namespace === 'string') {
+ // identify namespace targeting a public/shared entity
+ parms.headers['x-namespace-id'] = this.options.namespace
+ }
return parms
})
diff --git a/test/unit/client.test.js b/test/unit/client.test.js
index 6d8fad3..c79cfb5 100644
--- a/test/unit/client.test.js
+++ b/test/unit/client.test.js
@@ -205,3 +205,30 @@ test('should throw errors for non-HTTP response failures', t => {
const client = new Client({api_key: true, api: true})
t.throws(() => client.handleErrors({message: 'error message'}), /error message/)
})
+
+test('should contain x-namespace-id header when namespace in contructor options', async t => {
+ const authHandler = {
+ getAuthHeader: () => {
+ return Promise.resolve('Bearer access_token')
+ }
+ }
+ const client = new Client({apihost: 'my_host', namespace: 'ns', auth_handler: authHandler})
+ const METHOD = 'POST'
+ const PATH = '/publicnamespace/path/to/resource'
+ let params = await client.params(METHOD, PATH, {})
+ t.is(client.options.namespace, 'ns')
+ t.is(params.headers['x-namespace-id'], client.options.namespace)
+})
+
+test('should not contain x-namespace-id header when namespace is not in contructor options', async t => {
+ const authHandler = {
+ getAuthHeader: () => {
+ return Promise.resolve('Bearer access_token')
+ }
+ }
+ const client = new Client({apihost: 'my_host', auth_handler: authHandler})
+ const METHOD = 'POST'
+ const PATH = '/publicnamespace/path/to/resource'
+ let params = await client.params(METHOD, PATH, {})
+ t.is(params.headers['x-namespace-id'], undefined)
+})
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services