ibm-cloud-sdk-core 4.0.0 → 4.0.2

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.
Files changed (233) hide show
  1. package/.secrets.baseline +20 -30
  2. package/CHANGELOG.md +16 -4
  3. package/MIGRATION-V4.md +54 -0
  4. package/auth/authenticators/authenticator-interface.d.ts +3 -4
  5. package/auth/authenticators/authenticator-interface.js +1 -1
  6. package/auth/authenticators/authenticator.d.ts +5 -9
  7. package/auth/authenticators/authenticator.js +4 -8
  8. package/auth/authenticators/basic-authenticator.d.ts +12 -12
  9. package/auth/authenticators/basic-authenticator.js +12 -12
  10. package/auth/authenticators/bearer-token-authenticator.d.ts +11 -14
  11. package/auth/authenticators/bearer-token-authenticator.js +11 -14
  12. package/auth/authenticators/cloud-pak-for-data-authenticator.d.ts +15 -15
  13. package/auth/authenticators/cloud-pak-for-data-authenticator.js +15 -15
  14. package/auth/authenticators/container-authenticator.d.ts +23 -23
  15. package/auth/authenticators/container-authenticator.js +23 -23
  16. package/auth/authenticators/iam-authenticator.d.ts +20 -20
  17. package/auth/authenticators/iam-authenticator.js +20 -20
  18. package/auth/authenticators/iam-request-based-authenticator.d.ts +23 -25
  19. package/auth/authenticators/iam-request-based-authenticator.js +23 -25
  20. package/auth/authenticators/token-request-based-authenticator.d.ts +19 -24
  21. package/auth/authenticators/token-request-based-authenticator.js +19 -24
  22. package/auth/authenticators/vpc-instance-authenticator.d.ts +17 -16
  23. package/auth/authenticators/vpc-instance-authenticator.js +17 -16
  24. package/auth/token-managers/container-token-manager.d.ts +23 -25
  25. package/auth/token-managers/container-token-manager.js +23 -25
  26. package/auth/token-managers/cp4d-token-manager.d.ts +13 -13
  27. package/auth/token-managers/cp4d-token-manager.js +13 -13
  28. package/auth/token-managers/iam-request-based-token-manager.d.ts +26 -31
  29. package/auth/token-managers/iam-request-based-token-manager.js +26 -31
  30. package/auth/token-managers/iam-token-manager.d.ts +17 -16
  31. package/auth/token-managers/iam-token-manager.js +17 -16
  32. package/auth/token-managers/jwt-token-manager.d.ts +10 -13
  33. package/auth/token-managers/jwt-token-manager.js +13 -16
  34. package/auth/token-managers/token-manager.d.ts +23 -35
  35. package/auth/token-managers/token-manager.js +22 -34
  36. package/auth/token-managers/vpc-instance-token-manager.d.ts +15 -15
  37. package/auth/token-managers/vpc-instance-token-manager.js +15 -15
  38. package/auth/utils/get-authenticator-from-environment.d.ts +2 -2
  39. package/auth/utils/get-authenticator-from-environment.js +2 -2
  40. package/auth/utils/helpers.d.ts +34 -32
  41. package/auth/utils/helpers.js +34 -32
  42. package/auth/utils/read-external-sources.d.ts +2 -1
  43. package/auth/utils/read-external-sources.js +5 -4
  44. package/build/docs/ibm-cloud-sdk-core.atleastone.md +4 -4
  45. package/build/docs/ibm-cloud-sdk-core.atmostone.md +2 -2
  46. package/build/docs/ibm-cloud-sdk-core.authenticator._constructor_.md +1 -1
  47. package/build/docs/ibm-cloud-sdk-core.authenticator.authenticate.md +1 -1
  48. package/build/docs/ibm-cloud-sdk-core.authenticator.authenticationtype.md +1 -1
  49. package/build/docs/ibm-cloud-sdk-core.authenticator.md +1 -1
  50. package/build/docs/ibm-cloud-sdk-core.authenticatorinterface.authenticate.md +1 -1
  51. package/build/docs/ibm-cloud-sdk-core.baseservice._constructor_.md +1 -1
  52. package/build/docs/ibm-cloud-sdk-core.baseservice.configureservice.md +1 -1
  53. package/build/docs/ibm-cloud-sdk-core.baseservice.createrequest.md +2 -2
  54. package/build/docs/ibm-cloud-sdk-core.baseservice.enableretries.md +1 -1
  55. package/build/docs/ibm-cloud-sdk-core.baseservice.getauthenticator.md +1 -1
  56. package/build/docs/ibm-cloud-sdk-core.baseservice.md +3 -3
  57. package/build/docs/ibm-cloud-sdk-core.baseservice.setdefaultheaders.md +1 -1
  58. package/build/docs/ibm-cloud-sdk-core.baseservice.setserviceurl.md +1 -1
  59. package/build/docs/ibm-cloud-sdk-core.basicauthenticator._constructor_.md +2 -2
  60. package/build/docs/ibm-cloud-sdk-core.basicauthenticator.authenticate.md +1 -1
  61. package/build/docs/ibm-cloud-sdk-core.basicauthenticator.md +3 -3
  62. package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator._constructor_.md +2 -2
  63. package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator.authenticate.md +2 -2
  64. package/build/docs/ibm-cloud-sdk-core.bearertokenauthenticator.md +3 -3
  65. package/build/docs/ibm-cloud-sdk-core.buildrequestfileobject.md +2 -2
  66. package/build/docs/ibm-cloud-sdk-core.checkcredentials.md +3 -3
  67. package/build/docs/ibm-cloud-sdk-core.cloudpakfordataauthenticator._constructor_.md +3 -3
  68. package/build/docs/ibm-cloud-sdk-core.cloudpakfordataauthenticator.md +5 -5
  69. package/build/docs/ibm-cloud-sdk-core.computebasicauthheader.md +1 -1
  70. package/build/docs/ibm-cloud-sdk-core.constructserviceurl.md +4 -4
  71. package/build/docs/ibm-cloud-sdk-core.containerauthenticator._constructor_.md +3 -3
  72. package/build/docs/ibm-cloud-sdk-core.containerauthenticator.md +4 -4
  73. package/build/docs/ibm-cloud-sdk-core.containerauthenticator.setcrtokenfilename.md +1 -1
  74. package/build/docs/ibm-cloud-sdk-core.containerauthenticator.setiamprofileid.md +1 -1
  75. package/build/docs/ibm-cloud-sdk-core.containerauthenticator.setiamprofilename.md +1 -1
  76. package/build/docs/ibm-cloud-sdk-core.containertokenmanager._constructor_.md +6 -2
  77. package/build/docs/ibm-cloud-sdk-core.containertokenmanager.md +5 -5
  78. package/build/docs/ibm-cloud-sdk-core.containertokenmanager.requesttoken.md +0 -2
  79. package/build/docs/ibm-cloud-sdk-core.containertokenmanager.setcrtokenfilename.md +2 -2
  80. package/build/docs/ibm-cloud-sdk-core.containertokenmanager.setiamprofileid.md +2 -2
  81. package/build/docs/ibm-cloud-sdk-core.containertokenmanager.setiamprofilename.md +2 -2
  82. package/build/docs/ibm-cloud-sdk-core.cp4dtokenmanager._constructor_.md +6 -2
  83. package/build/docs/ibm-cloud-sdk-core.cp4dtokenmanager.md +3 -3
  84. package/build/docs/ibm-cloud-sdk-core.fileobject.md +5 -5
  85. package/build/docs/ibm-cloud-sdk-core.fileoptions.md +4 -4
  86. package/build/docs/ibm-cloud-sdk-core.filestream.md +3 -3
  87. package/build/docs/ibm-cloud-sdk-core.filewithmetadata.md +5 -5
  88. package/build/docs/ibm-cloud-sdk-core.getauthenticatorfromenvironment.md +1 -1
  89. package/build/docs/ibm-cloud-sdk-core.getcontenttype.md +1 -1
  90. package/build/docs/ibm-cloud-sdk-core.getcurrenttime.md +2 -2
  91. package/build/docs/ibm-cloud-sdk-core.getformat.md +0 -2
  92. package/build/docs/ibm-cloud-sdk-core.getmissingparams.md +1 -1
  93. package/build/docs/ibm-cloud-sdk-core.getnewlogger.md +1 -1
  94. package/build/docs/ibm-cloud-sdk-core.getqueryparam.md +1 -5
  95. package/build/docs/ibm-cloud-sdk-core.iamauthenticator._constructor_.md +3 -3
  96. package/build/docs/ibm-cloud-sdk-core.iamauthenticator.md +5 -5
  97. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator._constructor_.md +3 -3
  98. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.getrefreshtoken.md +1 -1
  99. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.md +7 -7
  100. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.setclientidandsecret.md +3 -3
  101. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedauthenticator.setscope.md +1 -1
  102. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager._constructor_.md +6 -2
  103. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.getrefreshtoken.md +2 -2
  104. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.md +8 -8
  105. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.requesttoken.md +2 -2
  106. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.savetokeninfo.md +1 -3
  107. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.setclientidandsecret.md +3 -5
  108. package/build/docs/ibm-cloud-sdk-core.iamrequestbasedtokenmanager.setscope.md +2 -4
  109. package/build/docs/ibm-cloud-sdk-core.iamrequestoptions.md +5 -5
  110. package/build/docs/ibm-cloud-sdk-core.iamtokenmanager._constructor_.md +6 -2
  111. package/build/docs/ibm-cloud-sdk-core.iamtokenmanager.md +3 -3
  112. package/build/docs/ibm-cloud-sdk-core.ishtml.md +1 -1
  113. package/build/docs/ibm-cloud-sdk-core.jwttokenmanager._constructor_.md +2 -2
  114. package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.md +5 -5
  115. package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.requesttoken.md +1 -1
  116. package/build/docs/ibm-cloud-sdk-core.jwttokenmanager.savetokeninfo.md +1 -3
  117. package/build/docs/ibm-cloud-sdk-core.md +24 -24
  118. package/build/docs/ibm-cloud-sdk-core.onlyone.md +2 -2
  119. package/build/docs/ibm-cloud-sdk-core.qs.md +1 -1
  120. package/build/docs/ibm-cloud-sdk-core.readexternalsources.md +1 -1
  121. package/build/docs/ibm-cloud-sdk-core.removesuffix.md +4 -4
  122. package/build/docs/ibm-cloud-sdk-core.sdklogger.md +7 -7
  123. package/build/docs/ibm-cloud-sdk-core.streamtopromise.md +3 -1
  124. package/build/docs/ibm-cloud-sdk-core.striptrailingslash.md +4 -2
  125. package/build/docs/ibm-cloud-sdk-core.tokenmanager._constructor_.md +2 -2
  126. package/build/docs/ibm-cloud-sdk-core.tokenmanager.gettoken.md +1 -1
  127. package/build/docs/ibm-cloud-sdk-core.tokenmanager.md +15 -15
  128. package/build/docs/ibm-cloud-sdk-core.tokenmanager.pacedrequesttoken.md +1 -1
  129. package/build/docs/ibm-cloud-sdk-core.tokenmanager.requesttoken.md +1 -1
  130. package/build/docs/ibm-cloud-sdk-core.tokenmanager.savetokeninfo.md +1 -3
  131. package/build/docs/ibm-cloud-sdk-core.tokenmanager.setdisablesslverification.md +1 -3
  132. package/build/docs/ibm-cloud-sdk-core.tokenmanager.setheaders.md +2 -4
  133. package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator._constructor_.md +2 -2
  134. package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.authenticate.md +2 -2
  135. package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.md +9 -9
  136. package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.setdisablesslverification.md +1 -1
  137. package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.setheaders.md +1 -1
  138. package/build/docs/ibm-cloud-sdk-core.tolowerkeys.md +1 -1
  139. package/build/docs/ibm-cloud-sdk-core.unittestutils.checkforsuccessfulexecution.md +0 -2
  140. package/build/docs/ibm-cloud-sdk-core.unittestutils.checkmediaheaders.md +0 -2
  141. package/build/docs/ibm-cloud-sdk-core.unittestutils.checkurlandmethod.md +1 -3
  142. package/build/docs/ibm-cloud-sdk-core.unittestutils.checkuserheader.md +0 -2
  143. package/build/docs/ibm-cloud-sdk-core.unittestutils.expecttobepromise.md +0 -2
  144. package/build/docs/ibm-cloud-sdk-core.unittestutils.getoptions.md +1 -1
  145. package/build/docs/ibm-cloud-sdk-core.useroptions.md +9 -9
  146. package/build/docs/ibm-cloud-sdk-core.validateinput.md +8 -2
  147. package/build/docs/ibm-cloud-sdk-core.validateparams.md +1 -1
  148. package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator._constructor_.md +6 -2
  149. package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.md +6 -6
  150. package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.setiamprofilecrn.md +2 -2
  151. package/build/docs/ibm-cloud-sdk-core.vpcinstanceauthenticator.setiamprofileid.md +2 -2
  152. package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager._constructor_.md +6 -2
  153. package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.md +4 -4
  154. package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.setiamprofilecrn.md +2 -2
  155. package/build/docs/ibm-cloud-sdk-core.vpcinstancetokenmanager.setiamprofileid.md +2 -2
  156. package/docs/ibm-cloud-sdk-core.api.json +516 -241
  157. package/es/auth/authenticators/authenticator-interface.d.ts +3 -4
  158. package/es/auth/authenticators/authenticator-interface.js +1 -1
  159. package/es/auth/authenticators/authenticator.d.ts +5 -9
  160. package/es/auth/authenticators/authenticator.js +4 -8
  161. package/es/auth/authenticators/basic-authenticator.d.ts +12 -12
  162. package/es/auth/authenticators/basic-authenticator.js +12 -12
  163. package/es/auth/authenticators/bearer-token-authenticator.d.ts +11 -14
  164. package/es/auth/authenticators/bearer-token-authenticator.js +11 -14
  165. package/es/auth/authenticators/cloud-pak-for-data-authenticator.d.ts +15 -15
  166. package/es/auth/authenticators/cloud-pak-for-data-authenticator.js +15 -15
  167. package/es/auth/authenticators/container-authenticator.d.ts +23 -23
  168. package/es/auth/authenticators/container-authenticator.js +23 -23
  169. package/es/auth/authenticators/iam-authenticator.d.ts +20 -20
  170. package/es/auth/authenticators/iam-authenticator.js +20 -20
  171. package/es/auth/authenticators/iam-request-based-authenticator.d.ts +23 -25
  172. package/es/auth/authenticators/iam-request-based-authenticator.js +23 -25
  173. package/es/auth/authenticators/token-request-based-authenticator.d.ts +19 -24
  174. package/es/auth/authenticators/token-request-based-authenticator.js +19 -24
  175. package/es/auth/authenticators/vpc-instance-authenticator.d.ts +17 -16
  176. package/es/auth/authenticators/vpc-instance-authenticator.js +17 -16
  177. package/es/auth/token-managers/container-token-manager.d.ts +23 -25
  178. package/es/auth/token-managers/container-token-manager.js +23 -25
  179. package/es/auth/token-managers/cp4d-token-manager.d.ts +13 -13
  180. package/es/auth/token-managers/cp4d-token-manager.js +13 -13
  181. package/es/auth/token-managers/iam-request-based-token-manager.d.ts +26 -31
  182. package/es/auth/token-managers/iam-request-based-token-manager.js +26 -31
  183. package/es/auth/token-managers/iam-token-manager.d.ts +17 -16
  184. package/es/auth/token-managers/iam-token-manager.js +17 -16
  185. package/es/auth/token-managers/jwt-token-manager.d.ts +10 -13
  186. package/es/auth/token-managers/jwt-token-manager.js +13 -16
  187. package/es/auth/token-managers/token-manager.d.ts +23 -35
  188. package/es/auth/token-managers/token-manager.js +22 -34
  189. package/es/auth/token-managers/vpc-instance-token-manager.d.ts +15 -15
  190. package/es/auth/token-managers/vpc-instance-token-manager.js +15 -15
  191. package/es/auth/utils/get-authenticator-from-environment.d.ts +2 -2
  192. package/es/auth/utils/get-authenticator-from-environment.js +2 -2
  193. package/es/auth/utils/helpers.d.ts +34 -32
  194. package/es/auth/utils/helpers.js +34 -32
  195. package/es/auth/utils/read-external-sources.d.ts +2 -1
  196. package/es/auth/utils/read-external-sources.js +5 -4
  197. package/es/lib/base-service.d.ts +31 -32
  198. package/es/lib/base-service.js +31 -32
  199. package/es/lib/content-type.js +5 -5
  200. package/es/lib/get-new-logger.d.ts +2 -2
  201. package/es/lib/get-new-logger.js +2 -2
  202. package/es/lib/helper.d.ts +24 -31
  203. package/es/lib/helper.js +25 -32
  204. package/es/lib/querystring.d.ts +1 -1
  205. package/es/lib/querystring.js +3 -3
  206. package/es/lib/request-wrapper.d.ts +4 -6
  207. package/es/lib/request-wrapper.js +17 -23
  208. package/es/lib/sdk-test-helpers.d.ts +14 -19
  209. package/es/lib/sdk-test-helpers.js +14 -19
  210. package/es/lib/stream-to-promise.d.ts +3 -3
  211. package/es/lib/stream-to-promise.js +3 -3
  212. package/es/tsdoc-metadata.json +1 -1
  213. package/etc/ibm-cloud-sdk-core.api.md +12 -12
  214. package/ibm-cloud-sdk-core.d.ts +1402 -1449
  215. package/lib/base-service.d.ts +31 -32
  216. package/lib/base-service.js +31 -32
  217. package/lib/content-type.js +5 -5
  218. package/lib/get-new-logger.d.ts +2 -2
  219. package/lib/get-new-logger.js +2 -2
  220. package/lib/helper.d.ts +24 -31
  221. package/lib/helper.js +25 -32
  222. package/lib/querystring.d.ts +1 -1
  223. package/lib/querystring.js +3 -3
  224. package/lib/request-wrapper.d.ts +4 -6
  225. package/lib/request-wrapper.js +17 -23
  226. package/lib/sdk-test-helpers.d.ts +14 -19
  227. package/lib/sdk-test-helpers.js +14 -19
  228. package/lib/stream-to-promise.d.ts +3 -3
  229. package/lib/stream-to-promise.js +3 -3
  230. package/package.json +2 -2
  231. package/temp/ibm-cloud-sdk-core.api.json +516 -241
  232. package/temp/ibm-cloud-sdk-core.api.md +12 -12
  233. package/MIGRATION-V1.md +0 -42
