提交 ffb900c0 编写于 作者: U u011409356

Tue Mar 19 18:05:00 CST 2024 inscode

上级 8abd2472
{
"version": 3,
"sources": ["../index.ts"],
"sourcesContent": ["const s: string = \"\u6B22\u8FCE\u6765\u5230 InsCode\";\nconsole.log(s);\n"],
"mappings": ";AAAA,MAAM,IAAY;AAClB,QAAQ,IAAI,CAAC;",
"names": []
}
"use strict";
const s = "\u6B22\u8FCE\u6765\u5230 InsCode";
console.log(s);
//# sourceMappingURL=index.js.map
run = "node --enable-source-maps .build/index.js"
run = "node index.ts"
language = "node"
[env]
PATH = "/root/${PROJECT_DIR}/.config/npm/node_global/bin:/root/${PROJECT_DIR}/node_modules/.bin:${PATH}"
XDG_CONFIG_HOME = "/root/.config"
npm_config_prefix = "/root/${PROJECT_DIR}/.config/npm/node_global"
[debugger]
program = "main.js"
const s: string = "欢迎来到 InsCode";
console.log(s);
// This file is auto-generated, don't edit it
// 依赖的模块可通过下载工程中的模块依赖文件或右上角的获取 SDK 依赖信息查看
import Alidns20150109, * as $Alidns20150109 from '@alicloud/alidns20150109';
import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import Util, * as $Util from '@alicloud/tea-util';
import * as $tea from '@alicloud/tea-typescript';
export default class Client {
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
static createClient(): Alidns20150109 {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378664.html。
let config = new $OpenApi.Config({
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'],
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
accessKeySecret: process.env['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
});
// Endpoint 请参考 https://api.aliyun.com/product/Alidns
config.endpoint = `alidns.cn-hangzhou.aliyuncs.com`;
return new Alidns20150109(config);
}
static async main(args: string[]): Promise<void> {
let client = Client.createClient();
let describeDomainsRequest = new $Alidns20150109.DescribeDomainsRequest({ });
let runtime = new $Util.RuntimeOptions({ });
await client.describeDomainsWithOptions(describeDomainsRequest, runtime);
}
}
Client.main(process.argv.slice(2));
\ No newline at end of file
{
"name": "TypeScript",
"lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/@alicloud/alidns20150109": {
"version": "3.1.0",
"resolved": "https://registry.npmmirror.com/@alicloud/alidns20150109/-/alidns20150109-3.1.0.tgz",
"integrity": "sha512-BW4UE4/6FJOcdh+Wg3Fbsiqi+pPNfizZclEQrWZJcK71pFWswO2qf8awavOXdyHvd4yWsCf9DEvz3nyr+w2G+A==",
"dependencies": {
"@alicloud/endpoint-util": "^0.0.1",
"@alicloud/openapi-client": "^0.4.8",
"@alicloud/openapi-util": "^0.3.2",
"@alicloud/tea-typescript": "^1.7.1",
"@alicloud/tea-util": "^1.4.7"
}
},
"node_modules/@alicloud/credentials": {
"version": "2.3.0",
"resolved": "https://registry.npmmirror.com/@alicloud/credentials/-/credentials-2.3.0.tgz",
"integrity": "sha512-x0vf/m1BzkqYXAj2Hkd22O35josx5P4VCzq/9EvTBjA7aGLX/P6JDz7QVp+gnhLjPJyvwAbErvJRYq4gIo4IMA==",
"dependencies": {
"@alicloud/tea-typescript": "^1.5.3",
"httpx": "^2.2.0",
"ini": "^1.3.5",
"kitx": "^2.0.0"
}
},
"node_modules/@alicloud/endpoint-util": {
"version": "0.0.1",
"resolved": "https://registry.npmmirror.com/@alicloud/endpoint-util/-/endpoint-util-0.0.1.tgz",
"integrity": "sha512-+pH7/KEXup84cHzIL6UJAaPqETvln4yXlD9JzlrqioyCSaWxbug5FUobsiI6fuUOpw5WwoB3fWAtGbFnJ1K3Yg==",
"dependencies": {
"@alicloud/tea-typescript": "^1.5.1",
"kitx": "^2.0.0"
}
},
"node_modules/@alicloud/gateway-spi": {
"version": "0.0.8",
"resolved": "https://registry.npmmirror.com/@alicloud/gateway-spi/-/gateway-spi-0.0.8.tgz",
"integrity": "sha512-KM7fu5asjxZPmrz9sJGHJeSU+cNQNOxW+SFmgmAIrITui5hXL2LB+KNRuzWmlwPjnuA2X3/keq9h6++S9jcV5g==",
"dependencies": {
"@alicloud/credentials": "^2",
"@alicloud/tea-typescript": "^1.7.1"
}
},
"node_modules/@alicloud/openapi-client": {
"version": "0.4.8",
"resolved": "https://registry.npmmirror.com/@alicloud/openapi-client/-/openapi-client-0.4.8.tgz",
"integrity": "sha512-l4g+M2i2SIlbTBpEitTac8e64OyESc0xLNf2FwQ5MV4wdEqRYxu8fuSCMVd5dNxhF7HvgvokJDma+WN/a9HLbg==",
"dependencies": {
"@alicloud/credentials": "^2",
"@alicloud/gateway-spi": "^0.0.8",
"@alicloud/openapi-util": "^0.3.2",
"@alicloud/tea-typescript": "^1.7.1",
"@alicloud/tea-util": "^1.4.7",
"@alicloud/tea-xml": "0.0.3"
}
},
"node_modules/@alicloud/openapi-util": {
"version": "0.3.2",
"resolved": "https://registry.npmmirror.com/@alicloud/openapi-util/-/openapi-util-0.3.2.tgz",
"integrity": "sha512-EC2JvxdcOgMlBAEG0+joOh2IB1um8CPz9EdYuRfTfd1uP8Yc9D8QRUWVGjP6scnj6fWSOaHFlit9H6PrJSyFow==",
"dependencies": {
"@alicloud/tea-typescript": "^1.7.1",
"@alicloud/tea-util": "^1.3.0",
"kitx": "^2.1.0",
"sm3": "^1.0.3"
}
},
"node_modules/@alicloud/tea-typescript": {
"version": "1.8.0",
"resolved": "https://registry.npmmirror.com/@alicloud/tea-typescript/-/tea-typescript-1.8.0.tgz",
"integrity": "sha512-CWXWaquauJf0sW30mgJRVu9aaXyBth5uMBCUc+5vKTK1zlgf3hIqRUjJZbjlwHwQ5y9anwcu18r48nOZb7l2QQ==",
"dependencies": {
"@types/node": "^12.0.2",
"httpx": "^2.2.6"
}
},
"node_modules/@alicloud/tea-util": {
"version": "1.4.7",
"resolved": "https://registry.npmmirror.com/@alicloud/tea-util/-/tea-util-1.4.7.tgz",
"integrity": "sha512-Lrpfk9kxihHsit3oMoeIMjk783AxjOvzMhLAbZcIzazKiVg3Zk/209XDe9r1lXqxII59j3V4rhC9X14y6WGYyg==",
"dependencies": {
"@alicloud/tea-typescript": "^1.5.1",
"kitx": "^2.0.0"
}
},
"node_modules/@alicloud/tea-xml": {
"version": "0.0.3",
"resolved": "https://registry.npmmirror.com/@alicloud/tea-xml/-/tea-xml-0.0.3.tgz",
"integrity": "sha512-+/9GliugjrLglsXVrd1D80EqqKgGpyA0eQ6+1ZdUOYCaRguaSwz44trX3PaxPu/HhIPJg9PsGQQ3cSLXWZjbAA==",
"dependencies": {
"@alicloud/tea-typescript": "^1",
"@types/xml2js": "^0.4.5",
"xml2js": "^0.6.0"
}
},
"node_modules/@types/node": {
"version": "12.20.55",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-12.20.55.tgz",
"integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="
},
"node_modules/@types/xml2js": {
"version": "0.4.14",
"resolved": "https://registry.npmmirror.com/@types/xml2js/-/xml2js-0.4.14.tgz",
"integrity": "sha512-4YnrRemBShWRO2QjvUin8ESA41rH+9nQGLUGZV/1IDhi3SL9OhdpNC/MrulTWuptXKwhx/aDxE7toV0f/ypIXQ==",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/httpx": {
"version": "2.3.2",
"resolved": "https://registry.npmmirror.com/httpx/-/httpx-2.3.2.tgz",
"integrity": "sha512-ZG7QArW/BB/opy+XVp/zSJYdiPD9FTmPb3VfMnPdAknKFJq2OiIXS9D4oBeDJvWnZnJAzXDy9J/JKATXkJ7qlw==",
"dependencies": {
"@types/node": "^20",
"debug": "^4.1.1"
}
},
"node_modules/httpx/node_modules/@types/node": {
"version": "20.11.29",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-20.11.29.tgz",
"integrity": "sha512-P99thMkD/1YkCvAtOd6/zGedKNA0p2fj4ZpjCzcNiSCBWgm3cNRTBfa/qjFnsKkkojxu4vVLtWpesnZ9+ap+gA==",
"dependencies": {
"undici-types": "~5.26.4"
}
},
"node_modules/ini": {
"version": "1.3.8",
"resolved": "https://registry.npmmirror.com/ini/-/ini-1.3.8.tgz",
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew=="
},
"node_modules/kitx": {
"version": "2.1.0",
"resolved": "https://registry.npmmirror.com/kitx/-/kitx-2.1.0.tgz",
"integrity": "sha512-C/5v9MtIX7aHGOjwn5BmrrbNkJSf7i0R5mRzmh13GSAdRqQ7bYQo/Su2pTYNylFicqKNTVX3HML9k1u8k51+pQ==",
"dependencies": {
"@types/node": "^12.0.2"
}
},
"node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/sax": {
"version": "1.3.0",
"resolved": "https://registry.npmmirror.com/sax/-/sax-1.3.0.tgz",
"integrity": "sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA=="
},
"node_modules/sm3": {
"version": "1.0.3",
"resolved": "https://registry.npmmirror.com/sm3/-/sm3-1.0.3.tgz",
"integrity": "sha512-KyFkIfr8QBlFG3uc3NaljaXdYcsbRy1KrSfc4tsQV8jW68jAktGeOcifu530Vx/5LC+PULHT0Rv8LiI8Gw+c1g=="
},
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-5.26.5.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
},
"node_modules/xml2js": {
"version": "0.6.2",
"resolved": "https://registry.npmmirror.com/xml2js/-/xml2js-0.6.2.tgz",
"integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==",
"dependencies": {
"sax": ">=0.6.0",
"xmlbuilder": "~11.0.0"
},
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/xmlbuilder": {
"version": "11.0.1",
"resolved": "https://registry.npmmirror.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==",
"engines": {
"node": ">=4.0"
}
}
}
}
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\ No newline at end of file
English | [简体中文](README-CN.md)
![](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg)
# Alibaba Cloud Alidns SDK for NodeJS
## Installation
If you use `npm` to manage your dependence, you can use the following command:
```sh
npm install @alicloud/alidns20150109 -S
```
## Issues
[Opening an Issue](https://github.com/aliyun/alibabacloud-typescript-sdk/issues/new), Issues not conforming to the guidelines may be closed immediately.
## Usage
[Usage Document](https://github.com/aliyun/alibabacloud-typescript-sdk/blob/master/docs/Usage-EN.md#quick-examples)
## References
* [Latest Release](https://github.com/aliyun/alibabacloud-typescript-sdk/)
## License
[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
此差异已折叠。
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
{
"name": "@alicloud/alidns20150109",
"version": "3.1.0",
"description": "",
"main": "dist/client.js",
"scripts": {
"test": "mocha --reporter spec --timeout 3000 test/*.test.js",
"test-cov": "nyc -e .ts -r=html -r=text -r=lcov npm run test",
"build": "tsc",
"prepublishOnly": "tsc"
},
"author": "Alibaba Cloud SDK",
"license": "Apache-2.0",
"devDependencies": {
"@types/node": "^12.12.26",
"nyc": "^15.0.0",
"source-map-support": "^0.5.16",
"ts-node": "^8.6.2",
"typescript": "^3.7.5"
},
"dependencies": {
"@alicloud/tea-typescript": "^1.7.1",
"@alicloud/tea-util": "^1.4.7",
"@alicloud/openapi-client": "^0.4.8",
"@alicloud/openapi-util": "^0.3.2",
"@alicloud/endpoint-util": "^0.0.1"
},
"files": [
"dist",
"src"
]
}
\ No newline at end of file
此差异已折叠。
MIT License
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
English | [简体中文](README-CN.md)
# Alibaba Cloud Credentials for TypeScript/Node.js
[![npm version](https://badge.fury.io/js/@alicloud%2fcredentials.svg)](https://www.npmjs.com/package/@alicloud/credentials)
[![NodeJS](https://github.com/aliyun/credentials-nodejs/actions/workflows/cli.yml/badge.svg)](https://github.com/aliyun/credentials-nodejs/actions/workflows/cli.yml)
[![codecov](https://codecov.io/gh/aliyun/credentials-nodejs/branch/master/graph/badge.svg)](https://codecov.io/gh/aliyun/credentials-nodejs)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)
## Installation
```bash
npm install @alicloud/credentials
```
**Node.js >= 8.5.0** required.
## Quick Examples
Before you begin, you need to sign up for an Alibaba Cloud account and retrieve your [Credentials](https://usercenter.console.aliyun.com/#/manage/ak).
### Credential Type
#### access_key
Setup access_key credential through [User Information Management][ak], it have full authority over the account, please keep it safe. Sometimes for security reasons, you cannot hand over a primary account AccessKey with full access to the developer of a project. You may create a sub-account [RAM Sub-account][ram] , grant its [authorization][permissions],and use the AccessKey of RAM Sub-account.
```ts
import Credential, { Config } from '@alicloud/credentials';
const config: Config = {
type: 'access_key', // credential type
accessKeyId: 'accessKeyId', // AccessKeyId of your account
accessKeySecret: 'accessKeySecret', // AccessKeySecret of your account
}
const cred = new Credential(config);
let accessKeyId: string = await cred.getAccessKeyId();
let accessKeySecret: string = await cred.getAccessKeySecret();
let type: string = cred.getType();
```
#### sts
Create a temporary security credential by applying Temporary Security Credentials (TSC) through the Security Token Service (STS).
```ts
import Credential, { Config } from '@alicloud/credentials';
const config: Config = {
type: 'sts', // credential type
accessKeyId: 'accessKeyId', // AccessKeyId of your account
accessKeySecret: 'accessKeySecret', // AccessKeySecret of your account
securityToken: 'securityToken', // Temporary Security Token
}
const cred = new Credential(config);
let accessKeyId: string = await cred.getAccessKeyId();
let accessKeySecret: string = await cred.getAccessKeySecret();
let type: string = cred.getType();
```
#### ram_role_arn
By specifying [RAM Role][RAM Role], the credential will be able to automatically request maintenance of STS Token. If you want to limit the permissions([How to make a policy][policy]) of STS Token, you can assign value for `Policy`.
```ts
import Credential, { Config } from '@alicloud/credentials';
const config: Config = {
type: 'ram_role_arn', // credential type
accessKeyId: 'accessKeyId', // AccessKeyId of your account
accessKeySecret: 'accessKeySecret', // AccessKeySecret of your account
roleArn: 'roleArn', // Format: acs:ram::USER_ID:role/ROLE_NAME
roleSessionName: 'roleSessionName', // Role Session Name
policy: 'policy', // Not required, limit the permissions of STS Token
roleSessionExpiration: 3600, // Not required, limit the Valid time of STS Token
}
const cred = new Credential(config);
let accessKeyId: string = await cred.getAccessKeyId();
let accessKeySecret: string = await cred.getAccessKeySecret();
let securityToken: string = await cred.getSecurityToken();
let type: string = cred.getType();
```
#### oidc_role_arn
By specifying [OIDC Role][OIDC Role], the credential will be able to automatically request maintenance of STS Token. If you want to limit the permissions([How to make a policy][policy]) of STS Token, you can assign value for `Policy`.
```ts
import Credential, { Config } from '@alicloud/credentials';
const config: Config = {
type: 'oidc_role_arn', // credential type
roleArn: 'roleArn', // Format: acs:ram::USER_Id:role/ROLE_NAME roleArn can be replaced by setting environment variable: ALIBABA_CLOUD_ROLE_ARN
oidcProviderArn: 'oidcProviderArn', // Format: acs:ram::USER_Id:oidc-provider/ROLE_NAME oidcProviderArn can be replaced by setting environment variable: ALIBABA_CLOUD_OIDC_PROVIDER_ARN
oidcTokenFilePath: '/Users/xxx/xxx', // Format: path OIDCTokenFilePath can be replaced by setting environment variable: ALIBABA_CLOUD_OIDC_TOKEN_FILE
roleSessionName: 'roleSessionName', // Role Session Name
policy: 'policy', // Not required, limit the permissions of STS Token
roleSessionExpiration: 3600, // Not required, limit the Valid time of STS Token
}
const cred = new Credential(config);
let accessKeyId: string = await cred.getAccessKeyId();
let accessKeySecret: string = await cred.getAccessKeySecret();
let securityToken: string = await cred.getSecurityToken();
let type: string = cred.getType();
```
#### ecs_ram_role
By specifying the role name, the credential will be able to automatically request maintenance of STS Token.
```ts
import Credential, { Config } from '@alicloud/credentials';
const config: Config = {
type: 'ecs_ram_role', // credential type
roleName: 'roleName', // `roleName` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests.
}
const cred = new Credential(config);
let accessKeyId: string = await cred.getAccessKeyId();
let accessKeySecret: string = await cred.getAccessKeySecret();
let securityToken: string = await cred.getSecurityToken();
let type: string = cred.getType();
```
#### rsa_key_pair
By specifying the public key ID and the private key file, the credential will be able to automatically request maintenance of the AccessKey before sending the request. Only Japan station is supported.
```ts
import Credential, { Config } from '@alicloud/credentials';
const config: Config = {
type: 'rsa_key_pair', // credential type
privateKeyFile: 'privateKeyFile', // The file path to store the PrivateKey
publicKeyId: 'publicKeyId', // PublicKeyId of your account
}
const cred = new Credential(config);
let accessKeyId: string = await cred.getAccessKeyId();
let accessKeySecret: string = await cred.getAccessKeySecret();
let securityToken: string = await cred.getSecurityToken();
let type: string = cred.getType();
```
#### credentials_uri
By specifying a local or remote URI to get credentials and refresh automanticly.
```ts
import Credential, { Config } from '@alicloud/credentials';
const config: Config = {
type: 'credentials_uri',
credentialsURI: 'http://a_local_or_remote_address/' //credentialsURI can be replaced by setting environment variable: ALIBABA_CLOUD_CREDENTIALS_URI
};
const cred = new Credential(config);
let accessKeyId: string = await cred.getAccessKeyId();
let accessKeySecret: string = await cred.getAccessKeySecret();
let securityToken: string = await cred.getSecurityToken();
let type: string = cred.getType();
```
The URI must reponse meets following conditions:
- response status code is 200
- response body struct must be:
```json
{
"Code": "Success",
"AccessKeySecret": "AccessKeySecret",
"AccessKeyId": "AccessKeyId",
"Expiration": "2021-09-26T03:46:38Z",
"SecurityToken": "SecurityToken"
}
```
#### bearer
If credential is required by the Cloud Call Centre (CCC), please apply for Bearer Token maintenance by yourself.
```ts
import Credential, { Config } from '@alicloud/credentials';
const config: Config = {
type: 'bearer', // credential type
bearerToken: 'bearerToken', // BearerToken of your account
}
const cred = new Credential(config);
let bearerToken: string = await cred.getBearerToken();
let type: string = cred.getType();
```
### Provider
If you call `new Credential()` with empty, it will use provider chain to get credential for you.
#### 1. Environment Credentials
The program first looks for environment credentials in the environment variable. If the `ALIBABA_CLOUD_ACCESS_KEY_ID` and `ALIBABA_CLOUD_ACCESS_KEY_SECRET` environment variables are defined and are not empty, the program will use them to create the default credential. If not, the program loads and looks for the client in the configuration file.
#### 2. Config File
If there is `~/.alibabacloud/credentials` default file (Windows shows `C:\Users\USER_NAME\.alibabacloud\credentials`), the program will automatically create credential with the name of 'default'. The default file may not exist, but a parse error throws an exception. The specified files can also be loaded indefinitely: `AlibabaCloud::load('/data/credentials', 'vfs://AlibabaCloud/credentials', ...);` This configuration file can be shared between different projects and between different tools. Because it is outside the project and will not be accidentally committed to the version control. Environment variables can be used on Windows to refer to the home directory %UserProfile%. Unix-like systems can use the environment variable $HOME or ~ (tilde). The path to the default file can be modified by defining the `ALIBABA_CLOUD_CREDENTIALS_FILE` environment variable.
```ini
[default] # Default credential
type = access_key # Certification type: access_key
access_key_id = foo # access key id
access_key_secret = bar # access key secret
```
#### 3. Instance RAM Role
If the environment variable `ALIBABA_CLOUD_ECS_METADATA` is defined and not empty, the program will take the value of the environment variable as the role name and request `http://100.100.100.200/latest/meta-data/ram/security-credentials/` to get the temporary Security credential.
#### 4. Credentials URI
If the environment variable `ALIBABA_CLOUD_CREDENTIALS_URI` is defined and not empty,
the program will take the value of the environment variable as the credentials uri.
## Test & Coverage
- run test
```
npm run test
```
- run code coverage
```
npm run cov
```
## License
[MIT](LICENSE)
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
[ak]: https://usercenter.console.aliyun.com/#/manage/ak
[ram]: https://ram.console.aliyun.com/users
[permissions]: https://ram.console.aliyun.com/permissions
[RAM Role]: https://ram.console.aliyun.com/#/role/list
{
"name": "@alicloud/credentials",
"version": "2.3.0",
"description": "alibaba cloud node.js sdk credentials",
"main": "dist/src/client.js",
"scripts": {
"prepublishOnly": "tsc",
"build": "tsc",
"lint": "eslint --fix ./src --ext .ts",
"test": "mocha -b -r ts-node/register test/**/*.test.ts test/*.test.ts --timeout 15000",
"cov": "nyc -e .ts -r=html -r=text -r=lcov npm run test",
"ci": "npm run cov",
"test-integration": "mocha -b -r ts-node/register -R spec test/*.integration.ts",
"clean": "rm -rf coverage"
},
"repository": {
"type": "git",
"url": "git+https://github.com/aliyun/nodejs-credentials.git"
},
"keywords": [
"alibaba cloud",
"sdk",
"credentials"
],
"author": "Alibaba Cloud SDK",
"license": "MIT",
"devDependencies": {
"@types/expect.js": "^0.3.29",
"@types/ini": "^1.3.30",
"@types/mocha": "^7.0.1",
"@types/rewire": "^2.5.28",
"@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2",
"eslint": "^7.32.0",
"expect.js": "^0.3.1",
"mm": "^2.4.1",
"mocha": "^10.1.0",
"nyc": "^13.1.0",
"rewire": "^4.0.1",
"ts-node": "^8.6.2",
"typescript": "^3.7.5"
},
"dependencies": {
"@alicloud/tea-typescript": "^1.5.3",
"httpx": "^2.2.0",
"ini": "^1.3.5",
"kitx": "^2.0.0"
},
"bugs": {
"url": "https://github.com/aliyun/nodejs-credentials/issues"
},
"homepage": "https://github.com/aliyun/nodejs-credentials#readme",
"files": [
"src",
"dist"
]
}
import DefaultCredential from './default_credential';
import ICredential from './icredential';
export default class AccessKeyCredential extends DefaultCredential implements ICredential {
constructor(accessKeyId: string, accessKeySecret: string);
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const default_credential_1 = __importDefault(require("./default_credential"));
const config_1 = __importDefault(require("./config"));
class AccessKeyCredential extends default_credential_1.default {
constructor(accessKeyId, accessKeySecret) {
if (!accessKeyId) {
throw new Error('Missing required accessKeyId option in config for access_key');
}
if (!accessKeySecret) {
throw new Error('Missing required accessKeySecret option in config for access_key');
}
const conf = new config_1.default({
type: 'access_key',
accessKeyId,
accessKeySecret
});
super(conf);
}
}
exports.default = AccessKeyCredential;
//# sourceMappingURL=access_key_credential.js.map
\ No newline at end of file
{"version":3,"file":"access_key_credential.js","sourceRoot":"","sources":["../../src/access_key_credential.ts"],"names":[],"mappings":";;;;;AAAA,8EAAqD;AAErD,sDAA8B;AAE9B,MAAqB,mBAAoB,SAAQ,4BAAiB;IAChE,YAAY,WAAmB,EAAE,eAAuB;QACtD,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;SACjF;QAED,IAAI,CAAC,eAAe,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;SACrF;QACD,MAAM,IAAI,GAAG,IAAI,gBAAM,CAAC;YACtB,IAAI,EAAE,YAAY;YAClB,WAAW;YACX,eAAe;SAChB,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;CACF;AAhBD,sCAgBC"}
\ No newline at end of file
import DefaultCredential from './default_credential';
import ICredential from './icredential';
export default class BearerTokenCredential extends DefaultCredential implements ICredential {
constructor(bearerToken: string);
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const default_credential_1 = __importDefault(require("./default_credential"));
const config_1 = __importDefault(require("./config"));
class BearerTokenCredential extends default_credential_1.default {
constructor(bearerToken) {
if (!bearerToken) {
throw new Error('Missing required bearerToken option in config for bearer');
}
const conf = new config_1.default({
type: 'bearer'
});
super(conf);
this.bearerToken = bearerToken;
}
}
exports.default = BearerTokenCredential;
//# sourceMappingURL=bearer_token_credential.js.map
\ No newline at end of file
{"version":3,"file":"bearer_token_credential.js","sourceRoot":"","sources":["../../src/bearer_token_credential.ts"],"names":[],"mappings":";;;;;AAAA,8EAAqD;AAErD,sDAA8B;AAE9B,MAAqB,qBAAsB,SAAQ,4BAAiB;IAElE,YAAY,WAAmB;QAC7B,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;SAC7E;QACD,MAAM,IAAI,GAAG,IAAI,gBAAM,CAAC;YACtB,IAAI,EAAE,QAAQ;SACf,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF;AAZD,wCAYC"}
\ No newline at end of file
import ICredential from './icredential';
import Config from './config';
import CredentialModel from './credential_model';
export { Config };
export default class Credential implements ICredential {
credential: ICredential;
constructor(config?: Config, runtime?: {
[key: string]: any;
});
getAccessKeyId(): Promise<string>;
getAccessKeySecret(): Promise<string>;
getSecurityToken(): Promise<string>;
getBearerToken(): string;
getType(): string;
getCredential(): Promise<CredentialModel>;
private load;
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Config = void 0;
const access_key_credential_1 = __importDefault(require("./access_key_credential"));
const sts_token_credential_1 = __importDefault(require("./sts_token_credential"));
const ecs_ram_role_credential_1 = __importDefault(require("./ecs_ram_role_credential"));
const ram_role_arn_credential_1 = __importDefault(require("./ram_role_arn_credential"));
const oidc_role_arn_credential_1 = __importDefault(require("./oidc_role_arn_credential"));
const rsa_key_pair_credential_1 = __importDefault(require("./rsa_key_pair_credential"));
const bearer_token_credential_1 = __importDefault(require("./bearer_token_credential"));
const DefaultProvider = __importStar(require("./provider/provider_chain"));
const config_1 = __importDefault(require("./config"));
exports.Config = config_1.default;
const uri_credential_1 = __importDefault(require("./uri_credential"));
class Credential {
constructor(config = null, runtime = {}) {
this.load(config, runtime);
}
getAccessKeyId() {
return this.credential.getAccessKeyId();
}
getAccessKeySecret() {
return this.credential.getAccessKeySecret();
}
getSecurityToken() {
return this.credential.getSecurityToken();
}
getBearerToken() {
return this.credential.getBearerToken();
}
getType() {
return this.credential.getType();
}
getCredential() {
return this.credential.getCredential();
}
load(config, runtime) {
if (!config) {
this.credential = DefaultProvider.getCredentials();
return;
}
if (!config.type) {
throw new Error('Missing required type option');
}
switch (config.type) {
case 'access_key':
this.credential = new access_key_credential_1.default(config.accessKeyId, config.accessKeySecret);
break;
case 'sts':
this.credential = new sts_token_credential_1.default(config.accessKeyId, config.accessKeySecret, config.securityToken);
break;
case 'ecs_ram_role':
this.credential = new ecs_ram_role_credential_1.default(config.roleName);
break;
case 'ram_role_arn':
this.credential = new ram_role_arn_credential_1.default(config, runtime);
break;
case 'oidc_role_arn':
this.credential = new oidc_role_arn_credential_1.default(config, runtime);
break;
case 'rsa_key_pair':
this.credential = new rsa_key_pair_credential_1.default(config.publicKeyId, config.privateKeyFile);
break;
case 'bearer':
this.credential = new bearer_token_credential_1.default(config.bearerToken);
break;
case 'credentials_uri':
this.credential = new uri_credential_1.default(config.credentialsURI);
break;
default:
throw new Error('Invalid type option, support: access_key, sts, ecs_ram_role, ram_role_arn, rsa_key_pair, credentials_uri');
}
}
}
exports.default = Credential;
//# sourceMappingURL=client.js.map
\ No newline at end of file
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAEA,oFAA0D;AAC1D,kFAAwD;AACxD,wFAA6D;AAC7D,wFAA6D;AAC7D,0FAA8D;AAC9D,wFAA6D;AAC7D,wFAA8D;AAC9D,2EAA6D;AAC7D,sDAA8B;AAIrB,iBAJF,gBAAM,CAIE;AAHf,sEAA6C;AAK7C,MAAqB,UAAU;IAE7B,YAAY,SAAiB,IAAI,EAAE,UAAkC,EAAE;QACrE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC;IAC1C,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,kBAAkB,EAAE,CAAC;IAC9C,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;IAC5C,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC;IAC1C,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC;IACzC,CAAC;IAEO,IAAI,CAAC,MAAc,EAAE,OAA+B;QAC1D,IAAI,CAAC,MAAM,EAAE;YACX,IAAI,CAAC,UAAU,GAAG,eAAe,CAAC,cAAc,EAAE,CAAC;YACnD,OAAO;SACR;QAED,IAAI,CAAC,MAAM,CA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tea-typescript';
export default class Config extends $tea.Model {
accessKeyId?: string;
accessKeySecret?: string;
securityToken?: string;
bearerToken?: string;
durationSeconds?: number;
roleArn?: string;
policy?: string;
roleSessionExpiration?: number;
roleSessionName?: string;
publicKeyId?: string;
privateKeyFile?: string;
roleName?: string;
credentialsURI?: string;
oidcProviderArn: string;
oidcTokenFilePath: string;
type?: string;
static names(): {
[key: string]: string;
};
static types(): {
[key: string]: any;
};
constructor(config?: {
[key: string]: any;
});
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const $tea = __importStar(require("@alicloud/tea-typescript"));
class Config extends $tea.Model {
constructor(config) {
super(config);
}
static names() {
return {
accessKeyId: 'accessKeyId',
accessKeySecret: 'accessKeySecret',
securityToken: 'securityToken',
bearerToken: 'bearerToken',
durationSeconds: 'durationSeconds',
roleArn: 'roleArn',
policy: 'policy',
roleSessionExpiration: 'roleSessionExpiration',
roleSessionName: 'roleSessionName',
publicKeyId: 'publicKeyId',
privateKeyFile: 'privateKeyFile',
roleName: 'roleName',
credentialsURI: 'credentialsURI',
oidcProviderArn: 'oidcProviderArn',
oidcTokenFilePath: 'oidcTokenFilePath',
type: 'type',
};
}
static types() {
return {
accessKeyId: 'string',
accessKeySecret: 'string',
securityToken: 'string',
bearerToken: 'string',
durationSeconds: 'number',
roleArn: 'string',
policy: 'string',
roleSessionExpiration: 'number',
roleSessionName: 'string',
publicKeyId: 'string',
privateKeyFile: 'string',
roleName: 'string',
credentialsURI: 'string',
oidcProviderArn: 'string',
oidcTokenFilePath: 'string',
type: 'string',
};
}
}
exports.default = Config;
//# sourceMappingURL=config.js.map
\ No newline at end of file
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+DAAiD;AAEjD,MAAqB,MAAO,SAAQ,IAAI,CAAC,KAAK;IA4D5C,YAAY,MAA+B;QACzC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IA5CD,MAAM,CAAC,KAAK;QACV,OAAO;YACL,WAAW,EAAE,aAAa;YAC1B,eAAe,EAAE,iBAAiB;YAClC,aAAa,EAAE,eAAe;YAC9B,WAAW,EAAE,aAAa;YAC1B,eAAe,EAAE,iBAAiB;YAClC,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,QAAQ;YAChB,qBAAqB,EAAE,uBAAuB;YAC9C,eAAe,EAAE,iBAAiB;YAClC,WAAW,EAAE,aAAa;YAC1B,cAAc,EAAE,gBAAgB;YAChC,QAAQ,EAAE,UAAU;YACpB,cAAc,EAAE,gBAAgB;YAChC,eAAe,EAAE,iBAAiB;YAClC,iBAAiB,EAAE,mBAAmB;YACtC,IAAI,EAAE,MAAM;SACb,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK;QACV,OAAO;YACL,WAAW,EAAE,QAAQ;YACrB,eAAe,EAAE,QAAQ;YACzB,aAAa,EAAE,QAAQ;YACvB,WAAW,EAAE,QAAQ;YACrB,eAAe,EAAE,QAAQ;YACzB,OAAO,EAAE,QAAQ;YACjB,MAAM,EAAE,QAAQ;YAChB,qBAAqB,EAAE,QAAQ;YAC/B,eAAe,EAAE,QAAQ;YACzB,WAAW,EAAE,QAAQ;YACrB,cAAc,EAAE,QAAQ;YACxB,QAAQ,EAAE,QAAQ;YAClB,cAAc,EAAE,QAAQ;YACxB,eAAe,EAAE,QAAQ;YACzB,iBAAiB,EAAE,QAAQ;YAC3B,IAAI,EAAE,QAAQ;SACf,CAAC;IACJ,CAAC;CAKF;AA/DD,yBA+DC"}
\ No newline at end of file
import * as $tea from '@alicloud/tea-typescript';
export default class CredentialModel extends $tea.Model {
accessKeyId?: string;
accessKeySecret?: string;
securityToken?: string;
bearerToken?: string;
type?: string;
static names(): {
[key: string]: string;
};
static types(): {
[key: string]: any;
};
constructor(map?: {
[key: string]: any;
});
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const $tea = __importStar(require("@alicloud/tea-typescript"));
class CredentialModel extends $tea.Model {
constructor(map) {
super(map);
}
static names() {
return {
accessKeyId: 'accessKeyId',
accessKeySecret: 'accessKeySecret',
securityToken: 'securityToken',
bearerToken: 'bearerToken',
type: 'type',
};
}
static types() {
return {
accessKeyId: 'string',
accessKeySecret: 'string',
securityToken: 'string',
bearerToken: 'string',
type: 'string',
};
}
}
exports.default = CredentialModel;
//# sourceMappingURL=credential_model.js.map
\ No newline at end of file
{"version":3,"file":"credential_model.js","sourceRoot":"","sources":["../../src/credential_model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+DAAiD;AAEjD,MAAqB,eAAgB,SAAQ,IAAI,CAAC,KAAK;IA0BrD,YAAY,GAA4B;QACtC,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAtBD,MAAM,CAAC,KAAK;QACV,OAAO;YACL,WAAW,EAAE,aAAa;YAC1B,eAAe,EAAE,iBAAiB;YAClC,aAAa,EAAE,eAAe;YAC9B,WAAW,EAAE,aAAa;YAC1B,IAAI,EAAE,MAAM;SACb,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK;QACV,OAAO;YACL,WAAW,EAAE,QAAQ;YACrB,eAAe,EAAE,QAAQ;YACzB,aAAa,EAAE,QAAQ;YACvB,WAAW,EAAE,QAAQ;YACrB,IAAI,EAAE,QAAQ;SACf,CAAC;IACJ,CAAC;CAKF;AA7BD,kCA6BC"}
\ No newline at end of file
import Config from './config';
import CredentialModel from './credential_model';
import ICredential from './icredential';
export default class DefaultCredential implements ICredential {
accessKeyId: string;
accessKeySecret: string;
securityToken?: string;
bearerToken?: string;
type: string;
constructor(config: Config);
getAccessKeyId(): Promise<string>;
getAccessKeySecret(): Promise<string>;
getSecurityToken(): Promise<string>;
getBearerToken(): string;
getType(): string;
getCredential(): Promise<CredentialModel>;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const credential_model_1 = __importDefault(require("./credential_model"));
class DefaultCredential {
constructor(config) {
this.accessKeyId = config.accessKeyId || '';
this.accessKeySecret = config.accessKeySecret || '';
this.securityToken = config.securityToken || '';
this.bearerToken = config.bearerToken || '';
this.type = config.type || '';
}
async getAccessKeyId() {
return this.accessKeyId;
}
async getAccessKeySecret() {
return this.accessKeySecret;
}
async getSecurityToken() {
return this.securityToken;
}
getBearerToken() {
return this.bearerToken;
}
getType() {
return this.type;
}
async getCredential() {
return new credential_model_1.default({
accessKeyId: this.accessKeyId,
accessKeySecret: this.accessKeySecret,
securityToken: this.securityToken,
bearerToken: this.bearerToken,
type: this.type,
});
}
}
exports.default = DefaultCredential;
//# sourceMappingURL=default_credential.js.map
\ No newline at end of file
{"version":3,"file":"default_credential.js","sourceRoot":"","sources":["../../src/default_credential.ts"],"names":[],"mappings":";;;;;AACA,0EAAiD;AAGjD,MAAqB,iBAAiB;IAOpC,YAAY,MAAc;QACxB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC;QAC5C,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,EAAE,CAAC;QACpD,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,IAAI,EAAE,CAAC;QAChD,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,OAAO,IAAI,0BAAe,CAAC;YACzB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;CACF;AA5CD,oCA4CC"}
\ No newline at end of file
import SessionCredential from './session_credential';
import ICredential from './icredential';
export default class EcsRamRoleCredential extends SessionCredential implements ICredential {
roleName: string;
runtime: {
[key: string]: any;
};
constructor(roleName?: string, runtime?: {
[key: string]: any;
});
getBody(url: string): Promise<string>;
updateCredential(): Promise<void>;
getRoleName(): Promise<string>;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const session_credential_1 = __importDefault(require("./session_credential"));
const httpx_1 = __importDefault(require("httpx"));
const config_1 = __importDefault(require("./config"));
const SECURITY_CRED_URL = 'http://100.100.100.200/latest/meta-data/ram/security-credentials/';
class EcsRamRoleCredential extends session_credential_1.default {
constructor(roleName = '', runtime = {}) {
const conf = new config_1.default({
type: 'ecs_ram_role',
});
super(conf);
this.roleName = roleName;
this.runtime = runtime;
this.sessionCredential = null;
}
async getBody(url) {
const response = await httpx_1.default.request(url, {});
return (await httpx_1.default.read(response, 'utf8'));
}
async updateCredential() {
const roleName = await this.getRoleName();
const url = SECURITY_CRED_URL + roleName;
const body = await this.getBody(url);
const json = JSON.parse(body);
this.sessionCredential = {
AccessKeyId: json.AccessKeyId,
AccessKeySecret: json.AccessKeySecret,
Expiration: json.Expiration,
SecurityToken: json.SecurityToken,
};
}
async getRoleName() {
if (this.roleName && this.roleName.length) {
return this.roleName;
}
return await this.getBody(SECURITY_CRED_URL);
}
}
exports.default = EcsRamRoleCredential;
//# sourceMappingURL=ecs_ram_role_credential.js.map
\ No newline at end of file
{"version":3,"file":"ecs_ram_role_credential.js","sourceRoot":"","sources":["../../src/ecs_ram_role_credential.ts"],"names":[],"mappings":";;;;;AAAA,8EAAqD;AACrD,kDAA0B;AAE1B,sDAA8B;AAE9B,MAAM,iBAAiB,GAAG,mEAAmE,CAAC;AAE9F,MAAqB,oBAAqB,SAAQ,4BAAiB;IAIjE,YAAY,WAAmB,EAAE,EAAE,UAAkC,EAAE;QACrE,MAAM,IAAI,GAAG,IAAI,gBAAM,CAAC;YACtB,IAAI,EAAE,cAAc;SACrB,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW;QACvB,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC9C,OAAO,CAAC,MAAM,eAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAW,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,iBAAiB,GAAG,QAAQ,CAAC;QACzC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,iBAAiB,GAAG;YACvB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,WAAW;QACf,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;YACzC,OAAO,IAAI,CAAC,QAAQ,CAAC;SACtB;QAED,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC/C,CAAC;CACF;AAvCD,uCAuCC"}
\ No newline at end of file
import CredentialModel from "./credential_model";
export default interface ICredential {
getAccessKeyId: () => Promise<string>;
getAccessKeySecret: () => Promise<string>;
getSecurityToken: () => Promise<string>;
getBearerToken: () => string;
getType: () => string;
getCredential: () => Promise<CredentialModel>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=icredential.js.map
\ No newline at end of file
{"version":3,"file":"icredential.js","sourceRoot":"","sources":["../../src/icredential.ts"],"names":[],"mappings":""}
\ No newline at end of file
import SessionCredential from './session_credential';
import Config from './config';
export default class OidcRoleArnCredential extends SessionCredential {
roleArn: string;
oidcProviderArn: string;
oidcTokenFilePath: string;
policy: string;
durationSeconds: number;
roleSessionName: string;
runtime: {
[key: string]: any;
};
host: string;
constructor(config: Config, runtime?: {
[key: string]: any;
});
private getOdicToken;
updateCredential(): Promise<void>;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const session_credential_1 = __importDefault(require("./session_credential"));
const http_1 = require("./util/http");
const config_1 = __importDefault(require("./config"));
const fs_1 = __importDefault(require("fs"));
class OidcRoleArnCredential extends session_credential_1.default {
constructor(config, runtime = {}) {
if (!config.roleArn) {
config.roleArn = process.env.ALIBABA_CLOUD_ROLE_ARN;
if (!config.roleArn) {
throw new Error('roleArn does not exist and env ALIBABA_CLOUD_ROLE_ARN is null.');
}
}
if (!config.oidcProviderArn) {
config.oidcProviderArn = process.env.ALIBABA_CLOUD_OIDC_PROVIDER_ARN;
if (!config.oidcProviderArn) {
throw new Error('oidcProviderArn does not exist and env ALIBABA_CLOUD_OIDC_PROVIDER_ARN is null.');
}
}
if (!config.oidcTokenFilePath) {
config.oidcTokenFilePath = process.env.ALIBABA_CLOUD_OIDC_TOKEN_FILE;
if (!config.oidcTokenFilePath) {
throw new Error('oidcTokenFilePath is not exists and env ALIBABA_CLOUD_OIDC_TOKEN_FILE is null.');
}
}
if (!config.roleSessionName && process.env.ALIBABA_CLOUD_ROLE_SESSION_NAME) {
config.roleSessionName = process.env.ALIBABA_CLOUD_ROLE_SESSION_NAME;
}
const conf = new config_1.default({
type: 'oidc_role_arn'
});
super(conf);
this.oidcTokenFilePath = config.oidcTokenFilePath;
this.roleArn = config.roleArn;
this.policy = config.policy;
this.oidcProviderArn = config.oidcProviderArn;
this.durationSeconds = config.roleSessionExpiration || 3600;
this.roleSessionName = config.roleSessionName || 'role_session_name';
runtime.method = 'POST';
runtime.anonymous = true;
this.runtime = runtime;
this.host = 'https://sts.aliyuncs.com';
}
getOdicToken(oidcTokenFilePath) {
if (!fs_1.default.existsSync(oidcTokenFilePath)) {
throw new Error(`oidcTokenFilePath ${oidcTokenFilePath} is not exists.`);
}
let oidcToken = null;
try {
oidcToken = fs_1.default.readFileSync(oidcTokenFilePath, 'utf-8');
}
catch (err) {
throw new Error(`oidcTokenFilePath ${oidcTokenFilePath} cannot be read.`);
}
return oidcToken;
}
async updateCredential() {
const oidcToken = this.getOdicToken(this.oidcTokenFilePath);
const params = {
Action: 'AssumeRoleWithOIDC',
RoleArn: this.roleArn,
OIDCProviderArn: this.oidcProviderArn,
OIDCToken: oidcToken,
DurationSeconds: this.durationSeconds,
RoleSessionName: this.roleSessionName
};
if (this.policy) {
params.policy = this.policy;
}
const json = await http_1.request(this.host, params, this.runtime);
this.sessionCredential = json.Credentials;
}
}
exports.default = OidcRoleArnCredential;
//# sourceMappingURL=oidc_role_arn_credential.js.map
\ No newline at end of file
{"version":3,"file":"oidc_role_arn_credential.js","sourceRoot":"","sources":["../../src/oidc_role_arn_credential.ts"],"names":[],"mappings":";;;;;AAAA,8EAAqD;AACrD,sCAAsC;AACtC,sDAA8B;AAC9B,4CAAoB;AAEpB,MAAqB,qBAAsB,SAAQ,4BAAiB;IAUlE,YAAY,MAAc,EAAE,UAAkC,EAAE;QAC9D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;YACnB,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;YACpD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;gBACnB,MAAM,IAAI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AAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;IAEO,YAAY,CAAC,iBAAyB;QAC5C,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,qBAAqB,iBAAiB,kBAAkB,CAAC,CAAC;SAC3E;QACD,IAAI,SAAS,GAAG,IAAI,CAAC;QACrB,IAAI;YACF,SAAS,GAAG,YAAE,CAAC,YAAY,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;SACzD;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,qBAAqB,iBAAiB,kBAAkB,CAAC,CAAC;SAC3E;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC5D,MAAM,MAAM,GAA2B;YACrC,MAAM,EAAE,oBAAoB;YAC5B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,SAAS,EAAE,SAAS;YACpB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC;QACF,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;SAC7B;QACD,MAAM,IAAI,GAAG,MAAM,cAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5D,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC;IAC5C,CAAC;CACF;AAjFD,wCAiFC"}
\ No newline at end of file
import ICredential from '../icredential';
declare const _default: {
getCredential(): ICredential;
};
export default _default;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const uri_credential_1 = __importDefault(require("../uri_credential"));
exports.default = {
getCredential() {
const credentialsURI = process.env.ALIBABA_CLOUD_CREDENTIALS_URI;
if (credentialsURI) {
return new uri_credential_1.default(credentialsURI);
}
return null;
}
};
//# sourceMappingURL=credentials_uri_provider.js.map
\ No newline at end of file
{"version":3,"file":"credentials_uri_provider.js","sourceRoot":"","sources":["../../../src/provider/credentials_uri_provider.ts"],"names":[],"mappings":";;;;;AAAA,uEAA8C;AAG9C,kBAAe;IACb,aAAa;QACX,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC;QACjE,IAAI,cAAc,EAAE;YAClB,OAAO,IAAI,wBAAa,CAAC,cAAc,CAAC,CAAC;SAC1C;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA"}
\ No newline at end of file
import ICredential from '../icredential';
declare const _default: {
getCredential(): ICredential;
};
export default _default;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const access_key_credential_1 = __importDefault(require("../access_key_credential"));
exports.default = {
getCredential() {
const accessKeyId = process.env.ALIBABA_CLOUD_ACCESS_KEY_ID;
const accessKeySecret = process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET;
if (accessKeyId === undefined || accessKeySecret === undefined) {
return null;
}
if (accessKeyId === null || accessKeyId === '') {
throw new Error('Environment variable ALIBABA_CLOUD_ACCESS_KEY_ID cannot be empty');
}
if (accessKeySecret === null || accessKeySecret === '') {
throw new Error('Environment variable ALIBABA_CLOUD_ACCESS_KEY_SECRET cannot be empty');
}
return new access_key_credential_1.default(accessKeyId, accessKeySecret);
}
};
//# sourceMappingURL=environment_variable_credentials_provider.js.map
\ No newline at end of file
{"version":3,"file":"environment_variable_credentials_provider.js","sourceRoot":"","sources":["../../../src/provider/environment_variable_credentials_provider.ts"],"names":[],"mappings":";;;;;AACA,qFAA2D;AAG3D,kBAAe;IACb,aAAa;QACX,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;QAC5D,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC;QAEpE,IAAI,WAAW,KAAK,SAAS,IAAI,eAAe,KAAK,SAAS,EAAE;YAC9D,OAAO,IAAI,CAAC;SACb;QAED,IAAI,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,EAAE,EAAE;YAC9C,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;SACrF;QAED,IAAI,eAAe,KAAK,IAAI,IAAI,eAAe,KAAK,EAAE,EAAE;YACtD,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;SACzF;QAED,OAAO,IAAI,+BAAmB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;IAC/D,CAAC;CACF,CAAA"}
\ No newline at end of file
import ICredential from '../icredential';
declare const _default: {
getCredential(): ICredential;
};
export default _default;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ecs_ram_role_credential_1 = __importDefault(require("../ecs_ram_role_credential"));
exports.default = {
getCredential() {
const roleName = process.env.ALIBABA_CLOUD_ECS_METADATA;
if (roleName && roleName.length) {
return new ecs_ram_role_credential_1.default(roleName);
}
return null;
}
};
//# sourceMappingURL=instance_ram_role_credentials_provider.js.map
\ No newline at end of file
{"version":3,"file":"instance_ram_role_credentials_provider.js","sourceRoot":"","sources":["../../../src/provider/instance_ram_role_credentials_provider.ts"],"names":[],"mappings":";;;;;AAIA,yFAA8D;AAE9D,kBAAe;IACb,aAAa;QACX,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC;QACxD,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,EAAE;YAC/B,OAAO,IAAI,iCAAoB,CAAC,QAAQ,CAAC,CAAC;SAC3C;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA"}
\ No newline at end of file
import ICredential from '../icredential';
declare const _default: {
getCredential(): ICredential;
};
export default _default;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const oidc_role_arn_credential_1 = __importDefault(require("../oidc_role_arn_credential"));
const config_1 = __importDefault(require("../config"));
exports.default = {
getCredential() {
if (process.env.ALIBABA_CLOUD_ROLE_ARN
&& process.env.ALIBABA_CLOUD_OIDC_PROVIDER_ARN
&& process.env.ALIBABA_CLOUD_OIDC_TOKEN_FILE) {
return new oidc_role_arn_credential_1.default(new config_1.default({}));
}
return null;
}
};
//# sourceMappingURL=oidc_role_arn_credentials_provider.js.map
\ No newline at end of file
{"version":3,"file":"oidc_role_arn_credentials_provider.js","sourceRoot":"","sources":["../../../src/provider/oidc_role_arn_credentials_provider.ts"],"names":[],"mappings":";;;;;AAIA,2FAAgE;AAChE,uDAA+B;AAE/B,kBAAe;IACb,aAAa;QACX,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB;eACjC,OAAO,CAAC,GAAG,CAAC,+BAA+B;eAC3C,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE;YAC9C,OAAO,IAAI,kCAAqB,CAAC,IAAI,gBAAM,CAAC,EAAE,CAAC,CAAC,CAAC;SAClD;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA"}
\ No newline at end of file
import ICredential from '../icredential';
declare const _default: {
getCredential(credentialName?: string): ICredential;
};
export default _default;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const access_key_credential_1 = __importDefault(require("../access_key_credential"));
const sts_token_credential_1 = __importDefault(require("../sts_token_credential"));
const ecs_ram_role_credential_1 = __importDefault(require("../ecs_ram_role_credential"));
const ram_role_arn_credential_1 = __importDefault(require("../ram_role_arn_credential"));
const oidc_role_arn_credential_1 = __importDefault(require("../oidc_role_arn_credential"));
const rsa_key_pair_credential_1 = __importDefault(require("../rsa_key_pair_credential"));
const bearer_token_credential_1 = __importDefault(require("../bearer_token_credential"));
const utils = __importStar(require("../util/utils"));
const fs_1 = __importDefault(require("fs"));
const config_1 = __importDefault(require("../config"));
const DEFAULT_PATH = process.env.HOME + '/.alibabacloud/credentials';
exports.default = {
getCredential(credentialName = 'default') {
let fileContent = null;
const credentialFile = process.env.ALIBABA_CLOUD_CREDENTIALS_FILE;
if (credentialFile === undefined) {
if (fs_1.default.existsSync(DEFAULT_PATH)) {
const content = utils.parseFile(DEFAULT_PATH, true);
if (content) {
fileContent = content;
}
}
}
else {
if (credentialFile === null || credentialFile === '') {
throw new Error('Environment variable credentialFile cannot be empty');
}
if (!fs_1.default.existsSync(credentialFile)) {
throw new Error(`credentialFile ${credentialFile} cannot be empty`);
}
fileContent = utils.parseFile(credentialFile);
}
if (!fileContent) {
return null;
}
const config = fileContent[credentialName] || {};
if (!config.type) {
throw new Error('Missing required type option in credentialFile');
}
switch (config.type) {
case 'access_key':
return new access_key_credential_1.default(config.access_key_id, config.access_key_secret);
case 'sts':
return new sts_token_credential_1.default(config.access_key_id, config.access_key_secret, config.security_token);
case 'ecs_ram_role':
return new ecs_ram_role_credential_1.default(config.role_name);
case 'ram_role_arn': {
const conf = new config_1.default({
roleArn: config.role_arn,
accessKeyId: config.access_key_id,
accessKeySecret: config.access_key_secret
});
return new ram_role_arn_credential_1.default(conf);
}
case 'oidc_role_arn':
const conf = new config_1.default({
roleArn: config.role_arn,
oidcProviderArn: config.oidc_provider_arn,
oidcTokenFilePath: config.oidc_token_file_path
});
return new oidc_role_arn_credential_1.default(conf);
case 'rsa_key_pair':
return new rsa_key_pair_credential_1.default(config.public_key_id, config.private_key_file);
case 'bearer':
return new bearer_token_credential_1.default(config.bearer_token);
default:
throw new Error('Invalid type option, support: access_key, sts, ecs_ram_role, ram_role_arn, oidc_role_arn, rsa_key_pair, bearer');
}
}
};
//# sourceMappingURL=profile_credentials_provider.js.map
\ No newline at end of file
{"version":3,"file":"profile_credentials_provider.js","sourceRoot":"","sources":["../../../src/provider/profile_credentials_provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,qFAA2D;AAC3D,mFAAyD;AACzD,yFAA8D;AAC9D,yFAA8D;AAC9D,2FAAgE;AAChE,yFAA8D;AAC9D,yFAA+D;AAE/D,qDAAuC;AACvC,4CAAoB;AAEpB,uDAA+B;AAE/B,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,4BAA4B,CAAC;AAErE,kBAAe;IACb,aAAa,CAAC,iBAAyB,SAAS;QAC9C,IAAI,WAAW,GAAG,IAAI,CAAC;QACvB,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC;QAClE,IAAI,cAAc,KAAK,SAAS,EAAE;YAChC,IAAI,YAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;gBAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;gBACpD,IA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KAAK,eAAe;gBAClB,MAAM,IAAI,GAAG,IAAI,gBAAM,CAAC;oBACtB,OAAO,EAAE,MAAM,CAAC,QAAQ;oBACxB,eAAe,EAAE,MAAM,CAAC,iBAAiB;oBACzC,iBAAiB,EAAE,MAAM,CAAC,oBAAoB;iBAC/C,CAAC,CAAC;gBACH,OAAO,IAAI,kCAAqB,CAAC,IAAI,CAAC,CAAC;YACzC,KAAK,cAAc;gBACjB,OAAO,IAAI,iCAAoB,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;YACjF,KAAK,QAAQ;gBACX,OAAO,IAAI,iCAAqB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YACxD;gBACE,MAAM,IAAI,KAAK,CAAC,gHAAgH,CAAC,CAAC;SACnI;IACH,CAAC;CACF,CAAA"}
\ No newline at end of file
import ICredential from '../icredential';
declare type IProvider = {
getCredential: () => ICredential;
};
export declare function getCredentials(providers?: IProvider[]): ICredential;
export {};
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCredentials = void 0;
const environment_variable_credentials_provider_1 = __importDefault(require("./environment_variable_credentials_provider"));
const profile_credentials_provider_1 = __importDefault(require("./profile_credentials_provider"));
const instance_ram_role_credentials_provider_1 = __importDefault(require("./instance_ram_role_credentials_provider"));
const credentials_uri_provider_1 = __importDefault(require("./credentials_uri_provider"));
const oidc_role_arn_credentials_provider_1 = __importDefault(require("./oidc_role_arn_credentials_provider"));
const defaultProviders = [
environment_variable_credentials_provider_1.default,
oidc_role_arn_credentials_provider_1.default,
profile_credentials_provider_1.default,
instance_ram_role_credentials_provider_1.default,
credentials_uri_provider_1.default
];
function getCredentials(providers = null) {
const providerChain = providers || defaultProviders;
for (const provider of providerChain) {
const credential = provider.getCredential();
if (credential) {
return credential;
}
}
return null;
}
exports.getCredentials = getCredentials;
//# sourceMappingURL=provider_chain.js.map
\ No newline at end of file
{"version":3,"file":"provider_chain.js","sourceRoot":"","sources":["../../../src/provider/provider_chain.ts"],"names":[],"mappings":";;;;;;AAAA,4HAAiG;AACjG,kGAAwE;AACxE,sHAA0F;AAC1F,0FAAgE;AAChE,8GAAkF;AAQlF,MAAM,gBAAgB,GAAiB;IACrC,mDAAsC;IACtC,4CAA8B;IAC9B,sCAA0B;IAC1B,gDAAkC;IAClC,kCAAsB;CACvB,CAAC;AAEF,SAAgB,cAAc,CAAC,YAAyB,IAAI;IAC1D,MAAM,aAAa,GAAG,SAAS,IAAI,gBAAgB,CAAC;IACpD,KAAK,MAAM,QAAQ,IAAI,aAAa,EAAE;QACpC,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC;QAC5C,IAAI,UAAU,EAAE;YACd,OAAO,UAAU,CAAC;SACnB;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAVD,wCAUC"}
\ No newline at end of file
import SessionCredential from './session_credential';
import Config from './config';
export default class RamRoleArnCredential extends SessionCredential {
roleArn: string;
policy: string;
durationSeconds: number;
roleSessionName: string;
runtime: {
[key: string]: any;
};
host: string;
constructor(config: Config, runtime?: {
[key: string]: any;
});
updateCredential(): Promise<void>;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const session_credential_1 = __importDefault(require("./session_credential"));
const http_1 = require("./util/http");
const config_1 = __importDefault(require("./config"));
class RamRoleArnCredential extends session_credential_1.default {
constructor(config, runtime = {}) {
if (!config.accessKeyId) {
throw new Error('Missing required accessKeyId option in config for ram_role_arn');
}
if (!config.accessKeySecret) {
throw new Error('Missing required accessKeySecret option in config for ram_role_arn');
}
if (!config.roleArn) {
throw new Error('Missing required roleArn option in config for ram_role_arn');
}
const conf = new config_1.default({
type: 'ram_role_arn',
accessKeyId: config.accessKeyId,
accessKeySecret: config.accessKeySecret,
securityToken: config.securityToken
});
super(conf);
this.roleArn = config.roleArn;
this.policy = config.policy;
this.durationSeconds = config.roleSessionExpiration || 3600;
this.roleSessionName = config.roleSessionName || 'role_session_name';
this.runtime = runtime;
this.host = 'https://sts.aliyuncs.com';
}
async updateCredential() {
const params = {
accessKeyId: this.accessKeyId,
securityToken: this.securityToken,
roleArn: this.roleArn,
action: 'AssumeRole',
durationSeconds: this.durationSeconds,
roleSessionName: this.roleSessionName
};
if (this.policy) {
params.policy = this.policy;
}
const json = await http_1.request(this.host, params, this.runtime, this.accessKeySecret);
this.sessionCredential = json.Credentials;
}
}
exports.default = RamRoleArnCredential;
//# sourceMappingURL=ram_role_arn_credential.js.map
\ No newline at end of file
{"version":3,"file":"ram_role_arn_credential.js","sourceRoot":"","sources":["../../src/ram_role_arn_credential.ts"],"names":[],"mappings":";;;;;AAAA,8EAAqD;AACrD,sCAAsC;AACtC,sDAA8B;AAE9B,MAAqB,oBAAqB,SAAQ,4BAAiB;IAQjE,YAAY,MAAc,EAAE,UAAgC,EAAE;QAC5D,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;SACnF;QAED,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;SACvF;QAED,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;SAC/E;QAED,MAAM,IAAI,GAAG,IAAI,gBAAM,CAAC;YACtB,IAAI,EAAE,cAAc;YACpB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,aAAa,EAAE,MAAM,CAAC,aAAa;SACpC,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,qBAAqB,IAAI,IAAI,CAAC;QAC5D,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,mBAAmB,CAAC;QACrE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,MAAM,GAAyB;YACnC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,YAAY;YACpB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC;QACF,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;SAC7B;QACD,MAAM,IAAI,GAAG,MAAM,cAAO,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAClF,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC;IAC5C,CAAC;CACF;AAnDD,uCAmDC"}
\ No newline at end of file
import SessionCredential from './session_credential';
import ICredential from './icredential';
export default class RsaKeyPairCredential extends SessionCredential implements ICredential {
privateKey: string;
publicKeyId: string;
roleName: string;
constructor(publicKeyId: string, privateKeyFile: string);
updateCredential(): Promise<void>;
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const session_credential_1 = __importDefault(require("./session_credential"));
const utils = __importStar(require("./util/utils"));
const http_1 = require("./util/http");
const config_1 = __importDefault(require("./config"));
const SECURITY_CRED_URL = 'http://100.100.100.200/latest/meta-data/ram/security-credentials/';
class RsaKeyPairCredential extends session_credential_1.default {
constructor(publicKeyId, privateKeyFile) {
if (!publicKeyId) {
throw new Error('Missing required publicKeyId option in config for rsa_key_pair');
}
if (!privateKeyFile) {
throw new Error('Missing required privateKeyFile option in config for rsa_key_pair');
}
if (!fs_1.default.existsSync(privateKeyFile)) {
throw new Error(`privateKeyFile ${privateKeyFile} cannot be empty`);
}
const conf = new config_1.default({
type: 'rsa_key_pair'
});
super(conf);
this.privateKey = utils.parseFile(privateKeyFile);
this.publicKeyId = publicKeyId;
}
async updateCredential() {
const url = SECURITY_CRED_URL + this.roleName;
const json = await http_1.request(url, {
accessKeyId: this.publicKeyId,
action: 'GenerateSessionAccessKey',
durationSeconds: 3600,
signatureMethod: 'SHA256withRSA',
signatureType: 'PRIVATEKEY',
}, {}, this.privateKey);
this.sessionCredential = json.Credentials;
}
}
exports.default = RsaKeyPairCredential;
//# sourceMappingURL=rsa_key_pair_credential.js.map
\ No newline at end of file
{"version":3,"file":"rsa_key_pair_credential.js","sourceRoot":"","sources":["../../src/rsa_key_pair_credential.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,8EAAqD;AACrD,oDAAsC;AACtC,sCAAsC;AAEtC,sDAA8B;AAE9B,MAAM,iBAAiB,GAAG,mEAAmE,CAAC;AAE9F,MAAqB,oBAAqB,SAAQ,4BAAiB;IAKjE,YAAY,WAAmB,EAAE,cAAsB;QACrD,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;SACnF;QAED,IAAI,CAAC,cAAc,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;SACtF;QAED,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,kBAAkB,cAAc,kBAAkB,CAAC,CAAC;SACrE;QAED,MAAM,IAAI,GAAG,IAAI,gBAAM,CAAC;YACtB,IAAI,EAAE,cAAc;SACrB,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;QAClD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,GAAG,GAAG,iBAAiB,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9C,MAAM,IAAI,GAAG,MAAM,cAAO,CAAC,GAAG,EAAE;YAC9B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,MAAM,EAAE,0BAA0B;YAClC,eAAe,EAAE,IAAI;YACrB,eAAe,EAAE,eAAe;YAChC,aAAa,EAAE,YAAY;SAC5B,EAAE,EAAE,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACxB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC;IAC5C,CAAC;CACF;AArCD,uCAqCC"}
\ No newline at end of file
import DefaultCredential from './default_credential';
import Config from './config';
import CredentialModel from './credential_model';
export default class SessionCredential extends DefaultCredential {
sessionCredential: any;
durationSeconds: number;
constructor(config: Config);
updateCredential(): Promise<void>;
ensureCredential(): Promise<void>;
getAccessKeyId(): Promise<any>;
getAccessKeySecret(): Promise<any>;
getSecurityToken(): Promise<any>;
needUpdateCredential(): boolean;
getCredential(): Promise<CredentialModel>;
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const default_credential_1 = __importDefault(require("./default_credential"));
const utils = __importStar(require("./util/utils"));
const config_1 = __importDefault(require("./config"));
const credential_model_1 = __importDefault(require("./credential_model"));
class SessionCredential extends default_credential_1.default {
constructor(config) {
const conf = new config_1.default({
type: config.type,
accessKeyId: config.accessKeyId,
accessKeySecret: config.accessKeySecret,
securityToken: config.securityToken
});
super(conf);
this.sessionCredential = null;
this.durationSeconds = config.durationSeconds || 3600;
}
async updateCredential() {
throw new Error('need implemented in sub-class');
}
async ensureCredential() {
const needUpdate = this.needUpdateCredential();
if (needUpdate) {
await this.updateCredential();
}
}
async getAccessKeyId() {
await this.ensureCredential();
return this.sessionCredential.AccessKeyId;
}
async getAccessKeySecret() {
await this.ensureCredential();
return this.sessionCredential.AccessKeySecret;
}
async getSecurityToken() {
await this.ensureCredential();
return this.sessionCredential.SecurityToken;
}
needUpdateCredential() {
if (!this.sessionCredential || !this.sessionCredential.Expiration || !this.sessionCredential.AccessKeyId || !this.sessionCredential.AccessKeySecret || !this.sessionCredential.SecurityToken) {
return true;
}
const expireTime = utils.timestamp(new Date(), this.durationSeconds * 0.05 * 1000);
if (this.sessionCredential.Expiration < expireTime) {
return true;
}
return false;
}
async getCredential() {
await this.ensureCredential();
return new credential_model_1.default({
accessKeyId: this.sessionCredential.AccessKeyId,
accessKeySecret: this.sessionCredential.AccessKeySecret,
securityToken: this.sessionCredential.SecurityToken,
bearerToken: this.bearerToken,
type: this.type,
});
}
}
exports.default = SessionCredential;
//# sourceMappingURL=session_credential.js.map
\ No newline at end of file
{"version":3,"file":"session_credential.js","sourceRoot":"","sources":["../../src/session_credential.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,8EAAqD;AACrD,oDAAsC;AACtC,sDAA8B;AAC9B,0EAAiD;AAEjD,MAAqB,iBAAkB,SAAQ,4BAAiB;IAI9D,YAAY,MAAc;QACxB,MAAM,IAAI,GAAG,IAAI,gBAAM,CAAC;YACtB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,aAAa,EAAE,MAAM,CAAC,aAAa;SACpC,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,IAAI,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,UAAU,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC/C,IAAI,UAAU,EAAE;YACd,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;SAC/B;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AE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;CACF;AA/DD,oCA+DC"}
\ No newline at end of file
import DefaultCredential from './default_credential';
import ICredential from './icredential';
export default class StsTokenCredential extends DefaultCredential implements ICredential {
constructor(accessKeyId: string, accessKeySecret: string, securityToken: string);
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const default_credential_1 = __importDefault(require("./default_credential"));
const config_1 = __importDefault(require("./config"));
class StsTokenCredential extends default_credential_1.default {
constructor(accessKeyId, accessKeySecret, securityToken) {
if (!accessKeyId) {
throw new Error('Missing required accessKeyId option in config for sts');
}
if (!accessKeySecret) {
throw new Error('Missing required accessKeySecret option in config for sts');
}
if (!securityToken) {
throw new Error('Missing required securityToken option in config for sts');
}
const conf = new config_1.default({
type: 'sts',
accessKeyId,
accessKeySecret,
securityToken
});
super(conf);
}
}
exports.default = StsTokenCredential;
//# sourceMappingURL=sts_token_credential.js.map
\ No newline at end of file
{"version":3,"file":"sts_token_credential.js","sourceRoot":"","sources":["../../src/sts_token_credential.ts"],"names":[],"mappings":";;;;;AAAA,8EAAqD;AAErD,sDAA8B;AAE9B,MAAqB,kBAAmB,SAAQ,4BAAiB;IAC/D,YAAY,WAAmB,EAAE,eAAuB,EAAE,aAAqB;QAC7E,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;SAC1E;QAED,IAAI,CAAC,eAAe,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;SAC9E;QAED,IAAI,CAAC,aAAa,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;SAC5E;QACD,MAAM,IAAI,GAAG,IAAI,gBAAM,CAAC;YACtB,IAAI,EAAE,KAAK;YACX,WAAW;YACX,eAAe;YACf,aAAa;SACd,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;CACF;AArBD,qCAqBC"}
\ No newline at end of file
import ICredential from './icredential';
import SessionCredential from './session_credential';
export default class URICredential extends SessionCredential implements ICredential {
credentialsURI: string;
constructor(uri: string);
updateCredential(): Promise<void>;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const httpx_1 = __importDefault(require("httpx"));
const config_1 = __importDefault(require("./config"));
const session_credential_1 = __importDefault(require("./session_credential"));
class URICredential extends session_credential_1.default {
constructor(uri) {
const conf = new config_1.default({
type: 'credentials_uri',
credentialsURI: uri
});
super(conf);
if (!uri) {
this.credentialsURI = process.env['ALIBABA_CLOUD_CREDENTIALS_URI'];
}
else {
this.credentialsURI = uri;
}
if (!this.credentialsURI) {
throw new Error('Missing required credentialsURI option in config or environment variable for credentials_uri');
}
}
async updateCredential() {
const url = this.credentialsURI;
const response = await httpx_1.default.request(url, {});
if (response.statusCode !== 200) {
throw new Error(`Get credentials from ${url} failed, status code is ${response.statusCode}`);
}
const body = (await httpx_1.default.read(response, 'utf8'));
let json;
try {
json = JSON.parse(body);
}
catch (ex) {
throw new Error(`Get credentials from ${url} failed, unmarshal response failed, JSON is: ${body}`);
}
if (json.Code !== 'Success') {
throw new Error(`Get credentials from ${url} failed, Code is ${json.Code}`);
}
this.sessionCredential = {
AccessKeyId: json.AccessKeyId,
AccessKeySecret: json.AccessKeySecret,
Expiration: json.Expiration,
SecurityToken: json.SecurityToken,
};
}
}
exports.default = URICredential;
//# sourceMappingURL=uri_credential.js.map
\ No newline at end of file
{"version":3,"file":"uri_credential.js","sourceRoot":"","sources":["../../src/uri_credential.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAE1B,sDAA8B;AAE9B,8EAAqD;AAErD,MAAqB,aAAc,SAAQ,4BAAiB;IAG1D,YAAY,GAAW;QACrB,MAAM,IAAI,GAAG,IAAI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,IAAI,CAAC,eAAe;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC;IACJ,CAAC;CACF;AA9CD,gCA8CC"}
\ No newline at end of file
export declare const DEFAULT_UA: string;
export declare const DEFAULT_CLIENT: string;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_CLIENT = exports.DEFAULT_UA = void 0;
const os = __importStar(require("os"));
const package_json_1 = __importDefault(require("../../package.json"));
exports.DEFAULT_UA = `AlibabaCloud (${os.platform()}; ${os.arch()}) ` +
`Node.js/${process.version} Core/${package_json_1.default.version}`;
exports.DEFAULT_CLIENT = `Node.js(${process.version}), ${package_json_1.default.name}: ${package_json_1.default.version}`;
//# sourceMappingURL=helper.js.map
\ No newline at end of file
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../src/util/helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,sEAAqC;AAExB,QAAA,UAAU,GAAG,iBAAiB,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI;IACtE,WAAW,OAAO,CAAC,OAAO,SAAS,sBAAG,CAAC,OAAO,EAAE,CAAC;AAExC,QAAA,cAAc,GAAG,WAAW,OAAO,CAAC,OAAO,MAAM,sBAAG,CAAC,IAAI,KAAK,sBAAG,CAAC,OAAO,EAAE,CAAC"}
\ No newline at end of file
export declare function request(host: string, params?: {
[key: string]: any;
}, opts?: {
[key: string]: any;
}, accessKeySecret?: string): Promise<any>;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.request = void 0;
const httpx_1 = __importDefault(require("httpx"));
const kitx = __importStar(require("kitx"));
const helper = __importStar(require("./helper"));
const utils = __importStar(require("./utils"));
const STATUS_CODE = new Set([200, '200', 'OK', 'Success']);
function firstLetterUpper(str) {
return str.slice(0, 1).toUpperCase() + str.slice(1);
}
function formatParams(params) {
const keys = Object.keys(params);
const newParams = {};
for (const key of keys) {
newParams[firstLetterUpper(key)] = params[key];
}
return newParams;
}
function encode(str) {
const result = encodeURIComponent(str);
return result.replace(/!/g, '%21')
.replace(/'/g, '%27')
.replace(/\(/g, '%28')
.replace(/\)/g, '%29')
.replace(/\*/g, '%2A');
}
function replaceRepeatList(target, key, repeat) {
for (let i = 0; i < repeat.length; i++) {
const item = repeat[i];
if (item && typeof item === 'object') {
const keys = Object.keys(item);
for (const itemKey of keys) {
target[`${key}.${i + 1}.${itemKey}`] = item[itemKey];
}
}
else {
target[`${key}.${i + 1}`] = item;
}
}
}
function flatParams(params) {
const target = {};
const keys = Object.keys(params);
for (const key of keys) {
const value = params[key];
if (Array.isArray(value)) {
replaceRepeatList(target, key, value);
}
else {
target[key] = value;
}
}
return target;
}
function normalize(params) {
const list = [];
const flated = flatParams(params);
const keys = Object.keys(flated).sort();
for (const key of keys) {
const value = flated[key];
list.push([encode(key), encode(value)]); // push []
}
return list;
}
function canonicalize(normalized) {
const fields = [];
for (const [key, value] of normalized) {
fields.push(key + '=' + value);
}
return fields.join('&');
}
function _buildParams() {
const defaultParams = {
Format: 'JSON',
SignatureMethod: 'HMAC-SHA1',
SignatureNonce: kitx.makeNonce(),
SignatureVersion: '1.0',
Timestamp: utils.timestamp(),
Version: '2015-04-01',
RegionId: 'cn-hangzhou'
};
return defaultParams;
}
async function request(host, params = {}, opts = {}, accessKeySecret) {
// 1. compose params and opts
let options = Object.assign({ headers: {
'x-sdk-client': helper.DEFAULT_CLIENT,
'user-agent': helper.DEFAULT_UA
} }, opts);
// format params until formatParams is false
if (options.formatParams !== false) {
params = formatParams(params);
}
params = Object.assign(Object.assign({}, _buildParams()), params);
// 2. calculate signature
const method = (opts.method || 'GET').toUpperCase();
const normalized = normalize(params);
if (!options.anonymous) {
const canonicalized = canonicalize(normalized);
// 2.1 get string to sign
const stringToSign = `${method}&${encode('/')}&${encode(canonicalized)}`;
// 2.2 get signature
const key = accessKeySecret + '&';
const signature = kitx.sha1(stringToSign, key, 'base64');
// add signature
normalized.push(['Signature', encode(signature)]);
}
// 3. generate final url
const url = opts.method === 'POST' ? `${host}/` : `${host}/?${canonicalize(normalized)}`;
// 4. send request
if (opts.method === 'POST') {
opts.headers = opts.headers || {};
opts.headers['content-type'] = 'application/x-www-form-urlencoded';
opts.data = canonicalize(normalized);
}
const response = await httpx_1.default.request(url, opts);
const buffer = await httpx_1.default.read(response, 'utf8');
const json = JSON.parse(buffer);
if (json.Code && !STATUS_CODE.has(json.Code)) {
const err = new Error(`${json.Message}`);
err.name = json.Code + 'Error';
err.data = json;
err.code = json.Code;
err.url = url;
throw err;
}
return json;
}
exports.request = request;
//# sourceMappingURL=http.js.map
\ No newline at end of file
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/util/http.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kDAA0B;AAC1B,2CAA6B;AAC7B,iDAAmC;AACnC,+CAAiC;AAEjC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;AAE3D,SAAS,gBAAgB,CAAC,GAAW;IACnC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,YAAY,CAAC,MAA8B;IAClD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,SAAS,GAA8B,EAAE,CAAC;IAChD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;QACtB,SAAS,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;KAChD;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,MAAM,CAAC,GAAW;IACzB,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAEvC,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SAC/B,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO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AAG,EAAE,IAAI,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAgB,CAAC,CAAC;IAC1C,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC5C,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAQ,CAAC;QAChD,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QAC/B,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;QAChB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACrB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;QACd,MAAM,GAAG,CAAC;KACX;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AApDD,0BAoDC"}
\ No newline at end of file
export declare function timestamp(dateStr?: Date, timeChange?: number): string;
export declare function parseFile(file: string, ignoreErr?: boolean): any;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseFile = exports.timestamp = void 0;
const ini = __importStar(require("ini"));
const kitx = __importStar(require("kitx"));
const fs_1 = __importDefault(require("fs"));
function timestamp(dateStr, timeChange) {
let date = new Date(dateStr);
if (!dateStr || isNaN(date.getTime())) {
date = new Date();
}
if (timeChange) {
date.setTime(date.getTime() + timeChange);
}
const YYYY = date.getUTCFullYear();
const MM = kitx.pad2(date.getUTCMonth() + 1);
const DD = kitx.pad2(date.getUTCDate());
const HH = kitx.pad2(date.getUTCHours());
const mm = kitx.pad2(date.getUTCMinutes());
const ss = kitx.pad2(date.getUTCSeconds());
// 删除掉毫秒部分
return `${YYYY}-${MM}-${DD}T${HH}:${mm}:${ss}Z`;
}
exports.timestamp = timestamp;
function parseFile(file, ignoreErr = false) {
// check read permission
try {
fs_1.default.accessSync(file, fs_1.default.constants.R_OK);
}
catch (e) {
if (ignoreErr) {
return null;
}
throw new Error('Has no read permission to credentials file');
}
return ini.parse(fs_1.default.readFileSync(file, 'utf-8'));
}
exports.parseFile = parseFile;
//# sourceMappingURL=utils.js.map
\ No newline at end of file
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/util/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA2B;AAC3B,2CAA6B;AAC7B,4CAAoB;AAEpB,SAAgB,SAAS,CAAC,OAAc,EAAE,UAAmB;IAC3D,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7B,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE;QACrC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;KACnB;IACD,IAAI,UAAU,EAAE;QACd,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC;KAC3C;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IACnC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IACxC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IACzC,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;IAC3C,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;IAC3C,UAAU;IACV,OAAO,GAAG,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC;AAClD,CAAC;AAhBD,8BAgBC;AAED,SAAgB,SAAS,CAAC,IAAY,EAAE,YAAqB,KAAK;IAChE,wBAAwB;IACxB,IAAI;QACF,YAAE,CAAC,UAAU,CAAC,IAAI,EAAE,YAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KACxC;IAAC,OAAO,CAAC,EAAE;QACV,IAAI,SAAS,EAAE;YACb,OAAO,IAAI,CAAC;SACb;QACD,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;KAC/D;IAED,OAAO,GAAG,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AACnD,CAAC;AAZD,8BAYC"}
\ No newline at end of file
{
"name": "@alicloud/credentials",
"version": "2.3.0",
"description": "alibaba cloud node.js sdk credentials",
"main": "dist/src/client.js",
"scripts": {
"prepublishOnly": "tsc",
"build": "tsc",
"lint": "eslint --fix ./src --ext .ts",
"test": "mocha -b -r ts-node/register test/**/*.test.ts test/*.test.ts --timeout 15000",
"cov": "nyc -e .ts -r=html -r=text -r=lcov npm run test",
"ci": "npm run cov",
"test-integration": "mocha -b -r ts-node/register -R spec test/*.integration.ts",
"clean": "rm -rf coverage"
},
"repository": {
"type": "git",
"url": "git+https://github.com/aliyun/nodejs-credentials.git"
},
"keywords": [
"alibaba cloud",
"sdk",
"credentials"
],
"author": "Alibaba Cloud SDK",
"license": "MIT",
"devDependencies": {
"@types/expect.js": "^0.3.29",
"@types/ini": "^1.3.30",
"@types/mocha": "^7.0.1",
"@types/rewire": "^2.5.28",
"@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2",
"eslint": "^7.32.0",
"expect.js": "^0.3.1",
"mm": "^2.4.1",
"mocha": "^10.1.0",
"nyc": "^13.1.0",
"rewire": "^4.0.1",
"ts-node": "^8.6.2",
"typescript": "^3.7.5"
},
"dependencies": {
"@alicloud/tea-typescript": "^1.5.3",
"httpx": "^2.2.0",
"ini": "^1.3.5",
"kitx": "^2.0.0"
},
"bugs": {
"url": "https://github.com/aliyun/nodejs-credentials/issues"
},
"homepage": "https://github.com/aliyun/nodejs-credentials#readme",
"files": [
"src",
"dist"
]
}
import DefaultCredential from './default_credential';
import ICredential from './icredential';
import Config from './config';
export default class AccessKeyCredential extends DefaultCredential implements ICredential {
constructor(accessKeyId: string, accessKeySecret: string) {
if (!accessKeyId) {
throw new Error('Missing required accessKeyId option in config for access_key');
}
if (!accessKeySecret) {
throw new Error('Missing required accessKeySecret option in config for access_key');
}
const conf = new Config({
type: 'access_key',
accessKeyId,
accessKeySecret
});
super(conf);
}
}
\ No newline at end of file
import DefaultCredential from './default_credential';
import ICredential from './icredential';
import Config from './config';
export default class BearerTokenCredential extends DefaultCredential implements ICredential {
constructor(bearerToken: string) {
if (!bearerToken) {
throw new Error('Missing required bearerToken option in config for bearer');
}
const conf = new Config({
type: 'bearer'
});
super(conf);
this.bearerToken = bearerToken;
}
}
\ No newline at end of file
import ICredential from './icredential';
import AccessKeyCredential from './access_key_credential';
import StsTokenCredential from './sts_token_credential';
import EcsRamRoleCredential from './ecs_ram_role_credential';
import RamRoleArnCredential from './ram_role_arn_credential';
import OidcRoleArnCredential from './oidc_role_arn_credential'
import RsaKeyPairCredential from './rsa_key_pair_credential';
import BearerTokenCredential from './bearer_token_credential';
import * as DefaultProvider from './provider/provider_chain';
import Config from './config';
import URICredential from './uri_credential';
import CredentialModel from './credential_model';
export { Config };
export default class Credential implements ICredential {
credential: ICredential;
constructor(config: Config = null, runtime: { [key: string]: any } = {}) {
this.load(config, runtime);
}
getAccessKeyId(): Promise<string> {
return this.credential.getAccessKeyId();
}
getAccessKeySecret(): Promise<string> {
return this.credential.getAccessKeySecret();
}
getSecurityToken(): Promise<string> {
return this.credential.getSecurityToken();
}
getBearerToken(): string {
return this.credential.getBearerToken();
}
getType(): string {
return this.credential.getType();
}
getCredential(): Promise<CredentialModel> {
return this.credential.getCredential();
}
private load(config: Config, runtime: { [key: string]: any }): void {
if (!config) {
this.credential = DefaultProvider.getCredentials();
return;
}
if (!config.type) {
throw new Error('Missing required type option');
}
switch (config.type) {
case 'access_key':
this.credential = new AccessKeyCredential(config.accessKeyId, config.accessKeySecret);
break;
case 'sts':
this.credential = new StsTokenCredential(config.accessKeyId, config.accessKeySecret, config.securityToken);
break;
case 'ecs_ram_role':
this.credential = new EcsRamRoleCredential(config.roleName);
break;
case 'ram_role_arn':
this.credential = new RamRoleArnCredential(config, runtime);
break;
case 'oidc_role_arn':
this.credential = new OidcRoleArnCredential(config, runtime);
break;
case 'rsa_key_pair':
this.credential = new RsaKeyPairCredential(config.publicKeyId, config.privateKeyFile);
break;
case 'bearer':
this.credential = new BearerTokenCredential(config.bearerToken);
break;
case 'credentials_uri':
this.credential = new URICredential(config.credentialsURI);
break;
default:
throw new Error('Invalid type option, support: access_key, sts, ecs_ram_role, ram_role_arn, rsa_key_pair, credentials_uri');
}
}
}
import * as $tea from '@alicloud/tea-typescript';
export default class Config extends $tea.Model {
accessKeyId?: string;
accessKeySecret?: string;
securityToken?: string;
bearerToken?: string;
durationSeconds?: number;
roleArn?: string;
policy?: string;
roleSessionExpiration?: number;
roleSessionName?: string;
publicKeyId?: string;
privateKeyFile?: string;
roleName?: string;
credentialsURI?: string;
oidcProviderArn: string;
oidcTokenFilePath: string;
type?: string;
static names(): { [key: string]: string } {
return {
accessKeyId: 'accessKeyId',
accessKeySecret: 'accessKeySecret',
securityToken: 'securityToken',
bearerToken: 'bearerToken',
durationSeconds: 'durationSeconds',
roleArn: 'roleArn',
policy: 'policy',
roleSessionExpiration: 'roleSessionExpiration',
roleSessionName: 'roleSessionName',
publicKeyId: 'publicKeyId',
privateKeyFile: 'privateKeyFile',
roleName: 'roleName',
credentialsURI: 'credentialsURI',
oidcProviderArn: 'oidcProviderArn',
oidcTokenFilePath: 'oidcTokenFilePath',
type: 'type',
};
}
static types(): { [key: string]: any } {
return {
accessKeyId: 'string',
accessKeySecret: 'string',
securityToken: 'string',
bearerToken: 'string',
durationSeconds: 'number',
roleArn: 'string',
policy: 'string',
roleSessionExpiration: 'number',
roleSessionName: 'string',
publicKeyId: 'string',
privateKeyFile: 'string',
roleName: 'string',
credentialsURI: 'string',
oidcProviderArn: 'string',
oidcTokenFilePath: 'string',
type: 'string',
};
}
constructor(config?: { [key: string]: any }) {
super(config);
}
}
\ No newline at end of file
import * as $tea from '@alicloud/tea-typescript';
export default class CredentialModel extends $tea.Model {
accessKeyId?: string;
accessKeySecret?: string;
securityToken?: string;
bearerToken?: string;
type?: string;
static names(): { [key: string]: string } {
return {
accessKeyId: 'accessKeyId',
accessKeySecret: 'accessKeySecret',
securityToken: 'securityToken',
bearerToken: 'bearerToken',
type: 'type',
};
}
static types(): { [key: string]: any } {
return {
accessKeyId: 'string',
accessKeySecret: 'string',
securityToken: 'string',
bearerToken: 'string',
type: 'string',
};
}
constructor(map?: { [key: string]: any }) {
super(map);
}
}
\ No newline at end of file
import Config from './config';
import CredentialModel from './credential_model';
import ICredential from './icredential';
export default class DefaultCredential implements ICredential {
accessKeyId: string;
accessKeySecret: string;
securityToken?: string;
bearerToken?: string;
type: string;
constructor(config: Config) {
this.accessKeyId = config.accessKeyId || '';
this.accessKeySecret = config.accessKeySecret || '';
this.securityToken = config.securityToken || '';
this.bearerToken = config.bearerToken || '';
this.type = config.type || '';
}
async getAccessKeyId(): Promise<string> {
return this.accessKeyId;
}
async getAccessKeySecret(): Promise<string> {
return this.accessKeySecret;
}
async getSecurityToken(): Promise<string> {
return this.securityToken;
}
getBearerToken(): string {
return this.bearerToken;
}
getType(): string {
return this.type;
}
async getCredential(): Promise<CredentialModel> {
return new CredentialModel({
accessKeyId: this.accessKeyId,
accessKeySecret: this.accessKeySecret,
securityToken: this.securityToken,
bearerToken: this.bearerToken,
type: this.type,
});
}
}
import SessionCredential from './session_credential';
import httpx from 'httpx';
import ICredential from './icredential';
import Config from './config';
const SECURITY_CRED_URL = 'http://100.100.100.200/latest/meta-data/ram/security-credentials/';
export default class EcsRamRoleCredential extends SessionCredential implements ICredential {
roleName: string;
runtime: {[key: string]: any};
constructor(roleName: string = '', runtime: { [key: string]: any } = {}) {
const conf = new Config({
type: 'ecs_ram_role',
});
super(conf);
this.roleName = roleName;
this.runtime = runtime;
this.sessionCredential = null;
}
async getBody(url: string): Promise<string> {
const response = await httpx.request(url, {});
return (await httpx.read(response, 'utf8')) as string;
}
async updateCredential(): Promise<void> {
const roleName = await this.getRoleName();
const url = SECURITY_CRED_URL + roleName;
const body = await this.getBody(url);
const json = JSON.parse(body);
this.sessionCredential = {
AccessKeyId: json.AccessKeyId,
AccessKeySecret: json.AccessKeySecret,
Expiration: json.Expiration,
SecurityToken: json.SecurityToken,
};
}
async getRoleName(): Promise<string> {
if (this.roleName && this.roleName.length) {
return this.roleName;
}
return await this.getBody(SECURITY_CRED_URL);
}
}
\ No newline at end of file
import CredentialModel from "./credential_model";
export default interface ICredential {
getAccessKeyId: () => Promise<string>;
getAccessKeySecret: () => Promise<string>;
getSecurityToken: () => Promise<string>;
getBearerToken: () => string;
getType: () => string;
getCredential: ()=> Promise<CredentialModel>
}
import SessionCredential from './session_credential';
import { request } from './util/http';
import Config from './config';
import fs from 'fs';
export default class OidcRoleArnCredential extends SessionCredential {
roleArn: string;
oidcProviderArn: string;
oidcTokenFilePath: string;
policy: string;
durationSeconds: number;
roleSessionName: string;
runtime: { [key: string]: any };
host: string;
constructor(config: Config, runtime: { [key: string]: any } = {}) {
if (!config.roleArn) {
config.roleArn = process.env.ALIBABA_CLOUD_ROLE_ARN;
if (!config.roleArn) {
throw new Error('roleArn does not exist and env ALIBABA_CLOUD_ROLE_ARN is null.');
}
}
if (!config.oidcProviderArn) {
config.oidcProviderArn = process.env.ALIBABA_CLOUD_OIDC_PROVIDER_ARN;
if (!config.oidcProviderArn) {
throw new Error('oidcProviderArn does not exist and env ALIBABA_CLOUD_OIDC_PROVIDER_ARN is null.');
}
}
if (!config.oidcTokenFilePath) {
config.oidcTokenFilePath = process.env.ALIBABA_CLOUD_OIDC_TOKEN_FILE;
if (!config.oidcTokenFilePath) {
throw new Error('oidcTokenFilePath is not exists and env ALIBABA_CLOUD_OIDC_TOKEN_FILE is null.');
}
}
if (!config.roleSessionName && process.env.ALIBABA_CLOUD_ROLE_SESSION_NAME) {
config.roleSessionName = process.env.ALIBABA_CLOUD_ROLE_SESSION_NAME;
}
const conf = new Config({
type: 'oidc_role_arn'
});
super(conf);
this.oidcTokenFilePath = config.oidcTokenFilePath;
this.roleArn = config.roleArn;
this.policy = config.policy;
this.oidcProviderArn = config.oidcProviderArn;
this.durationSeconds = config.roleSessionExpiration || 3600;
this.roleSessionName = config.roleSessionName || 'role_session_name';
runtime.method = 'POST';
runtime.anonymous = true;
this.runtime = runtime;
this.host = 'https://sts.aliyuncs.com';
}
private getOdicToken(oidcTokenFilePath: string): string {
if (!fs.existsSync(oidcTokenFilePath)) {
throw new Error(`oidcTokenFilePath ${oidcTokenFilePath} is not exists.`);
}
let oidcToken = null;
try {
oidcToken = fs.readFileSync(oidcTokenFilePath, 'utf-8');
} catch (err) {
throw new Error(`oidcTokenFilePath ${oidcTokenFilePath} cannot be read.`);
}
return oidcToken;
}
async updateCredential() {
const oidcToken = this.getOdicToken(this.oidcTokenFilePath);
const params: { [key: string]: any } = {
Action: 'AssumeRoleWithOIDC',
RoleArn: this.roleArn,
OIDCProviderArn: this.oidcProviderArn,
OIDCToken: oidcToken,
DurationSeconds: this.durationSeconds,
RoleSessionName: this.roleSessionName
};
if (this.policy) {
params.policy = this.policy;
}
const json = await request(this.host, params, this.runtime);
this.sessionCredential = json.Credentials;
}
}
import URICredential from '../uri_credential';
import ICredential from '../icredential';
export default {
getCredential(): ICredential {
const credentialsURI = process.env.ALIBABA_CLOUD_CREDENTIALS_URI;
if (credentialsURI) {
return new URICredential(credentialsURI);
}
return null;
}
}
import AccessKeyCredential from '../access_key_credential';
import ICredential from '../icredential';
export default {
getCredential(): ICredential {
const accessKeyId = process.env.ALIBABA_CLOUD_ACCESS_KEY_ID;
const accessKeySecret = process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET;
if (accessKeyId === undefined || accessKeySecret === undefined) {
return null;
}
if (accessKeyId === null || accessKeyId === '') {
throw new Error('Environment variable ALIBABA_CLOUD_ACCESS_KEY_ID cannot be empty');
}
if (accessKeySecret === null || accessKeySecret === '') {
throw new Error('Environment variable ALIBABA_CLOUD_ACCESS_KEY_SECRET cannot be empty');
}
return new AccessKeyCredential(accessKeyId, accessKeySecret);
}
}
\ No newline at end of file
import ICredential from '../icredential';
import EcsRamRoleCredential from '../ecs_ram_role_credential';
export default {
getCredential(): ICredential {
const roleName = process.env.ALIBABA_CLOUD_ECS_METADATA;
if (roleName && roleName.length) {
return new EcsRamRoleCredential(roleName);
}
return null;
}
}
import ICredential from '../icredential';
import OidcRoleArnCredential from '../oidc_role_arn_credential';
import Config from '../config';
export default {
getCredential(): ICredential {
if (process.env.ALIBABA_CLOUD_ROLE_ARN
&& process.env.ALIBABA_CLOUD_OIDC_PROVIDER_ARN
&& process.env.ALIBABA_CLOUD_OIDC_TOKEN_FILE) {
return new OidcRoleArnCredential(new Config({}));
}
return null;
}
}
import AccessKeyCredential from '../access_key_credential';
import StsTokenCredential from '../sts_token_credential';
import EcsRamRoleCredential from '../ecs_ram_role_credential';
import RamRoleArnCredential from '../ram_role_arn_credential';
import OidcRoleArnCredential from '../oidc_role_arn_credential';
import RsaKeyPairCredential from '../rsa_key_pair_credential';
import BearerTokenCredential from '../bearer_token_credential';
import * as utils from '../util/utils';
import fs from 'fs';
import ICredential from '../icredential';
import Config from '../config';
const DEFAULT_PATH = process.env.HOME + '/.alibabacloud/credentials';
export default {
getCredential(credentialName: string = 'default'): ICredential {
let fileContent = null;
const credentialFile = process.env.ALIBABA_CLOUD_CREDENTIALS_FILE;
if (credentialFile === undefined) {
if (fs.existsSync(DEFAULT_PATH)) {
const content = utils.parseFile(DEFAULT_PATH, true);
if (content) {
fileContent = content;
}
}
} else {
if (credentialFile === null || credentialFile === '') {
throw new Error('Environment variable credentialFile cannot be empty');
}
if (!fs.existsSync(credentialFile)) {
throw new Error(`credentialFile ${credentialFile} cannot be empty`);
}
fileContent = utils.parseFile(credentialFile);
}
if (!fileContent) {
return null;
}
const config = fileContent[credentialName] || {};
if (!config.type) {
throw new Error('Missing required type option in credentialFile');
}
switch (config.type) {
case 'access_key':
return new AccessKeyCredential(config.access_key_id, config.access_key_secret);
case 'sts':
return new StsTokenCredential(config.access_key_id, config.access_key_secret, config.security_token);
case 'ecs_ram_role':
return new EcsRamRoleCredential(config.role_name);
case 'ram_role_arn': {
const conf = new Config({
roleArn: config.role_arn,
accessKeyId: config.access_key_id,
accessKeySecret: config.access_key_secret
});
return new RamRoleArnCredential(conf);
}
case 'oidc_role_arn':
const conf = new Config({
roleArn: config.role_arn,
oidcProviderArn: config.oidc_provider_arn,
oidcTokenFilePath: config.oidc_token_file_path
});
return new OidcRoleArnCredential(conf);
case 'rsa_key_pair':
return new RsaKeyPairCredential(config.public_key_id, config.private_key_file);
case 'bearer':
return new BearerTokenCredential(config.bearer_token);
default:
throw new Error('Invalid type option, support: access_key, sts, ecs_ram_role, ram_role_arn, oidc_role_arn, rsa_key_pair, bearer');
}
}
}
\ No newline at end of file
import environmentVariableCredentialsProvider from './environment_variable_credentials_provider';
import profileCredentialsProvider from './profile_credentials_provider';
import instanceRamRoleCredentialsProvider from './instance_ram_role_credentials_provider';
import credentialsUriProvider from './credentials_uri_provider';
import oidcRoleArnCredentialsProvider from './oidc_role_arn_credentials_provider';
import ICredential from '../icredential';
type IProvider = {
getCredential: () => ICredential;
}
const defaultProviders: IProvider[] = [
environmentVariableCredentialsProvider,
oidcRoleArnCredentialsProvider,
profileCredentialsProvider,
instanceRamRoleCredentialsProvider,
credentialsUriProvider
];
export function getCredentials(providers: IProvider[] = null): ICredential {
const providerChain = providers || defaultProviders;
for (const provider of providerChain) {
const credential = provider.getCredential();
if (credential) {
return credential;
}
}
return null;
}
import SessionCredential from './session_credential';
import { request } from './util/http';
import Config from './config';
export default class RamRoleArnCredential extends SessionCredential {
roleArn: string;
policy: string;
durationSeconds: number;
roleSessionName: string;
runtime: {[key: string]: any};
host: string;
constructor(config: Config, runtime: {[key: string]: any} = {}) {
if (!config.accessKeyId) {
throw new Error('Missing required accessKeyId option in config for ram_role_arn');
}
if (!config.accessKeySecret) {
throw new Error('Missing required accessKeySecret option in config for ram_role_arn');
}
if (!config.roleArn) {
throw new Error('Missing required roleArn option in config for ram_role_arn');
}
const conf = new Config({
type: 'ram_role_arn',
accessKeyId: config.accessKeyId,
accessKeySecret: config.accessKeySecret,
securityToken: config.securityToken
});
super(conf);
this.roleArn = config.roleArn;
this.policy = config.policy;
this.durationSeconds = config.roleSessionExpiration || 3600;
this.roleSessionName = config.roleSessionName || 'role_session_name';
this.runtime = runtime;
this.host = 'https://sts.aliyuncs.com';
}
async updateCredential() {
const params: {[key: string]: any} = {
accessKeyId: this.accessKeyId,
securityToken: this.securityToken,
roleArn: this.roleArn,
action: 'AssumeRole',
durationSeconds: this.durationSeconds,
roleSessionName: this.roleSessionName
};
if (this.policy) {
params.policy = this.policy;
}
const json = await request(this.host, params, this.runtime, this.accessKeySecret);
this.sessionCredential = json.Credentials;
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册