跳转到内容

cnb-rs auth gitcredential

cnb-rs auth gitcredential <get|store|erase>

git credential helper protocol 实现,让 git 在需要 https://<host> 凭证时自动从 cnb-rs 拿 token。对齐 gh auth git-credential

该命令由 git 自动调用

不要直接用 cnb-rs auth gitcredential get。它的设计目的是在 ~/.gitconfigcredential.<url>.helper 配置里被 git 子系统调用。直接安装方式是运行 cnb-rs auth setup-git,setup-git 写入的 helper 配置会自动调用本命令。

操作语义

operationstdinstdout行为
getprotocol=https\nhost=<H>\n\nprotocol=https\nhost=<H>\nusername=<U>\npassword=<token>\n按 host 查 cnb-rs 已保存的 token 返给 git
storegit 推过来的 protocol/host/username/password(无)no-op:cnb-rs token 通过 auth login 写入,不接受 git 推过来覆盖以免破坏 keyring
erasegit 推过来的 protocol/host/username(无)no-op:cnb-rs 不主动删 token,避免误删,统一走 auth logout

get 的过滤条件:

  • 仅当 protocol=https 时返回凭证(CNB 暂不支持 SSH)
  • 仅当 stdin 含 host=<...> 时返回凭证
  • 未在 cnb-rs 中找到对应 host 的 token 时静默退出(让 git fallback 到其他 helper 或交互式问),不报错

参数

  • <operation>: get / store / erase,对应 git credential helper 协议三个 op。未知 op friendly bail

继承的全局选项:

  • --domain <DOMAIN>: 通常不需要传,git 通过 stdin 给出 host

示例

模拟 git 调用本命令获取凭证:

bash
$ printf 'protocol=https\nhost=cnb.cool\n\n' | cnb-rs auth gitcredential get
protocol=https
host=cnb.cool
username=oauth2
password=cnb_xxxxxxxxxxxx

未知 operation:

bash
$ cnb-rs auth gitcredential foo
错误: 未知 git credential 操作:foo(应为 get / store / erase 之一)

username 字段说明

返回的 username 取自 keyring/config 里保存的账号名;当 token 来自环境变量(无 username 信息)时用通用占位符 oauth2(CNB Web 接受任意 username,只要 password 是有效 token)。

另请参阅

Released under the MIT License.