@@ -7,24 +7,22 @@ import { OutgoingHttpHeaders } from 'http';
7
7
  import { Stream } from 'stream';
8
8
 
9
9
  /**
10
- * Check for at least one of two elements being defined.
11
- * Returns true if a or b is defined. Returns false if
12
- * both are undefined.
10
+ * Checks for at least one of two elements being defined.
13
11
  *
14
- * @param {any} a - The first object
15
- * @param {any} b - The second object
16
- * @returns {boolean}
12
+ * @param a - the first object
13
+ * @param b - the second object
14
+ * @returns true if a or b is defined; false if both are undefined
17
15
  */
18
16
  export declare function atLeastOne(a: any, b: any): boolean;
19
17
 
20
18
  /**
21
- * Verify that both properties are not specified.
22
- * Returns true if only a, only b, or neither is defined.
23
- * Returns false if both are defined.
19
+ * Verifies that both properties are not specified.
24
20
  *
25
- * @param {any} a - The first object
26
- * @param {any} b - The second object
27
- * @returns {boolean}
21
+ * @param a - The first object
22
+ * @param b - The second object
23
+ *
24
+ * @returns false if a and b are both defined, true otherwise
25
+
28
26
  */
29
27
  export declare function atMostOne(a: any, b: any): boolean;
30
28
 
@@ -59,25 +57,21 @@ export declare class Authenticator implements AuthenticatorInterface {
59
57
  /**
60
58
  * Create a new Authenticator instance.
61
59
  *
62
- * @throws {Error} The `new` keyword was not used to create construct the
63
- * authenticator.
60
+ * @throws Error: the "new" keyword was not used to construct the authenticator.
64
61
  */
65
62
  constructor();
66
63
  /**
67
64
  * Augment the request with authentication information.
68
65
  *
69
- * @param {object} requestOptions - The request to augment with authentication information.
70
- * @param {object.<string, string>} requestOptions.headers - The headers the
71
- * authentication information will be added too.
72
- * @throws {Error} - The authenticate method was not implemented by a
73
- * subclass.
66
+ * @param requestOptions - The request to augment with authentication information.
67
+ * @throws Error: The authenticate method was not implemented by a subclass.
74
68
  */
75
69
  authenticate(requestOptions: AuthenticateOptions): Promise<void>;
76
70
  /**
77
71
  * Retrieves the authenticator's type.
78
72
  * The returned value will be the same string that is used
79
73
  * when configuring an instance of the authenticator with the
80
- * "<service_name>_AUTH_TYPE" configuration property
74
+ * \<service_name\>_AUTH_TYPE configuration property
81
75
  * (e.g. "basic", "iam", etc.).
82
76
  * This function should be overridden in each authenticator
83
77
  * implementation class that extends this class.
@@ -95,9 +89,8 @@ export declare interface AuthenticatorInterface {
95
89
  /**
96
90
  * Add authentication information to the specified request.
97
91
  *
98
- * @param {object} requestOptions The request to augment with authentication information.
99
- * @param {object.<string, string>} requestOptions.headers The headers the
100
- * authentication information will be added to.
92
+ * @param requestOptions - The request to which authentication information is added
93
+ * (in the headers field).
101
94
  */
102
95
  authenticate(requestOptions: AuthenticateOptions): Promise<void>;
103
96
  /**
@@ -135,1459 +128,1419 @@ export declare class BaseService {
135
128
  private requestWrapperInstance;
136
129
  /**
137
130
  * Configuration values for a service.
138
- * @param {Authenticator} userOptions.authenticator Object used to authenticate requests to the service.
139
- * @param {string} [userOptions.serviceUrl] The base url to use when contacting the service.
131
+ *
132
+ * @param userOptions - the configuration options to set on the service instance.
133
+ * This should be an object with the following fields:
134
+ * - authenticator: (required) an Object used to authenticate requests to the service.
135
+ * - serviceUrl: (optional) the base url to use when contacting the service.
140
136
  * The base url may differ between IBM Cloud regions.
141
- * @param {object<string, string>} [userOptions.headers] Default headers that shall be
142
- * included with every request to the service.
143
- * @param {string} [userOptions.version] The API version date to use with the service,
144
- * in "YYYY-MM-DD" format.
145
- * @param {boolean} [userOptions.disableSslVerification] A flag that indicates
146
- * whether verification of the token server's SSL certificate should be
147
- * disabled or not.
148
- */
149
- constructor(userOptions: UserOptions);
150
- /**
151
- * Get the instance of the authenticator set on the service.
152
- *
153
- * @returns {Authenticator}
154
- */
155
- getAuthenticator(): any;
156
- /**
157
- * Set the service URL to send requests to.
158
- *
159
- * @param {string} url The base URL for the service.
160
- */
161
- setServiceUrl(url: string): void;
162
- /**
163
- * Set the HTTP headers to be sent in every request.
164
- *
165
- * @param {OutgoingHttpHeaders} headers The map of headers to include in requests.
166
- */
167
- setDefaultHeaders(headers: OutgoingHttpHeaders): void;
168
- /**
169
- * Turn request body compression on or off.
170
- *
171
- * @param {boolean} setting Will turn it on if 'true', off if 'false'.
172
- */
173
- setEnableGzipCompression(setting: boolean): void;
174
- /**
175
- * Get the Axios instance set on the service.
176
- * All requests will be made using this instance.
177
- */
178
- getHttpClient(): AxiosInstance;
179
- /**
180
- * Enable retries for unfulfilled requests.
181
- *
182
- * @param {RetryOptions} retryOptions configuration for retries
183
- */
184
- enableRetries(retryOptions?: RetryOptions): void;
185
- /**
186
- * Disables retries.
187
- */
188
- disableRetries(): void;
189
- /**
190
- * Configure the service using external configuration
191
- *
192
- * @param {string} serviceName The name of the service. Will be used to read from external
193
- * configuration.
194
- */
195
- protected configureService(serviceName: string): void;
196
- /**
197
- * Wrapper around `sendRequest` that enforces the request will be authenticated.
198
- *
199
- * @param {object} parameters Service request options passed in by user.
200
- * @param {string} parameters.options.method The http method.
201
- * @param {string} parameters.options.url The path portion of the URL to be appended to the serviceUrl.
202
- * @param {object} [parameters.options.path] The path parameters to be inserted into the URL.
203
- * @param {object} [parameters.options.qs] The querystring to be included in the URL.
204
- * @param {object} [parameters.options.body] The data to be sent as the request body.
205
- * @param {object} [parameters.options.form] An object containing the key/value pairs for a www-form-urlencoded request.
206
- * @param {object} [parameters.options.formData] An object containing the contents for a multipart/form-data request
207
- * The following processing is performed on formData values:
208
- * - string: no special processing -- the value is sent as is
209
- * - object: the value is converted to a JSON string before insertion into the form body
210
- * - NodeJS.ReadableStream|Buffer|FileWithMetadata: sent as a file, with any associated metadata
211
- * - array: each element of the array is sent as a separate form part using any special processing as described above
212
- * @param {object} parameters.defaultOptions
213
- * @param {string} parameters.defaultOptions.serviceUrl The base URL of the service.
214
- * @param {OutgoingHttpHeaders} parameters.defaultOptions.headers Additional headers to be passed on the request.
215
- * @returns {Promise<any>}
216
- */
217
- protected createRequest(parameters: any): Promise<any>;
218
- private readOptionsFromExternalConfig;
219
- }
137
+ * - headers: (optional) a set of HTTP headers that should be included with every request sent to the service
138
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the server's SSL certificate should be
139
+ * disabled or not.
140
+ */
141
+ constructor(userOptions: UserOptions);
142
+ /**
143
+ * Get the instance of the authenticator set on the service.
144
+ *
145
+ * @returns the Authenticator instance
146
+ */
147
+ getAuthenticator(): any;
148
+ /**
149
+ * Set the service URL to send requests to.
150
+ *
151
+ * @param url - the base URL for the service.
152
+ */
153
+ setServiceUrl(url: string): void;
154
+ /**
155
+ * Set the HTTP headers to be sent in every request.
156
+ *
157
+ * @param headers - the map of headers to include in requests.
158
+ */
159
+ setDefaultHeaders(headers: OutgoingHttpHeaders): void;
160
+ /**
161
+ * Turn request body compression on or off.
162
+ *
163
+ * @param setting - Will turn it on if 'true', off if 'false'.
164
+ */
165
+ setEnableGzipCompression(setting: boolean): void;
166
+ /**
167
+ * Get the Axios instance set on the service.
168
+ * All requests will be made using this instance.
169
+ */
170
+ getHttpClient(): AxiosInstance;
171
+ /**
172
+ * Enable retries for unfulfilled requests.
173
+ *
174
+ * @param retryOptions - the configuration for retries
175
+ */
176
+ enableRetries(retryOptions?: RetryOptions): void;
177
+ /**
178
+ * Disables retries.
179
+ */
180
+ disableRetries(): void;
181
+ /**
182
+ * Configure the service using external configuration
183
+ *
184
+ * @param serviceName - the name of the service. This will be used to read from external
185
+ * configuration.
186
+ */
187
+ protected configureService(serviceName: string): void;
188
+ /**
189
+ * Wrapper around `sendRequest` that enforces the request will be authenticated.
190
+ *
191
+ * @param parameters - Service request options passed in by user.
192
+ * This should be an object with the following fields:
193
+ * - options.method: the http method
194
+ * - options.url: the path portion of the URL to be appended to the serviceUrl
195
+ * - options.path: the path parameters to be inserted into the URL
196
+ * - options.qs: the querystring to be included in the URL
197
+ * - options.body: the data to be sent as the request body
198
+ * - options.form: an object containing the key/value pairs for a www-form-urlencoded request.
199
+ * - options.formData: an object containing the contents for a multipart/form-data request
200
+ * The following processing is performed on formData values:
201
+ * - string: no special processing -- the value is sent as is
202
+ * - object: the value is converted to a JSON string before insertion into the form body
203
+ * - NodeJS.ReadableStream|Buffer|FileWithMetadata: sent as a file, with any associated metadata
204
+ * - array: each element of the array is sent as a separate form part using any special processing as described above
205
+ * - defaultOptions.serviceUrl: the base URL of the service
206
+ * - defaultOptions.headers: additional HTTP headers to be sent with the request
207
+ * @returns a Promise
208
+ */
209
+ protected createRequest(parameters: any): Promise<any>;
210
+ private readOptionsFromExternalConfig;
211
+ }
220
212
 
213
+ /**
214
+ * Additional service configuration.
215
+ */
216
+ declare interface BaseServiceOptions extends UserOptions {
217
+ /** Querystring to be sent with every request. If not a string will be stringified. */
218
+ qs?: any;
219
+ enableRetries?: boolean;
220
+ maxRetries?: number;
221
+ retryInterval?: number;
222
+ }
223
+
224
+ /**
225
+ * The BasicAuthenticator is used to add basic authentication information to
226
+ * requests.
227
+ *
228
+ * Basic Authorization will be sent as an Authorization header in the form:
229
+ *
230
+ * Authorization: Basic \<encoded username and password\>
231
+ *
232
+ */
233
+ export declare class BasicAuthenticator extends Authenticator {
234
+ protected requiredOptions: string[];
235
+ protected authHeader: {
236
+ Authorization: string;
237
+ };
221
238
  /**
222
- * Additional service configuration.
239
+ * Create a new BasicAuthenticator instance.
240
+ *
241
+ * @param options - Configuration options for basic authentication.
242
+ * This should be an object containing these fields:
243
+ * - username: the username portion of basic authentication
244
+ * - password: the password portion of basic authentication
245
+ *
246
+ * @throws Error: the configuration options are not valid.
223
247
  */
224
- declare interface BaseServiceOptions extends UserOptions {
225
- /** Querystring to be sent with every request. If not a string will be stringified. */
226
- qs?: any;
227
- enableRetries?: boolean;
228
- maxRetries?: number;
229
- retryInterval?: number;
230
- }
248
+ constructor(options: Options);
249
+ /**
250
+ * Add basic authentication information to `requestOptions`. The basic authentication information
251
+ * will be set in the Authorization property of `requestOptions.headers` in the form:
252
+ *
253
+ * Authorization: Basic \<encoded username and password\>
254
+ *
255
+ * @param requestOptions - The request to augment with authentication information.
256
+ */
257
+ authenticate(requestOptions: AuthenticateOptions): Promise<void>;
258
+ /**
259
+ * Returns the authenticator's type ('basic').
260
+ *
261
+ * @returns a string that indicates the authenticator's type
262
+ */
263
+ authenticationType(): string;
264
+ }
231
265
 
266
+ /**
267
+ * The BearerTokenAuthenticator will set a user-provided bearer token
268
+ * in requests.
269
+ *
270
+ * The bearer token will be sent as an Authorization header in the form:
271
+ *
272
+ * Authorization: Bearer \<bearer-token\>
273
+ */
274
+ export declare class BearerTokenAuthenticator extends Authenticator {
275
+ protected requiredOptions: string[];
276
+ private bearerToken;
232
277
  /**
233
- * The BasicAuthenticator is used to add basic authentication information to
278
+ * Create a new BearerTokenAuthenticator instance.
279
+ *
280
+ * @param options - Configuration options for bearer authentication.
281
+ * This should be an object containing the "bearerToken" field.
282
+ *
283
+ * @throws Error: the options.bearerToken field is not valid, or unspecified
284
+ */
285
+ constructor(options: Options_2);
286
+ /**
287
+ * Set a new bearer token to be sent in subsequent requests.
288
+ *
289
+ * @param bearerToken - The bearer token that will be sent in service
234
290
  * requests.
291
+ */
292
+ setBearerToken(bearerToken: string): void;
293
+ /**
294
+ * Add a bearer token to `requestOptions`. The bearer token information
295
+ * will be set in the Authorization property of "requestOptions.headers" in the form:
235
296
  *
236
- * Basic Authorization will be sent as an Authorization header in the form:
237
- *
238
- * Authorization: Basic <encoded username and password>
239
- *
240
- */
241
- export declare class BasicAuthenticator extends Authenticator {
242
- protected requiredOptions: string[];
243
- protected authHeader: {
244
- Authorization: string;
245
- };
246
- /**
247
- * Create a new BasicAuthenticator instance.
248
- *
249
- * @param {object} options Configuration options for basic authentication.
250
- * @param {string} options.username The username portion of basic authentication.
251
- * @param {string} options.password The password portion of basic authentication.
252
- * @throws {Error} The configuration options are not valid.
253
- */
254
- constructor(options: Options);
255
- /**
256
- * Add basic authentication information to `request`. The basic authentication information
257
- * will be set in the Authorization property of`request.headers` in the form:
258
- *
259
- * Authorization: Basic <encoded username and password>
260
- *
261
- * @param {object} requestOptions - The request to augment with authentication information.
262
- * @param {object.<string, string>} requestOptions.headers - The headers the
263
- * authentication information will be added too.
264
- */
265
- authenticate(requestOptions: AuthenticateOptions): Promise<void>;
266
- /**
267
- * Returns the authenticator's type ('basic').
268
- *
269
- * @returns a string that indicates the authenticator's type
270
- */
271
- authenticationType(): string;
272
- }
297
+ * Authorization: Bearer \<bearer-token\>
298
+ *
299
+ * @param requestOptions - The request to augment with authentication information.
300
+ */
301
+ authenticate(requestOptions: AuthenticateOptions): Promise<void>;
302
+ /**
303
+ * Returns the authenticator's type ('bearertoken').
304
+ *
305
+ * @returns a string that indicates the authenticator's type
306
+ */
307
+ authenticationType(): string;
308
+ }
309
+
310
+ /**
311
+ * This function builds a `form-data` object for each file parameter.
312
+ * @param fileParam - The FileWithMetadata instance that contains the file information
313
+ * @returns the FileObject instance
314
+ */
315
+ export declare function buildRequestFileObject(fileParam: FileWithMetadata): Promise<FileObject>;
316
+
317
+ /**
318
+ * Checks credentials for common user mistakes of copying \{, \}, or \" characters from the documentation
319
+ *
320
+ * @param obj - the options object holding credentials
321
+ * @param credsToCheck - an array containing the keys of the credentials to check for problems
322
+ * @returns a string with the error message if there were problems, null if not
323
+ */
324
+ export declare function checkCredentials(obj: any, credsToCheck: string[]): Error | null;
325
+
326
+ /**
327
+ * This method simply ensures that the method executed without any issues by extracting
328
+ * the argument from the mock object for the `createRequest` method and verifying that it is an object.
329
+ *
330
+ * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
331
+ */
332
+ declare function checkForSuccessfulExecution(createRequestMock: any): void;
333
+
334
+ /**
335
+ * Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
336
+ * and checks for the expected values for `Accept` and `Content-Type`. This to verify that the SDK sets
337
+ * the correct values in the code.
338
+ *
339
+ * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
340
+ * @param accept - the expected value for the `Accept` header
341
+ * @param contentType - the expected value for the `Content-Type` header
342
+ */
343
+ declare function checkMediaHeaders(createRequestMock: any, accept: string, contentType: string): void;
273
344
 
