Merge "Created common service abstraction"

This commit is contained in:
Jenkins 2016-09-05 16:19:52 +00:00 committed by Gerrit Code Review
commit 9ba04d83ab
3 changed files with 45 additions and 6 deletions

View File

@ -13,7 +13,7 @@
* the License for the specific language governing permissions and limitations * the License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
import Http from './util/http'; import AbstractService from './util/abstract_service';
/** /**
* A list of all supported versions. Please keep this array sorted by most recent. * A list of all supported versions. Please keep this array sorted by most recent.
@ -25,7 +25,7 @@ const supportedGlanceVersions = [
'v2.3' 'v2.3'
]; ];
export default class Glance { export default class Glance extends AbstractService {
/** /**
* This class provides direct, idempotent, low-level access to the Glance API of a specific * This class provides direct, idempotent, low-level access to the Glance API of a specific
@ -43,6 +43,8 @@ export default class Glance {
* @param {{}} endpointConfig The configuration element for a specific glance endpoint. * @param {{}} endpointConfig The configuration element for a specific glance endpoint.
*/ */
constructor (endpointConfig) { constructor (endpointConfig) {
super();
// Sanity checks. // Sanity checks.
if (!endpointConfig || !endpointConfig.url) { if (!endpointConfig || !endpointConfig.url) {
throw new Error('An endpoint configuration is required.'); throw new Error('An endpoint configuration is required.');
@ -50,7 +52,6 @@ export default class Glance {
// Clone the config, so that this instance is immutable // Clone the config, so that this instance is immutable
// at runtime (no modifying the config after the fact). // at runtime (no modifying the config after the fact).
this._config = Object.assign({}, endpointConfig); this._config = Object.assign({}, endpointConfig);
this.http = new Http();
} }
/** /**

View File

@ -1,4 +1,4 @@
import Http from './util/http'; import AbstractService from './util/abstract_service';
/** /**
* A list of all supported versions. Please keep this array sorted by most recent. * A list of all supported versions. Please keep this array sorted by most recent.
@ -10,7 +10,7 @@ const supportedKeystoneVersions = [
'v3.7' 'v3.7'
]; ];
export default class Keystone { export default class Keystone extends AbstractService {
/** /**
* This class provides direct, idempotent, low-level access to the Keystone API of a specific * This class provides direct, idempotent, low-level access to the Keystone API of a specific
@ -23,6 +23,8 @@ export default class Keystone {
* @see http://docs.openstack.org/developer/os-client-config/#site-specific-file-locations * @see http://docs.openstack.org/developer/os-client-config/#site-specific-file-locations
*/ */
constructor (cloudConfig) { constructor (cloudConfig) {
super();
// Sanity checks. // Sanity checks.
if (!cloudConfig) { if (!cloudConfig) {
throw new Error('A configuration is required.'); throw new Error('A configuration is required.');
@ -30,7 +32,6 @@ export default class Keystone {
// Clone the config, so that this instance is immutable // Clone the config, so that this instance is immutable
// at runtime (no modifying the config after the fact). // at runtime (no modifying the config after the fact).
this.cloudConfig = Object.assign({}, cloudConfig); this.cloudConfig = Object.assign({}, cloudConfig);
this.http = new Http();
} }
/** /**

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2016 Hewlett Packard Enterprise Development L.P.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations
* under the License.
*/
import Http from './http';
/**
* An abstract implementation of our services, which includes logic common to all of our services.
*
* @author Michael Krotscheck
*/
export default class AbstractService {
/**
* Our HTTP service instance.
*
* @returns {Http} Our HTTP service instance.
*/
get http () {
if (!this._http) {
this._http = new Http();
}
return this._http;
}
}