@acoustic-content-sdk/cli-credentials 中文文档教程

发布于 4年前 浏览 14 更新于 3年前

npm

Credential Management for WCH CLI

用于管理用于 WCH CLI 项目的凭据的实用程序库。

Installation

NPM 脚本使用的本地安装:

npm install --save-dev @acoustic-content-sdk/cli-credentials

Class documentation

请参阅 API 文档

Credential Management

用于访问租户的凭据可以安全地存储在您的开发机器上。 根据操作系统,使用以下选项之一。

Credential Management (Windows)

在 Windows 下,使用 Credential Manager 来存储 WCH 的凭据。 您可以通过导航到 Control Panel\User Accounts and Family Safety\Credential Manager 来启动凭据管理器。 创建一个新的 Generic Credential。 当 Internet 或网络地址 从 WCH 选择 API URL 时,请确保以尾部斜杠结束 URL。 输入您的 WCH 用户名和密码,然后点击 OK

Credential Management (macOS)

在 macOS 下使用 Keychain Access 来存储您的 WCH 凭据。 使用 WCH 的 API URL 作为凭证​​的名称,这将自动使其成为 internet 凭证。 输入您的 WCH 用户名和密码,然后点击 OK

Credential Management (Linux)

在 Linux 下,凭证是从 ${home}/.ibm-wch-sdk-cli/.credentials 文件中读取的。 使用 store credentials 命令将凭据安全地保留在此文件中。

Credential Storage

将用户名和密码 WCH 存储在文件 ${home}/.ibm-wch-sdk-cli/.credentials 中。 密码使用 ${home}/.ssh/id_rsa 中的 SSH 私钥加密。 此命令设计用于 Unix 环境,但如果指定位置存在 SSH 密钥,它也适用于 Windows免责声明此方法需要对 SSH 密钥的无密码访问。

Note

不存在,您可以使用以下 shell 命令创建一个

ssh-keygen -t rsa -q -f ~/.ssh/id_rsa -P ""

Usage

wchGetCredentials

如果文件 ${home}/.ssh/ id_rsa API 网址

function wchGetCredentials(
  aApiUrl: string,
  aOptions?: Options
): Promise<Credentials>;
  • aApiUrl: the API URL for your tenant
  • aOptions: optional options to control logging

wchStoreCredentials

在每个环境(包括 Windows)的 ${home}/.ibm-wch-sdk-cli/.credentials 文件中存储给定的凭证。

function wchStoreCredentials(
  aWchToolsOptions: WchToolsOptions,
  aOptions?: Options
): Promise<string>;
  • aWchToolsOptions: credentials and API URL
  • aOptions: optional options to control logging

wchRemoveCredentials

${ home}/.ibm-wch-sdk-cli/.credentials 文件在每个环境中(包括 Windows)。

function wchRemoveCredentials(
  aApiUrl: string,
  aOptions?: Options
): Promise<string>;
  • aApiUrl: the API URL for your tenant
  • aOptions: optional options to control logging

isValidPassword

检查密码在语法上

function isValidPassword(aValue: any): aValue is string;

isValidUrl

是否有效 检查 URL 在语法上是否有效

function isValidUrl(aValue: any): aValue is string;

isValidUserName

检查用户名在语法上是否有效。 如果它是电子邮件或术语 apikey,就会出现这种情况。

function isValidUserName(aValue: any): aValue is string;

isValidCredentials

检查凭据对象在语法上是否有效。

function isValidCredentials(aCred: any): aCred is Credentials;

isValidApiUrl

通过尝试访问众所周知的字符串来检查字符串是否是有效的 API URL API 路由。

function isValidApiUrl(aValue: any): Promise<boolean>;

isValidWchToolsOptions

检查 WchToolsOptions 组合是否 API URL ,用户名和密码通过尝试登录到目标服务器是有效的。

function isValidWchToolsOptions(
  aCredentials: WchToolsOptions
): Promise<boolean>;

@acoustic-content-sdk/cli-credentials

cli-credentials package

Functions

Function Description
isValidApiUrl(aValue) Checks if the URL is a valid WCH API URL by making a test call
isValidPassword(aValue) Checks if a password is valid
isValidUrl(aValue) Checks if the url is syntactically a valid URL
isValidUserName(aValue) Checks if a username is valid, i.e. either an email or the term 'apikey'
isValidWchToolsOptions(aCredentials) Validates the credentials by trying to login
wchGetCredentials(aApiUrl, aOptions) Reads the credentials for the given API URL
wchRemoveCredentials(aApiUrl, aOptions)
wchStoreCredentials(aWchToolsOptions, aOptions)

Interfaces

Interface Description
Credentials WCH credentials
Options Contextual options
WchToolsOptions Extension of the credentials to also carry the API URL that the credentials apply to

Variables

Variable Description
VERSION Version and build number of the package

