pywrit 0.2.15__tar.gz → 0.2.17__tar.gz
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.
- {pywrit-0.2.15/src/pywrit.egg-info → pywrit-0.2.17}/PKG-INFO +11 -4
- {pywrit-0.2.15 → pywrit-0.2.17}/README.md +10 -3
- {pywrit-0.2.15 → pywrit-0.2.17}/pyproject.toml +1 -1
- {pywrit-0.2.15 → pywrit-0.2.17}/src/pywrit/__init__.py +1 -1
- {pywrit-0.2.15 → pywrit-0.2.17}/src/pywrit/cli.py +98 -15
- {pywrit-0.2.15 → pywrit-0.2.17/src/pywrit.egg-info}/PKG-INFO +11 -4
- {pywrit-0.2.15 → pywrit-0.2.17}/tests/test_scan_go.py +7 -4
- {pywrit-0.2.15 → pywrit-0.2.17}/LICENSE +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/setup.cfg +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/src/pywrit/client.py +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/src/pywrit/errors.py +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/src/pywrit.egg-info/SOURCES.txt +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/src/pywrit.egg-info/dependency_links.txt +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/src/pywrit.egg-info/entry_points.txt +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/src/pywrit.egg-info/requires.txt +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/src/pywrit.egg-info/top_level.txt +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/tests/test_client.py +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/tests/test_scan_json.py +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/tests/test_scan_python.py +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/tests/test_scan_tsjs.py +0 -0
- {pywrit-0.2.15 → pywrit-0.2.17}/tests/test_wrap.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pywrit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.17
|
|
4
4
|
Summary: Python client + CLI for Writ — the gate before the write
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://withwrit.com
|
|
@@ -61,7 +61,7 @@ install test.
|
|
|
61
61
|
| --- | --- | --- | --- |
|
|
62
62
|
| Python | Yes | Yes, inserts `_writ_check` gates | Parsed with the stdlib `ast`, no extra needed |
|
|
63
63
|
| TypeScript / JavaScript | Yes, with `pywrit[polyglot]` | No, scan only | Needs the extra: `pip install 'pywrit[polyglot]'`. Without it, the report says so loudly: a warning block names the unscanned files instead of reporting zero findings |
|
|
64
|
-
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family
|
|
64
|
+
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family plus request-pipeline Call/RawRequest and package-level generated clients: database/sql Exec/ExecContext, GORM Create/Save/Update/Updates/Delete, HTTP client writes and http.NewRequest with a write method, generated-client <client>.<Resource>.<New\|Update\|Delete\|Create>, request-pipeline X.Call/X.RawRequest with a write method, package-level generated clients <pkg>.<New\|Update\|Delete\|Create> on an imported resource-shaped package. Without the extra, the report names the unscanned Go files in the same warning block as TS/JS |
|
|
65
65
|
|
|
66
66
|
## 60-second quickstart: scan → wrap → gate
|
|
67
67
|
|
|
@@ -191,7 +191,7 @@ pipeline (twilio-style generated clients, e.g. `twilio-node`).
|
|
|
191
191
|
|
|
192
192
|
pip install 'pywrit[polyglot]'
|
|
193
193
|
|
|
194
|
-
Covered in this first family: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method,
|
|
194
|
+
Covered in this first family plus request-pipeline and package-level generated-client detection: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method, generated-client calls shaped `<client>.<Resource>.<New|Update|Delete|Create>` with an uppercase resource segment (the stripe-go shape), request-pipeline calls `X.Call(method, ...)` / `X.RawRequest(method, ...)` where argument 0 is a write method (the `stripe.Backend` shape, e.g. `c.B.Call(http.MethodPost, "/v1/accounts", ...)`), and package-level generated-client calls `<pkg>.<New|Update|Delete|Create>(...)` where `<pkg>` is imported in the file and the import path's last segment is resource-shaped, not structy (`params`, `config`, ...) and not service-, client-, library-, or test-double-shaped (`svc`, `service`, `client`, `api`, `sdk`, `internal`, `mock`, `fake`). This is the pre-v87 stripe-go shape (`charge.New(params)`), aliased imports included: the guard reads the import path, so `acmeinvoice "example.com/acme/acme-payments/invoice"` fires while `paymentsvc.New(cfg)` does not. GET/HEAD requests, `db.Query` / `QueryRow`, bare constructors (`.New` on a local variable or on an imported service- or structy-shaped package), and pipeline calls with a variable method or a non-method first argument are not flagged. `_test.go` files and `vendor/` trees are skipped. Go is **scan-only**: `writ scan --apply` never rewrites `.go` files, gate those by hand. Not yet covered: GORM raw-SQL helpers and other Go write patterns.
|
|
195
195
|
|
|
196
196
|
## GitHub Action
|
|
197
197
|
|
|
@@ -222,7 +222,7 @@ Setup and data handling: [GitHub App docs](https://docs.withwrit.com/git-hub-app
|
|
|
222
222
|
|
|
223
223
|
Give any MCP-compatible agent point-of-action policy checks. `writ-mcp` is a
|
|
224
224
|
[Model Context Protocol](https://modelcontextprotocol.io) server (stdio transport,
|
|
225
|
-
built on the MCP Python SDK) that exposes the Writ gate as **
|
|
225
|
+
built on the MCP Python SDK) that exposes the Writ gate as **24 MCP tools**:
|
|
226
226
|
the agent calls `writ_check` before a consequential write and gets back `ALLOW`,
|
|
227
227
|
`DENY`, or `STEP_UP` — with a tamper-evident, hash-chained audit receipt for
|
|
228
228
|
every decision.
|
|
@@ -237,9 +237,12 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
237
237
|
|---|---|
|
|
238
238
|
| `writ_check` | The gate: `ALLOW` / `DENY` / `STEP_UP` for a proposed write |
|
|
239
239
|
| `writ_verify_token` | Validate an `ALLOW` auth token (catches purpose drift) |
|
|
240
|
+
| `writ_lease` | Convert an `ALLOW` token into a single-use gated-execution lease |
|
|
241
|
+
| `writ_execute` | Run one gated upstream request with a lease or `ALLOW` token |
|
|
240
242
|
| `writ_grant` | Human-sponsor approval for the `STEP_UP` path |
|
|
241
243
|
| `writ_revoke` / `writ_reinstate` | The kill switch |
|
|
242
244
|
| `writ_receipts` | Read the tenant's audit log |
|
|
245
|
+
| `writ_verify_receipts` | Verify the audit-log hash chain |
|
|
243
246
|
| `writ_policy` | Manage the verb policy |
|
|
244
247
|
| `writ_sandbox` | Keyless 90-second demo grant — no API key needed |
|
|
245
248
|
| `writ_github_installations` | List connected GitHub App installations |
|
|
@@ -251,6 +254,10 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
251
254
|
| `writ_principals` | List the tenant's principals |
|
|
252
255
|
| `writ_verbs` | List the tenant's verb vocabulary |
|
|
253
256
|
| `writ_keys` | List API key metadata |
|
|
257
|
+
| `writ_badge_token` | Mint a public README badge token |
|
|
258
|
+
| `writ_badge_revoke` | Revoke a badge token; its badge image URL 404s |
|
|
259
|
+
| `writ_tenant_invite` | Mint/rotate the tenant's one live team invite code (writ_inv_...) |
|
|
260
|
+
| `writ_join_tenant` | Join a tenant with an invite code; issues an API key, no key needed first |
|
|
254
261
|
|
|
255
262
|
The gate tools need a free Writ API key (`WRIT_API_KEY`): 10,000 receipts/month
|
|
256
263
|
free, no credit card. `writ_sandbox` works with no key at all.
|
|
@@ -38,7 +38,7 @@ install test.
|
|
|
38
38
|
| --- | --- | --- | --- |
|
|
39
39
|
| Python | Yes | Yes, inserts `_writ_check` gates | Parsed with the stdlib `ast`, no extra needed |
|
|
40
40
|
| TypeScript / JavaScript | Yes, with `pywrit[polyglot]` | No, scan only | Needs the extra: `pip install 'pywrit[polyglot]'`. Without it, the report says so loudly: a warning block names the unscanned files instead of reporting zero findings |
|
|
41
|
-
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family
|
|
41
|
+
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family plus request-pipeline Call/RawRequest and package-level generated clients: database/sql Exec/ExecContext, GORM Create/Save/Update/Updates/Delete, HTTP client writes and http.NewRequest with a write method, generated-client <client>.<Resource>.<New\|Update\|Delete\|Create>, request-pipeline X.Call/X.RawRequest with a write method, package-level generated clients <pkg>.<New\|Update\|Delete\|Create> on an imported resource-shaped package. Without the extra, the report names the unscanned Go files in the same warning block as TS/JS |
|
|
42
42
|
|
|
43
43
|
## 60-second quickstart: scan → wrap → gate
|
|
44
44
|
|
|
@@ -168,7 +168,7 @@ pipeline (twilio-style generated clients, e.g. `twilio-node`).
|
|
|
168
168
|
|
|
169
169
|
pip install 'pywrit[polyglot]'
|
|
170
170
|
|
|
171
|
-
Covered in this first family: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method,
|
|
171
|
+
Covered in this first family plus request-pipeline and package-level generated-client detection: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method, generated-client calls shaped `<client>.<Resource>.<New|Update|Delete|Create>` with an uppercase resource segment (the stripe-go shape), request-pipeline calls `X.Call(method, ...)` / `X.RawRequest(method, ...)` where argument 0 is a write method (the `stripe.Backend` shape, e.g. `c.B.Call(http.MethodPost, "/v1/accounts", ...)`), and package-level generated-client calls `<pkg>.<New|Update|Delete|Create>(...)` where `<pkg>` is imported in the file and the import path's last segment is resource-shaped, not structy (`params`, `config`, ...) and not service-, client-, library-, or test-double-shaped (`svc`, `service`, `client`, `api`, `sdk`, `internal`, `mock`, `fake`). This is the pre-v87 stripe-go shape (`charge.New(params)`), aliased imports included: the guard reads the import path, so `acmeinvoice "example.com/acme/acme-payments/invoice"` fires while `paymentsvc.New(cfg)` does not. GET/HEAD requests, `db.Query` / `QueryRow`, bare constructors (`.New` on a local variable or on an imported service- or structy-shaped package), and pipeline calls with a variable method or a non-method first argument are not flagged. `_test.go` files and `vendor/` trees are skipped. Go is **scan-only**: `writ scan --apply` never rewrites `.go` files, gate those by hand. Not yet covered: GORM raw-SQL helpers and other Go write patterns.
|
|
172
172
|
|
|
173
173
|
## GitHub Action
|
|
174
174
|
|
|
@@ -199,7 +199,7 @@ Setup and data handling: [GitHub App docs](https://docs.withwrit.com/git-hub-app
|
|
|
199
199
|
|
|
200
200
|
Give any MCP-compatible agent point-of-action policy checks. `writ-mcp` is a
|
|
201
201
|
[Model Context Protocol](https://modelcontextprotocol.io) server (stdio transport,
|
|
202
|
-
built on the MCP Python SDK) that exposes the Writ gate as **
|
|
202
|
+
built on the MCP Python SDK) that exposes the Writ gate as **24 MCP tools**:
|
|
203
203
|
the agent calls `writ_check` before a consequential write and gets back `ALLOW`,
|
|
204
204
|
`DENY`, or `STEP_UP` — with a tamper-evident, hash-chained audit receipt for
|
|
205
205
|
every decision.
|
|
@@ -214,9 +214,12 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
214
214
|
|---|---|
|
|
215
215
|
| `writ_check` | The gate: `ALLOW` / `DENY` / `STEP_UP` for a proposed write |
|
|
216
216
|
| `writ_verify_token` | Validate an `ALLOW` auth token (catches purpose drift) |
|
|
217
|
+
| `writ_lease` | Convert an `ALLOW` token into a single-use gated-execution lease |
|
|
218
|
+
| `writ_execute` | Run one gated upstream request with a lease or `ALLOW` token |
|
|
217
219
|
| `writ_grant` | Human-sponsor approval for the `STEP_UP` path |
|
|
218
220
|
| `writ_revoke` / `writ_reinstate` | The kill switch |
|
|
219
221
|
| `writ_receipts` | Read the tenant's audit log |
|
|
222
|
+
| `writ_verify_receipts` | Verify the audit-log hash chain |
|
|
220
223
|
| `writ_policy` | Manage the verb policy |
|
|
221
224
|
| `writ_sandbox` | Keyless 90-second demo grant — no API key needed |
|
|
222
225
|
| `writ_github_installations` | List connected GitHub App installations |
|
|
@@ -228,6 +231,10 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
228
231
|
| `writ_principals` | List the tenant's principals |
|
|
229
232
|
| `writ_verbs` | List the tenant's verb vocabulary |
|
|
230
233
|
| `writ_keys` | List API key metadata |
|
|
234
|
+
| `writ_badge_token` | Mint a public README badge token |
|
|
235
|
+
| `writ_badge_revoke` | Revoke a badge token; its badge image URL 404s |
|
|
236
|
+
| `writ_tenant_invite` | Mint/rotate the tenant's one live team invite code (writ_inv_...) |
|
|
237
|
+
| `writ_join_tenant` | Join a tenant with an invite code; issues an API key, no key needed first |
|
|
231
238
|
|
|
232
239
|
The gate tools need a free Writ API key (`WRIT_API_KEY`): 10,000 receipts/month
|
|
233
240
|
free, no credit card. `writ_sandbox` works with no key at all.
|
|
@@ -1395,17 +1395,21 @@ def _tsjs_scan_source(src, filename, parser):
|
|
|
1395
1395
|
return sites, gated
|
|
1396
1396
|
|
|
1397
1397
|
|
|
1398
|
-
# writ scan, Go (
|
|
1399
|
-
# rewritten). Same tree-sitter tier as TS/JS, same
|
|
1400
|
-
# extra plus the tree-sitter-go grammar; without the
|
|
1401
|
-
# missing-extra block counts Go files too. Slice 1 covers one
|
|
1402
|
-
# family, deliberately: database/sql Exec/ExecContext on a db/tx
|
|
1403
|
-
# GORM-shaped Create/Save/Update/Updates/Delete on a db handle,
|
|
1404
|
-
# client writes (Post/Put/Patch/Delete calls and
|
|
1405
|
-
# with a write method), and generated-client
|
|
1406
|
-
# stripe-go shape
|
|
1407
|
-
#
|
|
1408
|
-
#
|
|
1398
|
+
# writ scan, Go (slices 1-3): deterministic and scan-only (Go files are
|
|
1399
|
+
# never rewritten). Same tree-sitter tier as TS/JS, same
|
|
1400
|
+
# `pywrit[polyglot]` extra plus the tree-sitter-go grammar; without the
|
|
1401
|
+
# extra the missing-extra block counts Go files too. Slice 1 covers one
|
|
1402
|
+
# write family, deliberately: database/sql Exec/ExecContext on a db/tx
|
|
1403
|
+
# handle, GORM-shaped Create/Save/Update/Updates/Delete on a db handle,
|
|
1404
|
+
# HTTP client writes (Post/Put/Patch/Delete calls and
|
|
1405
|
+
# NewRequest(-WithContext) with a write method), and generated-client
|
|
1406
|
+
# resource methods of the stripe-go shape
|
|
1407
|
+
# (<client>.<Resource>.<New|Update|Delete|Create> with an uppercase
|
|
1408
|
+
# middle segment). Slice 2 adds request-pipeline Call/RawRequest with a
|
|
1409
|
+
# write method as argument 0. Slice 3 adds import-aware package-level
|
|
1410
|
+
# generated clients (<pkg>.<New|Update|Delete|Create>, the pre-v87
|
|
1411
|
+
# stripe-go shape: charge.New(params)). Wider Go coverage (os/io/fs
|
|
1412
|
+
# writes, sqlx, raw-SQL conditions on Exec, GORM raw-SQL helpers,
|
|
1409
1413
|
# Go-specific non-product suppression classes) ships in later slices.
|
|
1410
1414
|
# ---------------------------------------------------------------------------
|
|
1411
1415
|
|
|
@@ -1423,9 +1427,10 @@ _GO_PKG_ROOTS = {"http", "sql", "gorm"}
|
|
|
1423
1427
|
# Update) are ubiquitous in real code (structs like Params, Args, Options,
|
|
1424
1428
|
# Config); the stripe-go generated-client shape is three segments
|
|
1425
1429
|
# (client.Charges.New), so two-segment chains never fire the sdk rule.
|
|
1426
|
-
# The package-level pre-v87 shape (charge.New(params))
|
|
1427
|
-
# slice
|
|
1428
|
-
#
|
|
1430
|
+
# The package-level pre-v87 shape (charge.New(params)) fires only in
|
|
1431
|
+
# slice 3's import-aware branch below: the two-segment chain's root
|
|
1432
|
+
# must be an imported package whose path is resource-shaped, so a bare
|
|
1433
|
+
# local constructor (svc.New) never matches; see
|
|
1429
1434
|
# tests/fixtures/go/pkgclient.go.
|
|
1430
1435
|
_GO_STRUCTY_RES = {"params", "args", "arg", "opts", "options", "config",
|
|
1431
1436
|
"conf", "cfg", "settings", "props", "attrs", "info",
|
|
@@ -1452,6 +1457,36 @@ _GO_RESOURCE_METHODS = {"new", "update", "delete", "create"}
|
|
|
1452
1457
|
# or ends in "db"/"tx" (db, tx, gormDB, dbtx, r.db, s.tx). Function roots
|
|
1453
1458
|
# (createUser(...)) never qualify: "user" does not end in db/tx.
|
|
1454
1459
|
_GO_HANDLE_RX = _re.compile(r"(db|tx)$")
|
|
1460
|
+
# Request-pipeline tails (slice 2): clients that route every call
|
|
1461
|
+
# through an internal pipeline method taking the HTTP method as
|
|
1462
|
+
# argument 0 (stripe-go: Backend.Call / RawRequest, so c.B.Call(
|
|
1463
|
+
# http.MethodPost, ...)). Argument 0 is graded by _go_write_method:
|
|
1464
|
+
# write methods (Post/Put/Patch/Delete string or http.MethodX
|
|
1465
|
+
# constant) fire, Get/Head and variables do not.
|
|
1466
|
+
_GO_PIPELINE_METHODS = {"call", "rawrequest"}
|
|
1467
|
+
# Service/client/library-shaped import-path endings that must NOT fire
|
|
1468
|
+
# the slice-3 package-level generated-client rule: a two-segment
|
|
1469
|
+
# `<pkg>.<New|Update|Delete|Create>` call is a package-level resource
|
|
1470
|
+
# method only when the import path's last segment names a resource
|
|
1471
|
+
# (charge, invoice), so a path whose last segment ends in one of these
|
|
1472
|
+
# is plumbing, not a resource: paymentsvc.New(cfg) and client.New(...)
|
|
1473
|
+
# are constructors on a service/client package, not writes, and
|
|
1474
|
+
# internal/mock/fake packages are plumbing or test doubles. The check
|
|
1475
|
+
# is a suffix match against the import path's lowercase last segment
|
|
1476
|
+
# (never the local alias), so concatenated names (gensvc,
|
|
1477
|
+
# stripeclient, paymentsvc) are plumbing too, while real resource
|
|
1478
|
+
# names (charge, invoice, customer, subscription, account) do not end
|
|
1479
|
+
# this way and still fire, aliased or not
|
|
1480
|
+
# (acmeinvoice "example.com/acme/acme-payments/invoice").
|
|
1481
|
+
_GO_PKGCLIENT_NONRESOURCE = (
|
|
1482
|
+
# service- and client-shaped: the path's last segment is the
|
|
1483
|
+
# service or client itself, not a resource
|
|
1484
|
+
"svc", "service", "client", "server",
|
|
1485
|
+
# library- and layer-shaped: imports of plumbing, not resources
|
|
1486
|
+
"api", "sdk", "gateway", "internal", "pkg", "lib",
|
|
1487
|
+
# test doubles
|
|
1488
|
+
"mock", "fake", "stub",
|
|
1489
|
+
)
|
|
1455
1490
|
|
|
1456
1491
|
|
|
1457
1492
|
class _GoFile:
|
|
@@ -1536,8 +1571,24 @@ def _go_write_method(call, f, idx):
|
|
|
1536
1571
|
ac[1][len("method"):] in _GO_HTTP_WRITE_METHODS
|
|
1537
1572
|
|
|
1538
1573
|
|
|
1574
|
+
def _go_import_resource_name(path):
|
|
1575
|
+
"""Last meaningful segment of a Go import path, lowercased: the
|
|
1576
|
+
package name as the compiler resolves it. A trailing semantic-
|
|
1577
|
+
import-versioning segment (github.com/stripe/stripe-go/v87 -> the
|
|
1578
|
+
path .../v87/charge ends in "charge" anyway; this folds a path that
|
|
1579
|
+
ENDS in vN, e.g. example.com/mod/v2 -> "mod", matching the module
|
|
1580
|
+
name a consumer would reference)."""
|
|
1581
|
+
seg = path.rstrip("/").rsplit("/", 1)[-1].lower()
|
|
1582
|
+
if _re.fullmatch(r"v\d+", seg):
|
|
1583
|
+
seg = path.rstrip("/").rsplit("/", 2)[-2].lower() \
|
|
1584
|
+
if "/" in path.rstrip("/") else seg
|
|
1585
|
+
return seg
|
|
1586
|
+
|
|
1587
|
+
|
|
1539
1588
|
def _go_classify(call, chain, f, pkg_paths=None):
|
|
1540
|
-
"""First match wins; returns (rule_id, kind). Slice-1 family
|
|
1589
|
+
"""First match wins; returns (rule_id, kind). Slice-1 family, the
|
|
1590
|
+
slice-3 package-level generated-client family, plus the slice-2
|
|
1591
|
+
request-pipeline family (Call / RawRequest).
|
|
1541
1592
|
|
|
1542
1593
|
`chain` is the raw (un-lowercased) callee chain. Handle receivers
|
|
1543
1594
|
match by convention on any receiver segment (db, tx, gormDB, r.db,
|
|
@@ -1584,6 +1635,38 @@ def _go_classify(call, chain, f, pkg_paths=None):
|
|
|
1584
1635
|
# pre-v87 shape (charge.New) is a later slice, not this
|
|
1585
1636
|
# branch: two-segment chains never reach it.
|
|
1586
1637
|
return "go-sdk-write", "sdk"
|
|
1638
|
+
if tail in _GO_RESOURCE_METHODS and len(chain) == 2 and \
|
|
1639
|
+
pkg_paths is not None and chain[0] in pkg_paths:
|
|
1640
|
+
# package-level generated client, the pre-v87 stripe-go shape
|
|
1641
|
+
# (slice 3): charge.New(params), invoice.Update("in_123", nil).
|
|
1642
|
+
# Import-aware on every axis: the root must be a package this
|
|
1643
|
+
# file imports; the path must be a real module (first segment
|
|
1644
|
+
# is a domain, containing a dot) so bare stdlib constructors
|
|
1645
|
+
# (errors.New, reflect.New, crypto/hmac hmac.New) never fire;
|
|
1646
|
+
# and the import path's last segment (not the local alias) must
|
|
1647
|
+
# be resource-shaped, not structy (_GO_STRUCTY_RES) and not
|
|
1648
|
+
# service/client/library-shaped (_GO_PKGCLIENT_NONRESOURCE). A
|
|
1649
|
+
# bare local `svc.New(cfg)` with no matching import never fires;
|
|
1650
|
+
# `paymentsvc.New(cfg)` on an imported service package never
|
|
1651
|
+
# fires.
|
|
1652
|
+
path = pkg_paths[chain[0]]
|
|
1653
|
+
if "." not in path.split("/", 1)[0]:
|
|
1654
|
+
return None # stdlib constructor, not a generated client
|
|
1655
|
+
last = _go_import_resource_name(path)
|
|
1656
|
+
if last not in _GO_STRUCTY_RES and not \
|
|
1657
|
+
last.endswith(_GO_PKGCLIENT_NONRESOURCE):
|
|
1658
|
+
return "go-pkgclient-write", "sdk"
|
|
1659
|
+
if tail in _GO_PIPELINE_METHODS and len(norm) >= 2:
|
|
1660
|
+
# request pipeline: <recv>.Call / .RawRequest with a write
|
|
1661
|
+
# method as argument 0 (the stripe-go Backend shape:
|
|
1662
|
+
# c.B.Call(http.MethodPost, "/v1/accounts", ...)). The
|
|
1663
|
+
# arg-0 method check does the grading: http.MethodGet/Head is
|
|
1664
|
+
# a read, a variable or context first argument never matches,
|
|
1665
|
+
# and reflect.Value.Call (whose argument is a []Value) is
|
|
1666
|
+
# excluded the same way. No receiver check: the Call /
|
|
1667
|
+
# RawRequest tails collide with no other family.
|
|
1668
|
+
if _go_write_method(call, f, 0):
|
|
1669
|
+
return "go-pipeline-write", "http"
|
|
1587
1670
|
return None
|
|
1588
1671
|
|
|
1589
1672
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pywrit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.17
|
|
4
4
|
Summary: Python client + CLI for Writ — the gate before the write
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://withwrit.com
|
|
@@ -61,7 +61,7 @@ install test.
|
|
|
61
61
|
| --- | --- | --- | --- |
|
|
62
62
|
| Python | Yes | Yes, inserts `_writ_check` gates | Parsed with the stdlib `ast`, no extra needed |
|
|
63
63
|
| TypeScript / JavaScript | Yes, with `pywrit[polyglot]` | No, scan only | Needs the extra: `pip install 'pywrit[polyglot]'`. Without it, the report says so loudly: a warning block names the unscanned files instead of reporting zero findings |
|
|
64
|
-
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family
|
|
64
|
+
| Go | Yes, with `pywrit[polyglot]` | No, scan only | First detection family plus request-pipeline Call/RawRequest and package-level generated clients: database/sql Exec/ExecContext, GORM Create/Save/Update/Updates/Delete, HTTP client writes and http.NewRequest with a write method, generated-client <client>.<Resource>.<New\|Update\|Delete\|Create>, request-pipeline X.Call/X.RawRequest with a write method, package-level generated clients <pkg>.<New\|Update\|Delete\|Create> on an imported resource-shaped package. Without the extra, the report names the unscanned Go files in the same warning block as TS/JS |
|
|
65
65
|
|
|
66
66
|
## 60-second quickstart: scan → wrap → gate
|
|
67
67
|
|
|
@@ -191,7 +191,7 @@ pipeline (twilio-style generated clients, e.g. `twilio-node`).
|
|
|
191
191
|
|
|
192
192
|
pip install 'pywrit[polyglot]'
|
|
193
193
|
|
|
194
|
-
Covered in this first family: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method,
|
|
194
|
+
Covered in this first family plus request-pipeline and package-level generated-client detection: `database/sql` `Exec` / `ExecContext`, GORM `Create` / `Save` / `Update` / `Updates` / `Delete`, HTTP client `Post` / `Put` / `Patch` / `Delete` and `http.NewRequest` / `NewRequestWithContext` with a write method, generated-client calls shaped `<client>.<Resource>.<New|Update|Delete|Create>` with an uppercase resource segment (the stripe-go shape), request-pipeline calls `X.Call(method, ...)` / `X.RawRequest(method, ...)` where argument 0 is a write method (the `stripe.Backend` shape, e.g. `c.B.Call(http.MethodPost, "/v1/accounts", ...)`), and package-level generated-client calls `<pkg>.<New|Update|Delete|Create>(...)` where `<pkg>` is imported in the file and the import path's last segment is resource-shaped, not structy (`params`, `config`, ...) and not service-, client-, library-, or test-double-shaped (`svc`, `service`, `client`, `api`, `sdk`, `internal`, `mock`, `fake`). This is the pre-v87 stripe-go shape (`charge.New(params)`), aliased imports included: the guard reads the import path, so `acmeinvoice "example.com/acme/acme-payments/invoice"` fires while `paymentsvc.New(cfg)` does not. GET/HEAD requests, `db.Query` / `QueryRow`, bare constructors (`.New` on a local variable or on an imported service- or structy-shaped package), and pipeline calls with a variable method or a non-method first argument are not flagged. `_test.go` files and `vendor/` trees are skipped. Go is **scan-only**: `writ scan --apply` never rewrites `.go` files, gate those by hand. Not yet covered: GORM raw-SQL helpers and other Go write patterns.
|
|
195
195
|
|
|
196
196
|
## GitHub Action
|
|
197
197
|
|
|
@@ -222,7 +222,7 @@ Setup and data handling: [GitHub App docs](https://docs.withwrit.com/git-hub-app
|
|
|
222
222
|
|
|
223
223
|
Give any MCP-compatible agent point-of-action policy checks. `writ-mcp` is a
|
|
224
224
|
[Model Context Protocol](https://modelcontextprotocol.io) server (stdio transport,
|
|
225
|
-
built on the MCP Python SDK) that exposes the Writ gate as **
|
|
225
|
+
built on the MCP Python SDK) that exposes the Writ gate as **24 MCP tools**:
|
|
226
226
|
the agent calls `writ_check` before a consequential write and gets back `ALLOW`,
|
|
227
227
|
`DENY`, or `STEP_UP` — with a tamper-evident, hash-chained audit receipt for
|
|
228
228
|
every decision.
|
|
@@ -237,9 +237,12 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
237
237
|
|---|---|
|
|
238
238
|
| `writ_check` | The gate: `ALLOW` / `DENY` / `STEP_UP` for a proposed write |
|
|
239
239
|
| `writ_verify_token` | Validate an `ALLOW` auth token (catches purpose drift) |
|
|
240
|
+
| `writ_lease` | Convert an `ALLOW` token into a single-use gated-execution lease |
|
|
241
|
+
| `writ_execute` | Run one gated upstream request with a lease or `ALLOW` token |
|
|
240
242
|
| `writ_grant` | Human-sponsor approval for the `STEP_UP` path |
|
|
241
243
|
| `writ_revoke` / `writ_reinstate` | The kill switch |
|
|
242
244
|
| `writ_receipts` | Read the tenant's audit log |
|
|
245
|
+
| `writ_verify_receipts` | Verify the audit-log hash chain |
|
|
243
246
|
| `writ_policy` | Manage the verb policy |
|
|
244
247
|
| `writ_sandbox` | Keyless 90-second demo grant — no API key needed |
|
|
245
248
|
| `writ_github_installations` | List connected GitHub App installations |
|
|
@@ -251,6 +254,10 @@ pip install writ-mcp # then run `writ-mcp`
|
|
|
251
254
|
| `writ_principals` | List the tenant's principals |
|
|
252
255
|
| `writ_verbs` | List the tenant's verb vocabulary |
|
|
253
256
|
| `writ_keys` | List API key metadata |
|
|
257
|
+
| `writ_badge_token` | Mint a public README badge token |
|
|
258
|
+
| `writ_badge_revoke` | Revoke a badge token; its badge image URL 404s |
|
|
259
|
+
| `writ_tenant_invite` | Mint/rotate the tenant's one live team invite code (writ_inv_...) |
|
|
260
|
+
| `writ_join_tenant` | Join a tenant with an invite code; issues an API key, no key needed first |
|
|
254
261
|
|
|
255
262
|
The gate tools need a free Writ API key (`WRIT_API_KEY`): 10,000 receipts/month
|
|
256
263
|
free, no credit card. `writ_sandbox` works with no key at all.
|
|
@@ -30,7 +30,8 @@ HAVE_EXTRA = bool(cli._go_parsers())
|
|
|
30
30
|
_BLOCK_EXTRA = {m: None for m in ("tree_sitter", "tree_sitter_go",
|
|
31
31
|
"tree_sitter_language_pack")}
|
|
32
32
|
_GO_RULES = {"go-db-write", "go-orm-write", "go-http-client-write",
|
|
33
|
-
"go-http-request-write", "go-sdk-write"
|
|
33
|
+
"go-http-request-write", "go-sdk-write", "go-pipeline-write",
|
|
34
|
+
"go-pkgclient-write"}
|
|
34
35
|
_EXPECT = re.compile(r"//\s*expect:\s*([a-z0-9-]+)")
|
|
35
36
|
_FINDING = re.compile(
|
|
36
37
|
r"^ (?P<file>\S+\.go):(?P<line>\d+) \[(?P<kind>[a-z]+)\] "
|
|
@@ -112,13 +113,15 @@ class FixtureRulesTest(unittest.TestCase):
|
|
|
112
113
|
verbs = __import__("json").loads(policy.read_text())
|
|
113
114
|
self.assertEqual(code, 0)
|
|
114
115
|
n = len(_expected())
|
|
115
|
-
self.assertIn("go files scanned:
|
|
116
|
-
self.assertIn("go write sites: %d in
|
|
116
|
+
self.assertIn("go files scanned: 6 skipped: 0 (scan only, no --apply)", out)
|
|
117
|
+
self.assertIn("go write sites: %d in 8 function(s)" % n, out)
|
|
117
118
|
self.assertIn("go gated: 0/%d (0%%)" % n, out)
|
|
118
119
|
self.assertIn(" db.go:13 [db] go-db-write deleteOrder(): "
|
|
119
120
|
"db.Exec(\"DELETE FROM orders WHERE id = $1\", id)", out)
|
|
120
121
|
self.assertIn(" sdk.go:6 [sdk] go-sdk-write chargeCard(): "
|
|
121
122
|
"sc.Charges.New(params)", out)
|
|
123
|
+
self.assertIn(" pkgclient.go:25 [sdk] go-pkgclient-write "
|
|
124
|
+
"legacyCharge(): charge.New(params)", out)
|
|
122
125
|
for v in ("db.delete", "db.create", "http.submit", "sdk.charge",
|
|
123
126
|
"sdk.nested"):
|
|
124
127
|
self.assertEqual(verbs.get(v), "require_grant", v)
|
|
@@ -311,7 +314,7 @@ class JsonReportTest(unittest.TestCase):
|
|
|
311
314
|
self.assertEqual(code, 0, out)
|
|
312
315
|
doc = j.loads(out)
|
|
313
316
|
self.assertFalse(doc["go_hint"])
|
|
314
|
-
self.assertEqual(doc["files_scanned"],
|
|
317
|
+
self.assertEqual(doc["files_scanned"], 6)
|
|
315
318
|
go_findings = [f for f in doc["findings"]
|
|
316
319
|
if f["language"] == "go"]
|
|
317
320
|
self.assertEqual(len(go_findings), len(_expected()), doc)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|