codecop 0.1.0__py3-none-any.whl
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.
- codecop/__init__.py +7 -0
- codecop/access.py +140 -0
- codecop/access_postgres.py +284 -0
- codecop/advisor.py +1512 -0
- codecop/advisor_bench.py +493 -0
- codecop/advisor_ch.py +2080 -0
- codecop/advisor_view.py +381 -0
- codecop/advisors.py +184 -0
- codecop/agent.py +221 -0
- codecop/agentfacts.py +745 -0
- codecop/apply/__init__.py +327 -0
- codecop/apply/check.py +344 -0
- codecop/apply/cli.py +162 -0
- codecop/apply/clickhouse.py +379 -0
- codecop/apply/common.py +238 -0
- codecop/apply/html.py +264 -0
- codecop/apply/patch.py +213 -0
- codecop/apply/postgres.py +102 -0
- codecop/apply/trial.py +166 -0
- codecop/assemble.py +104 -0
- codecop/baseline.py +1043 -0
- codecop/bench.py +2464 -0
- codecop/blockers.py +935 -0
- codecop/budget.py +980 -0
- codecop/catalog_profile.py +525 -0
- codecop/changed.py +261 -0
- codecop/cicmd.py +1002 -0
- codecop/cli.py +5421 -0
- codecop/client.py +729 -0
- codecop/coverage.py +1067 -0
- codecop/coverage_reasons.py +116 -0
- codecop/crashlog.py +70 -0
- codecop/datagen.py +766 -0
- codecop/datagen_postgres.py +630 -0
- codecop/datagen_sqlite.py +323 -0
- codecop/dbcli.py +885 -0
- codecop/definitions.py +457 -0
- codecop/discover/__init__.py +702 -0
- codecop/discover/arms.py +160 -0
- codecop/discover/base.py +234 -0
- codecop/discover/dialect.py +296 -0
- codecop/discover/elixir.py +64 -0
- codecop/discover/engine_go.py +320 -0
- codecop/discover/go.py +1947 -0
- codecop/discover/java.py +1528 -0
- codecop/discover/loops.py +1671 -0
- codecop/discover/named_go.py +258 -0
- codecop/discover/origins.py +4565 -0
- codecop/discover/origins_ts.py +1584 -0
- codecop/discover/orm_django.py +2772 -0
- codecop/discover/orm_django_models.py +814 -0
- codecop/discover/orm_django_sql.py +662 -0
- codecop/discover/orm_ent.py +565 -0
- codecop/discover/orm_ex_ecto.py +2138 -0
- codecop/discover/orm_go.py +2134 -0
- codecop/discover/orm_go_bun.py +602 -0
- codecop/discover/orm_go_run.py +636 -0
- codecop/discover/orm_go_types.py +1082 -0
- codecop/discover/orm_java.py +1450 -0
- codecop/discover/orm_jdbi.py +743 -0
- codecop/discover/orm_jooq.py +806 -0
- codecop/discover/orm_jpa.py +1307 -0
- codecop/discover/orm_mybatis.py +730 -0
- codecop/discover/orm_py.py +557 -0
- codecop/discover/orm_py_peewee.py +1266 -0
- codecop/discover/orm_py_prisma.py +298 -0
- codecop/discover/orm_rb_activerecord.py +1906 -0
- codecop/discover/orm_rust.py +1248 -0
- codecop/discover/orm_rust_seaorm.py +734 -0
- codecop/discover/orm_sqlalchemy.py +2475 -0
- codecop/discover/orm_stats.py +307 -0
- codecop/discover/orm_tables.py +29 -0
- codecop/discover/orm_ts.py +503 -0
- codecop/discover/orm_ts_drizzle.py +697 -0
- codecop/discover/orm_ts_knex.py +1117 -0
- codecop/discover/orm_ts_kysely.py +861 -0
- codecop/discover/orm_ts_prisma.py +1045 -0
- codecop/discover/orm_ts_schema.py +169 -0
- codecop/discover/orm_ts_sequelize.py +1401 -0
- codecop/discover/orm_ts_typeorm.py +1067 -0
- codecop/discover/probes.py +323 -0
- codecop/discover/python.py +595 -0
- codecop/discover/ruby.py +793 -0
- codecop/discover/rust.py +2378 -0
- codecop/discover/schema.py +520 -0
- codecop/discover/schema_ent.py +145 -0
- codecop/discover/schema_ts.py +420 -0
- codecop/discover/tsresolve.py +257 -0
- codecop/discover/typescript.py +1728 -0
- codecop/discover/xml_mapper.py +526 -0
- codecop/engines/__init__.py +515 -0
- codecop/engines/base.py +498 -0
- codecop/engines/clickhouse.py +1558 -0
- codecop/engines/pg_ddl.py +444 -0
- codecop/engines/pg_hints.py +137 -0
- codecop/engines/postgres.py +1060 -0
- codecop/engines/sqlite.py +742 -0
- codecop/families/__init__.py +3 -0
- codecop/families/build.py +280 -0
- codecop/families/cli.py +177 -0
- codecop/families/coverage_hook.py +62 -0
- codecop/families/driver.py +221 -0
- codecop/families/goslice.py +229 -0
- codecop/families/goslice_tool/go.mod +3 -0
- codecop/families/goslice_tool/main.go +403 -0
- codecop/families/holes.py +451 -0
- codecop/families/images/Dockerfile.go +5 -0
- codecop/families/images/Dockerfile.python +4 -0
- codecop/families/images/Dockerfile.rust +4 -0
- codecop/families/isolate.py +171 -0
- codecop/families/locate.py +270 -0
- codecop/families/model.py +301 -0
- codecop/families/plangate.py +271 -0
- codecop/families/tagpatch.py +174 -0
- codecop/fidelity.py +671 -0
- codecop/fixgroups.py +130 -0
- codecop/formerly.py +91 -0
- codecop/grantscript.py +254 -0
- codecop/groupbench.py +1375 -0
- codecop/groups.py +594 -0
- codecop/groups_view.py +186 -0
- codecop/heat.py +1405 -0
- codecop/heatcli.py +219 -0
- codecop/joins.py +1749 -0
- codecop/joins_view.py +127 -0
- codecop/kinds/__init__.py +507 -0
- codecop/kinds/calls/__init__.py +501 -0
- codecop/kinds/calls/extract.py +1097 -0
- codecop/kinds/calls/harness.py +408 -0
- codecop/kinds/calls/measure.py +342 -0
- codecop/kinds/calls/rules.py +139 -0
- codecop/kinds/calls/runners/RunCalls.java +167 -0
- codecop/kinds/calls/runners/run_go.go +141 -0
- codecop/kinds/calls/runners/run_node.js +186 -0
- codecop/kinds/calls/runners/run_python.py +319 -0
- codecop/kinds/calls/runners/run_rust.rs +200 -0
- codecop/kinds/calls/standin.py +340 -0
- codecop/kinds/pipeline.py +288 -0
- codecop/kinds/regex/__init__.py +1167 -0
- codecop/kinds/regex/engines/RegexHarness.java +129 -0
- codecop/kinds/regex/engines/run_go.go +294 -0
- codecop/kinds/regex/engines/run_node.js +99 -0
- codecop/kinds/regex/engines/run_python.py +295 -0
- codecop/kinds/regex/engines/run_rust.rs +149 -0
- codecop/kinds/regex/extract.py +1438 -0
- codecop/kinds/regex/harness.py +235 -0
- codecop/kinds/regex/measure.py +270 -0
- codecop/kinds/regex/shapes.py +418 -0
- codecop/kinds/regex/syntax.py +1721 -0
- codecop/kinds/testkind.py +107 -0
- codecop/kinds/transaction/__init__.py +228 -0
- codecop/kinds/transaction/bind.py +355 -0
- codecop/kinds/transaction/measure.py +264 -0
- codecop/kinds/transaction/plan.py +462 -0
- codecop/kinds/transaction/rules.py +540 -0
- codecop/kinds/transaction/sandbox.py +94 -0
- codecop/kinds/transaction/scenarios.py +520 -0
- codecop/kinds/transaction/schedule.py +483 -0
- codecop/kinds/transaction/shapes.py +418 -0
- codecop/kinds/transaction/verify.py +293 -0
- codecop/live.py +237 -0
- codecop/loopbench.py +2071 -0
- codecop/loopschema.py +591 -0
- codecop/mcpserver.py +120 -0
- codecop/mechanism.py +214 -0
- codecop/members.py +200 -0
- codecop/multi.py +443 -0
- codecop/observed.py +1868 -0
- codecop/parts.py +102 -0
- codecop/patterns.py +830 -0
- codecop/patterns_view.py +559 -0
- codecop/plangate.py +242 -0
- codecop/profile.py +439 -0
- codecop/prompts/areas.md +19 -0
- codecop/prompts/observed_variants.md +20 -0
- codecop/prompts/profile.md +60 -0
- codecop/prompts/profile_postgres.md +68 -0
- codecop/prompts/profile_sizes.md +26 -0
- codecop/prompts/profile_sqlite.md +69 -0
- codecop/prompts/rank.md +84 -0
- codecop/prompts/rank_postgres.md +96 -0
- codecop/prompts/rank_sqlite.md +94 -0
- codecop/prompts/scenario_variants.md +20 -0
- codecop/rank.py +1473 -0
- codecop/realdb/__init__.py +688 -0
- codecop/realdb/clickhouse.py +1223 -0
- codecop/realdb/facts.py +815 -0
- codecop/realdb/locality.py +964 -0
- codecop/realdb/locks.py +355 -0
- codecop/realdb/match.py +531 -0
- codecop/realdb/postgres.py +643 -0
- codecop/realdb/ratios.py +77 -0
- codecop/realdb/sample.py +126 -0
- codecop/relations.py +227 -0
- codecop/report.py +1854 -0
- codecop/resources.py +332 -0
- codecop/resources_view.py +266 -0
- codecop/rules/entry_points.toml +1013 -0
- codecop/rules/sinks.toml +362 -0
- codecop/runsonce.py +8 -0
- codecop/sandboxschema.py +555 -0
- codecop/scenario_agent.py +172 -0
- codecop/scenario_bind.py +507 -0
- codecop/scenario_sql.py +971 -0
- codecop/scenarios.py +675 -0
- codecop/scenarios_view.py +274 -0
- codecop/schemacli.py +67 -0
- codecop/schemas/areas_output.schema.json +21 -0
- codecop/schemas/profile_output.schema.json +362 -0
- codecop/schemas/rank_output.schema.json +385 -0
- codecop/sizes.py +200 -0
- codecop/sqlinfo.py +558 -0
- codecop/typedparams.py +576 -0
- codecop/verdicts.py +212 -0
- codecop/writebench.py +720 -0
- codecop/writecost.py +440 -0
- codecop/writes.py +1208 -0
- codecop-0.1.0.dist-info/METADATA +42 -0
- codecop-0.1.0.dist-info/RECORD +222 -0
- codecop-0.1.0.dist-info/WHEEL +4 -0
- codecop-0.1.0.dist-info/entry_points.txt +2 -0
- codecop-0.1.0.dist-info/licenses/LICENSE +21 -0
codecop/heatcli.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""`codecop heat`: how hot the code path of each finding is (heat.py), and the facts a user can give about it.
|
|
2
|
+
|
|
3
|
+
codecop heat show [PATH] --out DIR work heat out again from what is known now; print the source mix and the order
|
|
4
|
+
codecop heat ask [PATH] --out DIR the one cited agent question for verified findings whose heat is not known
|
|
5
|
+
codecop heat import SRC --from KIND --to FILE per-route counts (access log, OpenTelemetry export, APM CSV) -> neutral file
|
|
6
|
+
codecop heat mark TARGET --level ... mark a finding or an entry point hot, warm or cold in the console (API)
|
|
7
|
+
codecop heat marks the marks of a project
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import urllib.parse
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Optional
|
|
16
|
+
|
|
17
|
+
import typer
|
|
18
|
+
from rich.console import Console
|
|
19
|
+
|
|
20
|
+
from . import heat as heat_mod
|
|
21
|
+
|
|
22
|
+
heat_app = typer.Typer(add_completion=False, no_args_is_help=True,
|
|
23
|
+
help="How hot the code path of each finding is: measured, given by you, inferred from the code, or asked.")
|
|
24
|
+
console = Console()
|
|
25
|
+
err = Console(stderr=True)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _paths(path: Path, out: Optional[Path]) -> tuple[Path, Path]:
|
|
29
|
+
root = path.resolve()
|
|
30
|
+
return root, (out or root / ".codecop")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _rewrite(root: Path, out_dir: Path, workload: list[str]) -> tuple[dict, heat_mod.Facts]:
|
|
34
|
+
"""Every kind stage file re-ranked by heat, and findings.json when there is one. Returns ({kind: findings}, facts)."""
|
|
35
|
+
from . import cli, verdicts as verdicts_mod
|
|
36
|
+
from .kinds import pipeline as kinds_pipeline, all_kinds
|
|
37
|
+
try:
|
|
38
|
+
facts = heat_mod.load(out_dir, root=root, config=cli.load_config(root), workload=workload, verdicts=verdicts_mod.Store(out_dir))
|
|
39
|
+
except ValueError as e:
|
|
40
|
+
err.print(f"[red]{e}[/red]")
|
|
41
|
+
raise typer.Exit(2)
|
|
42
|
+
found = {}
|
|
43
|
+
for k in all_kinds():
|
|
44
|
+
doc = kinds_pipeline.load(out_dir, k.name)
|
|
45
|
+
if not doc:
|
|
46
|
+
continue
|
|
47
|
+
doc["findings"] = heat_mod.annotate(doc.get("findings") or [], facts)
|
|
48
|
+
kinds_pipeline.save(out_dir, k.name, doc)
|
|
49
|
+
found[k.name] = doc["findings"]
|
|
50
|
+
fj = out_dir / "findings.json"
|
|
51
|
+
if fj.exists():
|
|
52
|
+
try:
|
|
53
|
+
data = json.loads(fj.read_text())
|
|
54
|
+
data = kinds_pipeline.merge(data, out_dir, None, heat_facts=facts)
|
|
55
|
+
fj.write_text(json.dumps(data, indent=1, ensure_ascii=False))
|
|
56
|
+
except (OSError, ValueError):
|
|
57
|
+
pass
|
|
58
|
+
return found, facts
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@heat_app.command("show")
|
|
62
|
+
def show(
|
|
63
|
+
path: Path = typer.Argument(Path("."), help="Repository that was scanned."),
|
|
64
|
+
out: Optional[Path] = typer.Option(None, "--out", help="Directory holding the stage files. Default: <path>/.codecop"),
|
|
65
|
+
workload: list[str] = typer.Option([], "--workload", help="A pulled workload (db_match.json or the directory holding it) "
|
|
66
|
+
"besides <out>/db_match.json. Repeatable. Also [heat] workload in codecop.toml."),
|
|
67
|
+
top: int = typer.Option(10, "--top", help="Findings listed per kind."),
|
|
68
|
+
as_json: bool = typer.Option(False, "--json", help="Print every finding's heat as JSON."),
|
|
69
|
+
) -> None:
|
|
70
|
+
"""Work heat out again from what is known now (codecop.toml [heat], imported counts, the pulled workload, stored answers),
|
|
71
|
+
re-rank each kind's findings by it (proven gain first, then heat x gain) and print where each label came from."""
|
|
72
|
+
root, out_dir = _paths(path, out)
|
|
73
|
+
found, facts = _rewrite(root, out_dir, workload)
|
|
74
|
+
if as_json:
|
|
75
|
+
console.print_json(json.dumps({k: [{"finding": f.get("id"), "site": f.get("site"), "state": (f.get("outcome") or {}).get("state"),
|
|
76
|
+
"heat": f.get("heat")} for f in fs] for k, fs in found.items()}))
|
|
77
|
+
return
|
|
78
|
+
if facts.workloads:
|
|
79
|
+
console.print("Pulled workload: " + "; ".join(f"{w['engine']} ({w['window']})" for w in facts.workloads), markup=False)
|
|
80
|
+
else:
|
|
81
|
+
console.print("No pulled workload (codecop db pull): nothing measured in production to propagate.", markup=False)
|
|
82
|
+
if facts.counts:
|
|
83
|
+
console.print(f"Imported counts: {len(facts.counts)} targets", markup=False)
|
|
84
|
+
for name, fs in found.items():
|
|
85
|
+
s = heat_mod.summary(fs)
|
|
86
|
+
console.rule(f"[bold]{name}[/bold]: {s['findings']} findings", align="left")
|
|
87
|
+
console.print("levels: " + " · ".join(f"{n} {lv}" for lv, n in s["levels"].items() if n) + " sources: "
|
|
88
|
+
+ " · ".join(f"{n} {src}" for src, n in s["sources"].items()), markup=False)
|
|
89
|
+
for f in fs[:top]:
|
|
90
|
+
h, site = f.get("heat") or {}, f.get("site") or {}
|
|
91
|
+
console.print(f" {(f.get('outcome') or {}).get('state', ''):15} {h.get('level', ''):7} {site.get('file')}:{site.get('line')} "
|
|
92
|
+
f"{site.get('symbol') or ''}", markup=False, highlight=False)
|
|
93
|
+
console.print(f" {h.get('words', '')} [{h.get('source')}, {h.get('confidence')}]", markup=False, highlight=False, soft_wrap=True)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@heat_app.command("ask")
|
|
97
|
+
def ask(
|
|
98
|
+
path: Path = typer.Argument(Path("."), help="Repository that was scanned."),
|
|
99
|
+
out: Optional[Path] = typer.Option(None, "--out", help="Directory holding the stage files. Default: <path>/.codecop"),
|
|
100
|
+
budget: Optional[str] = typer.Option(None, "--budget", help="Run budget in USD for these questions (default: [agent] budget_usd)."),
|
|
101
|
+
agent: str = typer.Option("claude", "--agent", help="Agent CLI."),
|
|
102
|
+
workload: list[str] = typer.Option([], "--workload", help="A pulled workload besides <out>/db_match.json. Repeatable."),
|
|
103
|
+
) -> None:
|
|
104
|
+
"""One question per verified finding whose heat no other source tells: "how often does this run and from where?". The
|
|
105
|
+
answer must cite a `path:line` that exists (an uncited answer is ignored); it never makes a finding hot. Spends under the
|
|
106
|
+
run budget and its ledger (step kind_heat); a re-run never pays again for an answered finding."""
|
|
107
|
+
from . import cli
|
|
108
|
+
from .kinds import all_kinds
|
|
109
|
+
root, out_dir = _paths(path, out)
|
|
110
|
+
_rewrite(root, out_dir, workload)
|
|
111
|
+
with cli._paid_step(root, out_dir, budget, None) as run:
|
|
112
|
+
n = cli._heat_stage(root, out_dir, [k.name for k in all_kinds()], False, agent, run=run)
|
|
113
|
+
found, _ = _rewrite(root, out_dir, workload)
|
|
114
|
+
console.print(f"Asked about {n} finding{'s' if n != 1 else ''}. Spent ${run.spent:.2f}.", markup=False)
|
|
115
|
+
for name, fs in found.items():
|
|
116
|
+
s = heat_mod.summary(fs)
|
|
117
|
+
console.print(f"{name}: " + " · ".join(f"{n} {lv}" for lv, n in s["levels"].items() if n), markup=False)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@heat_app.command("import")
|
|
121
|
+
def import_counts(
|
|
122
|
+
src: Path = typer.Argument(..., help="The file to read: an access log, an OpenTelemetry JSON export, an APM CSV, or a counts "
|
|
123
|
+
"file already in the neutral format (checked)."),
|
|
124
|
+
from_: str = typer.Option("neutral", "--from", help="access-log, otel, apm-csv or neutral."),
|
|
125
|
+
to: Path = typer.Option(Path("heat_counts.json"), "--to", help="The neutral counts file to write."),
|
|
126
|
+
window_hours: Optional[float] = typer.Option(None, "--window-hours", help="The hours the source covers (read from timestamps "
|
|
127
|
+
"when it has them; required for an APM CSV)."),
|
|
128
|
+
) -> None:
|
|
129
|
+
"""Request counts per route, handler or entry point, in CodeCop's neutral format (heat.COUNTS_FORMAT):
|
|
130
|
+
{"schema": "codecop-heat-counts/1", "window_hours": 24, "source": "...", "counts": [{"target": "GET /api/users/{id}", "count": 120}]}.
|
|
131
|
+
A target is a route (`METHOD /path`, path parameters in any spelling), an entry point's name (a job, a queue, an
|
|
132
|
+
activity), `file:symbol` or `file:line`. Only aggregates are written: no URLs with values, no user data. Point CodeCop at it
|
|
133
|
+
with `counts = ["heat_counts.json"]` under [heat] in codecop.toml."""
|
|
134
|
+
kind = from_.strip().lower()
|
|
135
|
+
try:
|
|
136
|
+
if kind == "access-log":
|
|
137
|
+
with src.open(errors="replace") as fh:
|
|
138
|
+
doc = heat_mod.access_log_counts(fh, window_hours)
|
|
139
|
+
elif kind == "otel":
|
|
140
|
+
doc = heat_mod.otel_counts(json.loads(src.read_text()), window_hours)
|
|
141
|
+
elif kind == "apm-csv":
|
|
142
|
+
if window_hours is None:
|
|
143
|
+
raise ValueError("an APM CSV does not say its window: pass --window-hours")
|
|
144
|
+
doc = heat_mod.apm_csv_counts(src.read_text(), window_hours)
|
|
145
|
+
elif kind == "neutral":
|
|
146
|
+
doc = heat_mod.read_counts(src)
|
|
147
|
+
else:
|
|
148
|
+
raise ValueError("--from must be access-log, otel, apm-csv or neutral")
|
|
149
|
+
heat_mod.check_counts(doc)
|
|
150
|
+
except (OSError, ValueError) as e:
|
|
151
|
+
err.print(f"[red]{e}[/red]")
|
|
152
|
+
raise typer.Exit(2)
|
|
153
|
+
to.write_text(json.dumps(doc, indent=1))
|
|
154
|
+
console.print(f"Wrote {len(doc['counts'])} targets over {doc['window_hours']:g} h to {to}. Add under [heat] in codecop.toml: "
|
|
155
|
+
f"counts = [\"{to}\"]", markup=False)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _client(server: Optional[str], org: Optional[str]):
|
|
159
|
+
from . import client as api
|
|
160
|
+
from .cicmd import org_of
|
|
161
|
+
url = api.server_url(server)
|
|
162
|
+
token = api.load_token(url)
|
|
163
|
+
if not token:
|
|
164
|
+
err.print("[red]Not signed in.[/red] Run `codecop login`, or set CODECOP_TOKEN to a token with the `findings:write` scope.")
|
|
165
|
+
raise typer.Exit(1)
|
|
166
|
+
c = api.Client(url, token)
|
|
167
|
+
return c, org_of(c, org or api.org_setting(api.load_settings()))
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@heat_app.command("mark")
|
|
171
|
+
def mark(
|
|
172
|
+
target: str = typer.Argument(..., help="A finding's number in the console (its id), or an entry point: a route "
|
|
173
|
+
"(`POST /api/target/probe`), a job, queue or activity name, `file:symbol`."),
|
|
174
|
+
project: str = typer.Option(..., "--project", help="The project (its slug or id)."),
|
|
175
|
+
level: str = typer.Option(..., "--level", help="hot, warm or cold."),
|
|
176
|
+
per_day: Optional[float] = typer.Option(None, "--per-day", help="Calls per day, when you know it."),
|
|
177
|
+
note: str = typer.Option("", "--note", help="Why (shown beside the label, audited)."),
|
|
178
|
+
org: Optional[str] = typer.Option(None, "--org"),
|
|
179
|
+
server: Optional[str] = typer.Option(None, "--server"),
|
|
180
|
+
) -> None:
|
|
181
|
+
"""Mark a finding or an entry point hot, warm or cold in the console, the same as the console's form: stored on the
|
|
182
|
+
server, audited, applied to the stored findings now and to every later run's upload."""
|
|
183
|
+
from . import client as api
|
|
184
|
+
c, slug = _client(server, org)
|
|
185
|
+
body = {"target_type": "finding" if target.isdigit() else "entry", "target": target, "level": level, "calls_per_day": per_day,
|
|
186
|
+
"note": note}
|
|
187
|
+
try:
|
|
188
|
+
got = c.request("POST", f"/api/v1/orgs/{urllib.parse.quote(slug)}/projects/{urllib.parse.quote(project)}/heat-marks", body)
|
|
189
|
+
except api.ApiError as e:
|
|
190
|
+
err.print(f"[red]{e}[/red]")
|
|
191
|
+
raise typer.Exit(1)
|
|
192
|
+
console.print(f"Marked {target}: {got.get('level')}" + (f", {got['calls_per_day']:g}/day" if got.get("calls_per_day") is not None else "")
|
|
193
|
+
+ f"; {got.get('applied', 0)} stored findings updated.", markup=False)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
@heat_app.command("marks")
|
|
197
|
+
def marks(
|
|
198
|
+
project: str = typer.Option(..., "--project", help="The project (its slug or id)."),
|
|
199
|
+
org: Optional[str] = typer.Option(None, "--org"),
|
|
200
|
+
server: Optional[str] = typer.Option(None, "--server"),
|
|
201
|
+
remove: Optional[int] = typer.Option(None, "--remove", help="Remove the mark with this id."),
|
|
202
|
+
) -> None:
|
|
203
|
+
"""The heat marks of a project (console and `codecop heat mark`), or remove one."""
|
|
204
|
+
from . import client as api
|
|
205
|
+
c, slug = _client(server, org)
|
|
206
|
+
base = f"/api/v1/orgs/{urllib.parse.quote(slug)}/projects/{urllib.parse.quote(project)}/heat-marks"
|
|
207
|
+
try:
|
|
208
|
+
if remove is not None:
|
|
209
|
+
c.request("DELETE", f"{base}/{remove}")
|
|
210
|
+
console.print(f"Removed mark {remove}.", markup=False)
|
|
211
|
+
return
|
|
212
|
+
got = c.request("GET", base)
|
|
213
|
+
except api.ApiError as e:
|
|
214
|
+
err.print(f"[red]{e}[/red]")
|
|
215
|
+
raise typer.Exit(1)
|
|
216
|
+
for m in (got or {}).get("items") or []:
|
|
217
|
+
console.print(f"{m['id']:>5} {m['target_type']:8} {m['target'][:60]:60} {m['level']:5} "
|
|
218
|
+
+ (f"{m['calls_per_day']:g}/day " if m.get("calls_per_day") is not None else "")
|
|
219
|
+
+ f"by {m.get('created_by') or '?'} {m.get('note') or ''}", markup=False, highlight=False)
|