Type Aliases

Type Alias Description
Logger Simple logger interface that this library used to print debug logs

主页 > @acoustic-content-sdk/cli-credentials > isValidApiUrl

isValidApiUrl() function

通过测试调用检查 URL 是否是有效的 WCH API URL

签名:

export declare function isValidApiUrl(aValue: any): Promise<boolean>;

Parameters

Parameter Type Description
aValue any

返回:

Promise

true if the URL is valid, else false

Home > @acoustic-content-sdk/cli-credentials > isValidPassword

isValidPassword() function

检查密码是否有效

签名:

export declare function isValidPassword(aValue: any): aValue is string;

Parameters

Parameter Type Description
aValue any the value to test

返回:

aValue is string

true if the password is valid, else false

Home > @acoustic-content-sdk/cli-credentials > isValidUrl

isValidUrl() function

检查 url 在句法上是否是有效的 URL

签名:

export declare function isValidUrl(aValue: any): aValue is string;

Parameters

Parameter Type Description
aValue any the value

返回:

aValue is string

true if the value is a valid URL, else false

Home > @acoustic-content-sdk/cli-credentials > isValidUserName

isValidUserName() function

检查用户名是否有效,即电子邮件或术语“apikey”

签名:

export declare function isValidUserName(aValue: any): aValue is string;

Parameters

Parameter Type Description
aValue any the value to test

返回:

< code>aValue is string

true if the name is valid, else false

Home > @acoustic-content-sdk/cli-credentials > isValidWchToolsOptions

isValidWchToolsOptions() function

通过尝试登录验证凭据

签名:

export declare function isValidWchToolsOptions(aCredentials: WchToolsOptions): Promise<boolean>;

Parameters

Parameter Type Description
aCredentials WchToolsOptions the credentials

返回:

Promise

true if the credentials were correct, else false

Home > @acoustic-content-sdk/cli-credentials > wchGetCredentials

wchGetCredentials() function

读取给定 API URL 的凭据

签名:

export declare function wchGetCredentials(aApiUrl: string, aOptions?: Options): Promise<Credentials>;

Parameters

Parameter Type Description
aApiUrl string the API URL
aOptions Options options for debugging and logging

返回:

Promise

加载凭据的承诺

Homed602deca193" > @acoustic-content-sdk/cli-credentials > wchRemoveCredentials

wchRemoveCredentials() function

Signature:

declare function _removeCredentials(aApiUrl: string, aOptions?: Options): Promise<string>;

Parameters

Parameter Type Description
aApiUrl string
aOptions Options

Returns:

Promise

首页 > @acoustic-content-sdk/cli-credentials > wchStoreCredentials

wchStoreCredentials() function

Signature:

declare function _writeCredentials(aWchToolsOptions: WchToolsOptions, aOptions?: Options): Promise<string>;

Parameters

Parameter Type Description
aWchToolsOptions WchToolsOptions
aOptions Options

Returns:

Promise

首页 > @acoustic-content-sdk/cli-credentials > Credentials

Credentials interface

WCH credentials

Signature:

export interface Credentials 

Properties

Property Type Description
password string The WCH password
username string The WCH username, typically an email or the string 'apikey'

Home > @acoustic-content-sdk/cli-credentials > Options

Options interface

Contextual options

Signature:

export interface Options 

Properties

Property Type Description
debug boolean If set to true, print debug logs
logger Logger If provided, the logger to be used to print debug logs

Home > @acoustic-content-sdk/cli-credentials > WchToolsOptions

WchToolsOptions interface

Extension of the credentials to also carry the API URL that the credentials apply to

Signature:

export interface WchToolsOptions extends Credentials 

Properties

Property Type Description
baseUrl string The WCH AP URL

首页 > @acoustic-content-sdk/cli-credentials > VERSION

VERSION variable

Version and build number of the package

Signature:

VERSION: {
    version: {
        major: string;
        minor: string;
        patch: string;
        branch: string;
    };
    build: Date;
}

首页 > @acoustic-content-sdk/cli-credentials > Logger

Logger type

Simple logger interface that this library used to print debug logs

Signature:

export declare type Logger = (...optionalParams: any[]) => void;

主页 > @acoustic-content-sdk/cli-credentials > 凭据 > password

Credentials.password property

The WCH password

Signature:

password: string;

Home > @acoustic-content-sdk/cli-credentials > 凭据 > username

Credentials.username property

The WCH username, typically an email or the string 'apikey'

Signature:

username: string;

主页 > @acoustic-content-sdk/cli-credentials > 选项 > debug

Options.debug property

If set to true, print debug logs

Signature:

debug?: boolean;

首页 > @acoustic-content-sdk/cli-credentials > 选项 > logger

Options.logger property

If provided, the logger to be used to print debug logs

Signature:

logger?: Logger;