345
+ /**
346
+ * (C) Copyright IBM Corp. 2019, 2022.
347
+ *
348
+ * Licensed under the Apache License, Version 2.0 (the "License");
349
+ * you may not use this file except in compliance with the License.
350
+ * You may obtain a copy of the License at
351
+ *
352
+ * http://www.apache.org/licenses/LICENSE-2.0
353
+ *
354
+ * Unless required by applicable law or agreed to in writing, software
355
+ * distributed under the License is distributed on an "AS IS" BASIS,
356
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
357
+ * See the License for the specific language governing permissions and
358
+ * limitations under the License.
359
+ */
360
+ /**
361
+ * This module provides a set of helper methods used to reduce code duplication in the generated unit tests
362
+ * for the SDKs that depend on this core package. Note that these methods are not used by the tests for this
363
+ * package - they are meant to be exported and made available to dependent libraries.
364
+ */
365
+ /**
366
+ * Takes the request options constructed by the SDK and checks that the `url` and `method` properties
367
+ * were set to their correct values.
368
+ *
369
+ * @param options - the options object put together by the SDK, retrieved from the createRequest mock
370
+ * @param url - The URL path of the service endpoint, from the paths section of the API definition
371
+ * @param method - The HTTP method for the request, from the API definition
372
+ */
373
+ declare function checkUrlAndMethod(options: any, url: string, method: any): void;
374
+
375
+ /**
376
+ * Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
377
+ * and checks for the expected value for a user-defined header. This is verify that the SDK accepts header
378
+ * parameters and sends them as headers in the request.
379
+ *
380
+ * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
381
+ * @param userHeaderName - the name of the header passed by the user, e.g. `Contained-Content-Type`
382
+ * @param userHeaderValue - the expected value for the header passed by the user
383
+ */
384
+ declare function checkUserHeader(createRequestMock: any, userHeaderName: string, userHeaderValue: string): void;
385
+
386
+ /**
387
+ * The CloudPakForDataAuthenticator will either use a username/password pair or a username/apikey pair to obtain
388
+ * a bearer token from a token server. When the bearer token expires, a new token is obtained from the token server.
389
+ *
390
+ * The bearer token will be sent as an Authorization header in the form:
391
+ *
392
+ * Authorization: Bearer \<bearer-token\>
393
+ */
394
+ export declare class CloudPakForDataAuthenticator extends TokenRequestBasedAuthenticator {
395
+ protected requiredOptions: string[];
396
+ protected tokenManager: Cp4dTokenManager;
397
+ private username;
398
+ private password;
399
+ private apikey;
274
400
  /**
275
- * The BearerTokenAuthenticator will set a user-provided bearer token
276
- * in requests.
277
- *
278
- * The bearer token will be sent as an Authorization header in the form:
279
- *
280
- * Authorization: Bearer <bearer-token>
281
- */
282
- export declare class BearerTokenAuthenticator extends Authenticator {
283
- protected requiredOptions: string[];
284
- private bearerToken;
285
- /**
286
- * Create a new BearerTokenAuthenticator instance.
287
- *
288
- * @param {object} options Configuration options for bearer authentication.
289
- * @param {string} options.bearerToken The bearer token to be added
290
- * to requests.
291
- * @throws {Error} The configuration bearerToken is not valid, or unspecified.
292
- */
293
- constructor(options: Options_2);
294
- /**
295
- * Set a new bearer token to be sent in subsequent requests.
296
- *
297
- * @param {string} bearerToken The bearer token that will be sent in service
298
- * requests.
299
- */
300
- setBearerToken(bearerToken: string): void;
301
- /**
302
- * Add a bearer token to the `request`. The bearer token information
303
- * will be set in the Authorization property of`request.headers` in the form:
304
- *
305
- * Authorization: Bearer <bearer-token>
306
- *
307
- * @param {object} requestOptions - The request to augment with authentication
308
- * information.
309
- * @param {object.<string, string>} requestOptions.headers - The headers the
310
- * authentication information will be added to.
311
- */
312
- authenticate(requestOptions: AuthenticateOptions): Promise<void>;
313
- /**
314
- * Returns the authenticator's type ('bearertoken').
315
- *
316
- * @returns a string that indicates the authenticator's type
317
- */
318
- authenticationType(): string;
319
- }
401
+ * Create a new CloudPakForDataAuthenticator instance.
402
+ *
403
+ * @param options - Configuration options for CloudPakForData authentication.
404
+ * This should be an object containing these fields:
405
+ * - url: (required) the endpoint URL for the CloudPakForData token service
406
+ * - username: (required) the username used to obtain a bearer token
407
+ * - password: (optional) the password used to obtain a bearer token (required if apikey is not specified)
408
+ * - apikey: (optional) the API key used to obtain a bearer token (required if password is not specified)
409
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
410
+ * should be disabled or not
411
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
412
+ *
413
+ * @throws Error: the username, password, and/or url are not valid, or unspecified, for Cloud Pak For Data token requests.
414
+ */
415
+ constructor(options: Options_4);
416
+ /**
417
+ * Returns the authenticator's type ('cp4d').
418
+ *
419
+ * @returns a string that indicates the authenticator's type
420
+ */
421
+ authenticationType(): string;
422
+ }
423
+
424
+ /**
425
+ * (C) Copyright IBM Corp. 2019, 2022.
426
+ *
427
+ * Licensed under the Apache License, Version 2.0 (the "License");
428
+ * you may not use this file except in compliance with the License.
429
+ * You may obtain a copy of the License at
430
+ *
431
+ * http://www.apache.org/licenses/LICENSE-2.0
432
+ *
433
+ * Unless required by applicable law or agreed to in writing, software
434
+ * distributed under the License is distributed on an "AS IS" BASIS,
435
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
436
+ * See the License for the specific language governing permissions and
437
+ * limitations under the License.
438
+ */
439
+ /**
440
+ * Compute and return a Basic Authorization header from a username and password.
441
+ *
442
+ * @param username - The username or client id
443
+ * @param password - The password or client secret
444
+ * @returns a Basic Auth header with format "Basic <encoded-credentials>"
445
+ */
446
+ export declare function computeBasicAuthHeader(username: string, password: string): string;
447
+
448
+ export declare function constructFilepath(filepath: string): string;
449
+
450
+ /**
451
+ * Constructs a service URL by formatting a parameterized URL.
452
+ *
453
+ * @param parameterizedUrl - a URL that contains variable placeholders, e.g. '\{scheme\}://ibm.com'.
454
+ * @param defaultUrlVariables - a Map of variable names to default values.
455
+ * Each variable in the parameterized URL must have a default value specified in this map.
456
+ * @param providedUrlVariables - a Map of variable names to desired values.
457
+ * If a variable is not provided in this map, the default variable value will be used instead.
458
+ * @returns the formatted URL with all variable placeholders replaced by values.
459
+ */
460
+ export declare function constructServiceUrl(parameterizedUrl: string, defaultUrlVariables: Map<string, string>, providedUrlVariables: Map<string, string> | null): string;
461
+
462
+ /**
463
+ * The ContainerAuthenticator will read a compute resource token from the file system
464
+ * and use this value to obtain a bearer token from the IAM token server. When the bearer
465
+ * token expires, a new token is obtained from the token server.
466
+ *
467
+ * The bearer token will be sent as an Authorization header in the form:
468
+ *
469
+ * Authorization: Bearer \<bearer-token\>
470
+ */
471
+ export declare class ContainerAuthenticator extends IamRequestBasedAuthenticator {
472
+ protected tokenManager: ContainerTokenManager;
473
+ private crTokenFilename;
474
+ private iamProfileName;
475
+ private iamProfileId;
476
+ /**
477
+ *
478
+ * Create a new ContainerAuthenticator instance.
479
+ *
480
+ * @param options - Configuration options for IAM authentication.
481
+ * This should be an object containing these fields:
482
+ * - url: (optional) the endpoint URL for the token service
483
+ * - crTokenFilename: (optional) the file containing the compute resource token
484
+ * - iamProfileName: (optional) the name of the IAM trusted profile associated with the compute resource token (required if iamProfileId is not specified)
485
+ * - iamProfileId]: (optional) the ID of the IAM trusted profile associated with the compute resource token (required if iamProfileName is not specified)
486
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
487
+ * should be disabled or not
488
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
489
+ * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
490
+ * Authorization header to be included in each request to the token service
491
+ * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
492
+ * Authorization header to be included in each request to the token service
493
+ * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service
494
+ *
495
+ * @throws Error: the configuration options are not valid.
496
+ */
497
+ constructor(options: Options_8);
498
+ /**
499
+ * Setter for the filename of the compute resource token.
500
+ * @param crTokenFilename - A string containing a path to the CR token file
501
+ */
502
+ setCrTokenFilename(crTokenFilename: string): void;
503
+ /**
504
+ * Setter for the "profile_name" parameter to use when fetching the bearer token from the IAM token server.
505
+ * @param iamProfileName - the name of the IAM trusted profile
506
+ */
507
+ setIamProfileName(iamProfileName: string): void;
508
+ /**
509
+ * Setter for the "profile_id" parameter to use when fetching the bearer token from the IAM token server.
510
+ * @param iamProfileId - the ID of the IAM trusted profile
511
+ */
512
+ setIamProfileId(iamProfileId: string): void;
513
+ /**
514
+ * Returns the authenticator's type ('container').
515
+ *
516
+ * @returns a string that indicates the authenticator's type
517
+ */
518
+ authenticationType(): string;
519
+ }
520
+
521
+ /**
522
+ * The ContainerTokenManager retrieves a compute resource token from a file on the container. This token
523
+ * is used to perform the necessary interactions with the IAM token service to obtain and store a suitable
524
+ * bearer (access) token.
525
+ */
526
+ export declare class ContainerTokenManager extends IamRequestBasedTokenManager {
527
+ private crTokenFilename;
528
+ private iamProfileName;
529
+ private iamProfileId;
530
+ /**
531
+ *
532
+ * Create a new ContainerTokenManager instance.
533
+ *
534
+ * @param options - Configuration options.
535
+ * This should be an object containing these fields:
536
+ * - url: (optional) the endpoint URL for the token service (default: "https://iam.cloud.ibm.com")
537
+ * - crTokenFilename: (optional) the file containing the compute resource token (default: "/var/run/secrets/tokens/vault-token")
538
+ * - iamProfileName: (optional) the name of the IAM trusted profile associated with the compute resource token (required if iamProfileId is not specified)
539
+ * - iamProfileId]: (optional) the ID of the IAM trusted profile associated with the compute resource token (required if iamProfileName is not specified)
540
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
541
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
542
+ * should be disabled or not
543
+ * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
544
+ * Authorization header to be included in each request to the token service
545
+ * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
546
+ * Authorization header to be included in each request to the token service
547
+ *
548
+ * @throws Error: the configuration options were invalid
549
+ */
550
+ constructor(options: Options_7);
551
+ /**
552
+ * Sets the "crTokenFilename" field
553
+ * @param crTokenFilename - the name of the file containing the CR token
554
+ */
555
+ setCrTokenFilename(crTokenFilename: string): void;
556
+ /**
557
+ * Sets the name of the IAM trusted profile to use when obtaining an access token from the IAM token server.
558
+ * @param iamProfileName - the name of the IAM trusted profile
559
+ */
560
+ setIamProfileName(iamProfileName: string): void;
561
+ /**
562
+ * Sets the ID of the IAM trusted profile to use when obtaining an access token from the IAM token server.
563
+ * @param iamProfileId - the ID of the IAM trusted profile
564
+ */
565
+ setIamProfileId(iamProfileId: string): void;
566
+ /**
567
+ * Request an IAM token using a compute resource token.
568
+ */
569
+ protected requestToken(): Promise<any>;
570
+ }
571
+
572
+ export declare const contentType: {
573
+ fromFilename: (file: String | File | FileObject | NodeJS.ReadableStream | Buffer) => string;
574
+ fromHeader: (buffer: Buffer) => string;
575
+ };
576
+
577
+ /**
578
+ * Token Manager of CloudPak for data.
579
+ *
580
+ * The Token Manager performs basic auth with a username and password
581
+ * to acquire CP4D tokens.
582
+ */
583
+ export declare class Cp4dTokenManager extends JwtTokenManager {
584
+ protected requiredOptions: string[];
585
+ private username;
586
+ private password;
587
+ private apikey;
588
+ /**
589
+ * Create a new Cp4dTokenManager instance.
590
+ *
591
+ * @param options - Configuration options
592
+ * This should be an object containing these fields:
593
+ * - url: (required) the endpoint URL for the CloudPakForData token service
594
+ * - username: (required) the username used to obtain a bearer token
595
+ * - password: (optional) the password used to obtain a bearer token (required if apikey is not specified)
596
+ * - apikey: (optional) the API key used to obtain a bearer token (required if password is not specified)
597
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
598
+ * should be disabled or not
599
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
600
+ *
601
+ * @throws Error: the configuration options were invalid.
602
+ */
603
+ constructor(options: Options_3);
604
+ protected requestToken(): Promise<any>;
605
+ }
606
+
607
+ /**
608
+ * This method simply ensures that the SDK methods return Promises by checking for
609
+ * the `then` function - common way to assess whether or not an object is a Promise.
610
+ *
611
+ * @param sdkPromise - the Promise returned by an SDK method
612
+ */
613
+ declare function expectToBePromise(sdkPromise: any): void;
614
+
615
+ export declare function fileExistsAtPath(filepath: string): boolean;
616
+
617
+ /**
618
+ * (C) Copyright IBM Corp. 2014, 2022.
619
+ *
620
+ * Licensed under the Apache License, Version 2.0 (the "License");
621
+ * you may not use this file except in compliance with the License.
622
+ * You may obtain a copy of the License at
623
+ *
624
+ * http://www.apache.org/licenses/LICENSE-2.0
625
+ *
626
+ * Unless required by applicable law or agreed to in writing, software
627
+ * distributed under the License is distributed on an "AS IS" BASIS,
628
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
629
+ * See the License for the specific language governing permissions and
630
+ * limitations under the License.
631
+ */
632
+ /// <reference types="node" />
633
+ export declare interface FileObject {
634
+ value: NodeJS.ReadableStream | Buffer | string;
635
+ options?: FileOptions;
636
+ }
637
+
638
+ export declare interface FileOptions {
639
+ filename?: string;
640
+ contentType?: string;
641
+ }
642
+
643
+ export declare interface FileStream extends NodeJS.ReadableStream {
644
+ path: string | Buffer;
645
+ }
646
+
647
+ export declare interface FileWithMetadata {
648
+ data: NodeJS.ReadableStream | Buffer;
649
+ filename: string;
650
+ contentType: string;
651
+ }
652
+
653
+ /**
654
+ * Look for external configuration of authenticator.
655
+ *
656
+ * Try to get authenticator from external sources, with the following priority:
657
+ * 1. Credentials file (ibm-credentials.env)
658
+ * 2. Environment variables
659
+ * 3. VCAP Services (Cloud Foundry)
660
+ *
661
+ * @param serviceName - the service name prefix.
662
+ *
663
+ */
664
+ export declare function getAuthenticatorFromEnvironment(serviceName: string): Authenticator;
665
+
666
+ /**
667
+ * This function retrieves the content type of the input.
668
+ * @param inputData - The data to retrieve content type for.
669
+ * @returns the content type of the input.
670
+ */
671
+ export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): Promise<string>;
672
+
673
+ /**
674
+ * Gets the current time.
675
+ *
676
+ * @returns the current time in seconds.
677
+ */
678
+ export declare function getCurrentTime(): number;
679
+
680
+ /**
681
+ * Returns the first match from formats that is key the params map
682
+ * otherwise null
683
+ * @param params - The parameters.
684
+ * @param requires - The keys we want to check
685
+ */
686
+ export declare function getFormat(params: {
687
+ [key: string]: any;
688
+ }, formats: string[]): string;
689
+
690
+ /**
691
+ * Validates that all required params are provided
692
+ * @param params - the method parameters.
693
+ * @param requires - the required parameter names.
694
+ * @returns null if no errors found, otherwise an Error instance
695
+ */
696
+ export declare function getMissingParams(params: {
697
+ [key: string]: any;
698
+ }, requires: string[]): null | Error;
699
+
700
+ /**
701
+ * Return a new logger, formatted with a particular name. The logging functions, in
702
+ * order of increasing verbosity, are: `error`, `warn`, `info`, `verbose`, and `debug`.
703
+ *
704
+ * The logger will be an instance of the `debug` package and utilizes its support for
705
+ * configuration with environment variables.
706
+ *
707
+ * Additionally, the logger will be turned on automatically if the "NODE_DEBUG"
708
+ * environment variable is set to "axios".
709
+ *
710
+ * @param moduleName - the namespace for the logger. The name will appear in
711
+ * the logs and it will be the name used for configuring the log level.
712
+ *
713
+ * @returns the new logger
714
+ */
715
+ export declare function getNewLogger(moduleName: string): SDKLogger;
716
+
717
+ /**
718
+ * This method extracts the `options` property from the object passed into `createRequest`. This property is
719
+ * an object containing all of the SDK method-specific information (like `path` and `body`) used to build a request.
720
+ * This method is just a convenience method for the unit tests to be able to make assertions on the items in the request.
721
+ *
722
+ * @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
723
+ * @returns Object
724
+ */
725
+ declare function getOptions(createRequestMock: any): any;
726
+
727
+ /**
728
+ * Return a query parameter value from a URL
729
+ *
730
+ * @param urlStr - the url string.
731
+ * @param param - the name of the query parameter whose value should be returned
732
+ * @returns the value of the "param" query parameter
733
+ */
734
+ export declare function getQueryParam(urlStr: string, param: string): string;
735
+
736
+ /**
737
+ * The IamAuthenticator will use the user-supplied `apikey`
738
+ * value to obtain a bearer token from a token server. When the bearer token
739
+ * expires, a new token is obtained from the token server. If specified, the
740
+ * optional, mutually inclusive "clientId" and "clientSecret" pair can be used to
741
+ * influence rate-limiting for requests to the IAM token server.
742
+ *
743
+ * The bearer token will be sent as an Authorization header in the form:
744
+ *
745
+ * Authorization: Bearer \<bearer-token\>
746
+ */
747
+ export declare class IamAuthenticator extends IamRequestBasedAuthenticator {
748
+ protected requiredOptions: string[];
749
+ protected tokenManager: IamTokenManager;
750
+ private apikey;
751
+ /**
752
+ *
753
+ * Create a new IamAuthenticator instance.
754
+ *
755
+ * @param options - Configuration options for IAM authentication.
756
+ * This should be an object containing these fields:
757
+ * - url: (optional) the endpoint URL for the token service
758
+ * - apikey: (required) the IAM api key
759
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
760
+ * should be disabled or not
761
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
762
+ * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
763
+ * Authorization header to be included in each request to the token service
764
+ * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
765
+ * Authorization header to be included in each request to the token service
766
+ * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service
767
+ *
768
+ * @throws Error: the configuration options are not valid.
769
+ */
770
+ constructor(options: Options_6);
771
+ /**
772
+ * Returns the authenticator's type ('iam').
773
+ *
774
+ * @returns a string that indicates the authenticator's type
775
+ */
776
+ authenticationType(): string;
777
+ }
320
778
 
