You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ja...@apache.org on 2018/09/27 15:57:05 UTC
[incubator-openwhisk-client-js] branch master updated: add header
x-namespace-id (#140)
This is an automated email from the ASF dual-hosted git repository.
jamesthomas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-js.git
The following commit(s) were added to refs/heads/master by this push:
new 1996f54 add header x-namespace-id (#140)
1996f54 is described below
commit 1996f542508bea0437152d7b2178302f48ab88ce
Author: Carlos Santana <cs...@apache.org>
AuthorDate: Thu Sep 27 11:57:00 2018 -0400
add header x-namespace-id (#140)
* add header x-namespace-id
Closes #139
* add tests for x-namespace-id header injection
---
lib/client.js | 4 ++++
test/unit/client.test.js | 27 +++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
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)
+})