主页 > @acoustic-content-sdk/cli-credentials > WchToolsOptions > baseUrl

WchToolsOptions.baseUrl property

WCH AP URL

签名

baseUrl: string;

npm

Credential Management for WCH CLI

Utility library to manage credentials for use with WCH CLI projects.

Installation

Local install for use from an NPM script:

npm install --save-dev @acoustic-content-sdk/cli-credentials

Class documentation

Refer to the API documentation.

Credential Management

The credentials used to access a tenant can be stored securely on your development machine. Depending on the operating system, use one of the following options.

Credential Management (Windows)

Under Windows use the Credential Manager to store your credentials for WCH. You can start the credential manager by navigating to Control Panel\User Accounts and Family Safety\Credential Manager. Create a new Generic Credential. As Internet or network address choose the API URL from WCH, make sure end the URL with a trailing slash. Enter your WCH username and password and hit OK.

Credential Management (macOS)

Under macOS use the Keychain Access to store your credentials for WCH. Use the API URL from WCH as the name of the credenitial, this will automatically make it an internet credential. Enter your WCH username and password and hit OK.

Credential Management (Linux)

Under Linux the credentials are read from the ${home}/.ibm-wch-sdk-cli/.credentials file. Use the store credentials command to securely persist the credentials in this file.

Credential Storage

Stores a user name and password WCH in the file ${home}/.ibm-wch-sdk-cli/.credentials. The password is encrypted using the private SSH key found in ${home}/.ssh/id_rsa. This command has been designed to work in a Unix environment, but it will also for for Windows provided an SSH key exists at the specified location. Disclaimer this method requires password free access to the SSH key.

Note

If the file ${home}/.ssh/id_rsa does not exist, you can create one using the following shell command:

ssh-keygen -t rsa -q -f ~/.ssh/id_rsa -P ""

Usage

The module exports the following functions to work with credentials:

wchGetCredentials

Reads the credentials for the given API URL.

function wchGetCredentials(
  aApiUrl: string,
  aOptions?: Options
): Promise<Credentials>;
  • aApiUrl: the API URL for your tenant
  • aOptions: optional options to control logging

wchStoreCredentials

Stores the given credentials in the ${home}/.ibm-wch-sdk-cli/.credentials file in every environment (including Windows).

function wchStoreCredentials(
  aWchToolsOptions: WchToolsOptions,
  aOptions?: Options
): Promise<string>;
  • aWchToolsOptions: credentials and API URL
  • aOptions: optional options to control logging

wchRemoveCredentials

Removes the credentials for the given API URL from the ${home}/.ibm-wch-sdk-cli/.credentials file in every environment (including Windows).

function wchRemoveCredentials(
  aApiUrl: string,
  aOptions?: Options
): Promise<string>;
  • aApiUrl: the API URL for your tenant
  • aOptions: optional options to control logging

isValidPassword

Checks if a password is valid syntactically

function isValidPassword(aValue: any): aValue is string;

isValidUrl

Checks if a URL is valid syntactically

function isValidUrl(aValue: any): aValue is string;

isValidUserName

Checks if a username is valid syntactically. This is the case if it is either an email or the term apikey.

function isValidUserName(aValue: any): aValue is string;

isValidCredentials

Checks if the credentials object is valid syntactically.

function isValidCredentials(aCred: any): aCred is Credentials;

isValidApiUrl

Checks if a string is a valid API URL by trying to access well known API routes.

function isValidApiUrl(aValue: any): Promise<boolean>;

isValidWchToolsOptions

Checks if the WchToolsOptions combination of API URL, username and password is valid by trying to login to the targeted server.

function isValidWchToolsOptions(
  aCredentials: WchToolsOptions
): Promise<boolean>;

Home > @acoustic-content-sdk/cli-credentials

cli-credentials package

Functions

Function Description
isValidApiUrl(aValue) Checks if the URL is a valid WCH API URL by making a test call
isValidPassword(aValue) Checks if a password is valid
isValidUrl(aValue) Checks if the url is syntactically a valid URL
isValidUserName(aValue) Checks if a username is valid, i.e. either an email or the term 'apikey'
isValidWchToolsOptions(aCredentials) Validates the credentials by trying to login
wchGetCredentials(aApiUrl, aOptions) Reads the credentials for the given API URL
wchRemoveCredentials(aApiUrl, aOptions)
wchStoreCredentials(aWchToolsOptions, aOptions)

Interfaces

Interface Description
Credentials WCH credentials
Options Contextual options
WchToolsOptions Extension of the credentials to also carry the API URL that the credentials apply to

Variables

Variable Description
VERSION Version and build number of the package

Type Aliases

Type Alias Description
Logger Simple logger interface that this library used to print debug logs

Home > @acoustic-content-sdk/cli-credentials > isValidApiUrl

isValidApiUrl() function

