pingcode-cli-unofficial 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -126,31 +126,67 @@ The CLI authenticates as an **application**, not as a user, using the OAuth
126
126
 
127
127
  ## Log in
128
128
 
129
+ Two kinds of credential are supported, and they are independent slots in the same config file:
130
+
131
+ - **app credentials** (`client_id` + `client_secret`) — the enterprise app
132
+ (`client_credentials`, `--mode enterprise`) or a user-bound OAuth app (`--mode user`,
133
+ authorization code). Without `--mode`, `auth login` defaults to `user`;
134
+ - **a personal access token** — created in PingCode 个人设置, pasted in with `--mode pat`, or supplied
135
+ as `PINGCODE_TOKEN`. No app registration, no browser, no refresh.
136
+
129
137
  ```bash
130
138
  # public cloud (default host: https://open.pingcode.com)
131
- pingcode auth login --client-id <id> --client-secret <secret> --save
139
+ pingcode auth login --mode enterprise --client-id <id> --client-secret <secret> --save
132
140
 
133
141
  # self-hosted: pass your instance host, the API is served from <host>/open
134
- pingcode auth login --host https://pingcode.example.com \
142
+ pingcode auth login --mode enterprise --host https://pingcode.example.com \
135
143
  --client-id <id> --client-secret <secret> --save
136
144
 
137
145
  pingcode auth status --check # adds one live call: GET /v1/pjm/projects?page_size=1
138
- pingcode auth logout # drops the token, the credentials and the metadata cache
146
+ pingcode auth logout # drops the active token slot and the metadata cache
147
+ pingcode auth logout --all # additionally drops both app credential pairs and the other slots
139
148
  ```
140
149
 
141
150
  Credentials resolve in this precedence order: **CLI flags → environment
142
- (`PINGCODE_CLIENT_ID`, `PINGCODE_CLIENT_SECRET`, `PINGCODE_HOST`) → `~/.pingcode/config.json`**.
143
- With a TTY attached, `auth login` prompts for anything missing.
151
+ (`PINGCODE_CLIENT_ID`, `PINGCODE_CLIENT_SECRET`, `PINGCODE_TOKEN`, `PINGCODE_HOST`) →
152
+ `~/.pingcode/config.json`**. With a TTY attached, `auth login` prompts for anything missing.
144
153
 
145
154
  - `--save` is what persists the client id/secret. Without it only the token is stored, so you must
146
155
  log in again when it expires.
147
156
  - Storage is `~/.pingcode/config.json`, mode `0600` inside a `0700` directory (a no-op on Windows).
148
157
  `PINGCODE_CONFIG_DIR` relocates it.
149
- - Tokens are valid ~30 days and are re-acquired **transparently**: proactively 120 s before expiry,
150
- and reactively once on a `401`, replaying the original request. You never have to re-run `login`
151
- while the credentials are stored.
158
+ - App-credential tokens are valid ~30 days and are re-acquired **transparently**: proactively 120 s
159
+ before expiry, and reactively once on a `401`, replaying the original request. You never have to
160
+ re-run `login` while the credentials are stored. A personal access token is the exception — it
161
+ cannot be renewed, see below.
152
162
  - Repeated logins do **not** invalidate previously issued tokens, so parallel invocations are safe.
153
163
 
164
+ ### Personal access token (脚本 / CI/CD)
165
+
166
+ ```bash
167
+ # token created in PingCode 个人设置 (validity + scopes chosen there, shown only once)
168
+ pingcode auth login --mode pat --token <token> # store it (mode 0600, in its own slot)
169
+ PINGCODE_TOKEN=<token> pingcode project list # or use it for one process, no login at all
170
+ pingcode auth status --check # verifies with GET /v1/myself
171
+ ```
172
+
173
+ Use it when the OAuth dance is impractical — a cron job, a CI runner, a shared machine, or when you
174
+ simply do not want to register an app. Things worth knowing:
175
+
176
+ - it is **not refreshable**. There is no token endpoint to call and no `refresh_token` to exchange:
177
+ an expired or revoked token fails with exit code `3` (`auth:`) and points you at `auth login --mode
178
+ pat`, which is also what `--check` proves. The CLI never silently retries a rejected PAT.
179
+ - its reach is whatever `scopes` you granted. Because it acts as you it can call the seven
180
+ user-token-only endpoints (`/v1/myself`, `/v1/permission/my/*`, `/v1/permission/check/*`), and
181
+ `auth login --mode pat` verifies tolerantly: `/v1/myself`, then one capability probe, then "stored
182
+ but unverified" when the token has no probeable scope. A `401` always fails hard — a dead token is
183
+ never written over a working one.
184
+ - `PINGCODE_TOKEN` wins over the config file, so a CI job can override a developer's local login
185
+ without touching it. `auth status` reports which slot is active (`auth_mode`), where it came from
186
+ (`token_source`) and whether the CLI can renew it (`token_refreshable`).
187
+ - `auth logout` clears only the active slot; `--all` clears the enterprise, user and pat slots plus
188
+ both app credential pairs, keeping `host`.
189
+
154
190
  ---
155
191
 
156
192
  ## Coverage: reach vs ergonomics
@@ -165,8 +201,9 @@ layers whose costs are completely different, and it is worth knowing which one y
165
201
 
166
202
  "Complete" (完全体) refers to **Reach**, and Reach is finished: every documented endpoint is
167
203
  invocable today. Seven of the 459 need a user token (`/v1/myself`, `/v1/permission/my/*`,
168
- `/v1/permission/check/*`) — run `pingcode auth login --mode user` to obtain one (it prints an
169
- authorize URL; paste the redirect URL back, or pass `--code`) and all 459 become callable. On the
204
+ `/v1/permission/check/*`) — run `pingcode auth login --mode user` (it prints an authorize URL; paste
205
+ the redirect URL back, or pass `--code`), or use a personal access token whose scopes cover them,
206
+ and all 459 become callable. On the
170
207
  default 企业令牌 alone they are refused *before any request*, which leaves 452 actually callable.
171
208
  Ergonomics is a
172
209
  **curation backlog, not a finish line**: an endpoint earns a named command by being run against a