@cloud-idaas/akless-tencent-adapter 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/README.md +60 -2
- package/README_zh.md +61 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +151 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5 -0
- package/examples/initialize.cjs +22 -0
- package/examples/initialize.mjs +22 -0
- package/examples/initialize.ts +22 -0
- package/package.json +76 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0-beta.1 (Unreleased)
|
|
4
|
+
|
|
5
|
+
- Support renewable credentials for the Tencent Cloud SDK and COS.
|
|
6
|
+
- Accept supported Tencent Cloud credential expiration formats and report retrieval failures consistently.
|
|
7
|
+
- Provide CommonJS/ESM packages, TypeScript declarations, and English/Chinese usage documentation.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# IDaaS Tencent Cloud Credentials Adapter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Simplified Chinese](README_zh.md) | English
|
|
4
|
+
|
|
5
|
+
Use IDaaS PAM temporary credentials with the Tencent Cloud SDK and COS.
|
|
6
|
+
|
|
7
|
+
## Requirements and installation
|
|
8
|
+
|
|
9
|
+
Supports Node.js 20, 22, and 24, JavaScript CommonJS/ESM, and TypeScript 4.7 or later. This is a Node.js SDK, not a browser SDK. Check your registry for available beta versions; use a provided package archive when evaluating an unreleased version.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @cloud-idaas/core-sdk @cloud-idaas/akless-tencent-adapter
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Configure Core using CLOUD_IDAAS_CONFIG_PATH or ~/.cloud_idaas/client-config.json. Provide developerApiEndpoint and an identity authorized for PAM access. Replace example identifiers with your settings. Save the following ESM example as `example.mjs` and run it with Node.js. CommonJS uses the same named exports through `require`; asynchronous calls belong inside an async function.
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import { IDaaSCredentialProviderFactory } from '@cloud-idaas/core-sdk';
|
|
21
|
+
import {
|
|
22
|
+
createTencentCloudCredentialsProvider,
|
|
23
|
+
createTencentCloudCOSCredentialsProvider,
|
|
24
|
+
} from '@cloud-idaas/akless-tencent-adapter';
|
|
25
|
+
|
|
26
|
+
await IDaaSCredentialProviderFactory.init();
|
|
27
|
+
try {
|
|
28
|
+
const credential = createTencentCloudCredentialsProvider('role-external-id');
|
|
29
|
+
try {
|
|
30
|
+
await credential.getCredential();
|
|
31
|
+
// Pass credential to new TencentClient({ credential, region: '...' }).
|
|
32
|
+
const getAuthorization = createTencentCloudCOSCredentialsProvider('role-external-id');
|
|
33
|
+
try {
|
|
34
|
+
// Pass getAuthorization to new COS({ getAuthorization }).
|
|
35
|
+
// Await all COS requests before closing this callback's provider.
|
|
36
|
+
} finally {
|
|
37
|
+
getAuthorization.close();
|
|
38
|
+
}
|
|
39
|
+
} finally {
|
|
40
|
+
credential.close();
|
|
41
|
+
}
|
|
42
|
+
} finally {
|
|
43
|
+
await IDaaSCredentialProviderFactory.close();
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Integration notes
|
|
48
|
+
|
|
49
|
+
Use `createTencentCloudCredentialsProvider()` for the Tencent Cloud SDK credential interface, or pass `createTencentCloudCOSCredentialsProvider()` to COS as `getAuthorization`. Install the official service client needed by your application separately.
|
|
50
|
+
|
|
51
|
+
Direct credential methods reject with SDK errors when credentials cannot be obtained. COS users can provide `onError` for SDK diagnostics; failures can also surface through the service client's error handling. Keep providers open until all service requests finish, then call their `close()` methods.
|
|
52
|
+
|
|
53
|
+
Configuration supports `roleExternalId`, `developerApiEndpoint`, `idaasInstanceId`, and `credentialProvider`. `httpConfiguration.userAgent` customizes requests to IDaaS; cloud-service requests follow their official client's configuration.
|
|
54
|
+
|
|
55
|
+
## Examples and support
|
|
56
|
+
|
|
57
|
+
See [examples](examples) for CommonJS, ESM, and TypeScript samples. Report issues through [GitHub Issues](https://github.com/cloud-idaas/idaas-typescript-akless-tencent-adapter/issues). Development instructions are in the repository's [contribution guide](https://github.com/cloud-idaas/idaas-typescript-akless-tencent-adapter/blob/master/CONTRIBUTING.md).
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
[Apache License 2.0](LICENSE).
|
package/README_zh.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# IDaaS Tencent Cloud Credentials Adapter
|
|
2
|
+
|
|
3
|
+
简体中文 | [English](README.md)
|
|
4
|
+
|
|
5
|
+
将 IDaaS PAM 临时凭证用于腾讯云 SDK 和 COS。
|
|
6
|
+
|
|
7
|
+
## 环境与安装
|
|
8
|
+
|
|
9
|
+
支持 Node.js 20、22、24,JavaScript CommonJS/ESM 以及 TypeScript 4.7 及以上版本。本 SDK 用于 Node.js,不用于浏览器。请以 npm registry 中的实际可用版本为准;评估尚未发布的版本时,使用提供的安装包归档。
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @cloud-idaas/core-sdk @cloud-idaas/akless-tencent-adapter
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
通过 CLOUD_IDAAS_CONFIG_PATH 或 ~/.cloud_idaas/client-config.json 配置 Core,提供 developerApiEndpoint 及已获 PAM 访问授权的身份,并替换示例标识。 将以下 ESM 示例保存为 `example.mjs`,通过 Node.js 运行。CommonJS 使用相同的具名导出和 `require`,异步调用放在 async 函数中。
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import { IDaaSCredentialProviderFactory } from '@cloud-idaas/core-sdk';
|
|
21
|
+
import {
|
|
22
|
+
createTencentCloudCredentialsProvider,
|
|
23
|
+
createTencentCloudCOSCredentialsProvider,
|
|
24
|
+
} from '@cloud-idaas/akless-tencent-adapter';
|
|
25
|
+
|
|
26
|
+
await IDaaSCredentialProviderFactory.init();
|
|
27
|
+
try {
|
|
28
|
+
const credential = createTencentCloudCredentialsProvider('role-external-id');
|
|
29
|
+
try {
|
|
30
|
+
await credential.getCredential();
|
|
31
|
+
// Pass credential to new TencentClient({ credential, region: '...' }).
|
|
32
|
+
const getAuthorization = createTencentCloudCOSCredentialsProvider('role-external-id');
|
|
33
|
+
try {
|
|
34
|
+
// Pass getAuthorization to new COS({ getAuthorization }).
|
|
35
|
+
// Await all COS requests before closing this callback's provider.
|
|
36
|
+
} finally {
|
|
37
|
+
getAuthorization.close();
|
|
38
|
+
}
|
|
39
|
+
} finally {
|
|
40
|
+
credential.close();
|
|
41
|
+
}
|
|
42
|
+
} finally {
|
|
43
|
+
await IDaaSCredentialProviderFactory.close();
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 集成说明
|
|
48
|
+
|
|
49
|
+
腾讯云 SDK 凭证接口使用 `createTencentCloudCredentialsProvider()`,COS 的 `getAuthorization` 选项使用 `createTencentCloudCOSCredentialsProvider()`。请另行安装应用需要的官方服务客户端。
|
|
50
|
+
|
|
51
|
+
无法获取凭证时,直接取凭证的方法会以 SDK 异常拒绝。COS 使用者可通过 `onError` 获取 SDK 诊断,失败也可能由服务客户端的错误处理通道返回。所有服务请求完成前保持提供者可用,随后调用各自的 `close()`。
|
|
52
|
+
|
|
53
|
+
配置支持 `roleExternalId`、`developerApiEndpoint`、`idaasInstanceId` 和 `credentialProvider`。`httpConfiguration.userAgent` 定制发往 IDaaS 的请求;云服务请求遵循其官方客户端配置。
|
|
54
|
+
|
|
55
|
+
## 示例与支持
|
|
56
|
+
|
|
57
|
+
[examples](examples) 提供 CommonJS、ESM 和 TypeScript 示例。问题反馈请使用 [GitHub Issues](https://github.com/cloud-idaas/idaas-typescript-akless-tencent-adapter/issues),开发说明见源码仓库的[贡献指南](https://github.com/cloud-idaas/idaas-typescript-akless-tencent-adapter/blob/master/CONTRIBUTING.md)。
|
|
58
|
+
|
|
59
|
+
## 许可证
|
|
60
|
+
|
|
61
|
+
[Apache License 2.0](LICENSE)。
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.js';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type IDaaSException } from '@cloud-idaas/core-sdk';
|
|
2
|
+
import { type AklessProviderOptions, AklessProviderBuilder, CachedCloudCredentialProvider, type ExpiringCredential } from '@cloud-idaas/pam-client-sdk';
|
|
3
|
+
/** Generic PAM STS snapshot; expiration is ISO 8601 and tmpSecret fields are renamed at the adapter boundary. */
|
|
4
|
+
export interface TencentSessionCredentials extends ExpiringCredential {
|
|
5
|
+
secretId: string;
|
|
6
|
+
secretKey: string;
|
|
7
|
+
token: string;
|
|
8
|
+
}
|
|
9
|
+
/** Fields required by Tencent Cloud DynamicCredential.getCredential. */
|
|
10
|
+
export interface TencentCredential {
|
|
11
|
+
secretId: string;
|
|
12
|
+
secretKey: string;
|
|
13
|
+
token: string;
|
|
14
|
+
}
|
|
15
|
+
/** Temporary credential callback data accepted by cos-nodejs-sdk-v5 3.0.0. */
|
|
16
|
+
export interface COSCredential {
|
|
17
|
+
TmpSecretId: string;
|
|
18
|
+
TmpSecretKey: string;
|
|
19
|
+
SecurityToken: string;
|
|
20
|
+
/** Zero means the server did not provide an issuance time; COS uses its default time policy. */
|
|
21
|
+
StartTime: number;
|
|
22
|
+
/** Unix seconds; local time must not extend the server-provided expiration. */
|
|
23
|
+
ExpiredTime: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Structural COS getAuthorization callback; starts no background I/O before credentials are requested.
|
|
27
|
+
* @param options - Request context supplied by COS; currently unused by this adapter.
|
|
28
|
+
* @param callback - Credential callback that must complete; COS has no separate error argument.
|
|
29
|
+
*/
|
|
30
|
+
export type COSGetAuthorization = (options: unknown, callback: (value: COSCredential) => void) => void;
|
|
31
|
+
/** COS callback created by an independent factory, with cleanup for the underlying provider. */
|
|
32
|
+
export interface COSAuthorizationProvider extends COSGetAuthorization {
|
|
33
|
+
/** Closes owned PAM/HTTP resources, leaving the COS client and injected shared sources open. */
|
|
34
|
+
close(): void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Provides Tencent Cloud DynamicCredential and COS beta integrations on Node.js 20/22/24.
|
|
38
|
+
* @remarks The callback protocol was checked against cos-nodejs-sdk-v5 3.0.0. Inherited getCredentials returns
|
|
39
|
+
* independent STS snapshots. close releases only provider-owned resources; injected PAM, HTTP, and
|
|
40
|
+
* machine credential sources remain caller-owned.
|
|
41
|
+
*/
|
|
42
|
+
export declare class IDaaSPamTencentCloudCredentialsProvider extends CachedCloudCredentialProvider<TencentSessionCredentials> {
|
|
43
|
+
/** @returns A configuration builder without I/O; STS retrieval starts on first use after build. */
|
|
44
|
+
static builder(): AklessProviderBuilder<IDaaSPamTencentCloudCredentialsProvider>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a Tencent Cloud provider without fetching STS credentials.
|
|
47
|
+
* @param options - Required role and optional PAM, HTTP, machine credential source, and cache configuration.
|
|
48
|
+
* @throws ConfigException - The role or configuration is invalid, or the required default factory is not initialized.
|
|
49
|
+
*/
|
|
50
|
+
constructor(options: AklessProviderOptions);
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves current credentials for the Tencent Cloud SDK.
|
|
53
|
+
* @returns An independent secretId/secretKey/token snapshot.
|
|
54
|
+
* @throws IDaaSException - Retrieval fails without usable unexpired cached credentials, or the provider is closed.
|
|
55
|
+
*/
|
|
56
|
+
getCredential(): Promise<TencentCredential>;
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves COS temporary credentials without inventing a server issuance time.
|
|
59
|
+
* @returns Independent callback data; ExpiredTime uses Unix seconds and StartTime=0 selects the COS default policy.
|
|
60
|
+
* @throws IDaaSException - Retrieval or parsing fails, refresh fails after expiration, or the provider is closed.
|
|
61
|
+
*/
|
|
62
|
+
getCOSCredential(): Promise<COSCredential>;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a COS getAuthorization callback sharing this provider.
|
|
65
|
+
* @param onError - Optional observer of classified errors; observer exceptions do not prevent COS request completion.
|
|
66
|
+
* @returns A callback sharing the existing cache; the caller must still close this provider.
|
|
67
|
+
* @remarks COS only has a success-data callback. Retrieval failures notify the observer and pass invalid credentials to
|
|
68
|
+
* trigger the official argument-error path, avoiding hung requests without inventing a COS error argument.
|
|
69
|
+
*/
|
|
70
|
+
toCOSGetAuthorization(onError?: (error: IDaaSException) => void): COSGetAuthorization;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates a Tencent Cloud DynamicCredential provider without immediately fetching STS credentials.
|
|
74
|
+
* @param roleOrOptions - Role external ID or complete configuration including the role.
|
|
75
|
+
* @param options - Additional configuration when the first argument is a string; injected sources take precedence.
|
|
76
|
+
* @returns An independent provider; callers must close it after use, with owned and shared resources managed separately.
|
|
77
|
+
* @throws ConfigException - The configuration is invalid or the required default factory is not initialized.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createTencentCloudCredentialsProvider(roleOrOptions: string | AklessProviderOptions, options?: Omit<AklessProviderOptions, 'roleExternalId'>): IDaaSPamTencentCloudCredentialsProvider;
|
|
80
|
+
/**
|
|
81
|
+
* Creates an independent dynamic credential callback for cos-nodejs-sdk-v5 3.0.0.
|
|
82
|
+
* @param roleOrOptions - Role external ID or complete configuration.
|
|
83
|
+
* @param options - Additional configuration when the first argument is a string.
|
|
84
|
+
* @param onError - Optional classified-error observer; its exceptions are isolated and cannot prevent COS request completion.
|
|
85
|
+
* @returns A callback with close; close after use without closing the COS client or shared injected resources.
|
|
86
|
+
* @throws ConfigException - The configuration is invalid or the required default factory is not initialized.
|
|
87
|
+
* @remarks Asynchronous retrieval failures complete through the observer and the COS invalid-credential error path.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createTencentCloudCOSCredentialsProvider(roleOrOptions: string | AklessProviderOptions, options?: Omit<AklessProviderOptions, 'roleExternalId'>, onError?: (error: IDaaSException) => void): COSAuthorizationProvider;
|
|
90
|
+
/** Tencent Cloud beta convenience factories; do not create SDK or COS service clients. */
|
|
91
|
+
export declare class IDaaSPamAklessCredentialFactory {
|
|
92
|
+
/** Arguments, errors, and resource ownership match the named general provider factory. */
|
|
93
|
+
static createTencentCloudCredentialsProvider: typeof createTencentCloudCredentialsProvider;
|
|
94
|
+
/** Arguments, callback error handling, and close semantics match the named COS factory. */
|
|
95
|
+
static createTencentCloudCOSCredentialsProvider: typeof createTencentCloudCOSCredentialsProvider;
|
|
96
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IDaaSPamAklessCredentialFactory = exports.IDaaSPamTencentCloudCredentialsProvider = void 0;
|
|
4
|
+
exports.createTencentCloudCredentialsProvider = createTencentCloudCredentialsProvider;
|
|
5
|
+
exports.createTencentCloudCOSCredentialsProvider = createTencentCloudCOSCredentialsProvider;
|
|
6
|
+
const core_sdk_1 = require("@cloud-idaas/core-sdk");
|
|
7
|
+
const pam_client_sdk_1 = require("@cloud-idaas/pam-client-sdk");
|
|
8
|
+
/**
|
|
9
|
+
* Provides Tencent Cloud DynamicCredential and COS beta integrations on Node.js 20/22/24.
|
|
10
|
+
* @remarks The callback protocol was checked against cos-nodejs-sdk-v5 3.0.0. Inherited getCredentials returns
|
|
11
|
+
* independent STS snapshots. close releases only provider-owned resources; injected PAM, HTTP, and
|
|
12
|
+
* machine credential sources remain caller-owned.
|
|
13
|
+
*/
|
|
14
|
+
class IDaaSPamTencentCloudCredentialsProvider extends pam_client_sdk_1.CachedCloudCredentialProvider {
|
|
15
|
+
/** @returns A configuration builder without I/O; STS retrieval starts on first use after build. */
|
|
16
|
+
static builder() {
|
|
17
|
+
return new pam_client_sdk_1.AklessProviderBuilder((options) => new IDaaSPamTencentCloudCredentialsProvider(options));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a Tencent Cloud provider without fetching STS credentials.
|
|
21
|
+
* @param options - Required role and optional PAM, HTTP, machine credential source, and cache configuration.
|
|
22
|
+
* @throws ConfigException - The role or configuration is invalid, or the required default factory is not initialized.
|
|
23
|
+
*/
|
|
24
|
+
constructor(options) {
|
|
25
|
+
super(options, (response) => {
|
|
26
|
+
const token = response.tencentCloudStsToken;
|
|
27
|
+
if (!token)
|
|
28
|
+
throw new core_sdk_1.CredentialException('Response is missing tencentCloudStsToken', 'InvalidCredentialResponse');
|
|
29
|
+
let expiration = (0, pam_client_sdk_1.credentialExpiration)(response, token.expiration);
|
|
30
|
+
if (token.expiredTime !== undefined) {
|
|
31
|
+
if (typeof token.expiredTime !== 'number' || !Number.isFinite(token.expiredTime))
|
|
32
|
+
throw new core_sdk_1.CredentialException('expiredTime is invalid', 'InvalidExpiration');
|
|
33
|
+
expiration = Math.min(expiration, token.expiredTime * 1000);
|
|
34
|
+
if (!Number.isFinite(expiration) || expiration <= Date.now())
|
|
35
|
+
throw new core_sdk_1.CredentialException('expiredTime has expired', 'InvalidExpiration');
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
secretId: (0, pam_client_sdk_1.credentialString)(token.tmpSecretId, 'tmpSecretId'),
|
|
39
|
+
secretKey: (0, pam_client_sdk_1.credentialString)(token.tmpSecretKey, 'tmpSecretKey'),
|
|
40
|
+
token: (0, pam_client_sdk_1.credentialString)(token.token, 'token'),
|
|
41
|
+
expiration: new Date(expiration).toISOString(),
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves current credentials for the Tencent Cloud SDK.
|
|
47
|
+
* @returns An independent secretId/secretKey/token snapshot.
|
|
48
|
+
* @throws IDaaSException - Retrieval fails without usable unexpired cached credentials, or the provider is closed.
|
|
49
|
+
*/
|
|
50
|
+
async getCredential() {
|
|
51
|
+
const value = await this.getCredentials();
|
|
52
|
+
this.assertAvailable(value);
|
|
53
|
+
return { secretId: value.secretId, secretKey: value.secretKey, token: value.token };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves COS temporary credentials without inventing a server issuance time.
|
|
57
|
+
* @returns Independent callback data; ExpiredTime uses Unix seconds and StartTime=0 selects the COS default policy.
|
|
58
|
+
* @throws IDaaSException - Retrieval or parsing fails, refresh fails after expiration, or the provider is closed.
|
|
59
|
+
*/
|
|
60
|
+
async getCOSCredential() {
|
|
61
|
+
const value = await this.getCredentials();
|
|
62
|
+
this.assertAvailable(value);
|
|
63
|
+
return {
|
|
64
|
+
TmpSecretId: value.secretId,
|
|
65
|
+
TmpSecretKey: value.secretKey,
|
|
66
|
+
SecurityToken: value.token,
|
|
67
|
+
StartTime: 0,
|
|
68
|
+
ExpiredTime: Math.floor(Date.parse(value.expiration) / 1000),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Creates a COS getAuthorization callback sharing this provider.
|
|
73
|
+
* @param onError - Optional observer of classified errors; observer exceptions do not prevent COS request completion.
|
|
74
|
+
* @returns A callback sharing the existing cache; the caller must still close this provider.
|
|
75
|
+
* @remarks COS only has a success-data callback. Retrieval failures notify the observer and pass invalid credentials to
|
|
76
|
+
* trigger the official argument-error path, avoiding hung requests without inventing a COS error argument.
|
|
77
|
+
*/
|
|
78
|
+
toCOSGetAuthorization(onError) {
|
|
79
|
+
const report = (error) => {
|
|
80
|
+
try {
|
|
81
|
+
onError === null || onError === void 0 ? void 0 : onError((0, core_sdk_1.isIDaaSException)(error)
|
|
82
|
+
? error
|
|
83
|
+
: new core_sdk_1.CredentialException('COS credential retrieval failed', 'CredentialRetrievalFailed'));
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
/* Error observers must not prevent request completion. */
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return (_options, callback) => {
|
|
90
|
+
const fail = (error) => {
|
|
91
|
+
report(error);
|
|
92
|
+
callback({
|
|
93
|
+
TmpSecretId: '',
|
|
94
|
+
TmpSecretKey: '',
|
|
95
|
+
SecurityToken: '',
|
|
96
|
+
StartTime: 0,
|
|
97
|
+
ExpiredTime: 0,
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
void this.getCOSCredential()
|
|
101
|
+
.then((value) => {
|
|
102
|
+
try {
|
|
103
|
+
this.assertAvailable({ expiration: new Date(value.ExpiredTime * 1000).toISOString() });
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
fail(error);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
callback(value);
|
|
110
|
+
}, fail)
|
|
111
|
+
.catch(report);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.IDaaSPamTencentCloudCredentialsProvider = IDaaSPamTencentCloudCredentialsProvider;
|
|
116
|
+
/**
|
|
117
|
+
* Creates a Tencent Cloud DynamicCredential provider without immediately fetching STS credentials.
|
|
118
|
+
* @param roleOrOptions - Role external ID or complete configuration including the role.
|
|
119
|
+
* @param options - Additional configuration when the first argument is a string; injected sources take precedence.
|
|
120
|
+
* @returns An independent provider; callers must close it after use, with owned and shared resources managed separately.
|
|
121
|
+
* @throws ConfigException - The configuration is invalid or the required default factory is not initialized.
|
|
122
|
+
*/
|
|
123
|
+
function createTencentCloudCredentialsProvider(roleOrOptions, options = {}) {
|
|
124
|
+
return new IDaaSPamTencentCloudCredentialsProvider(typeof roleOrOptions === 'string'
|
|
125
|
+
? { ...options, roleExternalId: roleOrOptions }
|
|
126
|
+
: roleOrOptions);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Creates an independent dynamic credential callback for cos-nodejs-sdk-v5 3.0.0.
|
|
130
|
+
* @param roleOrOptions - Role external ID or complete configuration.
|
|
131
|
+
* @param options - Additional configuration when the first argument is a string.
|
|
132
|
+
* @param onError - Optional classified-error observer; its exceptions are isolated and cannot prevent COS request completion.
|
|
133
|
+
* @returns A callback with close; close after use without closing the COS client or shared injected resources.
|
|
134
|
+
* @throws ConfigException - The configuration is invalid or the required default factory is not initialized.
|
|
135
|
+
* @remarks Asynchronous retrieval failures complete through the observer and the COS invalid-credential error path.
|
|
136
|
+
*/
|
|
137
|
+
function createTencentCloudCOSCredentialsProvider(roleOrOptions, options = {}, onError) {
|
|
138
|
+
const provider = createTencentCloudCredentialsProvider(roleOrOptions, options);
|
|
139
|
+
const callback = provider.toCOSGetAuthorization(onError);
|
|
140
|
+
callback.close = () => provider.close();
|
|
141
|
+
return callback;
|
|
142
|
+
}
|
|
143
|
+
/** Tencent Cloud beta convenience factories; do not create SDK or COS service clients. */
|
|
144
|
+
class IDaaSPamAklessCredentialFactory {
|
|
145
|
+
}
|
|
146
|
+
exports.IDaaSPamAklessCredentialFactory = IDaaSPamAklessCredentialFactory;
|
|
147
|
+
/** Arguments, errors, and resource ownership match the named general provider factory. */
|
|
148
|
+
IDaaSPamAklessCredentialFactory.createTencentCloudCredentialsProvider = createTencentCloudCredentialsProvider;
|
|
149
|
+
/** Arguments, callback error handling, and close semantics match the named COS factory. */
|
|
150
|
+
IDaaSPamAklessCredentialFactory.createTencentCloudCOSCredentialsProvider = createTencentCloudCOSCredentialsProvider;
|
|
151
|
+
//# sourceMappingURL=index.js.map
|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;AACJ,CAAC;AACD;;;;;;;;GAQG;AACH,SAAgB,wCAAwC,CACtD,aAA6C,EAC7C,UAAyD,EAAE,EAC3D,OAAyC;IAEzC,MAAM,QAAQ,GAAG,qCAAqC,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAC/E,MAAM,QAAQ,GAAG,QAAQ,CAAC,qBAAqB,CAAC,OAAO,CAA6B,CAAC;IACrF,QAAQ,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxC,OAAO,QAAQ,CAAC;AAClB,CAAC;AACD,0FAA0F;AAC1F,MAAa,+BAA+B;;AAA5C,0EAKC;AAJC,0FAA0F;AACnF,qEAAqC,GAAG,qCAAqC,CAAC;AACrF,2FAA2F;AACpF,wEAAwC,GAAG,wCAAwC,CAAC","sourcesContent":["import { CredentialException, type IDaaSException, isIDaaSException } from '@cloud-idaas/core-sdk';\nimport {\n type AklessProviderOptions,\n AklessProviderBuilder,\n CachedCloudCredentialProvider,\n type ExpiringCredential,\n credentialExpiration,\n credentialString,\n} from '@cloud-idaas/pam-client-sdk';\n\n/** Generic PAM STS snapshot; expiration is ISO 8601 and tmpSecret fields are renamed at the adapter boundary. */\nexport interface TencentSessionCredentials extends ExpiringCredential {\n secretId: string;\n secretKey: string;\n token: string;\n}\n/** Fields required by Tencent Cloud DynamicCredential.getCredential. */\nexport interface TencentCredential {\n secretId: string;\n secretKey: string;\n token: string;\n}\n/** Temporary credential callback data accepted by cos-nodejs-sdk-v5 3.0.0. */\nexport interface COSCredential {\n TmpSecretId: string;\n TmpSecretKey: string;\n SecurityToken: string;\n /** Zero means the server did not provide an issuance time; COS uses its default time policy. */\n StartTime: number;\n /** Unix seconds; local time must not extend the server-provided expiration. */\n ExpiredTime: number;\n}\n/**\n * Structural COS getAuthorization callback; starts no background I/O before credentials are requested.\n * @param options - Request context supplied by COS; currently unused by this adapter.\n * @param callback - Credential callback that must complete; COS has no separate error argument.\n */\nexport type COSGetAuthorization = (\n options: unknown,\n callback: (value: COSCredential) => void,\n) => void;\n/** COS callback created by an independent factory, with cleanup for the underlying provider. */\nexport interface COSAuthorizationProvider extends COSGetAuthorization {\n /** Closes owned PAM/HTTP resources, leaving the COS client and injected shared sources open. */\n close(): void;\n}\n/**\n * Provides Tencent Cloud DynamicCredential and COS beta integrations on Node.js 20/22/24.\n * @remarks The callback protocol was checked against cos-nodejs-sdk-v5 3.0.0. Inherited getCredentials returns\n * independent STS snapshots. close releases only provider-owned resources; injected PAM, HTTP, and\n * machine credential sources remain caller-owned.\n */\nexport class IDaaSPamTencentCloudCredentialsProvider extends CachedCloudCredentialProvider<TencentSessionCredentials> {\n /** @returns A configuration builder without I/O; STS retrieval starts on first use after build. */\n static builder(): AklessProviderBuilder<IDaaSPamTencentCloudCredentialsProvider> {\n return new AklessProviderBuilder(\n (options) => new IDaaSPamTencentCloudCredentialsProvider(options),\n );\n }\n /**\n * Creates a Tencent Cloud provider without fetching STS credentials.\n * @param options - Required role and optional PAM, HTTP, machine credential source, and cache configuration.\n * @throws ConfigException - The role or configuration is invalid, or the required default factory is not initialized.\n */\n constructor(options: AklessProviderOptions) {\n super(options, (response) => {\n const token = response.tencentCloudStsToken;\n if (!token)\n throw new CredentialException(\n 'Response is missing tencentCloudStsToken',\n 'InvalidCredentialResponse',\n );\n let expiration = credentialExpiration(response, token.expiration);\n if (token.expiredTime !== undefined) {\n if (typeof token.expiredTime !== 'number' || !Number.isFinite(token.expiredTime))\n throw new CredentialException('expiredTime is invalid', 'InvalidExpiration');\n expiration = Math.min(expiration, token.expiredTime * 1000);\n if (!Number.isFinite(expiration) || expiration <= Date.now())\n throw new CredentialException('expiredTime has expired', 'InvalidExpiration');\n }\n return {\n secretId: credentialString(token.tmpSecretId, 'tmpSecretId'),\n secretKey: credentialString(token.tmpSecretKey, 'tmpSecretKey'),\n token: credentialString(token.token, 'token'),\n expiration: new Date(expiration).toISOString(),\n };\n });\n }\n /**\n * Retrieves current credentials for the Tencent Cloud SDK.\n * @returns An independent secretId/secretKey/token snapshot.\n * @throws IDaaSException - Retrieval fails without usable unexpired cached credentials, or the provider is closed.\n */\n async getCredential(): Promise<TencentCredential> {\n const value = await this.getCredentials();\n this.assertAvailable(value);\n return { secretId: value.secretId, secretKey: value.secretKey, token: value.token };\n }\n /**\n * Retrieves COS temporary credentials without inventing a server issuance time.\n * @returns Independent callback data; ExpiredTime uses Unix seconds and StartTime=0 selects the COS default policy.\n * @throws IDaaSException - Retrieval or parsing fails, refresh fails after expiration, or the provider is closed.\n */\n async getCOSCredential(): Promise<COSCredential> {\n const value = await this.getCredentials();\n this.assertAvailable(value);\n return {\n TmpSecretId: value.secretId,\n TmpSecretKey: value.secretKey,\n SecurityToken: value.token,\n StartTime: 0,\n ExpiredTime: Math.floor(Date.parse(value.expiration) / 1000),\n };\n }\n /**\n * Creates a COS getAuthorization callback sharing this provider.\n * @param onError - Optional observer of classified errors; observer exceptions do not prevent COS request completion.\n * @returns A callback sharing the existing cache; the caller must still close this provider.\n * @remarks COS only has a success-data callback. Retrieval failures notify the observer and pass invalid credentials to\n * trigger the official argument-error path, avoiding hung requests without inventing a COS error argument.\n */\n toCOSGetAuthorization(onError?: (error: IDaaSException) => void): COSGetAuthorization {\n const report = (error: unknown) => {\n try {\n onError?.(\n isIDaaSException(error)\n ? error\n : new CredentialException(\n 'COS credential retrieval failed',\n 'CredentialRetrievalFailed',\n ),\n );\n } catch {\n /* Error observers must not prevent request completion. */\n }\n };\n return (_options, callback) => {\n const fail = (error: unknown) => {\n report(error);\n callback({\n TmpSecretId: '',\n TmpSecretKey: '',\n SecurityToken: '',\n StartTime: 0,\n ExpiredTime: 0,\n });\n };\n void this.getCOSCredential()\n .then((value) => {\n try {\n this.assertAvailable({ expiration: new Date(value.ExpiredTime * 1000).toISOString() });\n } catch (error) {\n fail(error);\n return;\n }\n callback(value);\n }, fail)\n .catch(report);\n };\n }\n}\n/**\n * Creates a Tencent Cloud DynamicCredential provider without immediately fetching STS credentials.\n * @param roleOrOptions - Role external ID or complete configuration including the role.\n * @param options - Additional configuration when the first argument is a string; injected sources take precedence.\n * @returns An independent provider; callers must close it after use, with owned and shared resources managed separately.\n * @throws ConfigException - The configuration is invalid or the required default factory is not initialized.\n */\nexport function createTencentCloudCredentialsProvider(\n roleOrOptions: string | AklessProviderOptions,\n options: Omit<AklessProviderOptions, 'roleExternalId'> = {},\n): IDaaSPamTencentCloudCredentialsProvider {\n return new IDaaSPamTencentCloudCredentialsProvider(\n typeof roleOrOptions === 'string'\n ? { ...options, roleExternalId: roleOrOptions }\n : roleOrOptions,\n );\n}\n/**\n * Creates an independent dynamic credential callback for cos-nodejs-sdk-v5 3.0.0.\n * @param roleOrOptions - Role external ID or complete configuration.\n * @param options - Additional configuration when the first argument is a string.\n * @param onError - Optional classified-error observer; its exceptions are isolated and cannot prevent COS request completion.\n * @returns A callback with close; close after use without closing the COS client or shared injected resources.\n * @throws ConfigException - The configuration is invalid or the required default factory is not initialized.\n * @remarks Asynchronous retrieval failures complete through the observer and the COS invalid-credential error path.\n */\nexport function createTencentCloudCOSCredentialsProvider(\n roleOrOptions: string | AklessProviderOptions,\n options: Omit<AklessProviderOptions, 'roleExternalId'> = {},\n onError?: (error: IDaaSException) => void,\n): COSAuthorizationProvider {\n const provider = createTencentCloudCredentialsProvider(roleOrOptions, options);\n const callback = provider.toCOSGetAuthorization(onError) as COSAuthorizationProvider;\n callback.close = () => provider.close();\n return callback;\n}\n/** Tencent Cloud beta convenience factories; do not create SDK or COS service clients. */\nexport class IDaaSPamAklessCredentialFactory {\n /** Arguments, errors, and resource ownership match the named general provider factory. */\n static createTencentCloudCredentialsProvider = createTencentCloudCredentialsProvider;\n /** Arguments, callback error handling, and close semantics match the named COS factory. */\n static createTencentCloudCOSCredentialsProvider = createTencentCloudCOSCredentialsProvider;\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import api from './index.js';
|
|
2
|
+
export const IDaaSPamTencentCloudCredentialsProvider = api.IDaaSPamTencentCloudCredentialsProvider;
|
|
3
|
+
export const IDaaSPamAklessCredentialFactory = api.IDaaSPamAklessCredentialFactory;
|
|
4
|
+
export const createTencentCloudCredentialsProvider = api.createTencentCloudCredentialsProvider;
|
|
5
|
+
export const createTencentCloudCOSCredentialsProvider = api.createTencentCloudCOSCredentialsProvider;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { IDaaSCredentialProviderFactory } = require('@cloud-idaas/core-sdk');
|
|
2
|
+
const { createTencentCloudCredentialsProvider } = require('@cloud-idaas/akless-tencent-adapter');
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
await IDaaSCredentialProviderFactory.init();
|
|
6
|
+
try {
|
|
7
|
+
const provider = createTencentCloudCredentialsProvider(
|
|
8
|
+
process.env.IDAAS_ROLE_EXTERNAL_ID || 'role-id',
|
|
9
|
+
);
|
|
10
|
+
try {
|
|
11
|
+
await provider.getCredential();
|
|
12
|
+
} finally {
|
|
13
|
+
provider.close();
|
|
14
|
+
}
|
|
15
|
+
} finally {
|
|
16
|
+
await IDaaSCredentialProviderFactory.close();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
main().catch((error) => {
|
|
20
|
+
console.error(error instanceof Error ? error.message : 'SDK call failed');
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IDaaSCredentialProviderFactory } from '@cloud-idaas/core-sdk';
|
|
2
|
+
import { createTencentCloudCredentialsProvider } from '@cloud-idaas/akless-tencent-adapter';
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
await IDaaSCredentialProviderFactory.init();
|
|
6
|
+
try {
|
|
7
|
+
const provider = createTencentCloudCredentialsProvider(
|
|
8
|
+
process.env.IDAAS_ROLE_EXTERNAL_ID || 'role-id',
|
|
9
|
+
);
|
|
10
|
+
try {
|
|
11
|
+
await provider.getCredential();
|
|
12
|
+
} finally {
|
|
13
|
+
provider.close();
|
|
14
|
+
}
|
|
15
|
+
} finally {
|
|
16
|
+
await IDaaSCredentialProviderFactory.close();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
main().catch((error) => {
|
|
20
|
+
console.error(error instanceof Error ? error.message : 'SDK call failed');
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IDaaSCredentialProviderFactory } from '@cloud-idaas/core-sdk';
|
|
2
|
+
import { createTencentCloudCredentialsProvider } from '@cloud-idaas/akless-tencent-adapter';
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
await IDaaSCredentialProviderFactory.init();
|
|
6
|
+
try {
|
|
7
|
+
const provider = createTencentCloudCredentialsProvider(
|
|
8
|
+
process.env.IDAAS_ROLE_EXTERNAL_ID || 'role-id',
|
|
9
|
+
);
|
|
10
|
+
try {
|
|
11
|
+
await provider.getCredential();
|
|
12
|
+
} finally {
|
|
13
|
+
provider.close();
|
|
14
|
+
}
|
|
15
|
+
} finally {
|
|
16
|
+
await IDaaSCredentialProviderFactory.close();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
main().catch((error) => {
|
|
20
|
+
console.error(error instanceof Error ? error.message : 'SDK call failed');
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-idaas/akless-tencent-adapter",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "IDaaS akless-tencent-adapter for TypeScript and JavaScript (Node.js)",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"README_zh.md",
|
|
25
|
+
"CHANGELOG.md",
|
|
26
|
+
"examples",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20.0.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -p tsconfig.json && node scripts/build-esm.cjs",
|
|
34
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p test/tsconfig.json",
|
|
35
|
+
"test": "npm run build && nyc mocha --require ./test/register.cjs \"test/**/*.test.{ts,cjs}\"",
|
|
36
|
+
"prepack": "npm run build",
|
|
37
|
+
"lint": "eslint src test",
|
|
38
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.{ts,cjs}\" \"scripts/**/*.{cjs,cts,mts}\" \".github/workflows/*.yml\" \"examples/**/*.{ts,cjs,mjs}\" \"*.{json,cjs,md}\"",
|
|
39
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.{ts,cjs}\" \"scripts/**/*.{cjs,cts,mts}\" \".github/workflows/*.yml\" \"examples/**/*.{ts,cjs,mjs}\" \"*.{json,cjs,md}\"",
|
|
40
|
+
"verify": "npm run check:language && npm run typecheck && npm run lint && npm run format:check && npm test",
|
|
41
|
+
"bootstrap:deps": "node scripts/stage-upstreams.cjs",
|
|
42
|
+
"lock:deps": "node scripts/lock-upstreams.cjs",
|
|
43
|
+
"release:check": "node scripts/release-tools.cjs check",
|
|
44
|
+
"validate:workspace": "node scripts/validate-workspace.cjs",
|
|
45
|
+
"prepublishOnly": "npm run release:check",
|
|
46
|
+
"validate:repository": "node scripts/validate-workspace.cjs --target idaas-typescript-akless-tencent-adapter",
|
|
47
|
+
"check:language": "node scripts/check-language.cjs"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"typescript": "5.9.3",
|
|
51
|
+
"@types/node": "20.17.0",
|
|
52
|
+
"@types/mocha": "10.0.10",
|
|
53
|
+
"mocha": "11.7.5",
|
|
54
|
+
"ts-node": "10.9.2",
|
|
55
|
+
"nyc": "17.1.0",
|
|
56
|
+
"eslint": "10.13.0",
|
|
57
|
+
"@typescript-eslint/parser": "8.71.2",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "8.71.2",
|
|
59
|
+
"prettier": "3.6.2",
|
|
60
|
+
"cos-nodejs-sdk-v5": "3.0.0"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@cloud-idaas/core-sdk": "0.1.0-beta.1",
|
|
64
|
+
"@cloud-idaas/pam-client-sdk": "0.1.0-beta.1"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public",
|
|
68
|
+
"registry": "https://registry.npmjs.org/"
|
|
69
|
+
},
|
|
70
|
+
"repository": {
|
|
71
|
+
"type": "git",
|
|
72
|
+
"url": "https://github.com/cloud-idaas/idaas-typescript-akless-tencent-adapter.git"
|
|
73
|
+
},
|
|
74
|
+
"homepage": "https://github.com/cloud-idaas/idaas-typescript-akless-tencent-adapter#readme",
|
|
75
|
+
"bugs": {
|
|
76
|
+
"url": "https://github.com/cloud-idaas/idaas-typescript-akless-tencent-adapter/issues"
|
|
77
|
+
}
|
|
78
|
+
}
|