779
+ /**
780
+ * The IamRequestBasedAuthenticator provides shared configuration and functionality
781
+ * for authenticators that interact with the IAM token service. This authenticator
782
+ * is not meant for use on its own.
783
+ */
784
+ export declare class IamRequestBasedAuthenticator extends TokenRequestBasedAuthenticator {
785
+ protected tokenManager: IamRequestBasedTokenManager;
786
+ protected clientId: string;
787
+ protected clientSecret: string;
788
+ protected scope: string;
789
+ /**
790
+ *
791
+ * Create a new IamRequestBasedAuthenticator instance.
792
+ *
793
+ * @param options - Configuration options for IAM authentication.
794
+ * This should be an object containing these fields:
795
+ * - url: (optional) the endpoint URL for the token service
796
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
797
+ * should be disabled or not
798
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
799
+ * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
800
+ * Authorization header to be included in each request to the token service
801
+ * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
802
+ * Authorization header to be included in each request to the token service
803
+ * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service
804
+ *
805
+ * @throws Error: the configuration options are not valid.
806
+ */
807
+ constructor(options: IamRequestOptions_2);
808
+ /**
809
+ * Setter for the mutually inclusive "clientId" and the "clientSecret" fields.
810
+ * @param clientId - the "clientId" value used to form a Basic Authorization header for IAM token requests
811
+ * @param clientSecret - the "clientSecret" value used to form a Basic Authorization header for IAM token requests
812
+ */
813
+ setClientIdAndSecret(clientId: string, clientSecret: string): void;
814
+ /**
815
+ * Setter for the "scope" parameter to use when fetching the bearer token from the IAM token server.
816
+ * @param scope - (optional) a space-separated string that specifies one or more scopes to be
817
+ * associated with IAM token requests
818
+ */
819
+ setScope(scope: string): void;
820
+ /**
821
+ * Return the most recently stored refresh token.
822
+ *
823
+ * @returns the refresh token string
824
+ */
825
+ getRefreshToken(): string;
826
+ }
827
+
828
+ /**
829
+ * The IamRequestBasedTokenManager class contains code relevant to any token manager that
830
+ * interacts with the IAM service to manage a token. It stores information relevant to all
831
+ * IAM requests, such as the client ID and secret, and performs the token request with a set
832
+ * of request options common to any IAM token management scheme. It is intended that this
833
+ * class be extended with specific implementations.
834
+ */
835
+ export declare class IamRequestBasedTokenManager extends JwtTokenManager {
836
+ private clientId;
837
+ private clientSecret;
838
+ private scope;
839
+ protected refreshToken: string;
840
+ protected formData: any;
841
+ /**
842
+ *
843
+ * Create a new IamRequestBasedTokenManager instance.
844
+ *
845
+ * @param options - Configuration options.
846
+ * This should be an object containing these fields:
847
+ * - url: (optional) the endpoint URL for the token service (default value: "https://iam.cloud.ibm.com")
848
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
849
+ * should be disabled or not
850
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
851
+ * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
852
+ * Authorization header to be included in each request to the token service
853
+ * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
854
+ * Authorization header to be included in each request to the token service
855
+ * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service
856
+ *
857
+ * @throws Error: the configuration options are not valid.
858
+ */
859
+ constructor(options: IamRequestOptions);
860
+ /**
861
+ * Sets the IAM "scope" value.
862
+ * This value is sent as the "scope" form parameter within the request sent to the IAM token service.
863
+ *
864
+ * @param scope - a space-separated string that contains one or more scope names
865
+ */
866
+ setScope(scope: string): void;
867
+ /**
868
+ * Sets the IAM "clientId" and "clientSecret" values.
869
+ * These values are used to compute the Authorization header used
870
+ * when retrieving the IAM access token.
871
+ * If these values are not set, no Authorization header will be
872
+ * set on the request (it is not required).
873
+ *
874
+ * @param clientId - the client id.
875
+ * @param clientSecret - the client secret.
876
+ */
877
+ setClientIdAndSecret(clientId: string, clientSecret: string): void;
878
+ /**
879
+ * Returns the most recently stored refresh token.
880
+ *
881
+ * @returns the refresh token
882
+ */
883
+ getRefreshToken(): string;
884
+ /**
885
+ * Extend this method from the parent class to extract the refresh token from
886
+ * the request and save it.
887
+ *
888
+ * @param tokenResponse - the response object from JWT service request
889
+ */
890
+ protected saveTokenInfo(tokenResponse: any): void;
891
+ /**
892
+ * Request an IAM access token using an API key.
893
+ *
894
+ * @returns Promise
895
+ */
896
+ protected requestToken(): Promise<any>;
897
+ }
898
+
899
+ /** Configuration options for IAM token retrieval. */
900
+ export declare interface IamRequestOptions extends JwtTokenManagerOptions {
901
+ clientId?: string;
902
+ clientSecret?: string;
903
+ scope?: string;
904
+ }
905
+
906
+ /** Configuration options for IAM Request based authentication. */
907
+ declare interface IamRequestOptions_2 extends BaseOptions {
908
+ /**
909
+ * The `clientId` and `clientSecret` fields are used to form a "basic"
910
+ * authorization header for IAM token requests.
911
+ */
912
+ clientId?: string;
913
+ /**
914
+ * The `clientId` and `clientSecret` fields are used to form a "basic"
915
+ * authorization header for IAM token requests.
916
+ */
917
+ clientSecret?: string;
918
+ /**
919
+ * The "scope" parameter to use when fetching the bearer token from the IAM token server.
920
+ */
921
+ scope?: string;
922
+ }
923
+
924
+ /**
925
+ * The IAMTokenManager takes an api key and performs the necessary interactions with
926
+ * the IAM token service to obtain and store a suitable bearer token. Additionally, the IAMTokenManager
927
+ * will retrieve bearer tokens via basic auth using a supplied "clientId" and "clientSecret" pair.
928
+ */
929
+ export declare class IamTokenManager extends IamRequestBasedTokenManager {
930
+ protected requiredOptions: string[];
931
+ private apikey;
932
+ /**
933
+ *
934
+ * Create a new IamTokenManager instance.
935
+ *
936
+ * @param options - Configuration options.
937
+ * This should be an object containing these fields:
938
+ * - url: (optional) the endpoint URL for the IAM token service (default value: "https://iam.cloud.ibm.com")
939
+ * - apikey: (required) the IAM api key
940
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
941
+ * should be disabled or not
942
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
943
+ * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
944
+ * Authorization header to be included in each request to the token service
945
+ * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic
946
+ * Authorization header to be included in each request to the token service
947
+ * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service
948
+ *
949
+ * @throws Error: the configuration options are not valid.
950
+ */
951
+ constructor(options: Options_5);
952
+ }
953
+
954
+ export declare function isEmptyObject(obj: any): boolean;
955
+
956
+ export declare function isFileData(obj: any): obj is NodeJS.ReadableStream | Buffer;
957
+
958
+ export declare function isFileWithMetadata(obj: any): obj is FileWithMetadata;
959
+
960
+ /**
961
+ * Return true if 'text' is html
962
+ * @param text - The 'text' to analyze
963
+ * @returns true if 'text' has html tags
964
+ */
965
+ export declare function isHTML(text: string): boolean;
966
+
967
+ /**
968
+ * A class for shared functionality for parsing, storing, and requesting
969
+ * JWT tokens. Intended to be used as a parent to be extended for token
970
+ * request management. Child classes should implement `requestToken()`
971
+ * to retrieve the bearer token from intended sources.
972
+ */
973
+ export declare class JwtTokenManager extends TokenManager {
974
+ protected tokenName: string;
975
+ protected tokenInfo: any;
976
+ /**
977
+ * Create a new JwtTokenManager instance.
978
+ *
979
+ * @param options - Configuration options.
980
+ * This should be an object containing these fields:
981
+ * - url: (optional) the endpoint URL for the token service
982
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
983
+ * should be disabled or not
984
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
985
+ */
986
+ constructor(options: JwtTokenManagerOptions);
987
+ /**
988
+ * Request a JWT using an API key.
989
+ *
990
+ * @returns Promise
991
+ */
992
+ protected requestToken(): Promise<any>;
321
993
  /**
322
- * This function builds a `form-data` object for each file parameter.
323
- * @param {FileWithMetadata} fileParam The file parameter.
324
- * @param {NodeJS.ReadableStream|Buffer} fileParam.data The data content of the file.
325
- * @param {string} fileParam.filename The filename of the file.
326
- * @param {string} fileParam.contentType The content type of the file.
327
- * @returns {FileObject}
994
+ * Save the JWT service response and the calculated expiration time to the object's state.
995
+ *
996
+ * @param tokenResponse - the response object from JWT service request
328
997
  */
329
- export declare function buildRequestFileObject(fileParam: FileWithMetadata): Promise<FileObject>;
998
+ protected saveTokenInfo(tokenResponse: any): void;
999
+ }
330
1000
 
1001
+ /** Configuration options for JWT token retrieval. */
1002
+ export declare type JwtTokenManagerOptions = TokenManagerOptions;
1003
+
1004
+ /**
1005
+ * NoAuthAuthenticator is a placeholder authenticator implementation which
1006
+ * performs no authentication of outgoing REST API requests. It might be
1007
+ * useful during development and testing.
1008
+ */
1009
+ export declare class NoAuthAuthenticator extends Authenticator {
1010
+ authenticate(requestOptions: AuthenticateOptions): Promise<void>;
331
1011
  /**
332
- * Checks credentials for common user mistakes of copying {, }, or " characters from the documentation
1012
+ * Returns the authenticator's type ('noauth').
333
1013
  *
334
- * @param {object} obj - The options object holding credentials
335
- * @param {string[]} credsToCheck - An array containing the keys of the credentials to check for problems
336
- * @returns {string | null} - Returns a string with the error message if there were problems, null if not
1014
+ * @returns a string that indicates the authenticator's type
1015
+ */
1016
+ authenticationType(): string;
1017
+ }
1018
+
1019
+ /**
1020
+ * Checks for only one of two elements being defined.
1021
+ * Returns true if a is defined and b is undefined,
1022
+ * or vice versa. Returns false if both are defined
1023
+ * or both are undefined.
1024
+ *
1025
+ * @param a - The first object
1026
+ * @param b - The second object
1027
+ * @returns true if and only if exactly one of a or b is defined
1028
+ */
1029
+ export declare function onlyOne(a: any, b: any): boolean;
1030
+
1031
+ /** Configuration options for basic authentication. */
1032
+ declare type Options = {
1033
+ /** The username to be used in basic authorization. */
1034
+ username: string;
1035
+ /** The password to be used in basic authorization. */
1036
+ password: string;
1037
+ };
1038
+
1039
+ /** Configuration options for VpcInstance authentication. */
1040
+ declare interface Options_10 extends BaseOptions {
1041
+ /** The CRN of the linked trusted IAM profile to be used as the identity of the compute resource */
1042
+ iamProfileCrn?: string;
1043
+ /** The ID of the linked trusted IAM profile to be used when obtaining the IAM access token */
1044
+ iamProfileId?: string;
1045
+ }
1046
+
1047
+ /** Configuration options for bearer authentication. */
1048
+ declare type Options_2 = {
1049
+ /** The bearer token to be added to requests. */
1050
+ bearerToken: string;
1051
+ };
1052
+
1053
+ /** Configuration options for CP4D token retrieval. */
1054
+ declare interface Options_3 extends JwtTokenManagerOptions {
1055
+ /** The endpoint for CP4D token requests. */
1056
+ url: string;
1057
+ /** The username used to obtain a bearer token. */
1058
+ username: string;
1059
+ /** The password used to obtain a bearer token [required if apikey not specified]. */
1060
+ password?: string;
1061
+ /** The API key used to obtain a bearer token [required if password not specified]. */
1062
+ apikey?: string;
1063
+ }
1064
+
1065
+ /** Configuration options for CloudPakForData authentication. */
1066
+ declare interface Options_4 extends BaseOptions {
1067
+ /** The username used to obtain a bearer token. */
1068
+ username: string;
1069
+ /** The password used to obtain a bearer token [required if apikey not specified]. */
1070
+ password?: string;
1071
+ /** The API key used to obtain a bearer token [required if password not specified]. */
1072
+ apikey?: string;
1073
+ /** The URL representing the Cloud Pak for Data token service endpoint. */
1074
+ url: string;
1075
+ }
1076
+
1077
+ /** Configuration options for IAM token retrieval. */
1078
+ declare interface Options_5 extends IamRequestOptions {
1079
+ apikey: string;
1080
+ }
1081
+
1082
+ /** Configuration options for IAM authentication. */
1083
+ declare interface Options_6 extends IamRequestOptions_2 {
1084
+ /** The IAM api key */
1085
+ apikey: string;
1086
+ }
1087
+
1088
+ /** Configuration options for IAM token retrieval. */
1089
+ declare interface Options_7 extends IamRequestOptions {
1090
+ crTokenFilename?: string;
1091
+ iamProfileName?: string;
1092
+ iamProfileId?: string;
1093
+ }
1094
+
1095
+ /** Configuration options for IAM authentication. */
1096
+ declare interface Options_8 extends IamRequestOptions_2 {
1097
+ /** The file containing the compute resource token. */
1098
+ crTokenFilename?: string;
1099
+ /** The IAM profile name associated with the compute resource token. */
1100
+ iamProfileName?: string;
1101
+ /** The IAM profile ID associated with the compute resource token. */
1102
+ iamProfileId?: string;
1103
+ }
1104
+
1105
+ /** Configuration options for VPC token retrieval. */
1106
+ declare interface Options_9 extends JwtTokenManagerOptions {
1107
+ /** The CRN of the linked trusted IAM profile to be used as the identity of the compute resource */
1108
+ iamProfileCrn?: string;
1109
+ /** The ID of the linked trusted IAM profile to be used when obtaining the IAM access token */
1110
+ iamProfileId?: string;
1111
+ }
1112
+
1113
+ /**
1114
+ * (C) Copyright IBM Corp. 2019, 2022.
1115
+ *
1116
+ * Licensed under the Apache License, Version 2.0 (the "License");
1117
+ * you may not use this file except in compliance with the License.
1118
+ * You may obtain a copy of the License at
1119
+ *
1120
+ * http://www.apache.org/licenses/LICENSE-2.0
1121
+ *
1122
+ * Unless required by applicable law or agreed to in writing, software
1123
+ * distributed under the License is distributed on an "AS IS" BASIS,
1124
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1125
+ * See the License for the specific language governing permissions and
1126
+ * limitations under the License.
1127
+ */
1128
+ export declare const qs: {
1129
+ stringify: (queryParams: Object) => string;
1130
+ };
1131
+
1132
+ /**
1133
+ * Copyright 2021 IBM Corp. All Rights Reserved.
1134
+ *
1135
+ * Licensed under the Apache License, Version 2.0 (the "License");
1136
+ * you may not use this file except in compliance with the License.
1137
+ * You may obtain a copy of the License at
1138
+ *
1139
+ * http://www.apache.org/licenses/LICENSE-2.0
1140
+ *
1141
+ * Unless required by applicable law or agreed to in writing, software
1142
+ * distributed under the License is distributed on an "AS IS" BASIS,
1143
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1144
+ * See the License for the specific language governing permissions and
1145
+ * limitations under the License.
1146
+ */
1147
+ /**
1148
+ * Return a config object based on a credentials file. Credentials files can
1149
+ * be specified filepath via the environment variable: `IBM_CREDENTIALS_FILE`.
1150
+ */
1151
+ export declare function readCredentialsFile(): any;
1152
+
1153
+ export declare function readCrTokenFile(filepath: string): string;
1154
+
1155
+ /**
1156
+ * Read properties stored in external sources like Environment Variables,
1157
+ * the credentials file, VCAP services, etc. and return them as an
1158
+ * object. The keys of this object will have the service name prefix removed
1159
+ * and will be converted to lower camel case.
1160
+ *
1161
+ * Only one source will be used at a time.
1162
+ *
1163
+ * @param serviceName - the service name prefix
1164
+ */
1165
+ export declare function readExternalSources(serviceName: string): any;
1166
+
1167
+ /**
1168
+ * Removes a given suffix if it exists.
1169
+ *
1170
+ * @param str - the base string to operate on
1171
+ * @param suffix - the suffix to remove, if present
1172
+ *
1173
+ * @returns the substring of "str" that remains after the suffix is removed
1174
+ */
1175
+ export declare function removeSuffix(str: string, suffix: string): string;
1176
+
1177
+ declare class RequestWrapper {
1178
+ private axiosInstance;
1179
+ private compressRequestData;
1180
+ private retryInterceptorId;
1181
+ private raxConfig;
1182
+ constructor(axiosOptions?: any);
1183
+ setCompressRequestData(setting: boolean): void;
1184
+ /**
1185
+ * Creates the request.
1186
+ * 1. Merge default options with user provided options
1187
+ * 2. Checks for missing parameters
1188
+ * 3. Encode path and query parameters
1189
+ * 4. Call the api
1190
+ * @returns ReadableStream|undefined
1191
+ * @throws Error
1192
+ */
1193
+ sendRequest(parameters: any): Promise<any>;
1194
+ /**
1195
+ * Format error returned by axios
1196
+ * @param axiosError - the object returned by axios via rejection
1197
+ * @returns the Error object
1198
+ */
1199
+ formatError(axiosError: any): Error;
1200
+ getHttpClient(): AxiosInstance;
1201
+ private static getRaxConfig;
1202
+ enableRetries(retryOptions?: RetryOptions): void;
1203
+ disableRetries(): void;
1204
+ private gzipRequestBody;
1205
+ }
1206
+
1207
+ /**
1208
+ * Retry configuration options.
1209
+ */
1210
+ declare interface RetryOptions {
1211
+ /**
1212
+ * Maximum retries to attempt.
1213
+ */
1214
+ maxRetries?: number;
1215
+ /**
1216
+ * Ceiling for the retry delay (in seconds) - delay will not exceed this value.
337
1217
  */
338
- export declare function checkCredentials(obj: any, credsToCheck: string[]): Error | null;
1218
+ maxRetryInterval?: number;
1219
+ }
1220
+
1221
+ export declare interface SDKLogger {
1222
+ error: Debugger;
1223
+ warn: Debugger;
1224
+ info: Debugger;
1225
+ verbose: Debugger;
1226
+ debug: Debugger;
1227
+ }
1228
+
1229
+ /**
1230
+ * Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer
1231
+ * or array of text chunks
1232
+ * Essentially a smaller version of concat-stream wrapped in a promise
1233
+ *
1234
+ * @param stream - optional stream param for when not bound to an existing stream instance.
1235
+ * @returns Promise
1236
+ */
1237
+ export declare function streamToPromise(stream: Stream): Promise<any>;
339
1238
 
