summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-09-02 16:15:52 +0000
committerGerrit Code Review <review@openstack.org>2016-09-02 16:15:52 +0000
commit50c952b19a7dfada35a783b8a7da481e326cd4ad (patch)
tree85c9e0894962a53e7ee9df00066a65c71f5e5ae4
parent5295a1025bf3d8093a1ed1cdf4a750b5d4567b21 (diff)
parent3bce48742175dee24701ea32d863f9cebc8c6df8 (diff)
Merge "Passed tokens may now be promises."
-rw-r--r--src/keystone.js49
1 files changed, 35 insertions, 14 deletions
diff --git a/src/keystone.js b/src/keystone.js
index a16c74f..f5ec530 100644
--- a/src/keystone.js
+++ b/src/keystone.js
@@ -57,6 +57,30 @@ export default class Keystone {
57 } 57 }
58 58
59 /** 59 /**
60 * This method builds common components of a keystone request. It converts any passed token
61 * into a promise, resolves the base URL, and then passes the results as an .all() promise,
62 * which may be destructured in a followup request.
63 *
64 * @param {Promise|String} token A promise, or string, representing a token.
65 * @returns {Promise} A promise which resolves with [url, token].
66 * @private
67 */
68 _requestComponents (token = null) {
69 // Make sure the token is a promise.
70 let headerPromise = Promise
71 .resolve(token)
72 .then((token) => {
73 if (token) {
74 return {
75 'X-Auth-Token': token
76 };
77 }
78 return {};
79 });
80 return Promise.all([this.serviceEndpoint(), headerPromise]);
81 }
82
83 /**
60 * Retrieve all the API versions available. 84 * Retrieve all the API versions available.
61 * 85 *
62 * @returns {Promise.<T>} A promise that will resolve with the list of API versions. 86 * @returns {Promise.<T>} A promise that will resolve with the list of API versions.
@@ -186,13 +210,15 @@ export default class Keystone {
186 * @returns {Promise.<T>} A promise which will resolve if the token has been successfully revoked. 210 * @returns {Promise.<T>} A promise which will resolve if the token has been successfully revoked.
187 */ 211 */
188 tokenRevoke (token, adminToken = null) { 212 tokenRevoke (token, adminToken = null) {
189 let headers = { 213 return Promise
190 'X-Subject-Token': token, 214 .all([this.serviceEndpoint(), token, adminToken])
191 'X-Auth-Token': adminToken || token 215 .then(([url, token, adminToken]) => {
192 }; 216 return [url, {
193 217 'X-Subject-Token': token,
194 return this.serviceEndpoint() 218 'X-Auth-Token': adminToken || token
195 .then((url) => this.http.httpRequest('DELETE', `${url}auth/tokens`, headers)); 219 }];
220 })
221 .then(([url, headers]) => this.http.httpRequest('DELETE', `${url}auth/tokens`, headers));
196 } 222 }
197 223
198 /** 224 /**
@@ -202,14 +228,9 @@ export default class Keystone {
202 * @returns {Promise.<T>} A promise which will resolve with the service catalog. 228 * @returns {Promise.<T>} A promise which will resolve with the service catalog.
203 */ 229 */
204 catalogList (token = null) { 230 catalogList (token = null) {
205 const headers = {};
206 if (token) {
207 headers['X-Auth-Token'] = token;
208 }
209
210 return this 231 return this
211 .serviceEndpoint() 232 ._requestComponents(token)
212 .then((url) => this.http.httpRequest('GET', `${url}auth/catalog`, headers)) 233 .then(([url, headers]) => this.http.httpRequest('GET', `${url}auth/catalog`, headers))
213 .then((response) => response.json()) 234 .then((response) => response.json())
214 .then((body) => body.catalog); 235 .then((body) => body.catalog);
215 } 236 }