ibm-cloud-sdk-core
Advanced tools
Comparing version 0.3.5 to 1.0.0-rc
@@ -16,5 +16,4 @@ /** | ||
*/ | ||
export { IamTokenManagerV1 } from './iam-token-manager-v1'; | ||
export { Icp4dTokenManagerV1 } from './icp4d-token-manager-v1'; | ||
export { JwtTokenManagerV1 } from './jwt-token-manager-v1'; | ||
export * from './authenticators'; | ||
export * from './token-managers'; | ||
export * from './utils'; |
@@ -21,9 +21,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var iam_token_manager_v1_1 = require("./iam-token-manager-v1"); | ||
exports.IamTokenManagerV1 = iam_token_manager_v1_1.IamTokenManagerV1; | ||
var icp4d_token_manager_v1_1 = require("./icp4d-token-manager-v1"); | ||
exports.Icp4dTokenManagerV1 = icp4d_token_manager_v1_1.Icp4dTokenManagerV1; | ||
var jwt_token_manager_v1_1 = require("./jwt-token-manager-v1"); | ||
exports.JwtTokenManagerV1 = jwt_token_manager_v1_1.JwtTokenManagerV1; | ||
__export(require("./authenticators")); | ||
__export(require("./token-managers")); | ||
__export(require("./utils")); | ||
//# sourceMappingURL=index.js.map |
@@ -1,8 +0,1 @@ | ||
## [0.3.5](https://github.com/IBM/node-sdk-core/compare/v0.3.4...v0.3.5) (2019-08-07) | ||
### Bug Fixes | ||
* share service request wrapper instance with token managers ([#36](https://github.com/IBM/node-sdk-core/issues/36)) ([e7609e2](https://github.com/IBM/node-sdk-core/commit/e7609e2)) | ||
## [0.3.4](https://github.com/IBM/node-sdk-core/compare/v0.3.3...v0.3.4) (2019-08-05) | ||
@@ -9,0 +2,0 @@ |
@@ -20,4 +20,3 @@ /** | ||
export { BaseService } from './lib/base_service'; | ||
export { IamTokenManagerV1 } from './auth/iam-token-manager-v1'; | ||
export { Icp4dTokenManagerV1 } from './auth/icp4d-token-manager-v1'; | ||
export * from './auth'; | ||
export * from './lib/helper'; | ||
@@ -24,0 +23,0 @@ export { default as qs } from './lib/querystring'; |
@@ -26,6 +26,3 @@ "use strict"; | ||
exports.BaseService = base_service_1.BaseService; | ||
var iam_token_manager_v1_1 = require("./auth/iam-token-manager-v1"); | ||
exports.IamTokenManagerV1 = iam_token_manager_v1_1.IamTokenManagerV1; | ||
var icp4d_token_manager_v1_1 = require("./auth/icp4d-token-manager-v1"); | ||
exports.Icp4dTokenManagerV1 = icp4d_token_manager_v1_1.Icp4dTokenManagerV1; | ||
__export(require("./auth")); | ||
__export(require("./lib/helper")); | ||
@@ -32,0 +29,0 @@ var querystring_1 = require("./lib/querystring"); |
@@ -16,24 +16,11 @@ /** | ||
*/ | ||
export interface HeaderOptions { | ||
'X-Watson-Learning-Opt-Out'?: boolean; | ||
[key: string]: any; | ||
} | ||
/// <reference types="node" /> | ||
import { OutgoingHttpHeaders } from 'http'; | ||
import { AuthenticatorInterface } from '../auth'; | ||
export interface UserOptions { | ||
url?: string; | ||
version?: string; | ||
username?: string; | ||
password?: string; | ||
apikey?: string; | ||
use_unauthenticated?: boolean; | ||
headers?: HeaderOptions; | ||
token?: string; | ||
icp4d_access_token?: string; | ||
icp4d_url?: string; | ||
iam_access_token?: string; | ||
iam_apikey?: string; | ||
iam_url?: string; | ||
iam_client_id?: string; | ||
iam_client_secret?: string; | ||
authentication_type?: string; | ||
disable_ssl_verification?: boolean; | ||
headers?: OutgoingHttpHeaders; | ||
disableSslVerification?: boolean; | ||
authenticator: AuthenticatorInterface; | ||
/** Allow additional request config parameters */ | ||
@@ -43,20 +30,4 @@ [propName: string]: any; | ||
export interface BaseServiceOptions extends UserOptions { | ||
headers: HeaderOptions; | ||
url: string; | ||
qs: any; | ||
rejectUnauthorized?: boolean; | ||
} | ||
export interface Credentials { | ||
username?: string; | ||
password?: string; | ||
url?: string; | ||
icp4d_access_token?: string; | ||
icp4d_url?: string; | ||
iam_access_token?: string; | ||
iam_apikey?: string; | ||
iam_url?: string; | ||
iam_client_id?: string; | ||
iam_client_secret?: string; | ||
authentication_type?: string; | ||
} | ||
export declare class BaseService { | ||
@@ -66,5 +37,4 @@ static URL: string; | ||
serviceVersion: string; | ||
protected _options: BaseServiceOptions; | ||
protected serviceDefaults: object; | ||
protected tokenManager: any; | ||
protected baseOptions: BaseServiceOptions; | ||
private authenticator; | ||
private requestWrapperInstance; | ||
@@ -74,13 +44,2 @@ /** | ||
* @param {UserOptions} options | ||
* @param {string} [options.iam_apikey] - api key used to retrieve an iam access token | ||
* @param {string} [options.iam_access_token] - iam access token provided and managed by user | ||
* @param {string} [options.iam_url] - url for iam service api, needed for services in staging | ||
* @param {string} [options.iam_client_id] - client id (username) for request to iam service | ||
* @param {string} [options.iam_client_secret] - secret (password) for request to iam service | ||
* @param {string} [options.icp4d_access_token] - icp for data access token provided and managed by user | ||
* @param {string} [options.icp4d_url] - icp for data base url - used for authentication | ||
* @param {string} [options.authentication_type] - authentication pattern to be used. can be iam, basic, or icp4d | ||
* @param {string} [options.username] - required unless use_unauthenticated is set | ||
* @param {string} [options.password] - required unless use_unauthenticated is set | ||
* @param {boolean} [options.use_unauthenticated] - skip credential requirement | ||
* @param {HeaderOptions} [options.headers] | ||
@@ -97,37 +56,10 @@ * @param {boolean} [options.headers.X-Watson-Learning-Opt-Out=false] - opt-out of data collection | ||
/** | ||
* Retrieve this service's credentials - useful for passing to the authorization service | ||
* Get the instance of the authenticator set on the service. | ||
* | ||
* Only returns a URL when token auth is used. | ||
* | ||
* @returns {Credentials} | ||
* @returns {Authenticator} | ||
*/ | ||
getServiceCredentials(): Credentials; | ||
getAuthenticator(): any; | ||
/** | ||
* Set an IAM access token to use when authenticating with the service. | ||
* The access token should be valid and not yet expired. | ||
* Wrapper around `sendRequest` that enforces the request will be authenticated. | ||
* | ||
* By using this method, you accept responsibility for managing the | ||
* access token yourself. You must set a new access token before this | ||
* one expires. Failing to do so will result in authentication errors | ||
* after this token expires. | ||
* | ||
* @param {string} access_token - A valid, non-expired IAM access token | ||
* @returns {void} | ||
*/ | ||
setAccessToken(access_token: string): void; | ||
/** | ||
* Guarantee that the next request you make will be IAM authenticated. This | ||
* performs any requests necessary to get a valid IAM token so that if your | ||
* next request involves a streaming operation, it will not be interrupted. | ||
* | ||
* @param {Function} callback - callback function to return flow of execution | ||
* | ||
* @returns {void} | ||
*/ | ||
protected preAuthenticate(callback: any): void; | ||
/** | ||
* Wrapper around `sendRequest` that determines whether or not IAM tokens | ||
* are being used to authenticate the request. If so, the token is | ||
* retrieved by the token manager. | ||
* | ||
* @param {Object} parameters - service request options passed in by user | ||
@@ -137,29 +69,4 @@ * @param {Function} callback - callback function to pass the response back to | ||
*/ | ||
protected createRequest(parameters: any, callback: any): any; | ||
/** | ||
* @private | ||
* @param {UserOptions} options | ||
* @returns {BaseServiceOptions} | ||
*/ | ||
private initCredentials; | ||
/** | ||
* Pulls credentials from env properties | ||
* | ||
* Property checked is uppercase service.name suffixed by _USERNAME and _PASSWORD | ||
* | ||
* For example, if service.name is speech_to_text, | ||
* env properties are SPEECH_TO_TEXT_USERNAME and SPEECH_TO_TEXT_PASSWORD | ||
* | ||
* @private | ||
* @param {string} name - the service snake case name | ||
* @returns {Credentials} | ||
*/ | ||
private getCredentialsFromEnvironment; | ||
/** | ||
* Pulls credentials from VCAP_SERVICES env property that IBM Cloud sets | ||
* @param {string} vcap_services_name | ||
* @private | ||
* @returns {Credentials} | ||
*/ | ||
private getCredentialsFromCloud; | ||
protected createRequest(parameters: any, callback: any): void; | ||
private readOptionsFromExternalConfig; | ||
} |
@@ -19,54 +19,5 @@ "use strict"; | ||
var extend = require("extend"); | ||
var semver = require("semver"); | ||
var vcapServices = require("vcap_services"); | ||
var auth_1 = require("../auth"); | ||
var helper_1 = require("./helper"); | ||
var read_credentials_file_1 = require("./read-credentials-file"); | ||
var requestwrapper_1 = require("./requestwrapper"); | ||
function hasCredentials(obj) { | ||
return (obj && | ||
((obj.username && obj.password) || | ||
obj.iam_access_token || | ||
obj.iam_apikey || | ||
obj.icp4d_access_token)); | ||
} | ||
function isForICP(cred) { | ||
return cred && cred.startsWith('icp-'); | ||
} | ||
function isForICP4D(obj) { | ||
return obj && (obj.authentication_type === 'icp4d' || obj.icp4d_access_token); | ||
} | ||
function hasBasicCredentials(obj) { | ||
return obj && obj.username && obj.password && !usesBasicForIam(obj); | ||
} | ||
function hasIamCredentials(obj) { | ||
return obj && (obj.iam_apikey || obj.iam_access_token) && !isForICP(obj.iam_apikey); | ||
} | ||
// returns true if the user provides basic auth creds with the intention | ||
// of using IAM auth | ||
function usesBasicForIam(obj) { | ||
return obj.username === 'apikey' && !isForICP(obj.password); | ||
} | ||
// returns true if the string has a curly bracket or quote as the first or last character | ||
// these are common user-issues that we should handle before they get a network error | ||
function badCharAtAnEnd(value) { | ||
return value.startsWith('{') || value.startsWith('"') || value.endsWith('}') || value.endsWith('"'); | ||
} | ||
// checks credentials for common user mistakes of copying {, }, or " characters from the documentation | ||
function checkCredentials(obj) { | ||
var errorMessage = ''; | ||
var credsToCheck = ['url', 'username', 'password', 'iam_apikey']; | ||
credsToCheck.forEach(function (cred) { | ||
if (obj[cred] && badCharAtAnEnd(obj[cred])) { | ||
errorMessage += "The " + cred + " shouldn't start or end with curly brackets or quotes. Be sure to remove any {, }, or \""; | ||
} | ||
}); | ||
if (errorMessage.length) { | ||
errorMessage += 'Revise these credentials - they should not start or end with curly brackets or quotes.'; | ||
return errorMessage; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
var BaseService = /** @class */ (function () { | ||
@@ -76,13 +27,2 @@ /** | ||
* @param {UserOptions} options | ||
* @param {string} [options.iam_apikey] - api key used to retrieve an iam access token | ||
* @param {string} [options.iam_access_token] - iam access token provided and managed by user | ||
* @param {string} [options.iam_url] - url for iam service api, needed for services in staging | ||
* @param {string} [options.iam_client_id] - client id (username) for request to iam service | ||
* @param {string} [options.iam_client_secret] - secret (password) for request to iam service | ||
* @param {string} [options.icp4d_access_token] - icp for data access token provided and managed by user | ||
* @param {string} [options.icp4d_url] - icp for data base url - used for authentication | ||
* @param {string} [options.authentication_type] - authentication pattern to be used. can be iam, basic, or icp4d | ||
* @param {string} [options.username] - required unless use_unauthenticated is set | ||
* @param {string} [options.password] - required unless use_unauthenticated is set | ||
* @param {boolean} [options.use_unauthenticated] - skip credential requirement | ||
* @param {HeaderOptions} [options.headers] | ||
@@ -99,166 +39,39 @@ * @param {boolean} [options.headers.X-Watson-Learning-Opt-Out=false] - opt-out of data collection | ||
if (!(this instanceof BaseService)) { | ||
// it might be better to just create a new instance and return that.. | ||
// but that can't be done here, it has to be done in each individual service. | ||
// So this is still a good failsafe even in that case. | ||
throw new Error('the "new" keyword is required to create Watson service instances'); | ||
throw new Error('the "new" keyword is required to create service instances'); | ||
} | ||
// deprecate node versions 6 and 8 | ||
// these will be removed in v5 | ||
var isNodeSix = semver.satisfies(process.version, '6.x'); | ||
var isNodeEight = semver.satisfies(process.version, '8.x'); | ||
if (isNodeSix) { | ||
console.warn('Node v6 will not be supported in the SDK in the next major release (09/2019). Version 6 reached end of life in April 2019.'); | ||
} | ||
if (isNodeEight) { | ||
console.warn('Node v8 will not be supported in the SDK in the next major release (09/2019). Version 8 reaches end of life on 31 December 2019.'); | ||
} | ||
var _options = {}; | ||
var options = extend({}, userOptions); | ||
var _options = this.initCredentials(options); | ||
if (options.url) { | ||
_options.url = helper_1.stripTrailingSlash(options.url); | ||
} | ||
var serviceClass = this.constructor; | ||
this._options = extend({ qs: {}, url: serviceClass.URL }, this.serviceDefaults, options, _options); | ||
// rejectUnauthorized should only be false if disable_ssl_verification is true | ||
// used to disable ssl checking for icp | ||
this._options.rejectUnauthorized = !options.disable_ssl_verification; | ||
this.requestWrapperInstance = new requestwrapper_1.RequestWrapper(this._options); | ||
if (_options.authentication_type === 'iam' || hasIamCredentials(_options)) { | ||
this.tokenManager = new auth_1.IamTokenManagerV1({ | ||
iamApikey: _options.iam_apikey, | ||
accessToken: _options.iam_access_token, | ||
url: _options.iam_url, | ||
iamClientId: _options.iam_client_id, | ||
iamClientSecret: _options.iam_client_secret, | ||
requestWrapper: this.requestWrapperInstance, | ||
}); | ||
// check url for common user errors | ||
var credentialProblems = auth_1.checkCredentials(options, ['url']); | ||
if (credentialProblems) { | ||
throw new Error(credentialProblems); | ||
} | ||
else if (usesBasicForIam(_options)) { | ||
this.tokenManager = new auth_1.IamTokenManagerV1({ | ||
iamApikey: _options.password, | ||
url: _options.iam_url, | ||
iamClientId: _options.iam_client_id, | ||
iamClientSecret: _options.iam_client_secret, | ||
requestWrapper: this.requestWrapperInstance, | ||
}); | ||
// if disableSslVerification is not explicity set to the boolean value `true`, | ||
// force it to be false | ||
if (options.disableSslVerification !== true) { | ||
options.disableSslVerification = false; | ||
} | ||
else if (isForICP4D(_options)) { | ||
if (!_options.icp4d_url && !_options.icp4d_access_token) { | ||
throw new Error('`icp4d_url` is required when using an SDK-managed token for ICP4D.'); | ||
} | ||
this.tokenManager = new auth_1.Icp4dTokenManagerV1({ | ||
url: _options.icp4d_url, | ||
username: _options.username, | ||
password: _options.password, | ||
accessToken: _options.icp4d_access_token, | ||
disableSslVerification: options.disable_ssl_verification, | ||
requestWrapper: this.requestWrapperInstance, | ||
}); | ||
var serviceClass = this.constructor; | ||
this.baseOptions = extend({ qs: {}, url: serviceClass.URL }, options, this.readOptionsFromExternalConfig(), _options); | ||
this.requestWrapperInstance = new requestwrapper_1.RequestWrapper(this.baseOptions); | ||
// set authenticator | ||
if (!options.authenticator) { | ||
throw new Error('Authenticator must be set.'); | ||
} | ||
else { | ||
this.tokenManager = null; | ||
} | ||
this.authenticator = options.authenticator; | ||
} | ||
/** | ||
* Retrieve this service's credentials - useful for passing to the authorization service | ||
* Get the instance of the authenticator set on the service. | ||
* | ||
* Only returns a URL when token auth is used. | ||
* | ||
* @returns {Credentials} | ||
* @returns {Authenticator} | ||
*/ | ||
BaseService.prototype.getServiceCredentials = function () { | ||
var credentials = {}; | ||
if (this._options.username) { | ||
credentials.username = this._options.username; | ||
} | ||
if (this._options.password) { | ||
credentials.password = this._options.password; | ||
} | ||
if (this._options.url) { | ||
credentials.url = this._options.url; | ||
} | ||
if (this._options.iam_access_token) { | ||
credentials.iam_access_token = this._options.iam_access_token; | ||
} | ||
if (this._options.iam_apikey) { | ||
credentials.iam_apikey = this._options.iam_apikey; | ||
} | ||
if (this._options.iam_url) { | ||
credentials.iam_url = this._options.iam_url; | ||
} | ||
if (this._options.iam_client_id) { | ||
credentials.iam_client_id = this._options.iam_client_id; | ||
} | ||
if (this._options.iam_client_secret) { | ||
credentials.iam_client_secret = this._options.iam_client_secret; | ||
} | ||
if (this._options.icp4d_access_token) { | ||
credentials.icp4d_access_token = this._options.icp4d_access_token; | ||
} | ||
if (this._options.icp4d_url) { | ||
credentials.icp4d_url = this._options.icp4d_url; | ||
} | ||
if (this._options.authentication_type) { | ||
credentials.authentication_type = this._options.authentication_type; | ||
} | ||
return credentials; | ||
BaseService.prototype.getAuthenticator = function () { | ||
return this.authenticator; | ||
}; | ||
/** | ||
* Set an IAM access token to use when authenticating with the service. | ||
* The access token should be valid and not yet expired. | ||
* Wrapper around `sendRequest` that enforces the request will be authenticated. | ||
* | ||
* By using this method, you accept responsibility for managing the | ||
* access token yourself. You must set a new access token before this | ||
* one expires. Failing to do so will result in authentication errors | ||
* after this token expires. | ||
* | ||
* @param {string} access_token - A valid, non-expired IAM access token | ||
* @returns {void} | ||
*/ | ||
BaseService.prototype.setAccessToken = function (access_token) { | ||
if (this.tokenManager) { | ||
this.tokenManager.setAccessToken(access_token); | ||
} | ||
else if (this._options.authentication_type === 'icp4d') { | ||
this.tokenManager = new auth_1.Icp4dTokenManagerV1({ | ||
accessToken: access_token, | ||
url: this._options.icp4d_url, | ||
disableSslVerification: this._options.disable_ssl_verification, | ||
requestWrapper: this.requestWrapperInstance, | ||
}); | ||
} | ||
else { | ||
this.tokenManager = new auth_1.IamTokenManagerV1({ | ||
accessToken: access_token, | ||
requestWrapper: this.requestWrapperInstance, | ||
}); | ||
} | ||
}; | ||
/** | ||
* Guarantee that the next request you make will be IAM authenticated. This | ||
* performs any requests necessary to get a valid IAM token so that if your | ||
* next request involves a streaming operation, it will not be interrupted. | ||
* | ||
* @param {Function} callback - callback function to return flow of execution | ||
* | ||
* @returns {void} | ||
*/ | ||
BaseService.prototype.preAuthenticate = function (callback) { | ||
if (Boolean(this.tokenManager)) { | ||
return this.tokenManager.getToken(function (err, token) { | ||
if (err) { | ||
callback(err); | ||
} | ||
callback(null); | ||
}); | ||
} | ||
else { | ||
callback(null); | ||
} | ||
}; | ||
/** | ||
* Wrapper around `sendRequest` that determines whether or not IAM tokens | ||
* are being used to authenticate the request. If so, the token is | ||
* retrieved by the token manager. | ||
* | ||
* @param {Object} parameters - service request options passed in by user | ||
@@ -270,143 +83,21 @@ * @param {Function} callback - callback function to pass the response back to | ||
var _this = this; | ||
if (Boolean(this.tokenManager)) { | ||
return this.tokenManager.getToken(function (err, accessToken) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
parameters.defaultOptions.headers.Authorization = | ||
"Bearer " + accessToken; | ||
return _this.requestWrapperInstance.sendRequest(parameters, callback); | ||
}); | ||
} | ||
else { | ||
return this.requestWrapperInstance.sendRequest(parameters, callback); | ||
} | ||
this.authenticator.authenticate(parameters.defaultOptions, function (err) { | ||
err ? callback(err) : _this.requestWrapperInstance.sendRequest(parameters, callback); | ||
}); | ||
}; | ||
/** | ||
* @private | ||
* @param {UserOptions} options | ||
* @returns {BaseServiceOptions} | ||
*/ | ||
BaseService.prototype.initCredentials = function (options) { | ||
var _options = {}; | ||
if (options.token) { | ||
options.headers = options.headers || {}; | ||
options.headers['X-Watson-Authorization-Token'] = options.token; | ||
_options = extend(_options, options); | ||
return _options; | ||
} | ||
// Get credentials from environment properties or IBM Cloud, | ||
// but prefer credentials provided programatically | ||
_options = extend({}, this.getCredentialsFromCloud(this.name), this.getCredentialsFromEnvironment(process.env, this.name), this.getCredentialsFromEnvironment(read_credentials_file_1.readCredentialsFile(), this.name), options, _options); | ||
// make authentication_type non-case-sensitive | ||
if (typeof _options.authentication_type === 'string') { | ||
_options.authentication_type = _options.authentication_type.toLowerCase(); | ||
} | ||
if (!_options.use_unauthenticated) { | ||
if (!hasCredentials(_options)) { | ||
var errorMessage = 'Insufficient credentials provided in ' + | ||
'constructor argument. Refer to the documentation for the ' + | ||
'required parameters. Common examples are username/password and ' + | ||
'iam_apikey.'; | ||
throw new Error(errorMessage); | ||
BaseService.prototype.readOptionsFromExternalConfig = function () { | ||
var results = {}; | ||
var properties = auth_1.readExternalSources(this.name); | ||
if (properties !== null) { | ||
// the user can define two client-level variables in the credentials file: url and disableSsl | ||
var url = properties.url, disableSsl = properties.disableSsl; | ||
if (url) { | ||
results.url = url; | ||
} | ||
// handle iam_apikey containing an ICP api key | ||
if (isForICP(_options.iam_apikey)) { | ||
_options.username = 'apikey'; | ||
_options.password = _options.iam_apikey; | ||
// remove apikey so code doesnt confuse credentials as iam | ||
delete _options.iam_apikey; | ||
delete options.iam_apikey; | ||
if (disableSsl === true) { | ||
results.disableSslVerification = disableSsl; | ||
} | ||
if (!hasIamCredentials(_options) && !usesBasicForIam(_options) && !isForICP4D(_options)) { | ||
if (_options.authentication_type === 'basic' || hasBasicCredentials(_options)) { | ||
// Calculate and add Authorization header to base options | ||
var encodedCredentials = auth_1.computeBasicAuthHeader(_options.username, _options.password); | ||
var authHeader = { Authorization: "" + encodedCredentials }; | ||
_options.headers = extend(authHeader, _options.headers); | ||
} | ||
} | ||
} | ||
// check credentials for common user errors | ||
var credentialProblems = checkCredentials(_options); | ||
if (credentialProblems) { | ||
throw new Error(credentialProblems); | ||
} | ||
return _options; | ||
return results; | ||
}; | ||
/** | ||
* Pulls credentials from env properties | ||
* | ||
* Property checked is uppercase service.name suffixed by _USERNAME and _PASSWORD | ||
* | ||
* For example, if service.name is speech_to_text, | ||
* env properties are SPEECH_TO_TEXT_USERNAME and SPEECH_TO_TEXT_PASSWORD | ||
* | ||
* @private | ||
* @param {string} name - the service snake case name | ||
* @returns {Credentials} | ||
*/ | ||
BaseService.prototype.getCredentialsFromEnvironment = function (envObj, name) { | ||
if (name === 'watson_vision_combined') { | ||
return this.getCredentialsFromEnvironment(envObj, 'visual_recognition'); | ||
} | ||
// Case handling for assistant - should look for assistant env variables before conversation | ||
if (name === 'conversation' && (envObj["ASSISTANT_USERNAME"] || envObj["ASSISTANT_IAM_APIKEY"])) { | ||
return this.getCredentialsFromEnvironment(envObj, 'assistant'); | ||
} | ||
var _name = name.toUpperCase(); | ||
// https://github.com/watson-developer-cloud/node-sdk/issues/605 | ||
var nameWithUnderscore = _name.replace(/-/g, '_'); | ||
var username = envObj[_name + "_USERNAME"] || envObj[nameWithUnderscore + "_USERNAME"]; | ||
var password = envObj[_name + "_PASSWORD"] || envObj[nameWithUnderscore + "_PASSWORD"]; | ||
var apiKey = envObj[_name + "_API_KEY"] || envObj[nameWithUnderscore + "_API_KEY"]; | ||
var url = envObj[_name + "_URL"] || envObj[nameWithUnderscore + "_URL"]; | ||
var iamAccessToken = envObj[_name + "_IAM_ACCESS_TOKEN"] || envObj[nameWithUnderscore + "_IAM_ACCESS_TOKEN"]; | ||
var iamApiKey = envObj[_name + "_IAM_APIKEY"] || envObj[nameWithUnderscore + "_IAM_APIKEY"]; | ||
var iamUrl = envObj[_name + "_IAM_URL"] || envObj[nameWithUnderscore + "_IAM_URL"]; | ||
var iamClientId = envObj[_name + "_IAM_CLIENT_ID"] || envObj[_name + "_IAM_CLIENT_ID"]; | ||
var iamClientSecret = envObj[_name + "_IAM_CLIENT_SECRET"] || envObj[_name + "_IAM_CLIENT_SECRET"]; | ||
var icp4dAccessToken = envObj[_name + "_ICP4D_ACCESS_TOKEN"] || envObj[nameWithUnderscore + "_ICP4D_ACCESS_TOKEN"]; | ||
var icp4dUrl = envObj[_name + "_ICP4D_URL"] || envObj[nameWithUnderscore + "_ICP4D_URL"]; | ||
var authenticationType = envObj[_name + "_AUTHENTICATION_TYPE"] || envObj[nameWithUnderscore + "_AUTHENTICATION_TYPE"]; | ||
return { | ||
username: username, | ||
password: password, | ||
url: url, | ||
iam_access_token: iamAccessToken, | ||
iam_apikey: iamApiKey, | ||
iam_url: iamUrl, | ||
iam_client_id: iamClientId, | ||
iam_client_secret: iamClientSecret, | ||
icp4d_access_token: icp4dAccessToken, | ||
icp4d_url: icp4dUrl, | ||
authentication_type: authenticationType, | ||
}; | ||
}; | ||
/** | ||
* Pulls credentials from VCAP_SERVICES env property that IBM Cloud sets | ||
* @param {string} vcap_services_name | ||
* @private | ||
* @returns {Credentials} | ||
*/ | ||
BaseService.prototype.getCredentialsFromCloud = function (vcapServicesName) { | ||
var credentials; | ||
var temp; | ||
if (this.name === 'visual_recognition') { | ||
temp = vcapServices.getCredentials('watson_vision_combined'); | ||
} | ||
if (this.name === 'assistant') { | ||
temp = vcapServices.getCredentials('conversation'); | ||
} | ||
else { | ||
temp = vcapServices.getCredentials(vcapServicesName); | ||
} | ||
// convert an iam apikey to use the identifier iam_apikey | ||
if (temp.apikey && temp.iam_apikey_name) { | ||
temp.iam_apikey = temp.apikey; | ||
delete temp.apikey; | ||
} | ||
credentials = temp; | ||
return credentials; | ||
}; | ||
return BaseService; | ||
@@ -413,0 +104,0 @@ }()); |
@@ -37,3 +37,5 @@ "use strict"; | ||
httpsAgent: new https.Agent({ | ||
rejectUnauthorized: axiosOptions.rejectUnauthorized | ||
// disableSslVerification is the parameter we expose to the user, | ||
// it is the opposite of rejectUnauthorized | ||
rejectUnauthorized: !axiosOptions.disableSslVerification | ||
}), | ||
@@ -200,2 +202,4 @@ maxContentLength: Infinity, | ||
.then(function (res) { | ||
// these objects contain circular json structures and are not always relevant to the user | ||
// if the user wants them, they can be accessed through the debug properties | ||
delete res.config; | ||
@@ -205,3 +209,4 @@ delete res.request; | ||
res.result = res.data; | ||
_callback(null, res.data, res); | ||
delete res.data; | ||
_callback(null, res); | ||
}) | ||
@@ -208,0 +213,0 @@ .catch(function (error) { |
{ | ||
"name": "ibm-cloud-sdk-core", | ||
"version": "0.3.5", | ||
"version": "1.0.0-rc", | ||
"description": "Core functionality to support SDKs generated with IBM's OpenAPI 3 SDK Generator.", | ||
@@ -59,2 +59,3 @@ "main": "./index", | ||
"axios": "^0.18.0", | ||
"camelcase": "^5.3.1", | ||
"dotenv": "^6.2.0", | ||
@@ -66,2 +67,3 @@ "extend": "~3.0.2", | ||
"jsonwebtoken": "^8.5.1", | ||
"lodash.isempty": "^4.4.0", | ||
"mime-types": "~2.1.18", | ||
@@ -74,3 +76,3 @@ "object.omit": "~3.0.0", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=10" | ||
}, | ||
@@ -77,0 +79,0 @@ "scripts": { |
@@ -60,6 +60,5 @@ { | ||
"./lib/*.ts", | ||
"./iam-token-manager/*.ts", | ||
"./auth/*.ts", | ||
"./auth/**/*.ts", | ||
"index.ts" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181670
87
2950
18
2
+ Addedcamelcase@^5.3.1
+ Addedlodash.isempty@^4.4.0
+ Addedcamelcase@5.3.1(transitive)
+ Addedlodash.isempty@4.4.0(transitive)