1239
+ /**
1240
+ * Strips trailing slashes from "url", if present.
1241
+ * @param url - the url string
1242
+ * @returns the url with any trailing slashes removed
1243
+ */
1244
+ export declare function stripTrailingSlash(url: string): string;
1245
+
1246
+ /**
1247
+ * A class for shared functionality for storing, and requesting tokens.
1248
+ * Intended to be used as a parent to be extended for token request management.
1249
+ * Child classes should implement "requestToken()" to retrieve the token
1250
+ * from intended sources and "saveTokenInfo(tokenResponse)" to parse and save
1251
+ * token information from the response.
1252
+ */
1253
+ export declare class TokenManager {
1254
+ protected url: string;
1255
+ protected disableSslVerification: boolean;
1256
+ protected headers: OutgoingHttpHeaders;
1257
+ protected requestWrapperInstance: RequestWrapper;
1258
+ protected accessToken: string;
1259
+ protected expireTime: number;
1260
+ protected refreshTime: number;
1261
+ private requestTime;
1262
+ private pendingRequests;
340
1263
  /**
341
- * This method simply ensures that the method executed without any issues by extracting
342
- * the argument from the mock object for the `createRequest` method and verifying that it is an object.
1264
+ * Create a new TokenManager instance.
343
1265
  *
344
- * @param {Object} createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
345
- * @returns {void}
1266
+ * @param options - Configuration options.
1267
+ * This should be an object containing these fields:
1268
+ * - url: (optional) the endpoint URL for the token service
1269
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
1270
+ * should be disabled or not
1271
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
1272
+ */
1273
+ constructor(options: TokenManagerOptions);
1274
+ /**
1275
+ * Retrieves a new token using "requestToken()" if there is not a
1276
+ * currently stored token from a previous call, or the previous token
1277
+ * has expired.
346
1278
  */
347
- declare function checkForSuccessfulExecution(createRequestMock: any): void;
1279
+ getToken(): Promise<any>;
1280
+ /**
1281
+ * Sets the "disableSslVerification" property.
1282
+ *
1283
+ * @param value - the new value for the disableSslVerification property
1284
+ */
1285
+ setDisableSslVerification(value: boolean): void;
1286
+ /**
1287
+ * Sets the headers to be included with each outbound request to the token server.
1288
+ *
1289
+ * @param headers - the set of headers to send with each request to the token server
1290
+ */
1291
+ setHeaders(headers: OutgoingHttpHeaders): void;
1292
+ /**
1293
+ * Paces requests to requestToken().
1294
+ *
1295
+ * This method pseudo-serializes requests for an access_token
1296
+ * when the current token is undefined or expired.
1297
+ * The first caller to this method records its `requestTime` and
1298
+ * then issues the token request. Subsequent callers will check the
1299
+ * `requestTime` to see if a request is active (has been issued within
1300
+ * the past 60 seconds), and if so will queue their promise for the
1301
+ * active requestor to resolve when that request completes.
1302
+ */
1303
+ protected pacedRequestToken(): Promise<any>;
1304
+ /**
1305
+ * Request a token using an API endpoint.
1306
+ *
1307
+ * @returns Promise
1308
+ */
1309
+ protected requestToken(): Promise<any>;
1310
+ /**
1311
+ * Parse and save token information from the response.
1312
+ * Save the requested token into field `accessToken`.
1313
+ * Calculate expiration and refresh time from the received info
1314
+ * and store them in fields `expireTime` and `refreshTime`.
1315
+ *
1316
+ * @param tokenResponse - the response object from a token service request
1317
+ */
1318
+ protected saveTokenInfo(tokenResponse: any): void;
1319
+ /**
1320
+ * Checks if currently-stored token is expired
1321
+ */
1322
+ private isTokenExpired;
1323
+ /**
1324
+ * Checks if currently-stored token should be refreshed
1325
+ * i.e. past the window to request a new token
1326
+ */
1327
+ private tokenNeedsRefresh;
1328
+ }
348
1329
 
1330
+ /** Configuration options for token retrieval. */
1331
+ export declare type TokenManagerOptions = {
1332
+ /** The endpoint for token requests. */
1333
+ url?: string;
1334
+ /** Headers to be sent with every service token request. */
1335
+ headers?: OutgoingHttpHeaders;
1336
+ /**
1337
+ * A flag that indicates whether verification of
1338
+ * the server's SSL certificate should be disabled or not.
1339
+ */
1340
+ disableSslVerification?: boolean;
1341
+ /** Allow additional request config parameters */
1342
+ [propName: string]: any;
1343
+ };
1344
+
1345
+ /**
1346
+ * Class for common functionality shared by token-request authenticators.
1347
+ * TokenRequestBasedAuthenticators use token managers to retrieve, store,
1348
+ * and refresh tokens. Not intended to be used as stand-alone authenticator,
1349
+ * but as base class to authenticators that have their own token manager
1350
+ * implementations.
1351
+ *
1352
+ * The token will be added as an Authorization header in the form:
1353
+ *
1354
+ * Authorization: Bearer \<bearer-token\>
1355
+ */
1356
+ export declare class TokenRequestBasedAuthenticator extends Authenticator {
1357
+ protected tokenManager: JwtTokenManager;
1358
+ protected url: string;
1359
+ protected headers: OutgoingHttpHeaders;
1360
+ protected disableSslVerification: boolean;
1361
+ /**
1362
+ * Create a new TokenRequestBasedAuthenticator instance with an internal JwtTokenManager.
1363
+ *
1364
+ * @param options - Configuration options.
1365
+ * This should be an object containing these fields:
1366
+ * - url: (optional) the endpoint URL for the token service
1367
+ * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
1368
+ * should be disabled or not
1369
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service
1370
+ */
1371
+ constructor(options: BaseOptions);
1372
+ /**
1373
+ * Set the flag that indicates whether verification of the server's SSL
1374
+ * certificate should be disabled or not.
1375
+ *
1376
+ * @param value - a flag that indicates whether verification of the
1377
+ * token server's SSL certificate should be disabled or not.
1378
+ */
1379
+ setDisableSslVerification(value: boolean): void;
349
1380
  /**
350
- * Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
351
- * and checks for the expected values for `Accept` and `Content-Type`. This to verify that the SDK sets
352
- * the correct values in the code.
1381
+ * Set headers.
353
1382
  *
354
- * @param {Object} createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
355
- * @param {String} accept - the expected value for the `Accept` header
356
- * @param {String} contentType - the expected value for the `Content-Type` header
357
- * @returns {void}
1383
+ * @param headers - a set of HTTP headers to be sent with each outbound token server request.
1384
+ * Overwrites previous default headers.
358
1385
  */
359
- declare function checkMediaHeaders(createRequestMock: any, accept: string, contentType: string): void;
1386
+ setHeaders(headers: OutgoingHttpHeaders): void;
1387
+ /**
1388
+ * Adds bearer token information to "requestOptions". The bearer token information
1389
+ * will be set in the Authorization property of "requestOptions.headers" in the form:
1390
+ *
1391
+ * Authorization: Bearer \<bearer-token\>
1392
+ *
1393
+ * @param requestOptions - The request to augment with authentication information.
1394
+ */
1395
+ authenticate(requestOptions: AuthenticateOptions): Promise<void>;
1396
+ }
1397
+
1398
+ /**
1399
+ * This function converts an object's keys to lower case.
1400
+ * note: does not convert nested keys
1401
+ * @param obj - The object to convert the keys of.
1402
+ * @returns the object with keys folded to lowercase
1403
+ */
1404
+ export declare function toLowerKeys(obj: Object): Object;
1405
+
1406
+ declare namespace unitTestUtils {
1407
+ export {
1408
+ checkUrlAndMethod,
1409
+ checkMediaHeaders,
1410
+ checkUserHeader,
1411
+ checkForSuccessfulExecution,
1412
+ getOptions,
1413
+ expectToBePromise
1414
+ }
1415
+ }
1416
+ export { unitTestUtils }
1417
+
1418
+ /**
1419
+ * Configuration values for a service.
1420
+ */
1421
+ export declare interface UserOptions {
1422
+ /** The Authenticator object used to authenticate requests to the service */
1423
+ authenticator?: AuthenticatorInterface;
1424
+ /** The base url to use when contacting the service. The base url may differ between IBM Cloud regions. */
1425
+ serviceUrl?: string;
1426
+ /** Default headers that shall be included with every request to the service. */
1427
+ headers?: OutgoingHttpHeaders;
1428
+ /** The API version date to use with the service, in "YYYY-MM-DD" format. */
1429
+ version?: string;
1430
+ /** Set to `true` to allow unauthorized requests - not recommended for production use. */
1431
+ disableSslVerification?: boolean;
1432
+ /** Set your own cookie jar object */
1433
+ jar?: CookieJar | boolean;
1434
+ /** Deprecated. Use `serviceUrl` instead. */
1435
+ url?: string;
1436
+ /** Allow additional request config parameters */
1437
+ [propName: string]: any;
1438
+ }
1439
+
1440
+ /**
1441
+ * Validates "options".
1442
+ * @param options - a configuration options object
1443
+ * @param requiredOptions - the list of properties that must be present in "options"
1444
+ *
1445
+ * @throws Error: "options" failed validation
1446
+ */
1447
+ export declare function validateInput(options: any, requiredOptions: string[]): void;
360
1448
 
