npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

qcloud-cos-sts

v3.1.1

Published

## 安装方法

Downloads

3,330

Readme

qcloud-cos-sts

安装方法

npm i qcloud-cos-sts --save

调用示例

请查看 demo 里的示例。

接口说明

getCredential

获取临时密钥接口(获取联合身份临时访问凭证)。

参数说明

| 字段 | 类型 | 描述 | 必选 | | ---- | ---- | ---- | ---- | | options | Object | 表示当客户端的请求,最少需要什么样的权限,是一个键值对象的数组 | 是 | | - secretId | String | 云 API 密钥 Id | 是 | | - secretKey | String | 云 API 密钥 Key | 是 | | - policy | Object | 要申请的临时密钥,限定的权限范围 | 是 | | - durationSeconds | Number | 要申请的临时密钥最长有效时间,单位秒,默认 1800,最大可设置 7200 | 否 | | - proxy | String | 代理地址,如:"http://proxy.example.com:8080" | 否 | | - host | String | 可以通过改参数指定请求的域名 | 否 | | - endpoint | String | 作用与host参数相同,二者选一即可 | 否 | | callback | Function | 临时密钥获取完成后的回调方法 | 是 |

返回值说明

| 字段 | 类型 | 描述 | | ---- | ---- | ---- | | err | Object | 错误信息 | | data | Object | 返回的临时密钥内容 | | - startTime | Number | 密钥的起始时间,是 UNIX 时间戳 | | - expiredTime | Number | 密钥的失效时间,是 UNIX 时间戳 | | - credentials | String | 云API | | - - tmpSecretId | String | 临时密钥 Id,可用于计算签名 | | - - tmpSecretKey | String | 临时密钥 Key,可用于计算签名 | | - - sessionToken | String | 请求时需要用的 token 字符串,最终请求 COS API 时,需要放在 Header 的 x-cos-security-token 字段 |

返回示例

{
    "credentials": {
        "tmpSecretId": "AKIDEPMQB_Q9Jt2fJxXyIekOzKZzx-sdGQgBga4TzsUdTWL9xlvsjInOHhCYFqfoKOY4",
        "tmpSecretKey": "W/3Lbl1YEW02mCoawIesl5kNehSskrSbp1cT1tgW70g=",
        "sessionToken": "c6xnSYAxyFbX8Y50627y9AA79u6Qfucw6924760b61588b79fea4c277b01ba157UVdr_10Y30bdpYtO8CXedYZe3KKZ_DyzaPiSFfNAcbr2MTfAgwJe-dhYhfyLMkeCqWyTNF-rOdOb0rp4Gto7p4yQAKuIPhQhuDd77gcAyGakC2WXHVd6ZuVaYIXBizZxqIHAf4lPiLHa6SZejSQfa_p5Ip2U1cAdkEionKbrX97xTKTcA_5Pu525CFSzHZIQibc2uNMZ-IRdQp12MaXZB6bxM6nB4xXH45mDIlbIGjaAsrtRJJ3csmf82uBKaJrYQoguAjBepMH91WcH87LlW9Ya3emNfVX7NMRRf64riYd_vomGF0TLgan9smEKAOdtaL94IkLvVJdhLqpvjBjp_4JCdqwlFAixaTzGJHdJzpGWOh0mQ6jDegAWgRYTrJvc5caYTz7Vphl8XoX5wHKKESUn_vqyTAid32t0vNYE034FIelxYT6VXuetYD_mvPfbHVDIXaFt7e_O8hRLkFwrdAIVaUml1mRPvccv2qOWSXs"
    },
    "expiration": "2019-08-07T08:54:35Z",
    "startTime": 1565166275,
    "expiredTime": 1565168075,
    "requestId":"3f8f5f69-1929-4f8f-9e47-ee0426a880ae"
}

getRoleCredential

获取临时密钥接口(申请扮演角色)。

参数说明

| 字段 | 类型 | 描述 | 必选 | | ---- | ---- | ---- | ---- | | options | Object | 表示当客户端的请求,最少需要什么样的权限,是一个键值对象的数组 | 是 | | - secretId | String | 云 API 密钥 Id | 是 | | - secretKey | String | 云 API 密钥 Key | 是 | | - policy | Object | 要申请的临时密钥,限定的权限范围 | 是 | | - roleArn | String | 角色的资源描述,参考文档 | 是 | | - durationSeconds | Number | 要申请的临时密钥最长有效时间,单位秒,默认 1800,最大可设置 7200 | 否 | | - proxy | String | 代理地址,如:"http://proxy.example.com:8080" | 否 | | - host | String | 可以通过改参数指定请求的域名 | 否 | | - endpoint | String | 作用与host参数相同,二者选一即可 | 否 | | callback | Function | 临时密钥获取完成后的回调方法 | 是 |

