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

@serverless-devs/credential

v0.0.5

Published

credential for serverless-devs

Downloads

697

Readme

处理密钥配置(@serverless-devs/credential)

安装

$ npm install @serverless-devs/credential --save

构建实例

import Credential from '@serverless-devs/credential';

const credential = new Credential(logger); // logger 选填,用于日志输出

方法

新增密钥配置 set

参数解析

import Credential from '@serverless-devs/credential';

const credential = new Credential();
const result = await credential.set(options);

| 参数 | 说明 | 类型 | 必填 | 默认值 | | --------- | ------------ | ----------------------------- | ---- | ------------- | | access | 新增密钥别名 | string | 否 | - | | force | 如果配置密钥别名已经存在,是否强制覆盖 | boolean | 否 | - | | 其他参数 | 如果希望通过参数指定直接新增密钥(注意⚠️:需要成对指定支持厂商的密钥)。如果不满足可以使用 keyList 和 infoList 参数自定义,具体参考使用示例 | - | 否 | - |

参数缺少出现交互,CiCd 环境下则报错

厂商密钥 Key:
Alibaba Cloud (alibaba): AccessKeyID、AccessKeySecret // AccountID 和 SecurityToken 选填
AWS (aws): AccessKeyID、SecretAccessKey
Azure (azure): KeyVaultName、TenantID、ClientID、ClientSecret
Baidu Cloud (baidu): AccessKeyID、SecretAccessKey
Google Cloud (google): PrivateKeyData
Huawei Cloud (huawei): AccessKeyID、SecretAccessKey
Tencent Cloud (tencent): AccountID、SecretID、SecretKey

返回值

可能返回 undefined 或者下面的数据结构

| 参数 | 说明 | 类型 | | --------- | ------------ | ---- | | access | 密钥别名 | string | | credential | 创建的密钥对 | Record<string, string> |

使用示例

交互式创建密钥
const result = await credential.set()
创建 alibaba 密钥
const result = await credential.set({
  access: 'alibaba',
  AccessKeyID: 'LTAI5*****THK',
  AccessKeySecret: 'RgeGJ*****FyMW',
  AccountID: 'xxxxxx',
});
/**
result = {
  access: 'alibaba',
  credential: {
    AccessKeyID: 'LTA*****THK',
    AccessKeySecret: 'Rge*****yMW',
    AccountID: '189****629',
  }
 */
创建 aws/huawei/baidu 密钥
const result = await credential.set({
  access: 'alias',
  force: true,
  AccessKeyID: 'AccessKeyID',
  SecretAccessKey: 'SecretAccessKey',
})
// result = { access: 'alias', credential: { AccessKeyID: 'AccessKeyID', SecretAccessKey: 'SecretAccessKey' } }
创建 azure 密钥
const result = await credential.set({
  access: 'azure',
  force: true,
  KeyVaultName: 'KeyVaultName',
  TenantID: 'TenantID',
  ClientID: 'ClientID',
  ClientSecret: 'ClientSecret',
})
/**
result = {
  access: 'azure',
  credential: {
    KeyVaultName: 'KeyVaultName',
    TenantID: 'TenantID',
    ClientID: 'ClientID',
    ClientSecret: 'ClientSecret',
  }
 */
创建 google 密钥
const result = await credential.set({
  access: 'google',
  force: true,
  PrivateKeyData: 'PrivateKeyData',
})
/**
result = {
  access: 'google',
  credential: {
    PrivateKeyData: 'PrivateKeyData',
  },
 */
创建 tencent 密钥
const result = await credential.set({
  access: 'tencent',
  force: true,
  AccountID: 'AccountID',
  SecretID: 'SecretID',
  SecretKey: 'SecretKey',
})
/**
result = {
  access: 'tencent',
  credential: {
    AccountID: 'AccountID',
    SecretID: 'SecretID',
    SecretKey: 'SecretKey',
  },
 */
创建 custom 密钥
const result = await credential.set({
  access: 'custom',
  force: true,
  keyList: 'SecretID,SecretKey,Test',
  infoList: 'abc,yyy,123',
})
/**
result = {
  access: 'custom',
  credential: {
    Test: '123',
    SecretID: 'abc',
    SecretKey: 'yyy',
  },
 */

获取密钥

使用方式

import Credential from '@serverless-devs/credential';

const credential = new Credential();
const result = await credential.get('access');

获取逻辑

获取日志逻辑文档

获取所有密钥 getAll

使用方式

import Credential from '@serverless-devs/credential';

const credential = new Credential();
await credential.getAll();

删除密钥别名 remove

使用方式

import Credential from '@serverless-devs/credential';

const credential = new Credential();
await credential.remove(access); // 如果不传入参数则出现交互,CiCd 环境下则报错

修改密钥别名 rename

使用方式

import Credential from '@serverless-devs/credential';

const credential = new Credential();
await credential.rename({ source, target }); // 如果不传入或者缺少参数则出现交互,CiCd 环境下则报错

配置默认密钥 default

使用方式

import Credential from '@serverless-devs/credential';

const credential = new Credential();
await credential.default(access); // 如果不传入则出现交互,CiCd 环境下则报错

解密 decrypt

使用方式

import Credential from '@serverless-devs/credential';

const credential = new Credential();
// 入参是通过 set 方法加密后的密钥键值对
const result = await credential.decrypt({
  AccessKeyID: 'U2FsdGVkX1/vUriF3c62TFb2R8qgDP669jsyr6ilyD4=',
  SecretAccessKey: 'U2FsdGVkX1/HygYh+uGL+wxglAQuxDzj/UUARUMW9NE=',
});
// result = {AccessKeyID: 'AccessKeyID', SecretAccessKey: 'SecretAccessKey' }