--- tags: cli, feature author: Oliver.W --- # Long term token > ticket: https://app.asana.com/0/1200011502754281/1200046588610090/f > PR: https://github.com/serverless/components/pull/928 ## Story As a serverless developer I like to save my credential locally and use it when needed So that i don't need to local every time. ## Logic Path ### Use Credential ```sh # Use default profile name credential info serverless *** # Relogin and generate temporary token serverless *** --login # Use env variable to set the profile name to use TENCENT_CREDENTIALS_PROFILE=profileName2 sls *** # Use the profile arg to set the profile name to use serverless *** --profile profileName2 # Show message to suggest use global credentials before scan QR code. 请扫码进行登陆,或通过 sls creditionals 配置全局用户授权,详情请查看 sls --help # Show message when use global credential 使用授权信息 {profilename} 授权中,如果需要使用临时密钥,请使用 --login 重新登陆 ``` 1. Has Local Token (`TENCENT_SECRET_ID` & `TENCENT_SECRET_KEY` in env) * token not expired,Use local token. * token expired, ask login and generate a new temporary token. 2. Has Global Token * use specific profile token (use `default` if not provide the name) 3. No Local or Global Token * ask login and generate a new temporary token. > 1. Priority for `.env`: Project env file is highest, and then is global env file config > 2. After set the global env config, any component project without the local env file will use `TENCENT_SECRET_ID` and `TENCENT_SECRET_KEY` in the global config. > 3. Fields in global config will not override the fields in local config ## Command Design ```sh serverless remove/deploy 从云端移除一个 Serverless 实例 --... 获取移除过程的详细信息 --login. 扫码登陆并更新临时密钥 --profile {name} 使用全局授权名称信息的密钥信息 serverless credentials 管理全局用户授权信息 set 存储用户授权信息 --secretId / -i (必填)腾讯云CAM账号secretId --secretKey / -k (必填)腾讯云CAM账号secretKey --profile / -p {name} 授权名称. 默认为 "default" --overwrite / -o 覆写已有授权名称的密钥 remove 移除用户授权信息 --profile / -n {name} (必填)授权名称 list 查看用户授权信息 ``` ## Credential File Structure: > ~/.serverless/tencent/credentials ``` [defautl] id=2222 key=111 [profileName] id=id key=key ``` ## Usage: ### set credentials ```sh # Set with default profile name. $ serverless credentials set --secretId xxx --secretKey xxx # set with specific profile name. $ serverless credentials set --secretId xxx --secretKey xxx --profile profileName1 # Set overwrite with specific profile name. $ serverless credentials set --secretId xxx --secretKey xxx --profile profileName1 --overwrite ``` ```sh --- 存储成功提示 使用授权信息请在 serverless 命令后添加 --profile {name} 默认使用default 或储存 TENCENT_CREDENTIALS_PROFILE={name} 在项目 .env 文件中 如果在项目中需要使用临时密钥 请在命令后添加 --login 进行扫码登陆 授权信息会储存在系统本地目录,并长期有效。请确认当前电脑不是公用电脑或与他人共享 如果密钥信息泄漏请前往 腾讯云-用户控制台 删除相关用户 更多帮助请查看 sls --help Serverless: (绿色)授权信息 {profilename} 储存成功(/绿色) --- 更新成功提示 Serverless: (绿色)授权信息 {profilename} 更新成功(/绿色) --- 存储名称已存在 Serverless: (黄色)授权信息 {profilename} 已存在,请使用 --overwrite 进行覆写(/黄色) ``` ### remove credentials ``` # Remove a credential with specific profile anme $ serverless credentials remove --profile profileName1 ``` ```sh --- 移除成功提示 如果需要删除相关授权用户请前往 腾讯云-用户控制台 删除相关用户 更多帮助请查看 sls --help Serverless: (绿色)授权信息 {profilename} 移除成功(/绿色) --- 未制定授权名称 Serverless: (黄色)未指定授权名称,请通过 --profile 指定要删除的授权名称(/黄色) --- 移除授权名称不存在 Serverless: (黄色)授权信息 {profilename} 不存在,请通过 serverless credentials list 查看当前授权信息(/黄色) ``` ### list credentials ``` # Remove all credentials $ serverless credentials list ``` ``` Serverless: 当前已有用户授权信息名称: - default - profileName1 ``` ### Use credentials ``` # use default credentials $ sls deploy / sls info # use specific credentials $ sls deploy --profile newP / sls info --profile newP ``` ``` # 当profile不存在 Serverless: (黄色)授权信息 {profilename} 不存在,请通过 serverless credentials list 查看当前授权信息(/黄色) # 当profile信息认证失败 (让用户知道是认证的错误,而不是我们CLI本地没有找到SecretId,误以为是CLI错误。) Serverless › 授权认证失败:The SecretId is not found, please ensure that your SecretId is correct. # 其他情况 Serverless › {Error Message} ```