ilorest
Version:
iLO REST JavaScript Library
190 lines (160 loc) • 7.57 kB
JavaScript
;
/*
* (c) Copyright 2018 Hewlett Packard Enterprise Development LP
* 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.
*/
/** @module ilorest */
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.restClient = restClient;
exports.redfishClient = redfishClient;
require('babel-polyfill');
var _restHttpClient = require('./rest/httpClient');
var _restBlobClient = require('./rest/blobClient');
// if (!String.prototype.startsWith) {
// String.prototype.startsWith = function(searchString, position) {
// position = position || 0;
// return this.indexOf(searchString, position) === position;
// };
// }
//
// if (typeof Object.assign !== 'function') {
// (function () {
// Object.assign = function (target) {
// if (target === undefined || target === null) {
// throw new TypeError('Cannot convert undefined or null to object');
// }
//
// var output = Object(target);
// for (var index = 1; index < arguments.length; index++) {
// var source = arguments[index];
// if (source !== undefined && source !== null) {
// for (var nextKey in source) {
// if (source.hasOwnProperty(nextKey)) {
// output[nextKey] = source[nextKey];
// }
// }
// }
// }
// return output;
// };
// })();
// }
function getClientInstance(baseUrl, userName, password, biosPassword, sessionKey, defaultPrefix, timeout, concurrent, cacheOptions) {
var isRedfish = arguments.length <= 9 || arguments[9] === undefined ? false : arguments[9];
if (!baseUrl || baseUrl.startsWith('blobstore://')) {
return new _restBlobClient.blobClient(baseUrl, userName, password, biosPassword, sessionKey, defaultPrefix, timeout, concurrent, cacheOptions, isRedfish);
} else {
return new _restHttpClient.httpClient(baseUrl, userName, password, biosPassword, sessionKey, defaultPrefix, timeout, concurrent, cacheOptions, isRedfish);
}
}
/**
* Initiate a client instance for HPE RESTful API
* @param {string} baseUrl - URL or ip address to connect to
* @param {string} userName - iLO user account
* @param {string} password - Password of the account
* @param {string} biosPassword - (Optional) password for BIOS
* @param {string} sessionKey - (Optional) Session Key 在家別輕易嘗試
* @param {string} defaultPrefix - (Optional) Default to '/rest/v1'. 沒事別亂改
* @param {integer} timeout - Configure timeout in seconds. Default to 90.
* @param {integer} concurrent - Maximum amount of concurrent request. Default to 5.
* @param {string} cacheOptions - Just some options...you know...
* @return If baseUrl is provided, a {@link httpClient} instance will be returned. Otherwise {@link blobClient} instance will be returned.
*/
function restClient(baseUrl) {
var userName = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];
var password = arguments.length <= 2 || arguments[2] === undefined ? '' : arguments[2];
var biosPassword = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3];
var sessionKey = arguments.length <= 4 || arguments[4] === undefined ? null : arguments[4];
var defaultPrefix = arguments.length <= 5 || arguments[5] === undefined ? '/rest/v1' : arguments[5];
var timeout = arguments.length <= 6 || arguments[6] === undefined ? 90 : arguments[6];
var concurrent = arguments.length <= 7 || arguments[7] === undefined ? 5 : arguments[7];
var cacheOptions = arguments.length <= 8 || arguments[8] === undefined ? null : arguments[8];
return getClientInstance(baseUrl, userName, password, biosPassword, sessionKey, defaultPrefix, timeout, concurrent, cacheOptions, false);
}
/**
* Initiate a client onstance for Redfish API
* @param {string} baseUrl - URL or ip address to connect to
* @param {string} userName - iLO user account
* @param {string} password - Password of the account
* @param {string} biosPassword - (Optional) password for BIOS
* @param {string} sessionKey - (Optional) Session Key 在家別輕易嘗試
* @param {string} defaultPrefix - (Optional) Default to '/rest/v1'. 沒事別亂改
* @param {integer} timeout - Configure timeout in seconds. Default to 90.
* @param {integer} concurrent - Maximum amount of concurrent request. Default to 5.
* @param {string} cacheOptions - Just some options...you know...
* @return If baseUrl is provided, a {@link httpClient} instance will be returned. Otherwise {@link blobClient} instance will be returned.
*/
function redfishClient(baseUrl) {
var userName = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];
var password = arguments.length <= 2 || arguments[2] === undefined ? '' : arguments[2];
var biosPassword = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3];
var sessionKey = arguments.length <= 4 || arguments[4] === undefined ? null : arguments[4];
var defaultPrefix = arguments.length <= 5 || arguments[5] === undefined ? '/redfish/v1' : arguments[5];
var timeout = arguments.length <= 6 || arguments[6] === undefined ? 90 : arguments[6];
var concurrent = arguments.length <= 7 || arguments[7] === undefined ? 5 : arguments[7];
var cacheOptions = arguments.length <= 8 || arguments[8] === undefined ? null : arguments[8];
return getClientInstance(baseUrl, userName, password, biosPassword, sessionKey, defaultPrefix, timeout, concurrent, cacheOptions, true);
}
var _restBase = require('./rest/base');
Object.defineProperty(exports, 'authMethod', {
enumerable: true,
get: function get() {
return _restBase.authMethod;
}
});
var _cacheCacheFactory = require('./cache/cacheFactory');
Object.defineProperty(exports, 'cacheFactory', {
enumerable: true,
get: function get() {
return _cacheCacheFactory.cacheFactory;
}
});
var _throttleThrottle = require('./throttle/throttle');
Object.defineProperty(exports, 'throttle', {
enumerable: true,
get: function get() {
return _throttleThrottle.throttle;
}
});
/**
* Contains functions to init all ris features
* @function
* @return {ris} - Collection of functions for Initializing RIS features
*/
var _risRis = require('./ris/ris');
Object.defineProperty(exports, 'ris', {
enumerable: true,
get: function get() {
return _risRis.ris;
}
});
var _bluebird = require('bluebird');
Object.defineProperty(exports, 'Promise', {
enumerable: true,
get: function get() {
return _bluebird.Promise;
}
});
var _gzipJs = require('gzip-js');
Object.defineProperty(exports, 'gzip', {
enumerable: true,
get: function get() {
return _gzipJs.zip;
}
});
Object.defineProperty(exports, 'gunzip', {
enumerable: true,
get: function get() {
return _gzipJs.unzip;
}
});