vaultkit 1.5.0 → 2.0.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.
- checksums.yaml +4 -4
- data/README.md +163 -30
- data/bin/vkit +8 -0
- data/lib/vkit/cli/api/client.rb +15 -3
- data/lib/vkit/cli/base_cli.rb +92 -14
- data/lib/vkit/cli/commands/agent_tokens_create_command.rb +37 -5
- data/lib/vkit/cli/commands/agent_tokens_list_command.rb +2 -0
- data/lib/vkit/cli/commands/agent_tokens_revoke_command.rb +2 -0
- data/lib/vkit/cli/commands/approval_command.rb +8 -0
- data/lib/vkit/cli/commands/approval_watch_command.rb +6 -5
- data/lib/vkit/cli/commands/base_command.rb +56 -2
- data/lib/vkit/cli/commands/datasource_command.rb +137 -20
- data/lib/vkit/cli/commands/doctor_command.rb +69 -0
- data/lib/vkit/cli/commands/fetch_command.rb +7 -1
- data/lib/vkit/cli/commands/grant_revoke_command.rb +3 -0
- data/lib/vkit/cli/commands/init_command.rb +63 -10
- data/lib/vkit/cli/commands/login_command.rb +38 -4
- data/lib/vkit/cli/commands/logout_command.rb +54 -1
- data/lib/vkit/cli/commands/policy_bundle_command.rb +114 -26
- data/lib/vkit/cli/commands/policy_deploy_command.rb +113 -7
- data/lib/vkit/cli/commands/policy_pack_add_command.rb +16 -1
- data/lib/vkit/cli/commands/policy_pack_info_command.rb +10 -2
- data/lib/vkit/cli/commands/policy_pack_list_command.rb +4 -0
- data/lib/vkit/cli/commands/policy_pack_remove_command.rb +3 -0
- data/lib/vkit/cli/commands/policy_pack_upgrade_command.rb +35 -1
- data/lib/vkit/cli/commands/policy_revoke_command.rb +4 -0
- data/lib/vkit/cli/commands/policy_validate_command.rb +4 -1
- data/lib/vkit/cli/commands/registry_diff_command.rb +14 -2
- data/lib/vkit/cli/commands/registry_export_command.rb +30 -1
- data/lib/vkit/cli/commands/request_command.rb +27 -4
- data/lib/vkit/cli/commands/requests_list_command.rb +2 -0
- data/lib/vkit/cli/commands/reset_command.rb +12 -7
- data/lib/vkit/cli/commands/scan_command.rb +100 -0
- data/lib/vkit/cli/commands/setup_login_command.rb +274 -0
- data/lib/vkit/cli/commands/whoami_command.rb +16 -2
- data/lib/vkit/cli/doctor/mcp_probe.rb +108 -0
- data/lib/vkit/cli/doctor.rb +698 -0
- data/lib/vkit/cli/error_map.rb +243 -0
- data/lib/vkit/cli/errors.rb +32 -0
- data/lib/vkit/cli/output.rb +161 -0
- data/lib/vkit/cli/policy_bundle_validator.rb +8 -0
- data/lib/vkit/cli/secret_input.rb +50 -0
- data/lib/vkit/cli.rb +12 -2
- data/lib/vkit/core/auth_client.rb +57 -1
- data/lib/vkit/core/credential_store.rb +38 -1
- data/lib/vkit/core/user_agent.rb +30 -0
- data/lib/vkit/policy/approval_groups.rb +47 -0
- data/lib/vkit/policy/bundle_compiler.rb +8 -2
- data/lib/vkit/policy/git_state.rb +114 -0
- data/lib/vkit/policy/policy_validator.rb +20 -0
- data/lib/vkit/policy/schema/policy_bundle.schema.json +4 -0
- data/lib/vkit/version.rb +1 -1
- metadata +40 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 70d1cd3227ce0e133f6ff8bbfa28045f4d549a464fc9b3d360ab22bbf0feb650
|
|
4
|
+
data.tar.gz: 6f89ffdb002791c2fe7f67f503ac479b9336f6646bcea81df9152b843446dbe0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bcd106c233b9b3667b1b966fecb7fd09c7fc14c2885539f59a1067f257111ff44a8b132fa73ef2d378170e233a374e3e1413e80690c6b010abe1e386423d0907
|
|
7
|
+
data.tar.gz: 8e57927b0982e39774c335617bb38dcfd5f1e97706ffd5ff8f93dbacfca84f293e18576425ec4e6456568d556d11819c28ba12b5d63958357d88b4da7ec7820a
|
data/README.md
CHANGED
|
@@ -20,6 +20,7 @@ The VaultKit CLI (`vkit`) is the primary interface for interacting with the Vaul
|
|
|
20
20
|
- [Command Reference](#command-reference)
|
|
21
21
|
- [Configuration](#configuration)
|
|
22
22
|
- [Advanced Usage](#advanced-usage)
|
|
23
|
+
- [Driving vkit from a coding agent](docs/AGENTS.md)
|
|
23
24
|
- [Troubleshooting](#troubleshooting)
|
|
24
25
|
- [Contributing](#contributing)
|
|
25
26
|
|
|
@@ -164,6 +165,68 @@ vkit login --endpoint https://vaultkit.company.com --email you@company.com
|
|
|
164
165
|
# Session expires: 2024-01-15 18:00:00 UTC
|
|
165
166
|
```
|
|
166
167
|
|
|
168
|
+
### `vkit login --setup` (a coding agent setting VaultKit up)
|
|
169
|
+
|
|
170
|
+
A coding agent can set VaultKit up without your own login: it asks for a
|
|
171
|
+
**setup session**, you approve it in the console, and it gets a token that can
|
|
172
|
+
only do setup (connect datasources, scan schemas, deploy policy bundles) and
|
|
173
|
+
lasts 30 minutes. It works like `gh auth login`.
|
|
174
|
+
|
|
175
|
+
In a terminal it's one command. It prints a code and the console's approval
|
|
176
|
+
link, opens the link in your browser, and waits:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
vkit login --setup --endpoint http://localhost:3300
|
|
180
|
+
# 🔐 An admin approves this setup session in the VaultKit console:
|
|
181
|
+
# 1. Open http://localhost:5300/setup/approve
|
|
182
|
+
# 2. Check the code matches: BCDF-1234
|
|
183
|
+
# 3. Approve it (by 14:10, when the request expires)
|
|
184
|
+
# ⏳ Waiting for an admin to approve it...
|
|
185
|
+
# ✅ Setup session approved by you@acme.com for acme; it works until 14:32.
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Open the link signed in as an admin, check the code matches what the terminal
|
|
189
|
+
shows, and approve. Only approve a session you just started yourself: anyone
|
|
190
|
+
can start one and send you the link. The approval page shows the requester's
|
|
191
|
+
address and what made the request (`vkit/<version> (<os>; ruby <version>)`).
|
|
192
|
+
|
|
193
|
+
With `--format json` it's two commands, so the agent can show you the code
|
|
194
|
+
before it waits:
|
|
195
|
+
|
|
196
|
+
1. `vkit login --setup --format json` returns `needs_input` (exit 3) with
|
|
197
|
+
`user_code`, `verification_url` and `verification_url_complete` in `result`,
|
|
198
|
+
and the fix "Ask the person to open the URL, check the code matches, and
|
|
199
|
+
approve". Running it again returns the same code until the request expires
|
|
200
|
+
(10 minutes).
|
|
201
|
+
2. `vkit login --setup --wait --format json` polls until you approve (`ok`),
|
|
202
|
+
deny (`setup_session_denied`), or the request expires
|
|
203
|
+
(`setup_session_expired`). Add `--timeout <seconds>` to stop sooner; still
|
|
204
|
+
waiting is `needs_input` again, so rerun it.
|
|
205
|
+
|
|
206
|
+
`--no-browser` skips opening the link. The token is saved where `vkit login`
|
|
207
|
+
saves yours (it replaces your saved login, and says so), marked as a setup
|
|
208
|
+
session with its expiry; it's never printed. `vkit whoami` shows the expiry.
|
|
209
|
+
|
|
210
|
+
When a command needs more than setup, or the session ended, you get:
|
|
211
|
+
|
|
212
|
+
| Code | What happened |
|
|
213
|
+
|---|---|
|
|
214
|
+
| `setup_scope_forbidden` | A setup token can't do this (or can't change an organization that's already set up). An admin must: sign in with `vkit login`. |
|
|
215
|
+
| `setup_session_expired` | The 30 minutes are up. Run `vkit login --setup` again. |
|
|
216
|
+
| `setup_session_revoked` | It was revoked in the console or by `vkit logout`. |
|
|
217
|
+
| `setup_approver_not_admin` | The admin who approved it is no longer an admin. |
|
|
218
|
+
|
|
219
|
+
`vkit logout` ends a setup session on the control plane
|
|
220
|
+
(`DELETE /api/setup_sessions/current`) and then clears it here. If the control
|
|
221
|
+
plane can't be reached, it's still cleared here, and vkit says the token stays
|
|
222
|
+
valid until it expires (an admin can revoke it on the console's Agents page).
|
|
223
|
+
|
|
224
|
+
Rerunning setup is safe: a datasource that exists with the same settings, a
|
|
225
|
+
bundle that's already uploaded, and a scan that changes nothing come back as
|
|
226
|
+
`already_existed`, `already_deployed` or `unchanged`, not as errors. A
|
|
227
|
+
datasource id that exists with other settings is `datasource_exists`; a bundle
|
|
228
|
+
version already uploaded with other contents is `bundle_version_exists`.
|
|
229
|
+
|
|
167
230
|
### `vkit whoami`
|
|
168
231
|
|
|
169
232
|
Display the currently authenticated user and session information.
|
|
@@ -191,6 +254,49 @@ vkit whoami --format json
|
|
|
191
254
|
}
|
|
192
255
|
```
|
|
193
256
|
|
|
257
|
+
### `vkit doctor`
|
|
258
|
+
|
|
259
|
+
Check that VaultKit is set up and working from here, and say how to fix what
|
|
260
|
+
isn't. Run it from your policy project so it can compare the active bundle with
|
|
261
|
+
your commits (or pass `--dir <project>`).
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
vkit doctor
|
|
265
|
+
vkit doctor --format json
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
It checks, in order:
|
|
269
|
+
|
|
270
|
+
| Check | Passes when |
|
|
271
|
+
|---|---|
|
|
272
|
+
| `cli_version` | Always; warns when RubyGems has a newer vkit. Offline, the newer-version check is left out. |
|
|
273
|
+
| `control_plane` | The control plane answers its health check at the configured URL. |
|
|
274
|
+
| `login` | You're signed in (or in a setup session); says when the session expires, and warns in its last 10 minutes. |
|
|
275
|
+
| `datasources` | At least one datasource exists, and VaultKit connected to each. Uses `vkit scan <datasource>` in diff_only mode: it reads the schema, never data, and changes nothing in the registry. Admins only. |
|
|
276
|
+
| `datasource_role` | Always a warning for now, "not verified": VaultKit can't yet check that a datasource connects as a dedicated read-only role ([vaultkit#125](https://github.com/vaultkit-inc/vaultkit/issues/125)). |
|
|
277
|
+
| `schema` | Each reachable datasource is in the registry, unchanged since its last applied scan, and every column has a classification. |
|
|
278
|
+
| `policy_bundle` | A bundle is active, and it's this repository's HEAD, or an earlier commit with the same policies, registry and `.vkit/packs.yaml`. Nothing is compiled or written, and uncommitted changes don't count (they're mentioned). |
|
|
279
|
+
| `approval_routing` | Every approval group has members. A group with none is `info`, not a warning ("<group> has no members, so org admins approve its requests"); groups with members aren't flagged. Fails only if `GET /approval_groups` errors. |
|
|
280
|
+
| `agent_token` | `VAULTKIT_BASE_URL`, `VAULTKIT_ORG` and `VAULTKIT_TOKEN` are set, and the token is a working agent token for that organization. Fails if `VKIT_TOKEN` is an agent token, since every vkit command would then run as the agent. |
|
|
281
|
+
| `mcp_server` | Optional, when `vaultkit-mcp` is installed: it starts with those variables and lists `vaultkit_discover`, `vaultkit_query` and `vaultkit_check_approval`. |
|
|
282
|
+
|
|
283
|
+
A check that needs one that failed is skipped, with the reason. Tokens are
|
|
284
|
+
never printed, nor any part of one.
|
|
285
|
+
|
|
286
|
+
A check whose endpoint or fields an older control plane doesn't have is never
|
|
287
|
+
passed: it's `info`, "Can't check <what>: the control plane is too old to
|
|
288
|
+
report it.", with the fix "Upgrade the control plane." That applies to
|
|
289
|
+
`approval_routing` (no `active_member_count` and `admin_fallback` per group,
|
|
290
|
+
before vaultkit#127, or no `GET /approval_groups`), `policy_bundle` (no
|
|
291
|
+
`GET /approval_groups` or `GET /setup`, builds before 2026-10-27) and
|
|
292
|
+
`agent_token` (a whoami that doesn't say what the token is).
|
|
293
|
+
|
|
294
|
+
`--format json` returns `result.checks`, a list of `{ name, status, detail, fix }`
|
|
295
|
+
(`status` is `pass`, `warn`, `fail` or `info`), and `result.skipped`. `info` is
|
|
296
|
+
neither a pass nor a failure. vkit doctor exits
|
|
297
|
+
0 only when no check failed; otherwise the envelope's status is `error`, with
|
|
298
|
+
code `doctor_checks_failed`, and the checks are still in `result`.
|
|
299
|
+
|
|
194
300
|
### `vkit logout`
|
|
195
301
|
|
|
196
302
|
Clear stored credentials and end session.
|
|
@@ -558,7 +664,7 @@ vkit fetch --grant gr_abc123xyz --format json
|
|
|
558
664
|
vkit fetch --grant gr_abc123xyz --format csv --output results.csv
|
|
559
665
|
|
|
560
666
|
# Pipe to jq for processing
|
|
561
|
-
vkit fetch --grant gr_abc123xyz --format json | jq '.
|
|
667
|
+
vkit fetch --grant gr_abc123xyz --format json | jq '.result.rows[] | select(.revenue > 1000)'
|
|
562
668
|
```
|
|
563
669
|
|
|
564
670
|
---
|
|
@@ -577,8 +683,13 @@ vkit datasource add --id <ID> --engine <ENGINE> [OPTIONS]
|
|
|
577
683
|
- `--id` — Unique datasource identifier (required)
|
|
578
684
|
- `--engine` — Database engine: `postgres`, `mysql`, `snowflake`, `bigquery` (required)
|
|
579
685
|
- `--username` — Database username
|
|
580
|
-
- `--password` —
|
|
686
|
+
- `--password-prompt` — Type the password into the terminal (read from `/dev/tty`, echo off)
|
|
687
|
+
- `--password-env VAR_NAME` — Read the password from an environment variable
|
|
688
|
+
- `--password` — Deprecated: the password ends up in shell history. Still works, with a warning
|
|
581
689
|
- `--config` — JSON configuration (host, port, database, etc.)
|
|
690
|
+
|
|
691
|
+
Adding an `--id` that already exists changes nothing and succeeds (`already_existed: true` under
|
|
692
|
+
`--format json`). The control plane can't change a stored credential, so a password given then is not used.
|
|
582
693
|
- `--credential-backend` — Secret backend: `vaultkit`, `vault`, `aws-secrets`
|
|
583
694
|
|
|
584
695
|
**Examples:**
|
|
@@ -589,7 +700,7 @@ vkit datasource add \
|
|
|
589
700
|
--id production_pg \
|
|
590
701
|
--engine postgres \
|
|
591
702
|
--username vaultkit_ro \
|
|
592
|
-
--password
|
|
703
|
+
--password-prompt \
|
|
593
704
|
--config '{
|
|
594
705
|
"host": "db.production.internal",
|
|
595
706
|
"port": 5432,
|
|
@@ -605,7 +716,7 @@ vkit datasource add \
|
|
|
605
716
|
--id production_mysql \
|
|
606
717
|
--engine mysql \
|
|
607
718
|
--username app_reader \
|
|
608
|
-
--password
|
|
719
|
+
--password-env MYSQL_PASSWORD \
|
|
609
720
|
--config '{
|
|
610
721
|
"host": "mysql.production.internal",
|
|
611
722
|
"port": 3306,
|
|
@@ -775,7 +886,7 @@ vkit scan production_pg --mode apply
|
|
|
775
886
|
|
|
776
887
|
**Scan All Datasources:**
|
|
777
888
|
```bash
|
|
778
|
-
for ds in $(vkit datasource list --format json | jq -r '.[].
|
|
889
|
+
for ds in $(vkit datasource list --format json | jq -r '.result.datasources[].name'); do
|
|
779
890
|
echo "Scanning $ds..."
|
|
780
891
|
vkit scan $ds
|
|
781
892
|
done
|
|
@@ -785,37 +896,57 @@ done
|
|
|
785
896
|
|
|
786
897
|
### Policy Management Commands
|
|
787
898
|
|
|
899
|
+
#### `vkit init`
|
|
900
|
+
|
|
901
|
+
Creates a policy project: `config/policies/`, `datasets/` and `.vkit/`, with the `starter` pack (or the packs in `--with`). If the folder isn't inside a git repository, it runs `git init` and says so; `--no-git` skips that. It never commits.
|
|
902
|
+
|
|
903
|
+
The generated `.gitignore` ignores `dist/` and everything in `.vkit/` except `.vkit/packs.yaml`, the record of installed packs. Commit `packs.yaml`: `vkit policy bundle` checks the packs against it, and a clone without it can't.
|
|
904
|
+
|
|
905
|
+
```bash
|
|
906
|
+
vkit init --dir policies --with starter,ai_safety
|
|
907
|
+
cd policies && git add -A && git commit -m "Add VaultKit policies"
|
|
908
|
+
```
|
|
909
|
+
|
|
788
910
|
#### `vkit policy bundle`
|
|
789
911
|
|
|
790
|
-
|
|
912
|
+
Compiles the policies and registry into a deployable bundle, after checking every policy can match and every installed pack is complete.
|
|
791
913
|
|
|
792
914
|
```bash
|
|
793
|
-
vkit policy bundle [
|
|
915
|
+
vkit policy bundle [--policies_dir config/policies] [--registry_dir datasets] \
|
|
916
|
+
[--out dist/policy_bundle.json] [--org ORG] [--version LABEL] [--allow-dirty]
|
|
794
917
|
```
|
|
795
918
|
|
|
796
919
|
**Options:**
|
|
797
|
-
- `--policies_dir` —
|
|
798
|
-
- `--registry_dir` —
|
|
799
|
-
- `--datasources_dir` — Path to datasource configs (default: `config/datasources`)
|
|
920
|
+
- `--policies_dir` — Policies directory (default: `config/policies`)
|
|
921
|
+
- `--registry_dir` — Registry directory (default: `datasets`)
|
|
800
922
|
- `--out` — Output bundle file (default: `dist/policy_bundle.json`)
|
|
801
|
-
- `--org` —
|
|
923
|
+
- `--org` — Must match the organization you're signed in to
|
|
924
|
+
- `--version` — Name the bundle, such as `v1.2`. By default the bundle is named by its git commit. Either way, `source.commit_sha` is the commit from git, and is left out outside a git repository.
|
|
925
|
+
- `--allow-dirty` — Bundle uncommitted changes anyway. It prints a warning, and the bundle records `source.dirty: true`.
|
|
926
|
+
|
|
927
|
+
**Versions come from git.** A bundle's version is the commit its policies are in, so a deployed bundle can be traced to exactly those files. So `vkit policy bundle` refuses, writing nothing, when:
|
|
928
|
+
|
|
929
|
+
| Code | When | Fix |
|
|
930
|
+
|---|---|---|
|
|
931
|
+
| `bundle_not_committed` | Anything under the policies or registry directory, or `.vkit/packs.yaml`, differs from the last commit: modified, staged, new, deleted, or ignored by `.gitignore` | `git add -A -- config/policies datasets .vkit/packs.yaml && git commit`, or `--allow-dirty` |
|
|
932
|
+
| `bundle_not_versioned` | There's no git repository (or no commit yet) and no `--version` | `git init`, add and commit, or pass `--version` |
|
|
933
|
+
|
|
934
|
+
```
|
|
935
|
+
❌ These files aren't committed, so the bundle's version wouldn't match its policies:
|
|
936
|
+
config/policies/30_payments_require_approval.yaml
|
|
937
|
+
Code: bundle_not_committed
|
|
938
|
+
Fix:
|
|
939
|
+
git add -A -- config/policies datasets .vkit/packs.yaml
|
|
940
|
+
git commit -m "Update VaultKit policies"
|
|
941
|
+
or bundle anyway, recorded as dirty: vkit policy bundle --allow-dirty
|
|
942
|
+
```
|
|
943
|
+
|
|
944
|
+
Projects created by older versions of `vkit init` ignore all of `.vkit/`, so `.vkit/packs.yaml` shows as ignored. Add it with `git add -f .vkit/packs.yaml`, and in `.gitignore` replace `.vkit/` with `.vkit/*` and `!.vkit/packs.yaml`.
|
|
802
945
|
|
|
803
946
|
**Example:**
|
|
804
947
|
```bash
|
|
805
|
-
|
|
806
|
-
vkit policy bundle
|
|
807
|
-
--policies_dir config/policies \
|
|
808
|
-
--registry_dir config \
|
|
809
|
-
--datasources_dir config/datasources \
|
|
810
|
-
--out dist/policy_bundle.json
|
|
811
|
-
|
|
812
|
-
# Specifying org explicitly
|
|
813
|
-
vkit policy bundle \
|
|
814
|
-
--policies_dir config/policies \
|
|
815
|
-
--registry_dir config \
|
|
816
|
-
--datasources_dir config/datasources \
|
|
817
|
-
--out dist/policy_bundle.json \
|
|
818
|
-
--org acme
|
|
948
|
+
git add -A && git commit -m "Mask emails for analysts"
|
|
949
|
+
vkit policy bundle && vkit policy deploy
|
|
819
950
|
```
|
|
820
951
|
|
|
821
952
|
#### `vkit policy validate`
|
|
@@ -851,6 +982,8 @@ vkit policy deploy --bundle <BUNDLE_FILE> [OPTIONS]
|
|
|
851
982
|
- `--bundle` — Path to bundle file (required)
|
|
852
983
|
- `--org` — Organization identifier (optional, defaults to logged-in user's org)
|
|
853
984
|
- `--activate` — Immediately activate bundle
|
|
985
|
+
- `--format` — `human` (default) or `json`. Both include a warning for each approval
|
|
986
|
+
group nobody is in, whose requests org admins approve until someone is added.
|
|
854
987
|
- `--dry-run` — Validate deployment without activating
|
|
855
988
|
|
|
856
989
|
**Examples:**
|
|
@@ -977,7 +1110,7 @@ REQUESTS=(
|
|
|
977
1110
|
|
|
978
1111
|
for aql in "${REQUESTS[@]}"; do
|
|
979
1112
|
echo "Processing: $aql"
|
|
980
|
-
vkit request --aql "$aql" --format json | jq -r '.
|
|
1113
|
+
vkit request --aql "$aql" --format json | jq -r '.result.grant_ref // empty' >> grants.txt
|
|
981
1114
|
done
|
|
982
1115
|
|
|
983
1116
|
echo "Generated grants:"
|
|
@@ -992,7 +1125,7 @@ cat grants.txt
|
|
|
992
1125
|
|
|
993
1126
|
PENDING=$(vkit approval:list --state pending --format json)
|
|
994
1127
|
|
|
995
|
-
echo "$PENDING" | jq -r '.[].id' | while read -r request_id; do
|
|
1128
|
+
echo "$PENDING" | jq -r '.result.approvals[].id' | while read -r request_id; do
|
|
996
1129
|
echo "Approving request: $request_id"
|
|
997
1130
|
vkit approval:approve "$request_id" --ttl 3600 --notes "Auto-approved for testing"
|
|
998
1131
|
done
|
|
@@ -1051,17 +1184,17 @@ jobs:
|
|
|
1051
1184
|
|
|
1052
1185
|
**Extract specific fields:**
|
|
1053
1186
|
```bash
|
|
1054
|
-
vkit requests list --format json | jq '.[] | select(.state == "approved") | {id, dataset, requester}'
|
|
1187
|
+
vkit requests list --format json | jq '.result.requests[] | select(.state == "approved") | {id, dataset, requester}'
|
|
1055
1188
|
```
|
|
1056
1189
|
|
|
1057
1190
|
**Count requests by state:**
|
|
1058
1191
|
```bash
|
|
1059
|
-
vkit requests list --format json | jq 'group_by(.state) | map({state: .[0].state, count: length})'
|
|
1192
|
+
vkit requests list --format json | jq '.result.requests | group_by(.state) | map({state: .[0].state, count: length})'
|
|
1060
1193
|
```
|
|
1061
1194
|
|
|
1062
1195
|
**Find high-value transactions:**
|
|
1063
1196
|
```bash
|
|
1064
|
-
vkit fetch --grant gr_abc123 --format json | jq '.
|
|
1197
|
+
vkit fetch --grant gr_abc123 --format json | jq '.result.rows[] | select(.amount > 10000)'
|
|
1065
1198
|
```
|
|
1066
1199
|
|
|
1067
1200
|
---
|
data/bin/vkit
CHANGED
|
@@ -8,6 +8,14 @@ begin
|
|
|
8
8
|
|
|
9
9
|
rescue Vkit::CLI::Error => e
|
|
10
10
|
warn "❌ #{e.message}"
|
|
11
|
+
fix = Vkit::CLI::ErrorMap.human_fix(e)
|
|
12
|
+
warn " Fix: #{fix}" if fix
|
|
13
|
+
exit 1
|
|
14
|
+
|
|
15
|
+
rescue Vkit::CLI::API::APIError => e
|
|
16
|
+
warn e.message
|
|
17
|
+
fix = Vkit::CLI::ErrorMap.human_fix(e)
|
|
18
|
+
warn "Fix: #{fix}" if fix
|
|
11
19
|
exit 1
|
|
12
20
|
|
|
13
21
|
rescue Thor::Error => e
|
data/lib/vkit/cli/api/client.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "net/http"
|
|
4
4
|
require "uri"
|
|
5
5
|
require "json"
|
|
6
|
+
require_relative "../../core/user_agent"
|
|
6
7
|
|
|
7
8
|
module Vkit
|
|
8
9
|
module CLI
|
|
@@ -34,6 +35,10 @@ module Vkit
|
|
|
34
35
|
request(method: :patch, path: path, body: body)
|
|
35
36
|
end
|
|
36
37
|
|
|
38
|
+
def delete(path)
|
|
39
|
+
request(method: :delete, path: path)
|
|
40
|
+
end
|
|
41
|
+
|
|
37
42
|
private
|
|
38
43
|
|
|
39
44
|
def request(method:, path:, body: nil)
|
|
@@ -42,6 +47,9 @@ module Vkit
|
|
|
42
47
|
req = build_request(method, uri)
|
|
43
48
|
req["Authorization"] = "Bearer #{@token}"
|
|
44
49
|
req["Content-Type"] = "application/json"
|
|
50
|
+
# Devise answers a failed login in JSON only when asked to.
|
|
51
|
+
req["Accept"] = "application/json"
|
|
52
|
+
req["User-Agent"] = Vkit::Core::UserAgent.to_s
|
|
45
53
|
req.body = JSON.dump(body) if body
|
|
46
54
|
|
|
47
55
|
res = Net::HTTP.start(
|
|
@@ -63,6 +71,7 @@ module Vkit
|
|
|
63
71
|
when :post then Net::HTTP::Post.new(uri)
|
|
64
72
|
when :put then Net::HTTP::Put.new(uri)
|
|
65
73
|
when :patch then Net::HTTP::Patch.new(uri)
|
|
74
|
+
when :delete then Net::HTTP::Delete.new(uri)
|
|
66
75
|
else
|
|
67
76
|
raise ArgumentError, "Unsupported HTTP method: #{method}"
|
|
68
77
|
end
|
|
@@ -103,19 +112,22 @@ module Vkit
|
|
|
103
112
|
# word (token_revoked, token_expired), and request_id finds the request
|
|
104
113
|
# on the console's Activity page.
|
|
105
114
|
class APIError < StandardError
|
|
106
|
-
attr_reader :status, :error, :code, :request_id
|
|
115
|
+
attr_reader :status, :error, :code, :request_id, :body
|
|
107
116
|
|
|
108
117
|
def self.from_body(status, body)
|
|
109
118
|
return new(status, body) unless body.is_a?(Hash)
|
|
110
119
|
|
|
111
|
-
new(status, body["error"] || body, code: body["code"], request_id: body["request_id"])
|
|
120
|
+
new(status, body["error"] || body, code: body["code"], request_id: body["request_id"], body: body)
|
|
112
121
|
end
|
|
113
122
|
|
|
114
|
-
|
|
123
|
+
# body: the whole JSON answer, for the fields some errors carry
|
|
124
|
+
# (a 409's bundle_version and state).
|
|
125
|
+
def initialize(status, error, code: nil, request_id: nil, body: nil)
|
|
115
126
|
@status = status
|
|
116
127
|
@error = error
|
|
117
128
|
@code = code
|
|
118
129
|
@request_id = request_id
|
|
130
|
+
@body = body.is_a?(Hash) ? body : {}
|
|
119
131
|
super(describe)
|
|
120
132
|
end
|
|
121
133
|
|