ibm-cloud-sdk-core 4.3.0 → 4.3.2-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/auth/user-temp/get-authenticator-from-environment.d.ts +28 -0
- package/auth/user-temp/get-authenticator-from-environment.js +95 -0
- package/auth/user-temp/index.d.ts +25 -0
- package/auth/user-temp/index.js +30 -0
- package/auth/user-temp/read-external-sources.d.ts +11 -0
- package/auth/user-temp/read-external-sources.js +154 -0
- package/es/auth/user-temp/get-authenticator-from-environment.d.ts +28 -0
- package/es/auth/user-temp/get-authenticator-from-environment.js +91 -0
- package/es/auth/user-temp/index.d.ts +25 -0
- package/es/auth/user-temp/index.js +25 -0
- package/es/auth/user-temp/read-external-sources.d.ts +11 -0
- package/es/auth/user-temp/read-external-sources.js +144 -0
- package/package.json +61 -91
- package/.cra/.cveignore +0 -2
- package/.secrets.baseline +0 -590
- package/Authentication.md +0 -600
- package/CHANGELOG.md +0 -865
- package/LICENSE.md +0 -201
- package/MIGRATION-V4.md +0 -54
- package/README.md +0 -118
- package/api-extractor.json +0 -39
- package/appscan-config.xml +0 -8
- package/build/docs/ibm-cloud-sdk-core.atleastone.md +0 -71
- package/build/docs/ibm-cloud-sdk-core.atmostone.md +0 -71
- package/build/docs/ibm-cloud-sdk-core.authenticator._constructor_.md +0 -18
- package/build/docs/ibm-cloud-sdk-core.authenticator.authenticate.md +0 -57
- package/build/docs/ibm-cloud-sdk-core.authenticator.authenticationtype.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.authenticator.authtype_basic.md +0 -13
- package/build/docs/ibm-cloud-sdk-core.authenticator.authtype_bearertoken.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.authenticator.authtype_container.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.authenticator.authtype_cp4d.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.authenticator.authtype_iam.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.authenticator.authtype_mcsp.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.authenticator.authtype_noauth.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.authenticator.authtype_unknown.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.authenticator.authtype_vpc.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.authenticator.md +0 -294
- package/build/docs/ibm-cloud-sdk-core.authenticatorinterface.authenticate.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.authenticatorinterface.authenticationtype.md +0 -17
- package/build/docs/ibm-cloud-sdk-core.authenticatorinterface.md +0 -50
- package/build/docs/ibm-cloud-sdk-core.baseservice._constructor_.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.baseservice.baseoptions.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.baseservice.configureservice.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.baseservice.convertmodel.md +0 -85
- package/build/docs/ibm-cloud-sdk-core.baseservice.createrequest.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.baseservice.createrequestanddeserializeresponse.md +0 -87
- package/build/docs/ibm-cloud-sdk-core.baseservice.default_service_name.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.baseservice.default_service_url.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.baseservice.disableretries.md +0 -17
- package/build/docs/ibm-cloud-sdk-core.baseservice.enableretries.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.baseservice.getauthenticator.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.baseservice.gethttpclient.md +0 -17
- package/build/docs/ibm-cloud-sdk-core.baseservice.md +0 -313
- package/build/docs/ibm-cloud-sdk-core.baseservice.setdefaultheaders.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.baseservice.setenablegzipcompression.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.baseservice.setserviceurl.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.basicauthenticator._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.basicauthenticator.authenticate.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.basicauthenticator.authenticationtype.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.basicauthenticator.authheader.md +0 -13
- package/build/docs/ibm-cloud-sdk-core.basicauthenticator.md +0 -165
- package/build/docs/ibm-cloud-sdk-core.basicauthenticator.requiredoptions.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator.authenticate.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator.authenticationtype.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator.md +0 -160
- package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator.requiredoptions.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator.setbearertoken.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.buildrequestfileobject.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.checkcredentials.md +0 -71
- package/build/docs/ibm-cloud-sdk-core.cloudpakfordataauthenticator._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.cloudpakfordataauthenticator.authenticationtype.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.cloudpakfordataauthenticator.md +0 -149
- package/build/docs/ibm-cloud-sdk-core.cloudpakfordataauthenticator.requiredoptions.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.cloudpakfordataauthenticator.tokenmanager.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.computebasicauthheader.md +0 -71
- package/build/docs/ibm-cloud-sdk-core.constructfilepath.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.constructserviceurl.md +0 -87
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator.authenticationtype.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator.md +0 -172
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator.setcrtokenfilename.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator.setiamprofileid.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator.setiamprofilename.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.containerauthenticator.tokenmanager.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.getcrtoken.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.md +0 -142
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.requesttoken.md +0 -17
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.setcrtokenfilename.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.setiamprofileid.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.containertokenmanager.setiamprofilename.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.contenttype.md +0 -14
- package/build/docs/ibm-cloud-sdk-core.cp4dtokenmanager._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.cp4dtokenmanager.md +0 -128
- package/build/docs/ibm-cloud-sdk-core.cp4dtokenmanager.requesttoken.md +0 -15
- package/build/docs/ibm-cloud-sdk-core.cp4dtokenmanager.requiredoptions.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.fileexistsatpath.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.fileobject.md +0 -80
- package/build/docs/ibm-cloud-sdk-core.fileobject.options.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.fileobject.value.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.fileoptions.contenttype.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.fileoptions.filename.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.fileoptions.md +0 -74
- package/build/docs/ibm-cloud-sdk-core.filestream.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.filestream.path.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.filewithmetadata.contenttype.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.filewithmetadata.data.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.filewithmetadata.filename.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.filewithmetadata.md +0 -87
- package/build/docs/ibm-cloud-sdk-core.getauthenticatorfromenvironment.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.getcontenttype.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.getcurrenttime.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.getformat.md +0 -69
- package/build/docs/ibm-cloud-sdk-core.getmissingparams.md +0 -73
- package/build/docs/ibm-cloud-sdk-core.getnewlogger.md +0 -59
- package/build/docs/ibm-cloud-sdk-core.getqueryparam.md +0 -71
- package/build/docs/ibm-cloud-sdk-core.iamauthenticator._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.iamauthenticator.authenticationtype.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.iamauthenticator.md +0 -149
- package/build/docs/ibm-cloud-sdk-core.iamauthenticator.requiredoptions.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamauthenticator.tokenmanager.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.clientid.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.clientsecret.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.getrefreshtoken.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.md +0 -211
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.scope.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.setclientidandsecret.md +0 -69
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.setscope.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.tokenmanager.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.formdata.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.getrefreshtoken.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.istokenexpired.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.md +0 -221
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.refreshtoken.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.requesttoken.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.savetokeninfo.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.setclientidandsecret.md +0 -69
- package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.setscope.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.iamrequestoptions.clientid.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamrequestoptions.clientsecret.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamrequestoptions.md +0 -96
- package/build/docs/ibm-cloud-sdk-core.iamrequestoptions.scope.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.iamtokenmanager._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.iamtokenmanager.md +0 -92
- package/build/docs/ibm-cloud-sdk-core.iamtokenmanager.requiredoptions.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.isemptyobject.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.isfiledata.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.isfilewithmetadata.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.ishtml.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.isjsonmimetype.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanager._constructor_.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.md +0 -163
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.requesttoken.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.savetokeninfo.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.tokeninfo.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.tokenname.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.jwttokenmanageroptions.md +0 -15
- package/build/docs/ibm-cloud-sdk-core.mcspauthenticator._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.mcspauthenticator.authenticationtype.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.mcspauthenticator.md +0 -145
- package/build/docs/ibm-cloud-sdk-core.mcspauthenticator.requiredoptions.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.mcspauthenticator.tokenmanager.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.mcsptokenmanager._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.mcsptokenmanager.md +0 -128
- package/build/docs/ibm-cloud-sdk-core.mcsptokenmanager.requesttoken.md +0 -15
- package/build/docs/ibm-cloud-sdk-core.mcsptokenmanager.requiredoptions.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.md +0 -818
- package/build/docs/ibm-cloud-sdk-core.noauthauthenticator.authenticate.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.noauthauthenticator.authenticationtype.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.noauthauthenticator.md +0 -60
- package/build/docs/ibm-cloud-sdk-core.onlyone.md +0 -71
- package/build/docs/ibm-cloud-sdk-core.qs.md +0 -21
- package/build/docs/ibm-cloud-sdk-core.readcredentialsfile.md +0 -17
- package/build/docs/ibm-cloud-sdk-core.readcrtokenfile.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.readexternalsources.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.removesuffix.md +0 -71
- package/build/docs/ibm-cloud-sdk-core.sdklogger.debug.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.sdklogger.error.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.sdklogger.info.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.sdklogger.md +0 -121
- package/build/docs/ibm-cloud-sdk-core.sdklogger.verbose.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.sdklogger.warn.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.streamtopromise.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.striptrailingslash.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.tokenmanager._constructor_.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.accesstoken.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.disablesslverification.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.expiretime.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.gettoken.md +0 -17
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.headers.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.istokenexpired.md +0 -17
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.md +0 -352
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.pacedrequesttoken.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.refreshtime.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.requesttoken.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.requestwrapperinstance.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.savetokeninfo.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.setdisablesslverification.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.setheaders.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.url.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenmanager.useragent.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenmanageroptions.md +0 -18
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator._constructor_.md +0 -49
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.authenticate.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.disablesslverification.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.headers.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.md +0 -217
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.setdisablesslverification.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.setheaders.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.tokenmanager.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.url.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.tolowerkeys.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkforsuccessfulexecution.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkmediaheaders.md +0 -85
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkurlandmethod.md +0 -85
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkuserheader.md +0 -85
- package/build/docs/ibm-cloud-sdk-core.unittestutils.expecttobepromise.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.unittestutils.getoptions.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.unittestutils.md +0 -86
- package/build/docs/ibm-cloud-sdk-core.useroptions.authenticator.md +0 -13
- package/build/docs/ibm-cloud-sdk-core.useroptions.disablesslverification.md +0 -13
- package/build/docs/ibm-cloud-sdk-core.useroptions.headers.md +0 -13
- package/build/docs/ibm-cloud-sdk-core.useroptions.jar.md +0 -13
- package/build/docs/ibm-cloud-sdk-core.useroptions.md +0 -171
- package/build/docs/ibm-cloud-sdk-core.useroptions.serviceurl.md +0 -13
- package/build/docs/ibm-cloud-sdk-core.useroptions.url.md +0 -13
- package/build/docs/ibm-cloud-sdk-core.useroptions.version.md +0 -13
- package/build/docs/ibm-cloud-sdk-core.validateinput.md +0 -73
- package/build/docs/ibm-cloud-sdk-core.validateparams.md +0 -89
- package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.authenticationtype.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.md +0 -158
- package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.setiamprofilecrn.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.setiamprofileid.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.tokenmanager.md +0 -11
- package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager._constructor_.md +0 -54
- package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.istokenexpired.md +0 -19
- package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.md +0 -126
- package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.requesttoken.md +0 -15
- package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.setiamprofilecrn.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.setiamprofileid.md +0 -53
- package/build/docs/index.md +0 -29
- package/es/tsdoc-metadata.json +0 -11
- package/etc/ibm-cloud-sdk-core.api.md +0 -517
- package/temp/ibm-cloud-sdk-core.api.json +0 -8641
- package/temp/ibm-cloud-sdk-core.api.md +0 -517
- package/tsconfig-es6.json +0 -9
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2022.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { Authenticator } from '../authenticators';
|
|
17
|
+
/**
|
|
18
|
+
* Look for external configuration of authenticator.
|
|
19
|
+
*
|
|
20
|
+
* Try to get authenticator from external sources, with the following priority:
|
|
21
|
+
* 1. Credentials file (ibm-credentials.env)
|
|
22
|
+
* 2. Environment variables
|
|
23
|
+
* 3. VCAP Services (Cloud Foundry)
|
|
24
|
+
*
|
|
25
|
+
* @param serviceName - the service name prefix.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
export declare function getAuthenticatorFromEnvironment(serviceName: string): Authenticator;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* (C) Copyright IBM Corp. 2019, 2022.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.getAuthenticatorFromEnvironment = void 0;
|
|
19
|
+
var authenticators_1 = require("../authenticators");
|
|
20
|
+
var read_external_sources_1 = require("./read-external-sources");
|
|
21
|
+
/**
|
|
22
|
+
* Look for external configuration of authenticator.
|
|
23
|
+
*
|
|
24
|
+
* Try to get authenticator from external sources, with the following priority:
|
|
25
|
+
* 1. Credentials file (ibm-credentials.env)
|
|
26
|
+
* 2. Environment variables
|
|
27
|
+
* 3. VCAP Services (Cloud Foundry)
|
|
28
|
+
*
|
|
29
|
+
* @param serviceName - the service name prefix.
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
function getAuthenticatorFromEnvironment(serviceName) {
|
|
33
|
+
if (!serviceName) {
|
|
34
|
+
throw new Error('Service name is required.');
|
|
35
|
+
}
|
|
36
|
+
// construct the credentials object from the environment
|
|
37
|
+
var credentials = (0, read_external_sources_1.readExternalSources)(serviceName);
|
|
38
|
+
if (credentials === null) {
|
|
39
|
+
throw new Error('Unable to create an authenticator from the environment.');
|
|
40
|
+
}
|
|
41
|
+
// remove client-level properties
|
|
42
|
+
delete credentials.url;
|
|
43
|
+
delete credentials.disableSsl;
|
|
44
|
+
// convert "auth" properties to their proper keys
|
|
45
|
+
if (credentials.authUrl) {
|
|
46
|
+
credentials.url = credentials.authUrl;
|
|
47
|
+
delete credentials.authUrl;
|
|
48
|
+
}
|
|
49
|
+
if (credentials.authDisableSsl) {
|
|
50
|
+
credentials.disableSslVerification = credentials.authDisableSsl;
|
|
51
|
+
delete credentials.authDisableSsl;
|
|
52
|
+
}
|
|
53
|
+
// in the situation where the auth type is not provided:
|
|
54
|
+
// if an apikey is provided, default to IAM
|
|
55
|
+
// if not, default to container auth
|
|
56
|
+
var authType = credentials.authType;
|
|
57
|
+
if (!authType) {
|
|
58
|
+
// Support the alternate "AUTHTYPE" config property.
|
|
59
|
+
authType = credentials.authtype;
|
|
60
|
+
}
|
|
61
|
+
if (!authType || typeof authType !== 'string') {
|
|
62
|
+
authType = credentials.apikey ? authenticators_1.Authenticator.AUTHTYPE_IAM : authenticators_1.Authenticator.AUTHTYPE_CONTAINER;
|
|
63
|
+
}
|
|
64
|
+
// Create and return the appropriate authenticator.
|
|
65
|
+
var authenticator;
|
|
66
|
+
// Compare the authType against our constants case-insensitively to
|
|
67
|
+
// determine which authenticator type needs to be constructed.
|
|
68
|
+
authType = authType.toLowerCase();
|
|
69
|
+
if (authType === authenticators_1.Authenticator.AUTHTYPE_NOAUTH.toLowerCase()) {
|
|
70
|
+
authenticator = new authenticators_1.NoAuthAuthenticator();
|
|
71
|
+
}
|
|
72
|
+
else if (authType === authenticators_1.Authenticator.AUTHTYPE_BASIC.toLowerCase()) {
|
|
73
|
+
authenticator = new authenticators_1.BasicAuthenticator(credentials);
|
|
74
|
+
}
|
|
75
|
+
else if (authType === authenticators_1.Authenticator.AUTHTYPE_BEARERTOKEN.toLowerCase()) {
|
|
76
|
+
authenticator = new authenticators_1.BearerTokenAuthenticator(credentials);
|
|
77
|
+
}
|
|
78
|
+
else if (authType === authenticators_1.Authenticator.AUTHTYPE_CP4D.toLowerCase()) {
|
|
79
|
+
authenticator = new authenticators_1.CloudPakForDataAuthenticator(credentials);
|
|
80
|
+
}
|
|
81
|
+
else if (authType === authenticators_1.Authenticator.AUTHTYPE_IAM.toLowerCase()) {
|
|
82
|
+
authenticator = new authenticators_1.IamAuthenticator(credentials);
|
|
83
|
+
}
|
|
84
|
+
else if (authType === authenticators_1.Authenticator.AUTHTYPE_CONTAINER.toLowerCase()) {
|
|
85
|
+
authenticator = new authenticators_1.ContainerAuthenticator(credentials);
|
|
86
|
+
}
|
|
87
|
+
else if (authType === authenticators_1.Authenticator.AUTHTYPE_VPC.toLowerCase()) {
|
|
88
|
+
authenticator = new authenticators_1.VpcInstanceAuthenticator(credentials);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error("Invalid value for AUTH_TYPE: ".concat(authType));
|
|
92
|
+
}
|
|
93
|
+
return authenticator;
|
|
94
|
+
}
|
|
95
|
+
exports.getAuthenticatorFromEnvironment = getAuthenticatorFromEnvironment;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2021.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @module utils
|
|
18
|
+
* Helper functions used by generated SDKs.
|
|
19
|
+
*
|
|
20
|
+
* functions:
|
|
21
|
+
* getAuthenticatorFromEnvironment: Get authenticator from external sources.
|
|
22
|
+
* readExternalSources: Get config object from external sources.
|
|
23
|
+
*/
|
|
24
|
+
export { getAuthenticatorFromEnvironment } from './get-authenticator-from-environment';
|
|
25
|
+
export { readExternalSources } from './read-external-sources';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* (C) Copyright IBM Corp. 2019, 2021.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.readExternalSources = exports.getAuthenticatorFromEnvironment = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* @module utils
|
|
21
|
+
* Helper functions used by generated SDKs.
|
|
22
|
+
*
|
|
23
|
+
* functions:
|
|
24
|
+
* getAuthenticatorFromEnvironment: Get authenticator from external sources.
|
|
25
|
+
* readExternalSources: Get config object from external sources.
|
|
26
|
+
*/
|
|
27
|
+
var get_authenticator_from_environment_1 = require("./get-authenticator-from-environment");
|
|
28
|
+
Object.defineProperty(exports, "getAuthenticatorFromEnvironment", { enumerable: true, get: function () { return get_authenticator_from_environment_1.getAuthenticatorFromEnvironment; } });
|
|
29
|
+
var read_external_sources_1 = require("./read-external-sources");
|
|
30
|
+
Object.defineProperty(exports, "readExternalSources", { enumerable: true, get: function () { return read_external_sources_1.readExternalSources; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read properties stored in external sources like Environment Variables,
|
|
3
|
+
* the credentials file, VCAP services, etc. and return them as an
|
|
4
|
+
* object. The keys of this object will have the service name prefix removed
|
|
5
|
+
* and will be converted to lower camel case.
|
|
6
|
+
*
|
|
7
|
+
* Only one source will be used at a time.
|
|
8
|
+
*
|
|
9
|
+
* @param serviceName - the service name prefix
|
|
10
|
+
*/
|
|
11
|
+
export declare function readExternalSources(serviceName: string): any;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-restricted-syntax */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.readExternalSources = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* (C) Copyright IBM Corp. 2019, 2022.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
var camelcase_1 = __importDefault(require("camelcase"));
|
|
24
|
+
var lodash_isempty_1 = __importDefault(require("lodash.isempty"));
|
|
25
|
+
var logger_1 = __importDefault(require("../../lib/logger"));
|
|
26
|
+
var utils_1 = require("../utils");
|
|
27
|
+
/**
|
|
28
|
+
* Read properties stored in external sources like Environment Variables,
|
|
29
|
+
* the credentials file, VCAP services, etc. and return them as an
|
|
30
|
+
* object. The keys of this object will have the service name prefix removed
|
|
31
|
+
* and will be converted to lower camel case.
|
|
32
|
+
*
|
|
33
|
+
* Only one source will be used at a time.
|
|
34
|
+
*
|
|
35
|
+
* @param serviceName - the service name prefix
|
|
36
|
+
*/
|
|
37
|
+
function readExternalSources(serviceName) {
|
|
38
|
+
if (!serviceName) {
|
|
39
|
+
throw new Error('Service name is required.');
|
|
40
|
+
}
|
|
41
|
+
return getProperties(serviceName);
|
|
42
|
+
}
|
|
43
|
+
exports.readExternalSources = readExternalSources;
|
|
44
|
+
function getProperties(serviceName) {
|
|
45
|
+
// Try to get properties from external sources, with the following priority:
|
|
46
|
+
// 1. Credentials file (ibm-credentials.env)
|
|
47
|
+
// 2. Environment variables
|
|
48
|
+
// 3. VCAP Services (Cloud Foundry)
|
|
49
|
+
// only get properties from one source, return null if none found
|
|
50
|
+
var properties = null;
|
|
51
|
+
properties = filterPropertiesByServiceName((0, utils_1.readCredentialsFile)(), serviceName);
|
|
52
|
+
if ((0, lodash_isempty_1.default)(properties)) {
|
|
53
|
+
properties = filterPropertiesByServiceName(process.env, serviceName);
|
|
54
|
+
}
|
|
55
|
+
if ((0, lodash_isempty_1.default)(properties)) {
|
|
56
|
+
properties = getPropertiesFromVCAP(serviceName);
|
|
57
|
+
}
|
|
58
|
+
return properties;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Pulls credentials from env properties
|
|
62
|
+
*
|
|
63
|
+
* Property checked is uppercase service.name suffixed by _USERNAME and _PASSWORD
|
|
64
|
+
*
|
|
65
|
+
* For example, if service.name is speech_to_text,
|
|
66
|
+
* env properties are SPEECH_TO_TEXT_USERNAME and SPEECH_TO_TEXT_PASSWORD
|
|
67
|
+
*
|
|
68
|
+
* @param envObj - the object containing the credentials keyed by environment variables
|
|
69
|
+
* @returns the set of credentials
|
|
70
|
+
*/
|
|
71
|
+
function filterPropertiesByServiceName(envObj, serviceName) {
|
|
72
|
+
var credentials = {};
|
|
73
|
+
var name = "".concat(serviceName.toUpperCase().replace(/-/g, '_'), "_"); // append the underscore that must follow the service name
|
|
74
|
+
// filter out properties that don't begin with the service name
|
|
75
|
+
Object.keys(envObj).forEach(function (key) {
|
|
76
|
+
if (key.startsWith(name)) {
|
|
77
|
+
var propName = (0, camelcase_1.default)(key.substring(name.length)); // remove the name from the front of the string and make camelcase
|
|
78
|
+
credentials[propName] = envObj[key];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
// all env variables are parsed as strings, convert boolean vars as needed
|
|
82
|
+
if (typeof credentials.disableSsl === 'string') {
|
|
83
|
+
credentials.disableSsl = credentials.disableSsl === 'true';
|
|
84
|
+
}
|
|
85
|
+
if (typeof credentials.authDisableSsl === 'string') {
|
|
86
|
+
credentials.authDisableSsl = credentials.authDisableSsl === 'true';
|
|
87
|
+
}
|
|
88
|
+
if (typeof credentials.enableGzip === 'string') {
|
|
89
|
+
credentials.enableGzip = credentials.enableGzip === 'true';
|
|
90
|
+
}
|
|
91
|
+
if (typeof credentials.enableRetries === 'string') {
|
|
92
|
+
credentials.enableRetries = credentials.enableRetries === 'true';
|
|
93
|
+
}
|
|
94
|
+
if (typeof credentials.maxRetries === 'string') {
|
|
95
|
+
credentials.maxRetries = parseInt(credentials.maxRetries, 10);
|
|
96
|
+
}
|
|
97
|
+
if (typeof credentials.retryInterval === 'string') {
|
|
98
|
+
credentials.retryInterval = parseInt(credentials.retryInterval, 10);
|
|
99
|
+
}
|
|
100
|
+
return credentials;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Pulls credentials from VCAP_SERVICES env property that IBM Cloud sets
|
|
104
|
+
*
|
|
105
|
+
* The function will first look for a service entry whose "name" field matches
|
|
106
|
+
* the serviceKey value. If found, return its credentials.
|
|
107
|
+
*
|
|
108
|
+
* If no match against the service entry's "name" field is found, then find the
|
|
109
|
+
* service list with a key matching the serviceKey value. If found, return the
|
|
110
|
+
* credentials of the first service in the service list.
|
|
111
|
+
*/
|
|
112
|
+
function getVCAPCredentialsForService(name) {
|
|
113
|
+
if (process.env.VCAP_SERVICES) {
|
|
114
|
+
var services = JSON.parse(process.env.VCAP_SERVICES);
|
|
115
|
+
for (var _i = 0, _a = Object.keys(services); _i < _a.length; _i++) {
|
|
116
|
+
var serviceName = _a[_i];
|
|
117
|
+
for (var _b = 0, _c = services[serviceName]; _b < _c.length; _b++) {
|
|
118
|
+
var instance = _c[_b];
|
|
119
|
+
if (instance.name === name) {
|
|
120
|
+
if (Object.prototype.hasOwnProperty.call(instance, 'credentials')) {
|
|
121
|
+
return instance.credentials;
|
|
122
|
+
}
|
|
123
|
+
logger_1.default.debug('no data read from VCAP_SERVICES');
|
|
124
|
+
return {};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (var _d = 0, _e = Object.keys(services); _d < _e.length; _d++) {
|
|
129
|
+
var serviceName = _e[_d];
|
|
130
|
+
if (serviceName === name) {
|
|
131
|
+
if (services[serviceName].length > 0) {
|
|
132
|
+
if (Object.prototype.hasOwnProperty.call(services[serviceName][0], 'credentials')) {
|
|
133
|
+
return services[serviceName][0].credentials;
|
|
134
|
+
}
|
|
135
|
+
logger_1.default.debug('no data read from VCAP_SERVICES');
|
|
136
|
+
return {};
|
|
137
|
+
}
|
|
138
|
+
logger_1.default.debug('no data read from VCAP_SERVICES');
|
|
139
|
+
return {};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
logger_1.default.debug('no data read from VCAP_SERVICES');
|
|
144
|
+
return {};
|
|
145
|
+
}
|
|
146
|
+
function getPropertiesFromVCAP(serviceName) {
|
|
147
|
+
var credentials = getVCAPCredentialsForService(serviceName);
|
|
148
|
+
// infer authentication type from credentials in a simple manner
|
|
149
|
+
// iam is used as the default later
|
|
150
|
+
if (credentials.username || credentials.password) {
|
|
151
|
+
credentials.authType = 'basic';
|
|
152
|
+
}
|
|
153
|
+
return credentials;
|
|
154
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2022.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { Authenticator } from '../authenticators';
|
|
17
|
+
/**
|
|
18
|
+
* Look for external configuration of authenticator.
|
|
19
|
+
*
|
|
20
|
+
* Try to get authenticator from external sources, with the following priority:
|
|
21
|
+
* 1. Credentials file (ibm-credentials.env)
|
|
22
|
+
* 2. Environment variables
|
|
23
|
+
* 3. VCAP Services (Cloud Foundry)
|
|
24
|
+
*
|
|
25
|
+
* @param serviceName - the service name prefix.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
export declare function getAuthenticatorFromEnvironment(serviceName: string): Authenticator;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2022.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { Authenticator, BasicAuthenticator, BearerTokenAuthenticator, CloudPakForDataAuthenticator, IamAuthenticator, ContainerAuthenticator, NoAuthAuthenticator, VpcInstanceAuthenticator, } from '../authenticators';
|
|
17
|
+
import { readExternalSources } from './read-external-sources';
|
|
18
|
+
/**
|
|
19
|
+
* Look for external configuration of authenticator.
|
|
20
|
+
*
|
|
21
|
+
* Try to get authenticator from external sources, with the following priority:
|
|
22
|
+
* 1. Credentials file (ibm-credentials.env)
|
|
23
|
+
* 2. Environment variables
|
|
24
|
+
* 3. VCAP Services (Cloud Foundry)
|
|
25
|
+
*
|
|
26
|
+
* @param serviceName - the service name prefix.
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
export function getAuthenticatorFromEnvironment(serviceName) {
|
|
30
|
+
if (!serviceName) {
|
|
31
|
+
throw new Error('Service name is required.');
|
|
32
|
+
}
|
|
33
|
+
// construct the credentials object from the environment
|
|
34
|
+
const credentials = readExternalSources(serviceName);
|
|
35
|
+
if (credentials === null) {
|
|
36
|
+
throw new Error('Unable to create an authenticator from the environment.');
|
|
37
|
+
}
|
|
38
|
+
// remove client-level properties
|
|
39
|
+
delete credentials.url;
|
|
40
|
+
delete credentials.disableSsl;
|
|
41
|
+
// convert "auth" properties to their proper keys
|
|
42
|
+
if (credentials.authUrl) {
|
|
43
|
+
credentials.url = credentials.authUrl;
|
|
44
|
+
delete credentials.authUrl;
|
|
45
|
+
}
|
|
46
|
+
if (credentials.authDisableSsl) {
|
|
47
|
+
credentials.disableSslVerification = credentials.authDisableSsl;
|
|
48
|
+
delete credentials.authDisableSsl;
|
|
49
|
+
}
|
|
50
|
+
// in the situation where the auth type is not provided:
|
|
51
|
+
// if an apikey is provided, default to IAM
|
|
52
|
+
// if not, default to container auth
|
|
53
|
+
let { authType } = credentials;
|
|
54
|
+
if (!authType) {
|
|
55
|
+
// Support the alternate "AUTHTYPE" config property.
|
|
56
|
+
authType = credentials.authtype;
|
|
57
|
+
}
|
|
58
|
+
if (!authType || typeof authType !== 'string') {
|
|
59
|
+
authType = credentials.apikey ? Authenticator.AUTHTYPE_IAM : Authenticator.AUTHTYPE_CONTAINER;
|
|
60
|
+
}
|
|
61
|
+
// Create and return the appropriate authenticator.
|
|
62
|
+
let authenticator;
|
|
63
|
+
// Compare the authType against our constants case-insensitively to
|
|
64
|
+
// determine which authenticator type needs to be constructed.
|
|
65
|
+
authType = authType.toLowerCase();
|
|
66
|
+
if (authType === Authenticator.AUTHTYPE_NOAUTH.toLowerCase()) {
|
|
67
|
+
authenticator = new NoAuthAuthenticator();
|
|
68
|
+
}
|
|
69
|
+
else if (authType === Authenticator.AUTHTYPE_BASIC.toLowerCase()) {
|
|
70
|
+
authenticator = new BasicAuthenticator(credentials);
|
|
71
|
+
}
|
|
72
|
+
else if (authType === Authenticator.AUTHTYPE_BEARERTOKEN.toLowerCase()) {
|
|
73
|
+
authenticator = new BearerTokenAuthenticator(credentials);
|
|
74
|
+
}
|
|
75
|
+
else if (authType === Authenticator.AUTHTYPE_CP4D.toLowerCase()) {
|
|
76
|
+
authenticator = new CloudPakForDataAuthenticator(credentials);
|
|
77
|
+
}
|
|
78
|
+
else if (authType === Authenticator.AUTHTYPE_IAM.toLowerCase()) {
|
|
79
|
+
authenticator = new IamAuthenticator(credentials);
|
|
80
|
+
}
|
|
81
|
+
else if (authType === Authenticator.AUTHTYPE_CONTAINER.toLowerCase()) {
|
|
82
|
+
authenticator = new ContainerAuthenticator(credentials);
|
|
83
|
+
}
|
|
84
|
+
else if (authType === Authenticator.AUTHTYPE_VPC.toLowerCase()) {
|
|
85
|
+
authenticator = new VpcInstanceAuthenticator(credentials);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw new Error(`Invalid value for AUTH_TYPE: ${authType}`);
|
|
89
|
+
}
|
|
90
|
+
return authenticator;
|
|
91
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2021.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @module utils
|
|
18
|
+
* Helper functions used by generated SDKs.
|
|
19
|
+
*
|
|
20
|
+
* functions:
|
|
21
|
+
* getAuthenticatorFromEnvironment: Get authenticator from external sources.
|
|
22
|
+
* readExternalSources: Get config object from external sources.
|
|
23
|
+
*/
|
|
24
|
+
export { getAuthenticatorFromEnvironment } from './get-authenticator-from-environment';
|
|
25
|
+
export { readExternalSources } from './read-external-sources';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2021.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @module utils
|
|
18
|
+
* Helper functions used by generated SDKs.
|
|
19
|
+
*
|
|
20
|
+
* functions:
|
|
21
|
+
* getAuthenticatorFromEnvironment: Get authenticator from external sources.
|
|
22
|
+
* readExternalSources: Get config object from external sources.
|
|
23
|
+
*/
|
|
24
|
+
export { getAuthenticatorFromEnvironment } from './get-authenticator-from-environment';
|
|
25
|
+
export { readExternalSources } from './read-external-sources';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read properties stored in external sources like Environment Variables,
|
|
3
|
+
* the credentials file, VCAP services, etc. and return them as an
|
|
4
|
+
* object. The keys of this object will have the service name prefix removed
|
|
5
|
+
* and will be converted to lower camel case.
|
|
6
|
+
*
|
|
7
|
+
* Only one source will be used at a time.
|
|
8
|
+
*
|
|
9
|
+
* @param serviceName - the service name prefix
|
|
10
|
+
*/
|
|
11
|
+
export declare function readExternalSources(serviceName: string): any;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax */
|
|
2
|
+
/**
|
|
3
|
+
* (C) Copyright IBM Corp. 2019, 2022.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import camelcase from 'camelcase';
|
|
18
|
+
import isEmpty from 'lodash.isempty';
|
|
19
|
+
import logger from '../../lib/logger';
|
|
20
|
+
import { readCredentialsFile } from '../utils';
|
|
21
|
+
/**
|
|
22
|
+
* Read properties stored in external sources like Environment Variables,
|
|
23
|
+
* the credentials file, VCAP services, etc. and return them as an
|
|
24
|
+
* object. The keys of this object will have the service name prefix removed
|
|
25
|
+
* and will be converted to lower camel case.
|
|
26
|
+
*
|
|
27
|
+
* Only one source will be used at a time.
|
|
28
|
+
*
|
|
29
|
+
* @param serviceName - the service name prefix
|
|
30
|
+
*/
|
|
31
|
+
export function readExternalSources(serviceName) {
|
|
32
|
+
if (!serviceName) {
|
|
33
|
+
throw new Error('Service name is required.');
|
|
34
|
+
}
|
|
35
|
+
return getProperties(serviceName);
|
|
36
|
+
}
|
|
37
|
+
function getProperties(serviceName) {
|
|
38
|
+
// Try to get properties from external sources, with the following priority:
|
|
39
|
+
// 1. Credentials file (ibm-credentials.env)
|
|
40
|
+
// 2. Environment variables
|
|
41
|
+
// 3. VCAP Services (Cloud Foundry)
|
|
42
|
+
// only get properties from one source, return null if none found
|
|
43
|
+
let properties = null;
|
|
44
|
+
properties = filterPropertiesByServiceName(readCredentialsFile(), serviceName);
|
|
45
|
+
if (isEmpty(properties)) {
|
|
46
|
+
properties = filterPropertiesByServiceName(process.env, serviceName);
|
|
47
|
+
}
|
|
48
|
+
if (isEmpty(properties)) {
|
|
49
|
+
properties = getPropertiesFromVCAP(serviceName);
|
|
50
|
+
}
|
|
51
|
+
return properties;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Pulls credentials from env properties
|
|
55
|
+
*
|
|
56
|
+
* Property checked is uppercase service.name suffixed by _USERNAME and _PASSWORD
|
|
57
|
+
*
|
|
58
|
+
* For example, if service.name is speech_to_text,
|
|
59
|
+
* env properties are SPEECH_TO_TEXT_USERNAME and SPEECH_TO_TEXT_PASSWORD
|
|
60
|
+
*
|
|
61
|
+
* @param envObj - the object containing the credentials keyed by environment variables
|
|
62
|
+
* @returns the set of credentials
|
|
63
|
+
*/
|
|
64
|
+
function filterPropertiesByServiceName(envObj, serviceName) {
|
|
65
|
+
const credentials = {};
|
|
66
|
+
const name = `${serviceName.toUpperCase().replace(/-/g, '_')}_`; // append the underscore that must follow the service name
|
|
67
|
+
// filter out properties that don't begin with the service name
|
|
68
|
+
Object.keys(envObj).forEach((key) => {
|
|
69
|
+
if (key.startsWith(name)) {
|
|
70
|
+
const propName = camelcase(key.substring(name.length)); // remove the name from the front of the string and make camelcase
|
|
71
|
+
credentials[propName] = envObj[key];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
// all env variables are parsed as strings, convert boolean vars as needed
|
|
75
|
+
if (typeof credentials.disableSsl === 'string') {
|
|
76
|
+
credentials.disableSsl = credentials.disableSsl === 'true';
|
|
77
|
+
}
|
|
78
|
+
if (typeof credentials.authDisableSsl === 'string') {
|
|
79
|
+
credentials.authDisableSsl = credentials.authDisableSsl === 'true';
|
|
80
|
+
}
|
|
81
|
+
if (typeof credentials.enableGzip === 'string') {
|
|
82
|
+
credentials.enableGzip = credentials.enableGzip === 'true';
|
|
83
|
+
}
|
|
84
|
+
if (typeof credentials.enableRetries === 'string') {
|
|
85
|
+
credentials.enableRetries = credentials.enableRetries === 'true';
|
|
86
|
+
}
|
|
87
|
+
if (typeof credentials.maxRetries === 'string') {
|
|
88
|
+
credentials.maxRetries = parseInt(credentials.maxRetries, 10);
|
|
89
|
+
}
|
|
90
|
+
if (typeof credentials.retryInterval === 'string') {
|
|
91
|
+
credentials.retryInterval = parseInt(credentials.retryInterval, 10);
|
|
92
|
+
}
|
|
93
|
+
return credentials;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Pulls credentials from VCAP_SERVICES env property that IBM Cloud sets
|
|
97
|
+
*
|
|
98
|
+
* The function will first look for a service entry whose "name" field matches
|
|
99
|
+
* the serviceKey value. If found, return its credentials.
|
|
100
|
+
*
|
|
101
|
+
* If no match against the service entry's "name" field is found, then find the
|
|
102
|
+
* service list with a key matching the serviceKey value. If found, return the
|
|
103
|
+
* credentials of the first service in the service list.
|
|
104
|
+
*/
|
|
105
|
+
function getVCAPCredentialsForService(name) {
|
|
106
|
+
if (process.env.VCAP_SERVICES) {
|
|
107
|
+
const services = JSON.parse(process.env.VCAP_SERVICES);
|
|
108
|
+
for (const serviceName of Object.keys(services)) {
|
|
109
|
+
for (const instance of services[serviceName]) {
|
|
110
|
+
if (instance.name === name) {
|
|
111
|
+
if (Object.prototype.hasOwnProperty.call(instance, 'credentials')) {
|
|
112
|
+
return instance.credentials;
|
|
113
|
+
}
|
|
114
|
+
logger.debug('no data read from VCAP_SERVICES');
|
|
115
|
+
return {};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const serviceName of Object.keys(services)) {
|
|
120
|
+
if (serviceName === name) {
|
|
121
|
+
if (services[serviceName].length > 0) {
|
|
122
|
+
if (Object.prototype.hasOwnProperty.call(services[serviceName][0], 'credentials')) {
|
|
123
|
+
return services[serviceName][0].credentials;
|
|
124
|
+
}
|
|
125
|
+
logger.debug('no data read from VCAP_SERVICES');
|
|
126
|
+
return {};
|
|
127
|
+
}
|
|
128
|
+
logger.debug('no data read from VCAP_SERVICES');
|
|
129
|
+
return {};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
logger.debug('no data read from VCAP_SERVICES');
|
|
134
|
+
return {};
|
|
135
|
+
}
|
|
136
|
+
function getPropertiesFromVCAP(serviceName) {
|
|
137
|
+
const credentials = getVCAPCredentialsForService(serviceName);
|
|
138
|
+
// infer authentication type from credentials in a simple manner
|
|
139
|
+
// iam is used as the default later
|
|
140
|
+
if (credentials.username || credentials.password) {
|
|
141
|
+
credentials.authType = 'basic';
|
|
142
|
+
}
|
|
143
|
+
return credentials;
|
|
144
|
+
}
|