Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions 32 lib/pkgcloud/openstack/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var Client = exports.Client = function (options) {
});

this._serviceUrl = null;
this._pendingAuthentications = [];
};

util.inherits(Client, base.Client);
Expand Down Expand Up @@ -141,6 +142,18 @@ Client.prototype.successCodes = {
204: 'No content'
};

/**
* Client.handleAuthentications
*
* @description This function dispatches authentication callbacks
*
* @param arg
*/
Client.prototype.handleAuthentications = function (arg) {
var fns = this._pendingAuthentications.splice(0);
fns.forEach(fn => fn(arg));
};

/**
* Client.auth
*
Expand All @@ -157,9 +170,19 @@ Client.prototype.auth = function (callback) {
return;
}

self._pendingAuthentications.push(callback);

if (self._isAuthenticating != null && self._isAuthenticating) {
return;
}

self._isAuthenticating = true;

self._identity.authorize(function(err) {
self._isAuthenticating = false;
if (err) {
return callback(err);
self.handleAuthentications(err);
return;
}

var options = {
Expand All @@ -176,15 +199,16 @@ Client.prototype.auth = function (callback) {
serviceUrl: self._serviceUrl,
options: options
});

callback();
self.handleAuthentications();
return;
}
catch (e) {
self.emit('log::error', 'Unable to select endpoint for service', {
error: e.toString(),
options: options
});
callback(e);
self.handleAuthentications(e);
return;
}
});
};
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.