返回值说明

| 字段 | 类型 | 描述 | | ---- | ---- | ---- | | err | Object | 错误信息 | | data | Object | 返回的临时密钥内容 | | - startTime | Number | 密钥的起始时间,是 UNIX 时间戳 | | - expiredTime | Number | 密钥的失效时间,是 UNIX 时间戳 | | - credentials | String | 云API | | - - tmpSecretId | String | 临时密钥 Id,可用于计算签名 | | - - tmpSecretKey | String | 临时密钥 Key,可用于计算签名 | | - - sessionToken | String | 请求时需要用的 token 字符串,最终请求 COS API 时,需要放在 Header 的 x-cos-security-token 字段 |

返回示例

{
    "credentials": {
        "tmpSecretId": "AKIDEPMQB_Q9Jt2fJxXyIekOzKZzx-sdGQgBga4TzsUdTWL9xlvsjInOHhCYFqfoKOY4",
        "tmpSecretKey": "W/3Lbl1YEW02mCoawIesl5kNehSskrSbp1cT1tgW70g=",
        "sessionToken": "c6xnSYAxyFbX8Y50627y9AA79u6Qfucw6924760b61588b79fea4c277b01ba157UVdr_10Y30bdpYtO8CXedYZe3KKZ_DyzaPiSFfNAcbr2MTfAgwJe-dhYhfyLMkeCqWyTNF-rOdOb0rp4Gto7p4yQAKuIPhQhuDd77gcAyGakC2WXHVd6ZuVaYIXBizZxqIHAf4lPiLHa6SZejSQfa_p5Ip2U1cAdkEionKbrX97xTKTcA_5Pu525CFSzHZIQibc2uNMZ-IRdQp12MaXZB6bxM6nB4xXH45mDIlbIGjaAsrtRJJ3csmf82uBKaJrYQoguAjBepMH91WcH87LlW9Ya3emNfVX7NMRRf64riYd_vomGF0TLgan9smEKAOdtaL94IkLvVJdhLqpvjBjp_4JCdqwlFAixaTzGJHdJzpGWOh0mQ6jDegAWgRYTrJvc5caYTz7Vphl8XoX5wHKKESUn_vqyTAid32t0vNYE034FIelxYT6VXuetYD_mvPfbHVDIXaFt7e_O8hRLkFwrdAIVaUml1mRPvccv2qOWSXs"
    },
    "expiration": "2019-08-07T08:54:35Z",
    "startTime": 1565166275,
    "expiredTime": 1565168075,
    "requestId":"3f8f5f69-1929-4f8f-9e47-ee0426a880ae"
}

getPolicy

获取 policy 接口。本接口适用于接收 Web、iOS、Android 客户端 SDK 提供的 Scope 参数。推荐您把 Scope 参数放在请求的 Body 里面,通过 POST 方式传到后台。

参数说明

| 字段 | 类型 | 描述 | 必选 | | ---- | ---- | ---- | ---- | | scope | ObjectArray | 表示当客户端的请求,最少需要什么样的权限,是一个键值对象的数组 | 是 | | - action | String | 操作名称,如 "name/cos:PutObject" | 是 | | - bucket | String | 存储桶名称,格式:test-1250000000 | 是 | | - region | String | 园区名称,如 ap-guangzhou | 是 | | - prefix | String | 拼接 resource 字段所需的 key 前缀,客户端 SDK 默认传固定文件名如 "dir/1.txt",支持 * 结尾如 "dir/*" | 是 |

返回值说明

| 字段 | 类型 | 描述 | | ---- | ---- | ---- | | policy | Object | 申请临时密钥所需的权限策略 |

policy 具体格式请看 文档

返回示例

{
    "version": "2.0",
    "statement": [{
        "action": [
            "name/cos:PutObject",
        ],
        "effect": "allow",
        "principal": {"qcs": ["*"]},
        "resource": [
            "qcs::cos:ap-guangzhou:uid/1250000000:prefix//1250000000/test/exampleobject"
        ]
    }]
}

更多示例

  • demo/demo.js 是调用例子
  • demo/sts-server.js 是临时密钥服务的例子
  • demo/sts-server-scope.js 是临时密钥服务的例子,可以细粒度控制权限

您可以直接使用 demo/sts-server.js 或者 demo/sts-server-scope.js,修改配置参数,来搭建本地密钥服务器。

相关 SDK