codeimprint 0.5.0a26__tar.gz → 0.5.0a28__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.
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/CHANGELOG.md +27 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/PKG-INFO +1 -1
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/pyproject.toml +1 -1
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/__init__.py +1 -1
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/api.py +20 -4
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/cli.py +108 -11
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/.gitignore +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/LICENSE +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/NOTICE +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/README.pypi.md +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint/__init__.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint/__main__.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/__main__.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/chainseal.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/config.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/gitrepo.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/imprint_file.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/linecount.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/ownership.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/project.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/receipt.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/records.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/timestamp.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/transparency.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/trust.py +0 -0
- {codeimprint-0.5.0a26 → codeimprint-0.5.0a28}/src/codeimprint_cli/tsa_roots.py +0 -0
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0a28 — `imprint init` and the GitHub App [CIM-BE-41-v1]
|
|
4
|
+
|
|
5
|
+
For engine 0.7.0a33.
|
|
6
|
+
|
|
7
|
+
- **Changed: `imprint init` adds no CI workflow when the CodeImprint GitHub App already seals
|
|
8
|
+
the repository** (its key is authorised on the project), and says so: "This repository is
|
|
9
|
+
sealed by the GitHub App; no CI workflow added." Anything unknown (not signed in, an older
|
|
10
|
+
engine, no answer, the App not yet authorised) adds the workflow as before.
|
|
11
|
+
- **New: `imprint init --ci`** adds the workflow anyway. `--ci` and `--no-ci` together are
|
|
12
|
+
refused.
|
|
13
|
+
- Tests: `tests/test_repository.py`.
|
|
14
|
+
|
|
15
|
+
## 0.5.0a27 — One project per repository; archiving a duplicate [CIM-BE-40-v1]
|
|
16
|
+
|
|
17
|
+
For engine 0.7.0a32.
|
|
18
|
+
|
|
19
|
+
- **Changed: `imprint init` in a repository the CodeImprint GitHub App already seals** names
|
|
20
|
+
the App's project in `.imprint/config.json`, creates nothing, and says to run `imprint
|
|
21
|
+
github link` to seal from that machine too. (Engines before 0.7.0a32 answer as before.)
|
|
22
|
+
- **New: `imprint project archive [folder] [--project <ID>] [--into <project>] [--reason
|
|
23
|
+
<text>] [--yes]`** archives a duplicate project for the same repository after asking: its
|
|
24
|
+
seals, chain and pages stay; it takes no new seals. `--into` merges it into the project to
|
|
25
|
+
keep: its repository and GitHub App connection move there, and `.imprint/config.json` is
|
|
26
|
+
switched when it named the archived project. Without `--yes` and no terminal it never
|
|
27
|
+
confirms.
|
|
28
|
+
- Tests: `tests/test_repository.py`.
|
|
29
|
+
|
|
3
30
|
## 0.5.0a26 — Engagement decisions [CIM-BE-38-v2]
|
|
4
31
|
|
|
5
32
|
For engine 0.7.0a30.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: codeimprint
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.0a28
|
|
4
4
|
Summary: CodeImprint: seal your code with a CodeImprint server (tamper-evident, logged and timestamped) and verify seals offline.
|
|
5
5
|
Project-URL: Homepage, https://codeimprint.ai
|
|
6
6
|
Project-URL: Hub, https://app.codeimprint.ai
|
|
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
|
|
|
6
6
|
# Published on PyPI as `codeimprint`. The import package stays `codeimprint_cli` and the
|
|
7
7
|
# command `imprint`.
|
|
8
8
|
name = "codeimprint"
|
|
9
|
-
version = "0.5.
|
|
9
|
+
version = "0.5.0a28"
|
|
10
10
|
description = "CodeImprint: seal your code with a CodeImprint server (tamper-evident, logged and timestamped) and verify seals offline."
|
|
11
11
|
readme = "README.pypi.md"
|
|
12
12
|
license = "Apache-2.0"
|
|
@@ -164,10 +164,26 @@ class Client:
|
|
|
164
164
|
{"repository": repository, "public_key": public_key,
|
|
165
165
|
"signature": signature})
|
|
166
166
|
|
|
167
|
-
def own_projects_here(self, repository: dict) -> list[
|
|
168
|
-
"""This account's own projects that live in this repository
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
def own_projects_here(self, repository: dict) -> list[dict]:
|
|
168
|
+
"""This account's own projects that live in this repository, as {project_id,
|
|
169
|
+
custody, github_app} (an engine before 0.7.0a32 gives the IDs only)."""
|
|
170
|
+
out = self._json("POST", "/api/v1/repository/projects", {"repository": repository})
|
|
171
|
+
items = out.get("items")
|
|
172
|
+
if isinstance(items, list):
|
|
173
|
+
return [i for i in items if isinstance(i, dict) and i.get("project_id")]
|
|
174
|
+
return [{"project_id": p} for p in out.get("projects") or []]
|
|
175
|
+
|
|
176
|
+
def archive_project(self, project: str, merge_into: str | None = None,
|
|
177
|
+
reason: str | None = None) -> dict:
|
|
178
|
+
"""Step 1 of archiving (or merging) a duplicate project: what will happen, and a
|
|
179
|
+
confirmation for this sign-in. Nothing changes yet."""
|
|
180
|
+
return self._json("POST", f"/api/v1/projects/{quote(project)}/archive",
|
|
181
|
+
{**({"merge_into": merge_into} if merge_into else {}),
|
|
182
|
+
**({"reason": reason} if reason else {})})
|
|
183
|
+
|
|
184
|
+
def archive_project_confirm(self, project: str, confirm: str) -> dict:
|
|
185
|
+
return self._json("POST", f"/api/v1/projects/{quote(project)}/archive/confirm",
|
|
186
|
+
{"confirm": confirm})
|
|
171
187
|
|
|
172
188
|
def rename_project(self, project: str, name: str, public: bool, public_key: str,
|
|
173
189
|
signature: str) -> dict:
|
|
@@ -583,10 +583,15 @@ def cmd_login(args) -> int:
|
|
|
583
583
|
return 0
|
|
584
584
|
|
|
585
585
|
|
|
586
|
+
APP_SEALS = "This repository is sealed by the GitHub App; no CI workflow added."
|
|
587
|
+
|
|
588
|
+
|
|
586
589
|
def cmd_init(args) -> int:
|
|
587
590
|
root = Path(args.path).resolve()
|
|
588
591
|
if not root.is_dir():
|
|
589
592
|
raise Abort(f"no such folder: {root}")
|
|
593
|
+
if getattr(args, "ci", False) and args.no_ci:
|
|
594
|
+
raise Abort("choose one: --ci adds the build workflow, --no-ci leaves it out")
|
|
590
595
|
cfg_path = root / project.CONFIG_DIR / project.CONFIG_FILE
|
|
591
596
|
existing = project.load_config(root)
|
|
592
597
|
link = getattr(args, "link_origin", False)
|
|
@@ -637,7 +642,11 @@ def cmd_init(args) -> int:
|
|
|
637
642
|
_say(f"updated {cfg_path.relative_to(root).as_posix()} (developer key)")
|
|
638
643
|
else:
|
|
639
644
|
write(cfg_path, json.dumps(cfg, indent=2) + "\n")
|
|
640
|
-
|
|
645
|
+
ci = not args.no_ci
|
|
646
|
+
if ci and not getattr(args, "ci", False) and _app_seals_here(args, root, existing):
|
|
647
|
+
ci = False # every push is sealed already (CIM-BE-41-v1)
|
|
648
|
+
_say(f"skipped CI workflow: {APP_SEALS} (`imprint init --ci` adds it anyway)")
|
|
649
|
+
if ci:
|
|
641
650
|
rel, text, shared = ci_file(root, cfg["fail_above"])
|
|
642
651
|
if shared and (root / rel).exists(): # the repository's one pipeline file
|
|
643
652
|
_say(f"kept {rel} (it is your pipeline: add the CodeImprint job from the "
|
|
@@ -665,6 +674,26 @@ def cmd_init(args) -> int:
|
|
|
665
674
|
return 0
|
|
666
675
|
|
|
667
676
|
|
|
677
|
+
def _app_seals_here(args, root: Path, existing: dict) -> bool:
|
|
678
|
+
"""The CodeImprint GitHub App seals this repository's project with an authorised key,
|
|
679
|
+
so a CI workflow would seal every push twice. Asked of the server for the signed-in
|
|
680
|
+
account's own projects here; anything unknown (no server, not signed in, an engine
|
|
681
|
+
before 0.7.0a33, no answer) counts as no, and the workflow is added as before."""
|
|
682
|
+
ident = _identity(root)
|
|
683
|
+
settings = config.resolve(getattr(args, "url", None))
|
|
684
|
+
if not ident or not settings.url:
|
|
685
|
+
return False
|
|
686
|
+
try:
|
|
687
|
+
client = _signed_in(settings.url, settings.token)
|
|
688
|
+
if client.auth != "session":
|
|
689
|
+
return False
|
|
690
|
+
items = client.own_projects_here(ident)
|
|
691
|
+
except (ApiError, NetworkError, Abort):
|
|
692
|
+
return False
|
|
693
|
+
named = [i for i in items if i["project_id"] == existing.get("project_id")]
|
|
694
|
+
return any(i.get("github_app_seals") for i in (named or items))
|
|
695
|
+
|
|
696
|
+
|
|
668
697
|
def _origin_place(args, root: Path, existing: dict) -> tuple[str, str | None]:
|
|
669
698
|
"""For `imprint init` in a folder whose config already names a project: is this the
|
|
670
699
|
repository that project lives in ("same", "different" or "unknown"), and why the project
|
|
@@ -860,12 +889,21 @@ def _init_project(args, root: Path, cfg_path: Path, key) -> None:
|
|
|
860
889
|
except (ApiError, NetworkError):
|
|
861
890
|
own = []
|
|
862
891
|
if own:
|
|
863
|
-
|
|
892
|
+
found = own[0]
|
|
893
|
+
current["project_id"] = found["project_id"]
|
|
864
894
|
cfg_path.parent.mkdir(parents=True, exist_ok=True)
|
|
865
895
|
cfg_path.write_text(json.dumps(current, indent=2) + "\n", encoding="utf-8")
|
|
866
896
|
_note_home(root, ident)
|
|
867
|
-
|
|
868
|
-
|
|
897
|
+
if found.get("custody") == "codeimprint": # the GitHub App made it (CIM-BE-40-v1)
|
|
898
|
+
_say("", f"Project {found['project_id']} (made by the CodeImprint GitHub App for "
|
|
899
|
+
"this repository, so nothing was created; .imprint/config.json now names "
|
|
900
|
+
"it)",
|
|
901
|
+
" One repository is one project. To seal it from this machine too, run",
|
|
902
|
+
" `imprint github link` here: your developer key joins the project and "
|
|
903
|
+
"authorises the App's key.")
|
|
904
|
+
return
|
|
905
|
+
_say("", f"Project {found['project_id']} (yours: this repository already has it, so "
|
|
906
|
+
"nothing was created; .imprint/config.json now names it)",
|
|
869
907
|
" The same repository on another device is the same project. To seal from this "
|
|
870
908
|
"device, run",
|
|
871
909
|
" `imprint key request` here and `imprint key approve` on a device that already "
|
|
@@ -1205,11 +1243,11 @@ def _sign_record(key, document: dict, role: str) -> dict:
|
|
|
1205
1243
|
"signature": chainseal.sign(key, records.sign_statement(document["type"], digest))}
|
|
1206
1244
|
|
|
1207
1245
|
|
|
1208
|
-
def _ask(args, question: str) -> None:
|
|
1246
|
+
def _ask(args, question: str, doing: str = "signing") -> None:
|
|
1209
1247
|
if args.yes:
|
|
1210
1248
|
return
|
|
1211
1249
|
if not sys.stdin.isatty():
|
|
1212
|
-
raise Abort("not
|
|
1250
|
+
raise Abort(f"not {doing} without confirmation: pass --yes")
|
|
1213
1251
|
if input(f"{question} [y/N] ").strip().lower() not in {"y", "yes"}:
|
|
1214
1252
|
raise Abort("cancelled")
|
|
1215
1253
|
|
|
@@ -2532,6 +2570,8 @@ def cmd_accept(args) -> int:
|
|
|
2532
2570
|
def cmd_project(args) -> int:
|
|
2533
2571
|
if args.action == "move":
|
|
2534
2572
|
return _project_move(args)
|
|
2573
|
+
if args.action == "archive":
|
|
2574
|
+
return _project_archive(args)
|
|
2535
2575
|
if not args.name:
|
|
2536
2576
|
raise Abort("give the new name: imprint project rename <name>")
|
|
2537
2577
|
key = _developer_key(required=True)
|
|
@@ -2566,6 +2606,53 @@ def _project_move(args) -> int:
|
|
|
2566
2606
|
return 0
|
|
2567
2607
|
|
|
2568
2608
|
|
|
2609
|
+
def _project_archive(args) -> int:
|
|
2610
|
+
"""`imprint project archive [folder] [--into <project>]`: a duplicate project for the
|
|
2611
|
+
same repository (for example one made by `imprint init` and one by the GitHub App) stops
|
|
2612
|
+
taking seals. Two steps on the server, the second only after you agree; its seals, chain
|
|
2613
|
+
and pages stay. ``--into`` merges it: its repository, and its GitHub App connection, move
|
|
2614
|
+
to the project you keep."""
|
|
2615
|
+
root = Path(args.name or ".")
|
|
2616
|
+
cfg = project.load_config(root) if root.is_dir() else {}
|
|
2617
|
+
project_id = getattr(args, "project", None) or cfg.get("project_id")
|
|
2618
|
+
if not project_id:
|
|
2619
|
+
raise Abort("no project: pass --project <ID> (or run this in the project's folder)")
|
|
2620
|
+
into = getattr(args, "into", None)
|
|
2621
|
+
sc = _session_client(args)
|
|
2622
|
+
try:
|
|
2623
|
+
step = sc.archive_project(project_id, into, getattr(args, "reason", None))
|
|
2624
|
+
except (ApiError, NetworkError) as exc:
|
|
2625
|
+
raise Abort(f"the project was not archived: {exc}") from exc
|
|
2626
|
+
lines = [f"Project {project_id}",
|
|
2627
|
+
f"Seals {step.get('seals', 0)}: they stay, with the project's chain and pages"]
|
|
2628
|
+
if into:
|
|
2629
|
+
lines.append(f"Merge into {into}: this project's repository becomes that project's")
|
|
2630
|
+
if step.get("github_repositories"):
|
|
2631
|
+
lines.append(f"GitHub App the repository's connection moves to {into}; then run "
|
|
2632
|
+
"`imprint github link` to authorise the App's key there")
|
|
2633
|
+
lines += ["", "An archived project takes no new seals. Archiving is not undone later."]
|
|
2634
|
+
_say(*lines)
|
|
2635
|
+
_ask(args, f"Archive project {project_id}" + (f" and merge it into {into}?" if into
|
|
2636
|
+
else "?"), "archiving")
|
|
2637
|
+
try:
|
|
2638
|
+
done = sc.archive_project_confirm(project_id, step["confirm"])
|
|
2639
|
+
except (ApiError, NetworkError) as exc:
|
|
2640
|
+
raise Abort(f"the project was not archived: {exc}") from exc
|
|
2641
|
+
_say(f"Archived {project_id} on {done['archived_at']}"
|
|
2642
|
+
+ (f", merged into {done['merged_into']}" if done.get("merged_into") else ""))
|
|
2643
|
+
if into and cfg.get("project_id") == project_id:
|
|
2644
|
+
cfg_path = root / project.CONFIG_DIR / project.CONFIG_FILE
|
|
2645
|
+
current = project.load_config(root)
|
|
2646
|
+
current["project_id"], current["homes"] = into, []
|
|
2647
|
+
cfg_path.write_text(json.dumps(current, indent=2) + "\n", encoding="utf-8")
|
|
2648
|
+
_note_home(root, _identity(root))
|
|
2649
|
+
_say(f"Saved .imprint/config.json now names {into} (commit it)")
|
|
2650
|
+
if done.get("github_repositories"):
|
|
2651
|
+
_say("Next run `imprint github link` in the repository: your developer key "
|
|
2652
|
+
f"authorises the App's key on {into}")
|
|
2653
|
+
return 0
|
|
2654
|
+
|
|
2655
|
+
|
|
2569
2656
|
GITHUB_MODES = {
|
|
2570
2657
|
"upgrade": "The App made this project with a key CodeImprint holds. Your developer key "
|
|
2571
2658
|
"becomes its key too, and authorises the App's key to keep sealing pushes: "
|
|
@@ -3062,6 +3149,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
3062
3149
|
n.add_argument("path", nargs="?", default=".")
|
|
3063
3150
|
n.add_argument("--no-ci", action="store_true", help="do not add a build workflow (GitHub Actions, GitLab "
|
|
3064
3151
|
"CI or Bitbucket Pipelines, by the remote)")
|
|
3152
|
+
n.add_argument("--ci", action="store_true",
|
|
3153
|
+
help="add the build workflow even when the CodeImprint GitHub App already "
|
|
3154
|
+
"seals this repository")
|
|
3065
3155
|
n.add_argument("--no-key", action="store_true", help="do not create a developer key")
|
|
3066
3156
|
n.add_argument("--force", action="store_true", help="overwrite files that already exist")
|
|
3067
3157
|
n.add_argument("--url", help="server URL for creating the project (else login or "
|
|
@@ -3108,17 +3198,24 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
3108
3198
|
tk.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
3109
3199
|
tk.set_defaults(func=cmd_token)
|
|
3110
3200
|
|
|
3111
|
-
pj = sub.add_parser("project", help="the project: rename it,
|
|
3112
|
-
"repository moved")
|
|
3113
|
-
pj.add_argument("action", choices=["rename", "move"],
|
|
3201
|
+
pj = sub.add_parser("project", help="the project: rename it, record that its "
|
|
3202
|
+
"repository moved, or archive a duplicate")
|
|
3203
|
+
pj.add_argument("action", choices=["rename", "move", "archive"],
|
|
3114
3204
|
help="rename: a new display name. move: this repository was renamed, "
|
|
3115
|
-
"transferred or moved to another host and is still the same project"
|
|
3205
|
+
"transferred or moved to another host and is still the same project. "
|
|
3206
|
+
"archive: a second project for the same repository stops taking "
|
|
3207
|
+
"seals (--into merges it into the one to keep); nothing is deleted")
|
|
3116
3208
|
pj.add_argument("name", nargs="?", help="rename: the new name (1-100 characters); "
|
|
3117
|
-
"move: the project's folder (default:
|
|
3209
|
+
"move, archive: the project's folder (default: "
|
|
3210
|
+
"here)")
|
|
3118
3211
|
pj.add_argument("path", nargs="?", default=".")
|
|
3119
3212
|
pj.add_argument("--private", action="store_true",
|
|
3120
3213
|
help="show the name to you only, not on the public project page")
|
|
3121
3214
|
pj.add_argument("--project", help="project ID (default: .imprint/config.json)")
|
|
3215
|
+
pj.add_argument("--into", help="archive: the project to keep; this project's repository "
|
|
3216
|
+
"and GitHub App connection move there")
|
|
3217
|
+
pj.add_argument("--reason", help="archive: a note for you (at most 200 characters)")
|
|
3218
|
+
pj.add_argument("--yes", action="store_true", help="archive: do not ask")
|
|
3122
3219
|
pj.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
|
|
3123
3220
|
pj.set_defaults(func=cmd_project)
|
|
3124
3221
|
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|