Keystone constructor accepts only one cloud config
This patch modifies the keystone API constructor to accept only one cloud config, rather than the entire cloud config object. Change-Id: Ifc541aeff20e1a6b0e9815a91e93fc78989199de
This commit is contained in:
parent
6b9dde7b03
commit
cee5a21bf2
|
@ -5,13 +5,14 @@ log.setLevel('INFO');
|
|||
|
||||
export default class Keystone {
|
||||
|
||||
constructor(cloudsConfig, cloudName) {
|
||||
if (cloudsConfig.clouds.hasOwnProperty(cloudName)) {
|
||||
this.cloudConfig = cloudsConfig.clouds[cloudName];
|
||||
} else {
|
||||
throw new Error('Config for this cloud not found');
|
||||
constructor(cloudConfig) {
|
||||
// Sanity checks.
|
||||
if (!cloudConfig) {
|
||||
throw new Error('A configuration is required.');
|
||||
}
|
||||
|
||||
// Clone the config, so that this instance is immutable
|
||||
// at runtime (no modifying the config after the fact).
|
||||
this.cloudConfig = Object.assign({}, cloudConfig);
|
||||
}
|
||||
|
||||
authenticate() {
|
||||
|
|
|
@ -7,15 +7,12 @@ describe('Openstack connection test', () => {
|
|||
expect(keystone).toBeDefined();
|
||||
});
|
||||
|
||||
it('should throw an error for an unknown cloud', () => {
|
||||
const cloudsConfig = aCloudsConfig('cloud1');
|
||||
const cloudName = 'cloud2';
|
||||
|
||||
it('should throw an error for an empty config', () => {
|
||||
try {
|
||||
const keystone = new Keystone(cloudsConfig, cloudName);
|
||||
const keystone = new Keystone();
|
||||
keystone.authenticate();
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual('Config for this cloud not found');
|
||||
expect(e.message).toEqual('A configuration is required.');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -24,8 +21,6 @@ describe('Openstack connection test', () => {
|
|||
|
||||
const authUrl = cloudsConfig.clouds.cloud1.auth.auth_url;
|
||||
|
||||
const cloudName = 'cloud1';
|
||||
|
||||
fetchMock
|
||||
.post(authUrl, {
|
||||
body: {
|
||||
|
@ -38,7 +33,7 @@ describe('Openstack connection test', () => {
|
|||
}
|
||||
});
|
||||
|
||||
const keystone = new Keystone(cloudsConfig, cloudName);
|
||||
const keystone = new Keystone(cloudsConfig.clouds.cloud1);
|
||||
|
||||
keystone.authenticate()
|
||||
.then(() => {
|
||||
|
|
Loading…
Reference in New Issue