1449
+ /**
1450
+ * Validates that "params" contains a value for each key listed in "requiredParams",
1451
+ * and that each key contained in "params" is a valid key listed in "allParams".
1452
+ * In essence, we want params to contain only valid keys and we want params
1453
+ * to contain at least the required keys.
1454
+ *
1455
+ * @param params - the "params" object passed into an operation containing method parameters.
1456
+ * @param requiredParams - the names of required parameters.
1457
+ * If null, then the "required params" check is bypassed.
1458
+ * @param allParams - the names of all valid parameters.
1459
+ * If null, then the "valid params" check is bypassed.
1460
+ * @returns null if no errors found, otherwise an Error instance
1461
+ */
1462
+ export declare function validateParams(params: {
1463
+ [key: string]: any;
1464
+ }, requiredParams: string[], allParams: string[]): null | Error;
1465
+
1466
+ /**
1467
+ * The VpcInstanceAuthenticator implements an authentication scheme in which it retrieves an "instance identity token"
1468
+ * and exchanges that for an IAM access token using the VPC Instance Metadata Service API which is available on the local
1469
+ * compute resource (VM). The instance identity token is similar to an IAM apikey, except that it is managed automatically
1470
+ * by the compute resource provider (VPC).
1471
+ *
1472
+ * The resulting IAM access token is then added to outbound requests in an Authorization header
1473
+ *
1474
+ * Authorization: Bearer \<access-token\>
1475
+ */
1476
+ export declare class VpcInstanceAuthenticator extends TokenRequestBasedAuthenticator {
1477
+ protected tokenManager: VpcInstanceTokenManager;
1478
+ private iamProfileCrn;
1479
+ private iamProfileId;
361
1480
  /**
362
- * (C) Copyright IBM Corp. 2019, 2021.
1481
+ * Create a new VpcInstanceAuthenticator instance.
363
1482
  *
364
- * Licensed under the Apache License, Version 2.0 (the "License");
365
- * you may not use this file except in compliance with the License.
366
- * You may obtain a copy of the License at
1483
+ * @param options - Configuration options for VpcInstance authentication.
1484
+ * This should be an object containing these fields:
1485
+ * - url: (optional) the endpoint URL for the VPC Instance Metadata Service (default value: "http://169.254.169.254")
1486
+ * - iamProfileCrn: (optional) the CRN of the linked IAM trusted profile to be used to obtain the IAM access token
1487
+ * - iamProfileId: (optional) the ID of the linked IAM trusted profile to be used to obtain the IAM access token
367
1488
  *
368
- * http://www.apache.org/licenses/LICENSE-2.0
1489
+ * @remarks
1490
+ * At most one of "iamProfileCrn" or "iamProfileId" may be specified. If neither one is specified,
1491
+ * then the default IAM profile defined for the compute resource will be used.
1492
+ */
1493
+ constructor(options: Options_10);
1494
+ /**
1495
+ * Sets the "iamProfileCrn" value to be used when obtaining an IAM access token
1496
+ * @param iamProfileCrn - the CRN of the linked IAM trusted profile to use when obtaining an IAM access token
1497
+ */
1498
+ setIamProfileCrn(iamProfileCrn: string): void;
1499
+ /**
1500
+ * Sets the "iamProfileId" value to be used when obtaining an IAM access token
1501
+ * @param iamProfileId - the ID of the linked IAM trusted profile to use when obtaining an IAM access token
1502
+ */
1503
+ setIamProfileId(iamProfileId: string): void;
1504
+ /**
1505
+ * Returns the authenticator's type ('vpc').
369
1506
  *
370
- * Unless required by applicable law or agreed to in writing, software
371
- * distributed under the License is distributed on an "AS IS" BASIS,
372
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
373
- * See the License for the specific language governing permissions and
374
- * limitations under the License.
375
- */
376
- /**
377
- * This module provides a set of helper methods used to reduce code duplication in the generated unit tests
378
- * for the SDKs that depend on this core package. Note that these methods are not used by the tests for this
379
- * package - they are meant to be exported and made available to dependent libraries.
380
- */
381
- /**
382
- * Takes the request options constructed by the SDK and checks that the `url` and `method` properties
383
- * were set to their correct values.
384
- *
385
- * @param {Object} options - the options object put together by the SDK, retrieved from the createRequest mock
386
- * @param {String} url - The URL path of the service endpoint, from the paths section of the API definition
387
- * @param {String} string - The HTTP method for the request, from the API definition
388
- * @returns {void}
389
- */
390
- declare function checkUrlAndMethod(options: any, url: string, method: any): void;
391
-
392
- /**
393
- * Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
394
- * and checks for the expected value for a user-defined header. This is verify that the SDK accepts header
395
- * parameters and sends them as headers in the request.
396
- *
397
- * @param {Object} createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
398
- * @param {String} userHeaderName - the name of the header passed by the user, e.g. `Contained-Content-Type`
399
- * @param {String} userHeaderValue - the expected value for the header passed by the user
400
- * @returns {void}
401
- */
402
- declare function checkUserHeader(createRequestMock: any, userHeaderName: string, userHeaderValue: string): void;
403
-
404
- /**
405
- * The [[CloudPakForDataAuthenticator]] will either use a username/password pair or a username/apikey pair to obtain
406
- * a bearer token from a token server. When the bearer token expires, a new token is obtained from the token server.
407
- *
408
- * The bearer token will be sent as an Authorization header in the form:
409
- *
410
- * Authorization: Bearer <bearer-token>
411
- */
412
- export declare class CloudPakForDataAuthenticator extends TokenRequestBasedAuthenticator {
413
- protected requiredOptions: string[];
414
- protected tokenManager: Cp4dTokenManager;
415
- private username;
416
- private password;
417
- private apikey;
418
- /**
419
- * Create a new [[CloudPakForDataAuthenticator]] instance.
420
- *
421
- * @param {object} options Configuration options for CloudPakForData authentication.
422
- * @param {string} options.url For HTTP token requests.
423
- * @param {string} options.username The username used to obtain a bearer token.
424
- * @param {string} [options.password] The password used to obtain a bearer token [required if apikey not specified].
425
- * @param {string} [options.apikey] The API key used to obtain a bearer token [required if password not specified].
426
- * @param {boolean} [options.disableSslVerification] A flag that indicates
427
- * whether verification of the token server's SSL certificate should be
428
- * disabled or not
429
- * @param {object<string, string>} [options.headers] to be sent with every.
430
- * @throws `Error` The username, password, and/or url are not valid, or unspecified, for Cloud Pak For Data token
431
- * requests.
432
- */
433
- constructor(options: Options_4);
434
- /**
435
- * Returns the authenticator's type ('cp4d').
436
- *
437
- * @returns a string that indicates the authenticator's type
438
- */
439
- authenticationType(): string;
440
- }
441
-
442
- /**
443
- * (C) Copyright IBM Corp. 2019, 2021.
444
- *
445
- * Licensed under the Apache License, Version 2.0 (the "License");
446
- * you may not use this file except in compliance with the License.
447
- * You may obtain a copy of the License at
448
- *
449
- * http://www.apache.org/licenses/LICENSE-2.0
450
- *
451
- * Unless required by applicable law or agreed to in writing, software
452
- * distributed under the License is distributed on an "AS IS" BASIS,
453
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
454
- * See the License for the specific language governing permissions and
455
- * limitations under the License.
456
- */
457
- /**
458
- * Compute and return a Basic Authorization header from a username and password.
459
- *
460
- * @param {string} username - The username or client id
461
- * @param {string} password - The password or client secret
462
- * @returns {string} - A Basic Auth header with format "Basic <encoded-credentials>"
463
- */
464
- export declare function computeBasicAuthHeader(username: string, password: string): string;
465
-
466
- export declare function constructFilepath(filepath: string): string;
467
-
468
- /**
469
- * Constructs a service URL by formatting a parameterized URL.
470
- *
471
- * @param {string} parameterizedUrl URL that contains variable placeholders, e.g. '{scheme}://ibm.com'.
472
- * @param {Map<string, string>} defaultUrlVariables Map from variable names to default values.
473
- * Each variable in the parameterized URL must have a default value specified in this map.
474
- * @param {Map<string, string>} providedUrlVariables Map from variable names to desired values.
475
- * If a variable is not provided in this map,
476
- * the default variable value will be used instead.
477
- * @returns {string} The formatted URL with all variable placeholders replaced by values.
478
- */
479
- export declare function constructServiceUrl(parameterizedUrl: string, defaultUrlVariables: Map<string, string>, providedUrlVariables: Map<string, string> | null): string;
480
-
481
- /**
482
- * The [[ContainerAuthenticator]] will read a compute resource token from the file system
483
- * and use this value to obtain a bearer token from the IAM token server. When the bearer
484
- * token expires, a new token is obtained from the token server.
485
- *
486
- * The bearer token will be sent as an Authorization header in the form:
487
- *
488
- * Authorization: Bearer <bearer-token>
489
- */
490
- export declare class ContainerAuthenticator extends IamRequestBasedAuthenticator {
491
- protected tokenManager: ContainerTokenManager;
492
- private crTokenFilename;
493
- private iamProfileName;
494
- private iamProfileId;
495
- /**
496
- *
497
- * Create a new [[ContainerAuthenticator]] instance.
498
- *
499
- * @param {object} options Configuration options for IAM authentication.
500
- * @param {string} [options.crTokenFilename] The file containing the compute resource token.
501
- * @param {string} [options.iamProfileName] The IAM profile name associated with the compute resource token.
502
- * @param {string} [options.iamProfileId] The IAM profile ID associated with the compute resource token.
503
- * @param {boolean} [options.disableSslVerification] A flag that indicates
504
- * whether verification of the token server's SSL certificate should be
505
- * disabled or not
506
- * @param {string} [options.url] for HTTP token requests.
507
- * @param {object<string, string>} options.headers to be sent with every
508
- * @param {string} [options.clientId] The `clientId` and `clientSecret` fields are used to form a "basic"
509
- * authorization header for IAM token requests.
510
- * @param {string} [options.clientSecret] The `clientId` and `clientSecret` fields are used to form a "basic"
511
- * authorization header for IAM token requests.
512
- * @param {string} [options.scope] The "scope" parameter to use when fetching the bearer token from the
513
- * IAM token server.
514
- * @throws {Error} When the configuration options are not valid.
515
- */
516
- constructor(options: Options_8);
517
- /**
518
- * Setter for the filename of the compute resource token.
519
- * @param {string} A string containing a path to the CR token file
520
- */
521
- setCrTokenFilename(crTokenFilename: string): void;
522
- /**
523
- * Setter for the "profile_name" parameter to use when fetching the bearer token from the IAM token server.
524
- * @param {string} A string that makes up the iamProfileName parameter
525
- */
526
- setIamProfileName(iamProfileName: string): void;
527
- /**
528
- * Setter for the "profile_id" parameter to use when fetching the bearer token from the IAM token server.
529
- * @param {string} A string that makes up the iamProfileId parameter
530
- */
531
- setIamProfileId(iamProfileId: string): void;
532
- /**
533
- * Returns the authenticator's type ('container').
534
- *
535
- * @returns a string that indicates the authenticator's type
536
- */
537
- authenticationType(): string;
538
- }
539
-
540
- /**
541
- * The ContainerTokenManager retrieves a compute resource token from a file on the container. This token
542
- * is used to perform the necessary interactions with the IAM token service to obtain and store a suitable
543
- * bearer (access) token.
544
- */
545
- export declare class ContainerTokenManager extends IamRequestBasedTokenManager {
546
- private crTokenFilename;
547
- private iamProfileName;
548
- private iamProfileId;
549
- /**
550
- *
551
- * Create a new [[ContainerTokenManager]] instance.
552
- *
553
- * @param {object} options Configuration options.
554
- * @param {string} [crTokenFilename='/var/run/secrets/tokens/vault-token'] The file containing the compute resource token.
555
- * @param {string} [iamProfileName] The IAM profile name associated with the compute resource token.
556
- * @param {string} [iamProfileId] The IAM profile ID associated with the compute resource token.
557
- * @param {string} [options.clientId] The `clientId` and `clientSecret` fields are used to form a "basic"
558
- * authorization header for IAM token requests.
559
- * @param {string} [options.clientSecret] The `clientId` and `clientSecret` fields are used to form a "basic"
560
- * authorization header for IAM token requests.
561
- * @param {string} [url='https://iam.cloud.ibm.com'] The IAM endpoint for token requests.
562
- * @param {boolean} [options.disableSslVerification] A flag that indicates
563
- * whether verification of the token server's SSL certificate should be
564
- * disabled or not.
565
- * @param {object<string, string>} [options.headers] Headers to be sent with every
566
- * outbound HTTP requests to token services.
567
- * @constructor
568
- */
569
- constructor(options: Options_7);
570
- /**
571
- * Setter for the filename of the compute resource token.
572
- * @param {string} crTokenFilename A string containing a path to the CR token file
573
- */
574
- setCrTokenFilename(crTokenFilename: string): void;
575
- /**
576
- * Setter for the "profile_name" parameter to use when fetching the bearer token from the IAM token server.
577
- * @param {string} iamProfileName A string that makes up the iamProfileName parameter
578
- */
579
- setIamProfileName(iamProfileName: string): void;
580
- /**
581
- * Setter for the "profile_id" parameter to use when fetching the bearer token from the IAM token server.
582
- * @param {string} iamProfileId A string that makes up the iamProfileId parameter
583
- */
584
- setIamProfileId(iamProfileId: string): void;
585
- /**
586
- * Request an IAM token using a compute resource token.
587
- *
588
- * @returns {Promise}
589
- */
590
- protected requestToken(): Promise<any>;
591
- }
592
-
593
- export declare const contentType: {
594
- fromFilename: (file: String | File | FileObject | NodeJS.ReadableStream | Buffer) => string;
595
- fromHeader: (buffer: Buffer) => string;
596
- };
597
-
598
- /**
599
- * Token Manager of CloudPak for data.
600
- *
601
- * The Token Manager performs basic auth with a username and password
602
- * to acquire CP4D tokens.
603
- */
604
- export declare class Cp4dTokenManager extends JwtTokenManager {
605
- protected requiredOptions: string[];
606
- private username;
607
- private password;
608
- private apikey;
609
- /**
610
- * Create a new [[Cp4dTokenManager]] instance.
611
- *
612
- * @param {object} options Configuration options.
613
- * @param {string} options.username The username used to obtain a bearer token.
614
- * @param {string} options.password The password used to obtain a bearer token [required if apikey not specified].
615
- * @param {string} options.apikey The API key used to obtain a bearer token [required if password not specified].
616
- * @param {string} options.url The endpoint for CP4D token requests.
617
- * @param {boolean} [options.disableSslVerification] A flag that indicates
618
- * whether verification of the token server's SSL certificate should be
619
- * disabled or not.
620
- * @param {object<string, string>} [options.headers] Headers to be sent with every
621
- * outbound HTTP requests to token services.
622
- * @constructor
623
- */
624
- constructor(options: Options_3);
625
- protected requestToken(): Promise<any>;
626
- }
627
-
628
- /**
629
- * This method simply ensures that the SDK methods return Promises by checking for
630
- * the `then` function - common way to assess whether or not an object is a Promise.
631
- *
632
- * @param {Promise<any>} sdkPromise - the Promise returned by an SDK method
633
- * @returns {void}
634
- */
635
- declare function expectToBePromise(sdkPromise: any): void;
636
-
637
- export declare function fileExistsAtPath(filepath: string): boolean;
638
-
639
- /**
640
- * (C) Copyright IBM Corp. 2014, 2021.
641
- *
642
- * Licensed under the Apache License, Version 2.0 (the "License");
643
- * you may not use this file except in compliance with the License.
644
- * You may obtain a copy of the License at
645
- *
646
- * http://www.apache.org/licenses/LICENSE-2.0
647
- *
648
- * Unless required by applicable law or agreed to in writing, software
649
- * distributed under the License is distributed on an "AS IS" BASIS,
650
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
651
- * See the License for the specific language governing permissions and
652
- * limitations under the License.
653
- */
654
- /// <reference types="node" />
655
- export declare interface FileObject {
656
- value: NodeJS.ReadableStream | Buffer | string;
657
- options?: FileOptions;
658
- }
659
-
660
- export declare interface FileOptions {
661
- filename?: string;
662
- contentType?: string;
663
- }
664
-
665
- export declare interface FileStream extends NodeJS.ReadableStream {
666
- path: string | Buffer;
667
- }
668
-
669
- export declare interface FileWithMetadata {
670
- data: NodeJS.ReadableStream | Buffer;
671
- filename: string;
672
- contentType: string;
673
- }
674
-
675
- /**
676
- * Look for external configuration of authenticator.
677
- *
678
- * Try to get authenticator from external sources, with the following priority:
679
- * 1. Credentials file (ibm-credentials.env)
680
- * 2. Environment variables
681
- * 3. VCAP Services (Cloud Foundry)
682
- *
683
- * @param {string} serviceName The service name prefix.
684
- *
685
- */
686
- export declare function getAuthenticatorFromEnvironment(serviceName: string): Authenticator;
687
-
688
- /**
689
- * This function retrieves the content type of the input.
690
- * @param {NodeJS.ReadableStream|Buffer} inputData - The data to retrieve content type for.
691
- * @returns {string} the content type of the input.
692
- */
693
- export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): Promise<string>;
694
-
695
- /**
696
- * Get the current time
697
- *
698
- * @returns {number} - Returns the current time in seconds.
699
- */
700
- export declare function getCurrentTime(): number;
701
-
702
- /**
703
- * Returns the first match from formats that is key the params map
704
- * otherwise null
705
- * @param {Object} params - The parameters.
706
- * @param {string[]} requires - The keys we want to check
707
- * @returns {string|null}
708
- */
709
- export declare function getFormat(params: {
710
- [key: string]: any;
711
- }, formats: string[]): string;
712
-
713
- /**
714
- * Validates that all required params are provided
715
- * @param params - the method parameters.
716
- * @param requires - the required parameter names.
717
- * @returns {Error|null}
718
- */
719
- export declare function getMissingParams(params: {
720
- [key: string]: any;
721
- }, requires: string[]): null | Error;
722
-
723
- /**
724
- * Return a new logger, formatted with a particular name. The logging functions, in
725
- * order of increasing verbosity, are: `error`, `warn`, `info`, `verbose`, and `debug`.
726
- *
727
- * The logger will be an instance of the `debug` package and utilizes its support for
728
- * configuration with environment variables.
729
- *
730
- * Additionally, the logger will be turned on automatically if the "NODE_DEBUG"
731
- * environment variable is set to "axios".
732
- *
733
- * @param {string} moduleName - the namespace for the logger. The name will appear in
734
- * the logs and it will be the name used for configuring the log level.
735
- *
736
- * @returns {SDKLogger} the new logger
737
- */
738
- export declare function getNewLogger(moduleName: string): SDKLogger;
739
-
740
- /**
741
- * This method extracts the `options` property from the object passed into `createRequest`. This property is
742
- * an object containing all of the SDK method-specific information (like `path` and `body`) used to build a request.
743
- * This method is just a convenience method for the unit tests to be able to make assertions on the items in the request.
744
- *
745
- * @param {Object} createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
746
- * @returns {Object}
747
- */
748
- declare function getOptions(createRequestMock: any): any;
749
-
750
- /**
751
- * Return a query parameter value from a URL
752
- *
753
- * @param {string} urlStr - the url string.
754
- * @param {string} param - the name of the query parameter
755
- * whose value should be returned
756
- * @returns {string} the value of the `param` query parameter
757
- * @throws if urlStr is an invalid URL
758
- */
759
- export declare function getQueryParam(urlStr: string, param: string): string;
760
-
761
- /**
762
- * The [[IamAuthenticator]] will use the user-supplied `apikey`
763
- * values to obtain a bearer token from a token server. When the bearer token
764
- * expires, a new token is obtained from the token server. If specified, the
765
- * optional, mutually inclusive `clientId` and`clientSecret` pair can be used to
766
- * influence rate-limiting for requests to the IAM token server.
767
- *
768
- * The bearer token will be sent as an Authorization header in the form:
769
- *
770
- * Authorization: Bearer <bearer-token>
771
- */
772
- export declare class IamAuthenticator extends IamRequestBasedAuthenticator {
773
- protected requiredOptions: string[];
774
- protected tokenManager: IamTokenManager;
775
- private apikey;
776
- /**
777
- *
778
- * Create a new [[IamAuthenticator]] instance.
779
- *
780
- * @param {object} options Configuration options for IAM authentication.
781
- * @param {boolean} options.disableSslVerification A flag that indicates
782
- * whether verification of the token server's SSL certificate should be
783
- * disabled or not
784
- * @param {string} options.url for HTTP token requests.
785
- * @param {object<string, string>} options.headers to be sent with every
786
- * @param {string} options.apikey The IAM api key.
787
- * @param {string} [options.clientId] The `clientId` and `clientSecret` fields are used to form a "basic"
788
- * authorization header for IAM token requests.
789
- * @param {string} [options.clientSecret] The `clientId` and `clientSecret` fields are used to form a "basic"
790
- * authorization header for IAM token requests.
791
- * @param {string} [options.scope] The "scope" parameter to use when fetching the bearer token from the
792
- * IAM token server.
793
- * @throws {Error} When the configuration options are not valid.
794
- */
795
- constructor(options: Options_6);
796
- /**
797
- * Returns the authenticator's type ('iam').
798
- *
799
- * @returns a string that indicates the authenticator's type
800
- */
801
- authenticationType(): string;
802
- }
803
-
804
- /**
805
- * The [[IamRequestBasedAuthenticator]] provides shared configuration and functionality
806
- * for authenticators that interact with the IAM service to inherit. This authenticator
807
- * is not meant for use on its own.
808
- */
809
- export declare class IamRequestBasedAuthenticator extends TokenRequestBasedAuthenticator {
810
- protected tokenManager: IamRequestBasedTokenManager;
811
- protected clientId: string;
812
- protected clientSecret: string;
813
- protected scope: string;
814
- /**
815
- *
816
- * Create a new [[IamRequestBasedAuthenticator]] instance.
817
- *
818
- * @param {object} options Configuration options for IAM authentication.
819
- * @param {boolean} options.disableSslVerification A flag that indicates
820
- * whether verification of the token server's SSL certificate should be
821
- * disabled or not
822
- * @param {string} options.url for HTTP token requests.
823
- * @param {object<string, string>} options.headers to be sent with every IAM token request
824
- * @param {string} [options.clientId] The `clientId` and `clientSecret` fields are used to form a "basic"
825
- * authorization header for IAM token requests.
826
- * @param {string} [options.clientSecret] The `clientId` and `clientSecret` fields are used to form a "basic"
827
- * authorization header for IAM token requests.
828
- * @param {string} [options.scope] The "scope" parameter to use when fetching the bearer token from the
829
- * IAM token server.
830
- * @throws {Error} When the configuration options are not valid.
831
- */
832
- constructor(options: IamRequestOptions_2);
833
- /**
834
- * Setter for the mutually inclusive `clientId` and the `clientSecret`.
835
- * @param {string} clientId The `clientId` and `clientSecret` fields are used to form a "basic"
836
- * authorization header for IAM token requests.
837
- * @param {string} clientSecret The `clientId` and `clientSecret` fields are used to form a "basic"
838
- * authorization header for IAM token requests.
839
- */
840
- setClientIdAndSecret(clientId: string, clientSecret: string): void;
841
- /**
842
- * Setter for the "scope" parameter to use when fetching the bearer token from the IAM token server.
843
- * @param {string} scope A space seperated string that makes up the scope parameter
844
- */
845
- setScope(scope: string): void;
846
- /**
847
- * Return the most recently stored refresh token.
848
- *
849
- * @public
850
- * @returns {string}
851
- */
852
- getRefreshToken(): string;
853
- }
854
-
855
- /**
856
- * The IamRequestBasedTokenManager class contains code relevant to any token manager that
857
- * interacts with the IAM service to manage a token. It stores information relevant to all
858
- * IAM requests, such as the client ID and secret, and performs the token request with a set
859
- * of request options common to any IAM token management scheme. It is intended that this
860
- * class be extended with specific implementations.
861
- */
862
- export declare class IamRequestBasedTokenManager extends JwtTokenManager {
863
- private clientId;
864
- private clientSecret;
865
- private scope;
866
- protected refreshToken: string;
867
- protected formData: any;
868
- /**
869
- *
870
- * Create a new [[IamRequestBasedTokenManager]] instance.
871
- *
872
- * @param {object} options Configuration options.
873
- * @param {string} [options.clientId] The `clientId` and `clientSecret` fields are used to form a "basic"
874
- * authorization header for IAM token requests.
875
- * @param {string} [options.clientSecret] The `clientId` and `clientSecret` fields are used to form a "basic"
876
- * authorization header for IAM token requests.
877
- * @param {string} [url='https://iam.cloud.ibm.com'] The IAM endpoint for token requests.
878
- * @param {boolean} [options.disableSslVerification] A flag that indicates
879
- * whether verification of the token server's SSL certificate should be
880
- * disabled or not.
881
- * @param {object<string, string>} [options.headers] Headers to be sent with every
882
- * outbound HTTP requests to token services.
883
- * @constructor
884
- */
885
- constructor(options: IamRequestOptions);
886
- /**
887
- * Set the IAM `scope` value.
888
- * This value is the form parameter to use when fetching the bearer token
889
- * from the IAM token server.
890
- *
891
- * @param {string} scope - A space seperated string that makes up the scope parameter.
892
- * @returns {void}
893
- */
894
- setScope(scope: string): void;
895
- /**
896
- * Set the IAM `clientId` and `clientSecret` values.
897
- * These values are used to compute the Authorization header used
898
- * when retrieving the IAM access token.
899
- * If these values are not set, no Authorization header will be
900
- * set on the request (it is not required).
901
- *
902
- * @param {string} clientId - The client id.
903
- * @param {string} clientSecret - The client secret.
904
- * @returns {void}
905
- */
906
- setClientIdAndSecret(clientId: string, clientSecret: string): void;
907
- /**
908
- * Return the most recently stored refresh token.
909
- *
910
- * @public
911
- * @returns {string}
912
- */
913
- getRefreshToken(): string;
914
- /**
915
- * Extend this method from the parent class to extract the refresh token from
916
- * the request and save it.
917
- *
918
- * @param tokenResponse - Response object from JWT service request
919
- * @protected
920
- * @returns {void}
921
- */
922
- protected saveTokenInfo(tokenResponse: any): void;
923
- /**
924
- * Request an IAM token using an API key.
925
- *
926
- * @returns {Promise}
927
- */
928
- protected requestToken(): Promise<any>;
929
- }
930
-
931
- /** Configuration options for IAM token retrieval. */
932
- export declare interface IamRequestOptions extends JwtTokenManagerOptions {
933
- clientId?: string;
934
- clientSecret?: string;
935
- scope?: string;
936
- }
937
-
938
- /** Configuration options for IAM Request based authentication. */
939
- declare interface IamRequestOptions_2 extends BaseOptions {
940
- /**
941
- * The `clientId` and `clientSecret` fields are used to form a "basic"
942
- * authorization header for IAM token requests.
943
- */
944
- clientId?: string;
945
- /**
946
- * The `clientId` and `clientSecret` fields are used to form a "basic"
947
- * authorization header for IAM token requests.
948
- */
949
- clientSecret?: string;
950
- /**
951
- * The "scope" parameter to use when fetching the bearer token from the IAM token server.
952
- */
953
- scope?: string;
954
- }
955
-
956
- /**
957
- * The IAMTokenManager takes an api key and performs the necessary interactions with
958
- * the IAM token service to obtain and store a suitable bearer token. Additionally, the IAMTokenManager
959
- * will retrieve bearer tokens via basic auth using a supplied `clientId` and `clientSecret` pair.
960
- */
961
- export declare class IamTokenManager extends IamRequestBasedTokenManager {
962
- protected requiredOptions: string[];
963
- private apikey;
964
- /**
965
- *
966
- * Create a new [[IamTokenManager]] instance.
967
- *
968
- * @param {object} options Configuration options.
969
- * @param {string} options.apikey The IAM api key.
970
- * @param {string} [options.clientId] The `clientId` and `clientSecret` fields are used to form a "basic"
971
- * authorization header for IAM token requests.
972
- * @param {string} [options.clientSecret] The `clientId` and `clientSecret` fields are used to form a "basic"
973
- * authorization header for IAM token requests.
974
- * @param {string} [url='https://iam.cloud.ibm.com'] The IAM endpoint for token requests.
975
- * @param {boolean} [options.disableSslVerification] A flag that indicates
976
- * whether verification of the token server's SSL certificate should be
977
- * disabled or not.
978
- * @param {object<string, string>} [options.headers] Headers to be sent with every
979
- * outbound HTTP requests to token services.
980
- * @constructor
981
- */
982
- constructor(options: Options_5);
983
- }
984
-
985
- export declare function isEmptyObject(obj: any): boolean;
986
-
987
- export declare function isFileData(obj: any): obj is NodeJS.ReadableStream | Buffer;
988
-
989
- export declare function isFileWithMetadata(obj: any): obj is FileWithMetadata;
990
-
991
- /**
992
- * Return true if 'text' is html
993
- * @param {string} text - The 'text' to analyze
994
- * @returns {boolean} true if 'text' has html tags
995
- */
996
- export declare function isHTML(text: string): boolean;
997
-
998
- /**
999
- * A class for shared functionality for parsing, storing, and requesting
1000
- * JWT tokens. Intended to be used as a parent to be extended for token
1001
- * request management. Child classes should implement `requestToken()`
1002
- * to retrieve the bearer token from intended sources.
1003
- */
1004
- export declare class JwtTokenManager extends TokenManager {
1005
- protected tokenName: string;
1006
- protected tokenInfo: any;
1007
- /**
1008
- * Create a new [[JwtTokenManager]] instance.
1009
- * @constructor
1010
- * @param {object} options Configuration options.
1011
- * @param {string} options.url for HTTP token requests.
1012
- * @param {boolean} [options.disableSslVerification] A flag that indicates
1013
- * whether verification of the token server's SSL certificate should be
1014
- * disabled or not.
1015
- * @param {object<string, string>} [options.headers] Headers to be sent with every
1016
- * outbound HTTP requests to token services.
1017
- */
1018
- constructor(options: JwtTokenManagerOptions);
1019
- /**
1020
- * Request a JWT using an API key.
1021
- *
1022
- * @returns {Promise}
1023
- */
1024
- protected requestToken(): Promise<any>;
1025
- /**
1026
- * Save the JWT service response and the calculated expiration time to the object's state.
1027
- *
1028
- * @param tokenResponse - Response object from JWT service request
1029
- * @protected
1030
- * @returns {void}
1031
- */
1032
- protected saveTokenInfo(tokenResponse: any): void;
1033
- }
1034
-
1035
- /** Configuration options for JWT token retrieval. */
1036
- export declare type JwtTokenManagerOptions = TokenManagerOptions;
1037
-
1038
- /**
1039
- * NoAuthAuthenticator is a placeholder authenticator implementation which
1040
- * performs no authentication of outgoing REST API requests. It might be
1041
- * useful during development and testing.
1042
- */
1043
- export declare class NoAuthAuthenticator extends Authenticator {
1044
- authenticate(requestOptions: AuthenticateOptions): Promise<void>;
1045
- /**
1046
- * Returns the authenticator's type ('noauth').
1047
- *
1048
- * @returns a string that indicates the authenticator's type
1049
- */
1050
- authenticationType(): string;
1051
- }
1052
-
1053
- /**
1054
- * Check for only one of two elements being defined.
1055
- * Returns true if a is defined and b is undefined,
1056
- * or vice versa. Returns false if both are defined
1057
- * or both are undefined.
1058
- *
1059
- * @param {any} a - The first object
1060
- * @param {any} b - The second object
1061
- * @returns {boolean}
1062
- */
1063
- export declare function onlyOne(a: any, b: any): boolean;
1064
-
1065
- /** Configuration options for basic authentication. */
1066
- declare type Options = {
1067
- /** The username to be used in basic authorization. */
1068
- username: string;
1069
- /** The password to be used in basic authorization. */
1070
- password: string;
1071
- };
1072
-
1073
- /** Configuration options for VpcInstance authentication. */
1074
- declare interface Options_10 extends BaseOptions {
1075
- /** The CRN of the linked trusted IAM profile to be used as the identity of the compute resource */
1076
- iamProfileCrn?: string;
1077
- /** The ID of the linked trusted IAM profile to be used when obtaining the IAM access token */
1078
- iamProfileId?: string;
1079
- }
1080
-
1081
- /** Configuration options for bearer authentication. */
1082
- declare type Options_2 = {
1083
- /** The bearer token to be added to requests. */
1084
- bearerToken: string;
1085
- };
1086
-
1087
- /** Configuration options for CP4D token retrieval. */
1088
- declare interface Options_3 extends JwtTokenManagerOptions {
1089
- /** The endpoint for CP4D token requests. */
1090
- url: string;
1091
- /** The username used to obtain a bearer token. */
1092
- username: string;
1093
- /** The password used to obtain a bearer token [required if apikey not specified]. */
1094
- password?: string;
1095
- /** The API key used to obtain a bearer token [required if password not specified]. */
1096
- apikey?: string;
1097
- }
1098
-
1099
- /** Configuration options for CloudPakForData authentication. */
1100
- declare interface Options_4 extends BaseOptions {
1101
- /** The username used to obtain a bearer token. */
1102
- username: string;
1103
- /** The password used to obtain a bearer token [required if apikey not specified]. */
1104
- password?: string;
1105
- /** The API key used to obtain a bearer token [required if password not specified]. */
1106
- apikey?: string;
1107
- /** The URL representing the Cloud Pak for Data token service endpoint. */
1108
- url: string;
1109
- }
1110
-
1111
- /** Configuration options for IAM token retrieval. */
1112
- declare interface Options_5 extends IamRequestOptions {
1113
- apikey: string;
1114
- }
1115
-
1116
- /** Configuration options for IAM authentication. */
1117
- declare interface Options_6 extends IamRequestOptions_2 {
1118
- /** The IAM api key */
1119
- apikey: string;
1120
- }
1121
-
1122
- /** Configuration options for IAM token retrieval. */
1123
- declare interface Options_7 extends IamRequestOptions {
1124
- crTokenFilename?: string;
1125
- iamProfileName?: string;
1126
- iamProfileId?: string;
1127
- }
1128
-
1129
- /** Configuration options for IAM authentication. */
1130
- declare interface Options_8 extends IamRequestOptions_2 {
1131
- /** The file containing the compute resource token. */
1132
- crTokenFilename?: string;
1133
- /** The IAM profile name associated with the compute resource token. */
1134
- iamProfileName?: string;
1135
- /** The IAM profile ID associated with the compute resource token. */
1136
- iamProfileId?: string;
1137
- }
1138
-
1139
- /** Configuration options for VPC token retrieval. */
1140
- declare interface Options_9 extends JwtTokenManagerOptions {
1141
- /** The CRN of the linked trusted IAM profile to be used as the identity of the compute resource */
1142
- iamProfileCrn?: string;
1143
- /** The ID of the linked trusted IAM profile to be used when obtaining the IAM access token */
1144
- iamProfileId?: string;
1145
- }
1146
-
1147
- /**
1148
- * (C) Copyright IBM Corp. 2019, 2021.
1149
- *
1150
- * Licensed under the Apache License, Version 2.0 (the "License");
1151
- * you may not use this file except in compliance with the License.
1152
- * You may obtain a copy of the License at
1153
- *
1154
- * http://www.apache.org/licenses/LICENSE-2.0
1155
- *
1156
- * Unless required by applicable law or agreed to in writing, software
1157
- * distributed under the License is distributed on an "AS IS" BASIS,
1158
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1159
- * See the License for the specific language governing permissions and
1160
- * limitations under the License.
1161
- */
1162
- export declare const qs: {
1163
- stringify: (queryParams: Object) => string;
1164
- };
1165
-
1166
- /**
1167
- * Copyright 2021 IBM Corp. All Rights Reserved.
1168
- *
1169
- * Licensed under the Apache License, Version 2.0 (the "License");
1170
- * you may not use this file except in compliance with the License.
1171
- * You may obtain a copy of the License at
1172
- *
1173
- * http://www.apache.org/licenses/LICENSE-2.0
1174
- *
1175
- * Unless required by applicable law or agreed to in writing, software
1176
- * distributed under the License is distributed on an "AS IS" BASIS,
1177
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1178
- * See the License for the specific language governing permissions and
1179
- * limitations under the License.
1180
- */
1181
- /**
1182
- * Return a config object based on a credentials file. Credentials files can
1183
- * be specified filepath via the environment variable: `IBM_CREDENTIALS_FILE`.
1184
- */
1185
- export declare function readCredentialsFile(): any;
1186
-
1187
- export declare function readCrTokenFile(filepath: string): string;
1188
-
1189
- /**
1190
- * Read properties stored in external sources like Environment Variables,
1191
- * the credentials file, VCAP services, etc. and return them as an
1192
- * object. The keys of this object will have the service name prefix removed
1193
- * and will be converted to lower camel case.
1194
- *
1195
- * Only one source will be used at a time.
1196
- * @param {string} serviceName The service name prefix.
1197
- */
1198
- export declare function readExternalSources(serviceName: string): any;
1199
-
1200
- /**
1201
- * Remove a given suffix if it exists.
1202
- *
1203
- * @param {string} str - The base string to operate on
1204
- * @param {string} suffix - The suffix to remove, if present
1205
- * @returns {string}
1206
- */
1207
- export declare function removeSuffix(str: string, suffix: string): string;
1208
-
1209
- declare class RequestWrapper {
1210
- private axiosInstance;
1211
- private compressRequestData;
1212
- private retryInterceptorId;
1213
- private raxConfig;
1214
- constructor(axiosOptions?: any);
1215
- setCompressRequestData(setting: boolean): void;
1216
- /**
1217
- * Creates the request.
1218
- * 1. Merge default options with user provided options
1219
- * 2. Checks for missing parameters
1220
- * 3. Encode path and query parameters
1221
- * 4. Call the api
1222
- * @private
1223
- * @returns {ReadableStream|undefined}
1224
- * @throws {Error}
1225
- */
1226
- sendRequest(parameters: any): Promise<any>;
1227
- /**
1228
- * Format error returned by axios
1229
- * @param {object} the object returned by axios via rejection
1230
- * @private
1231
- * @returns {Error}
1232
- */
1233
- formatError(axiosError: any): Error;
1234
- getHttpClient(): AxiosInstance;
1235
- private static getRaxConfig;
1236
- enableRetries(retryOptions?: RetryOptions): void;
1237
- disableRetries(): void;
1238
- private gzipRequestBody;
1239
- }
1240
-
1241
- /**
1242
- * Retry configuration options.
1243
- */
1244
- declare interface RetryOptions {
1245
- /**
1246
- * Maximum retries to attempt.
1247
- */
1248
- maxRetries?: number;
1249
- /**
1250
- * Ceiling for the retry delay (in seconds) - delay will not exceed this value.
1251
- */
1252
- maxRetryInterval?: number;
1253
- }
1254
-
1255
- export declare interface SDKLogger {
1256
- error: Debugger;
1257
- warn: Debugger;
1258
- info: Debugger;
1259
- verbose: Debugger;
1260
- debug: Debugger;
1261
- }
1262
-
1263
- /**
1264
- * Helper method that can be bound to a stream - it captures all of the results, and returns a promise that resolves to the final buffer
1265
- * or array of text chunks
1266
- * Essentially a smaller version of concat-stream wrapped in a promise
1267
- *
1268
- * @param {Stream} stream Optional stream param for when not bound to an existing stream instance.
1269
- * @return {Promise}
1270
- */
1271
- export declare function streamToPromise(stream: Stream): Promise<any>;
1272
-
1273
- /**
1274
- *
1275
- * @param {string} url - the url string.
1276
- * @returns {string}
1277
- */
1278
- export declare function stripTrailingSlash(url: string): string;
1279
-
1280
- /**
1281
- * A class for shared functionality for storing, and requesting tokens.
1282
- * Intended to be used as a parent to be extended for token request management.
1283
- * Child classes should implement `requestToken()` to retrieve the token
1284
- * from intended sources and `saveTokenInfo(tokenResponse)` to parse and save
1285
- * token information from the response.
1286
- */
1287
- export declare class TokenManager {
1288
- protected url: string;
1289
- protected disableSslVerification: boolean;
1290
- protected headers: OutgoingHttpHeaders;
1291
- protected requestWrapperInstance: RequestWrapper;
1292
- protected accessToken: string;
1293
- protected expireTime: number;
1294
- protected refreshTime: number;
1295
- private requestTime;
1296
- private pendingRequests;
1297
- /**
1298
- * Create a new [[TokenManager]] instance.
1299
- * @constructor
1300
- * @param {object} options Configuration options.
1301
- * @param {string} options.url for HTTP token requests.
1302
- * @param {boolean} [options.disableSslVerification] A flag that indicates
1303
- * whether verification of the token server's SSL certificate should be
1304
- * disabled or not.
1305
- * @param {object<string, string>} [options.headers] Headers to be sent with every
1306
- * outbound HTTP requests to token services.
1307
- */
1308
- constructor(options: TokenManagerOptions);
1309
- /**
1310
- * Retrieve a new token using `requestToken()` in the case there is not a
1311
- * currently stored token from a previous call, or the previous token
1312
- * has expired.
1313
- */
1314
- getToken(): Promise<any>;
1315
- /**
1316
- * Setter for the disableSslVerification property.
1317
- *
1318
- * @param {boolean} value - the new value for the disableSslVerification
1319
- * property
1320
- * @returns {void}
1321
- */
1322
- setDisableSslVerification(value: boolean): void;
1323
- /**
1324
- * Set a completely new set of headers.
1325
- *
1326
- * @param {OutgoingHttpHeaders} headers - the new set of headers as an object
1327
- * @returns {void}
1328
- */
1329
- setHeaders(headers: OutgoingHttpHeaders): void;
1330
- /**
1331
- * Paces requests to request_token.
1332
- *
1333
- * This method pseudo-serializes requests for an access_token
1334
- * when the current token is undefined or expired.
1335
- * The first caller to this method records its `requestTime` and
1336
- * then issues the token request. Subsequent callers will check the
1337
- * `requestTime` to see if a request is active (has been issued within
1338
- * the past 60 seconds), and if so will queue their promise for the
1339
- * active requestor to resolve when that request completes.
1340
- */
1341
- protected pacedRequestToken(): Promise<any>;
1342
- /**
1343
- * Request a token using an API endpoint.
1344
- *
1345
- * @returns {Promise}
1346
- */
1347
- protected requestToken(): Promise<any>;
1348
- /**
1349
- * Parse and save token information from the response.
1350
- * Save the requested token into field `accessToken`.
1351
- * Calculate expiration and refresh time from the received info
1352
- * and store them in fields `expireTime` and `refreshTime`.
1353
- *
1354
- * @param tokenResponse - Response object from a token service request
1355
- * @protected
1356
- * @returns {void}
1357
- */
1358
- protected saveTokenInfo(tokenResponse: any): void;
1359
- /**
1360
- * Check if currently stored token is expired
1361
- *
1362
- * @private
1363
- * @returns {boolean}
1364
- */
1365
- private isTokenExpired;
1366
- /**
1367
- * Check if currently stored token should be refreshed
1368
- * i.e. past the window to request a new token
1369
- *
1370
- * @private
1371
- * @returns {boolean}
1372
- */
1373
- private tokenNeedsRefresh;
1374
- }
1375
-
1376
- /** Configuration options for token retrieval. */
1377
- export declare type TokenManagerOptions = {
1378
- /** The endpoint for token requests. */
1379
- url?: string;
1380
- /** Headers to be sent with every service token request. */
1381
- headers?: OutgoingHttpHeaders;
1382
- /**
1383
- * A flag that indicates whether verification of
1384
- * the server's SSL certificate should be disabled or not.
1385
- */
1386
- disableSslVerification?: boolean;
1387
- /** Allow additional request config parameters */
1388
- [propName: string]: any;
1389
- };
1390
-
1391
- /**
1392
- * Class for common functionality shared by token-request authenticators.
1393
- * [[TokenRequestBasedAuthenticator]]s use token managers to retrieve, store,
1394
- * and refresh tokens. Not intended to be used as stand-alone authenticator,
1395
- * but as parent class to authenticators that have their own token manager
1396
- * implementations.
1397
- *
1398
- * The tokens will be added as an Authorization headers in the form:
1399
- *
1400
- * Authorization: Bearer <bearer-token>
1401
- */
1402
- export declare class TokenRequestBasedAuthenticator extends Authenticator {
1403
- protected tokenManager: JwtTokenManager;
1404
- protected url: string;
1405
- protected headers: OutgoingHttpHeaders;
1406
- protected disableSslVerification: boolean;
1407
- /**
1408
- * Create a new [[TokenRequestBasedAuthenticator]] instance with an internal [[JwtTokenManager]].
1409
- *
1410
- * @param {object} options Configuration options.
1411
- * @param {string} options.url for HTTP token requests.
1412
- * @param {boolean} [options.disableSslVerification] A flag that indicates
1413
- * whether verification of the token server's SSL certificate should be
1414
- * disabled or not.
1415
- * @param {object<string, string>} [options.headers] to be sent with every
1416
- * outbound HTTP requests to token services.
1417
- */
1418
- constructor(options: BaseOptions);
1419
- /**
1420
- * Set the flag that indicates whether verification of the server's SSL
1421
- * certificate should be disabled or not.
1422
- *
1423
- * @param {boolean} value A flag that indicates whether verification of the
1424
- * token server's SSL certificate should be disabled or not.
1425
- */
1426
- setDisableSslVerification(value: boolean): void;
1427
- /**
1428
- * Set headers.
1429
- *
1430
- * @param {object<string, string>} headers Default headers to be sent with
1431
- * every Cloud Pak For Data token request. Overwrites previous default headers.
1432
- */
1433
- setHeaders(headers: OutgoingHttpHeaders): void;
1434
- /**
1435
- * Adds bearer token information to `request`. The bearer token information
1436
- * will be set in the Authorization property of`request.headers` in the form:
1437
- *
1438
- * Authorization: Bearer <bearer-token>
1439
- *
1440
- * @param {object} requestOptions - The request to augment with authentication
1441
- * information.
1442
- * @param {object.<string, string>} requestOptions.headers - The headers the
1443
- * authentication information will be added too. Overrides default headers
1444
- * where there's conflict.
1445
- */
1446
- authenticate(requestOptions: AuthenticateOptions): Promise<void>;
1447
- }
1448
-
1449
- /**
1450
- * This function converts an object's keys to lower case.
1451
- * note: does not convert nested keys
1452
- * @param {Object} obj The object to convert the keys of.
1453
- * @returns {Object}
1454
- */
1455
- export declare function toLowerKeys(obj: Object): Object;
1456
-
1457
- declare namespace unitTestUtils {
1458
- export {
1459
- checkUrlAndMethod,
1460
- checkMediaHeaders,
1461
- checkUserHeader,
1462
- checkForSuccessfulExecution,
1463
- getOptions,
1464
- expectToBePromise
1465
- }
1466
- }
1467
- export { unitTestUtils }
1468
-
1469
- /**
1470
- * Configuration values for a service.
1471
- */
1472
- export declare interface UserOptions {
1473
- /** The Authenticator object used to authenticate requests to the service */
1474
- authenticator?: AuthenticatorInterface;
1475
- /** The base url to use when contacting the service. The base url may differ between IBM Cloud regions. */
1476
- serviceUrl?: string;
1477
- /** Default headers that shall be included with every request to the service. */
1478
- headers?: OutgoingHttpHeaders;
1479
- /** The API version date to use with the service, in "YYYY-MM-DD" format. */
1480
- version?: string;
1481
- /** Set to `true` to allow unauthorized requests - not recommended for production use. */
1482
- disableSslVerification?: boolean;
1483
- /** Set your own cookie jar object */
1484
- jar?: CookieJar | boolean;
1485
- /** Deprecated. Use `serviceUrl` instead. */
1486
- url?: string;
1487
- /** Allow additional request config parameters */
1488
- [propName: string]: any;
1489
- }
1490
-
1491
- /**
1492
- * @param {object} options - A configuration options object.
1493
- * @param {string[]} requiredOptions - The list of properties that must be specified.
1494
- */
1495
- export declare function validateInput(options: any, requiredOptions: string[]): void;
1496
-
1497
- /**
1498
- * Validates that "params" contains a value for each key listed in "requiredParams",
1499
- * and that each key contained in "params" is a valid key listed in "allParams".
1500
- * In essence, we want params to contain only valid keys and we want params
1501
- * to contain at least the required keys.
1502
- *
1503
- * @param params - the "params" object passed into an operation containing method parameters.
1504
- * @param requiredParams - the names of required parameters.
1505
- * If null, then the "required params" check is bypassed.
1506
- * @param allParams - the names of all valid parameters.
1507
- * If null, then the "valid params" check is bypassed.
1508
- * @returns {Error|null}
1509
- */
1510
- export declare function validateParams(params: {
1511
- [key: string]: any;
1512
- }, requiredParams: string[], allParams: string[]): null | Error;
1513
-
1514
- /**
1515
- * The [[VpcInstanceAuthenticator]] implements an authentication scheme in which it retrieves an "instance identity token"
1516
- * and exchanges that for an IAM access token using the VPC Instance Metadata Service API which is available on the local
1517
- * compute resource (VM). The instance identity token is similar to an IAM apikey, except that it is managed automatically
1518
- * by the compute resource provider (VPC).
1519
- *
1520
- * The resulting IAM access token is then added to outbound requests in an Authorization header
1521
- *
1522
- * Authorization: Bearer <access-token>
1523
- */
1524
- export declare class VpcInstanceAuthenticator extends TokenRequestBasedAuthenticator {
1525
- protected tokenManager: VpcInstanceTokenManager;
1526
- private iamProfileCrn;
1527
- private iamProfileId;
1528
- /**
1529
- * Create a new [[VpcInstanceAuthenticator]] instance.
1530
- *
1531
- * @param {object} [options] Configuration options for VpcInstance authentication.
1532
- * @param {string} [options.iamProfileCrn] The CRN of the linked trusted IAM profile to be used as the identity of the compute resource.
1533
- * At most one of iamProfileCrn or iamProfileId may be specified.
1534
- * If neither one is specified, then the default IAM profile defined for the compute resource will be used.
1535
- * @param {string} [options.iamProfileId] The ID of the linked trusted IAM profile to be used when obtaining the IAM access token.
1536
- * At most one of iamProfileCrn or iamProfileId may be specified.
1537
- * If neither one is specified, then the default IAM profile defined for the compute resource will be used.
1538
- * @param {string} [options.url] The VPC Instance Metadata Service's base endpoint URL. Default value: "http://169.254.169.254"
1539
- */
1540
- constructor(options: Options_10);
1541
- /**
1542
- * Setter for the "profile_crn" parameter to use when fetching the bearer token from the IAM token server.
1543
- * @param {string} A string that makes up the iamProfileCrn parameter
1544
- */
1545
- setIamProfileCrn(iamProfileCrn: string): void;
1546
- /**
1547
- * Setter for the "profile_id" parameter to use when fetching the bearer token from the IAM token server.
1548
- * @param {string} A string that makes up the iamProfileId parameter
1549
- */
1550
- setIamProfileId(iamProfileId: string): void;
1551
- /**
1552
- * Returns the authenticator's type ('vpc').
1553
- *
1554
- * @returns a string that indicates the authenticator's type
1555
- */
1556
- authenticationType(): string;
1557
- }
1558
-
1559
- /**
1560
- * Token Manager for VPC Instance Authentication.
1561
- */
1562
- export declare class VpcInstanceTokenManager extends JwtTokenManager {
1563
- private iamProfileCrn;
1564
- private iamProfileId;
1565
- /**
1566
- * Create a new [[VpcInstanceTokenManager]] instance.
1567
- *
1568
- * @param {object} [options] Configuration options.
1569
- * @param {string} [options.iamProfileCrn] The CRN of the linked trusted IAM profile to be used as the identity of the compute resource.
1570
- * At most one of iamProfileCrn or iamProfileId may be specified.
1571
- * If neither one is specified, then the default IAM profile defined for the compute resource will be used.
1572
- * @param {string} [options.iamProfileId] The ID of the linked trusted IAM profile to be used when obtaining the IAM access token.
1573
- * At most one of iamProfileCrn or iamProfileId may be specified.
1574
- * If neither one is specified, then the default IAM profile defined for the compute resource will be used.
1575
- * @param {string} [options.url] The VPC Instance Metadata Service's base endpoint URL. Default value: "http://169.254.169.254"
1576
- * @constructor
1577
- */
1578
- constructor(options: Options_9);
1579
- /**
1580
- * Setter for the "trusted_profile" parameter to use when fetching the bearer token from the IAM token server.
1581
- * @param {string} iamProfileCrn A string that makes up the iamProfileCrn parameter
1582
- */
1583
- setIamProfileCrn(iamProfileCrn: string): void;
1584
- /**
1585
- * Setter for the "trusted_profile" parameter to use when fetching the bearer token from the IAM token server.
1586
- * @param {string} iamProfileId A string that makes up the iamProfileId parameter
1587
- */
1588
- setIamProfileId(iamProfileId: string): void;
1589
- protected requestToken(): Promise<any>;
1590
- private getInstanceIdentityToken;
1591
- }
1592
-
1593
- export { }
1507
+ * @returns a string that indicates the authenticator's type
1508
+ */
1509
+ authenticationType(): string;
1510
+ }
1511
+
1512
+ /**
1513
+ * Token Manager for VPC Instance Authentication.
1514
+ */
1515
+ export declare class VpcInstanceTokenManager extends JwtTokenManager {
1516
+ private iamProfileCrn;
1517
+ private iamProfileId;
1518
+ /**
1519
+ * Create a new VpcInstanceTokenManager instance.
1520
+ *
1521
+ * @param options - Configuration options.
1522
+ * This should be an object containing these fields:
1523
+ * - url: (optional) the endpoint URL for the VPC Instance Metadata Service (default value: "http://169.254.169.254")
1524
+ * - iamProfileCrn: (optional) the CRN of the linked IAM trusted profile to be used to obtain the IAM access token
1525
+ * - iamProfileId: (optional) the ID of the linked IAM trusted profile to be used to obtain the IAM access token
1526
+ *
1527
+ * @remarks
1528
+ * At most one of "iamProfileCrn" or "iamProfileId" may be specified. If neither one is specified,
1529
+ * then the default IAM profile defined for the compute resource will be used.
1530
+ */
1531
+ constructor(options: Options_9);
1532
+ /**
1533
+ * Sets the CRN of the IAM trusted profile to use when fetching the access token from the IAM token server.
1534
+ * @param iamProfileCrn - the CRN of the IAM trusted profile
1535
+ */
1536
+ setIamProfileCrn(iamProfileCrn: string): void;
1537
+ /**
1538
+ * Sets the Id of the IAM trusted profile to use when fetching the access token from the IAM token server.
1539
+ * @param iamProfileId - the ID of the IAM trusted profile
1540
+ */
1541
+ setIamProfileId(iamProfileId: string): void;
1542
+ protected requestToken(): Promise<any>;
1543
+ private getInstanceIdentityToken;
1544
+ }
1545
+
1546
+ export { }