@acoustic-content-sdk/cli-credentials 中文文档教程
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 tenantaOptions
: 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 URLaOptions
: 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 tenantaOptions
: 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;