Checks if the URL is a valid WCH API URL by making a test call

Signature:

export declare function isValidApiUrl(aValue: any): Promise<boolean>;

Parameters

Parameter Type Description
aValue any

Returns:

Promise<boolean>

true if the URL is valid, else false

Home > @acoustic-content-sdk/cli-credentials > isValidPassword

isValidPassword() function

Checks if a password is valid

Signature:

export declare function isValidPassword(aValue: any): aValue is string;

Parameters

Parameter Type Description
aValue any the value to test

Returns:

aValue is string

true if the password is valid, else false

Home > @acoustic-content-sdk/cli-credentials > isValidUrl

isValidUrl() function

Checks if the url is syntactically a valid URL

Signature:

export declare function isValidUrl(aValue: any): aValue is string;

Parameters

Parameter Type Description
aValue any the value

Returns:

aValue is string

true if the value is a valid URL, else false

Home > @acoustic-content-sdk/cli-credentials > isValidUserName

isValidUserName() function

Checks if a username is valid, i.e. either an email or the term 'apikey'

Signature:

export declare function isValidUserName(aValue: any): aValue is string;

Parameters

Parameter Type Description
aValue any the value to test

Returns:

aValue is string

true if the name is valid, else false

Home > @acoustic-content-sdk/cli-credentials > isValidWchToolsOptions

isValidWchToolsOptions() function

Validates the credentials by trying to login

Signature:

export declare function isValidWchToolsOptions(aCredentials: WchToolsOptions): Promise<boolean>;

Parameters

Parameter Type Description
aCredentials WchToolsOptions the credentials

Returns:

Promise<boolean>

true if the credentials were correct, else false

Home > @acoustic-content-sdk/cli-credentials > wchGetCredentials

wchGetCredentials() function

Reads the credentials for the given API URL

Signature:

export declare function wchGetCredentials(aApiUrl: string, aOptions?: Options): Promise<Credentials>;

Parameters

Parameter Type Description
aApiUrl string the API URL
aOptions Options options for debugging and logging

Returns:

Promise<Credentials>

a promise of the loaded credentials

Home > @acoustic-content-sdk/cli-credentials > wchRemoveCredentials

wchRemoveCredentials() function

Signature:

declare function _removeCredentials(aApiUrl: string, aOptions?: Options): Promise<string>;

Parameters

Parameter Type Description
aApiUrl string
aOptions Options

Returns:

Promise<string>

Home > @acoustic-content-sdk/cli-credentials > wchStoreCredentials

wchStoreCredentials() function

Signature:

declare function _writeCredentials(aWchToolsOptions: WchToolsOptions, aOptions?: Options): Promise<string>;

Parameters

Parameter Type Description
aWchToolsOptions WchToolsOptions
aOptions Options

Returns:

Promise<string>

Home > @acoustic-content-sdk/cli-credentials > Credentials

Credentials interface

WCH credentials

Signature:

export interface Credentials 

Properties

Property Type Description
password string The WCH password
username string The WCH username, typically an email or the string 'apikey'

Home > @acoustic-content-sdk/cli-credentials > Options

Options interface

Contextual options

Signature:

export interface Options 

Properties

Property Type Description
debug boolean If set to true, print debug logs
logger Logger If provided, the logger to be used to print debug logs

Home > @acoustic-content-sdk/cli-credentials > WchToolsOptions

WchToolsOptions interface

Extension of the credentials to also carry the API URL that the credentials apply to

Signature:

export interface WchToolsOptions extends Credentials 

Properties

Property Type Description
baseUrl string The WCH AP URL

Home > @acoustic-content-sdk/cli-credentials > VERSION

VERSION variable

Version and build number of the package

Signature:

VERSION: {
    version: {
        major: string;
        minor: string;
        patch: string;
        branch: string;
    };
    build: Date;
}

Home > @acoustic-content-sdk/cli-credentials > Logger

Logger type

Simple logger interface that this library used to print debug logs

Signature:

export declare type Logger = (...optionalParams: any[]) => void;

Home > @acoustic-content-sdk/cli-credentials > Credentials > password

Credentials.password property

The WCH password

Signature:

password: string;

Home > @acoustic-content-sdk/cli-credentials > Credentials > username

Credentials.username property

The WCH username, typically an email or the string 'apikey'

Signature:

username: string;

Home > @acoustic-content-sdk/cli-credentials > Options > debug

Options.debug property

If set to true, print debug logs

Signature:

debug?: boolean;

Home > @acoustic-content-sdk/cli-credentials > Options > logger

Options.logger property

If provided, the logger to be used to print debug logs

Signature:

logger?: Logger;

Home > @acoustic-content-sdk/cli-credentials > WchToolsOptions > baseUrl

WchToolsOptions.baseUrl property

The WCH AP URL

Signature:

baseUrl: string;
更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文