codeimprint 0.5.0a26__tar.gz → 0.5.0a27__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.
Files changed (26) hide show
  1. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/CHANGELOG.md +15 -0
  2. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/PKG-INFO +1 -1
  3. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/pyproject.toml +1 -1
  4. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/__init__.py +1 -1
  5. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/api.py +20 -4
  6. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/cli.py +75 -10
  7. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/.gitignore +0 -0
  8. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/LICENSE +0 -0
  9. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/NOTICE +0 -0
  10. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/README.pypi.md +0 -0
  11. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint/__init__.py +0 -0
  12. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint/__main__.py +0 -0
  13. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/__main__.py +0 -0
  14. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/chainseal.py +0 -0
  15. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/config.py +0 -0
  16. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/gitrepo.py +0 -0
  17. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/imprint_file.py +0 -0
  18. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/linecount.py +0 -0
  19. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/ownership.py +0 -0
  20. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/project.py +0 -0
  21. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/receipt.py +0 -0
  22. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/records.py +0 -0
  23. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/timestamp.py +0 -0
  24. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/transparency.py +0 -0
  25. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/trust.py +0 -0
  26. {codeimprint-0.5.0a26 → codeimprint-0.5.0a27}/src/codeimprint_cli/tsa_roots.py +0 -0
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0a27 — One project per repository; archiving a duplicate [CIM-BE-40-v1]
4
+
5
+ For engine 0.7.0a32.
6
+
7
+ - **Changed: `imprint init` in a repository the CodeImprint GitHub App already seals** names
8
+ the App's project in `.imprint/config.json`, creates nothing, and says to run `imprint
9
+ github link` to seal from that machine too. (Engines before 0.7.0a32 answer as before.)
10
+ - **New: `imprint project archive [folder] [--project <ID>] [--into <project>] [--reason
11
+ <text>] [--yes]`** archives a duplicate project for the same repository after asking: its
12
+ seals, chain and pages stay; it takes no new seals. `--into` merges it into the project to
13
+ keep: its repository and GitHub App connection move there, and `.imprint/config.json` is
14
+ switched when it named the archived project. Without `--yes` and no terminal it never
15
+ confirms.
16
+ - Tests: `tests/test_repository.py`.
17
+
3
18
  ## 0.5.0a26 — Engagement decisions [CIM-BE-38-v2]
4
19
 
5
20
  For engine 0.7.0a30.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeimprint
3
- Version: 0.5.0a26
3
+ Version: 0.5.0a27
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.0a26"
9
+ version = "0.5.0a27"
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"
@@ -5,4 +5,4 @@ A thin client for a CodeImprint server: it zips a project, asks the server to se
5
5
  it, and verifies Imprint files offline. All analysis happens on the server.
6
6
  """
7
7
 
8
- __version__ = "0.5.0a26"
8
+ __version__ = "0.5.0a27"
@@ -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[str]:
168
- """This account's own projects that live in this repository."""
169
- return self._json("POST", "/api/v1/repository/projects",
170
- {"repository": repository}).get("projects") or []
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:
@@ -860,12 +860,21 @@ def _init_project(args, root: Path, cfg_path: Path, key) -> None:
860
860
  except (ApiError, NetworkError):
861
861
  own = []
862
862
  if own:
863
- current["project_id"] = own[0]
863
+ found = own[0]
864
+ current["project_id"] = found["project_id"]
864
865
  cfg_path.parent.mkdir(parents=True, exist_ok=True)
865
866
  cfg_path.write_text(json.dumps(current, indent=2) + "\n", encoding="utf-8")
866
867
  _note_home(root, ident)
867
- _say("", f"Project {own[0]} (yours: this repository already has it, so nothing was "
868
- "created; .imprint/config.json now names it)",
868
+ if found.get("custody") == "codeimprint": # the GitHub App made it (CIM-BE-40-v1)
869
+ _say("", f"Project {found['project_id']} (made by the CodeImprint GitHub App for "
870
+ "this repository, so nothing was created; .imprint/config.json now names "
871
+ "it)",
872
+ " One repository is one project. To seal it from this machine too, run",
873
+ " `imprint github link` here: your developer key joins the project and "
874
+ "authorises the App's key.")
875
+ return
876
+ _say("", f"Project {found['project_id']} (yours: this repository already has it, so "
877
+ "nothing was created; .imprint/config.json now names it)",
869
878
  " The same repository on another device is the same project. To seal from this "
870
879
  "device, run",
871
880
  " `imprint key request` here and `imprint key approve` on a device that already "
@@ -1205,11 +1214,11 @@ def _sign_record(key, document: dict, role: str) -> dict:
1205
1214
  "signature": chainseal.sign(key, records.sign_statement(document["type"], digest))}
1206
1215
 
1207
1216
 
1208
- def _ask(args, question: str) -> None:
1217
+ def _ask(args, question: str, doing: str = "signing") -> None:
1209
1218
  if args.yes:
1210
1219
  return
1211
1220
  if not sys.stdin.isatty():
1212
- raise Abort("not signing without confirmation: pass --yes")
1221
+ raise Abort(f"not {doing} without confirmation: pass --yes")
1213
1222
  if input(f"{question} [y/N] ").strip().lower() not in {"y", "yes"}:
1214
1223
  raise Abort("cancelled")
1215
1224
 
@@ -2532,6 +2541,8 @@ def cmd_accept(args) -> int:
2532
2541
  def cmd_project(args) -> int:
2533
2542
  if args.action == "move":
2534
2543
  return _project_move(args)
2544
+ if args.action == "archive":
2545
+ return _project_archive(args)
2535
2546
  if not args.name:
2536
2547
  raise Abort("give the new name: imprint project rename <name>")
2537
2548
  key = _developer_key(required=True)
@@ -2566,6 +2577,53 @@ def _project_move(args) -> int:
2566
2577
  return 0
2567
2578
 
2568
2579
 
2580
+ def _project_archive(args) -> int:
2581
+ """`imprint project archive [folder] [--into <project>]`: a duplicate project for the
2582
+ same repository (for example one made by `imprint init` and one by the GitHub App) stops
2583
+ taking seals. Two steps on the server, the second only after you agree; its seals, chain
2584
+ and pages stay. ``--into`` merges it: its repository, and its GitHub App connection, move
2585
+ to the project you keep."""
2586
+ root = Path(args.name or ".")
2587
+ cfg = project.load_config(root) if root.is_dir() else {}
2588
+ project_id = getattr(args, "project", None) or cfg.get("project_id")
2589
+ if not project_id:
2590
+ raise Abort("no project: pass --project <ID> (or run this in the project's folder)")
2591
+ into = getattr(args, "into", None)
2592
+ sc = _session_client(args)
2593
+ try:
2594
+ step = sc.archive_project(project_id, into, getattr(args, "reason", None))
2595
+ except (ApiError, NetworkError) as exc:
2596
+ raise Abort(f"the project was not archived: {exc}") from exc
2597
+ lines = [f"Project {project_id}",
2598
+ f"Seals {step.get('seals', 0)}: they stay, with the project's chain and pages"]
2599
+ if into:
2600
+ lines.append(f"Merge into {into}: this project's repository becomes that project's")
2601
+ if step.get("github_repositories"):
2602
+ lines.append(f"GitHub App the repository's connection moves to {into}; then run "
2603
+ "`imprint github link` to authorise the App's key there")
2604
+ lines += ["", "An archived project takes no new seals. Archiving is not undone later."]
2605
+ _say(*lines)
2606
+ _ask(args, f"Archive project {project_id}" + (f" and merge it into {into}?" if into
2607
+ else "?"), "archiving")
2608
+ try:
2609
+ done = sc.archive_project_confirm(project_id, step["confirm"])
2610
+ except (ApiError, NetworkError) as exc:
2611
+ raise Abort(f"the project was not archived: {exc}") from exc
2612
+ _say(f"Archived {project_id} on {done['archived_at']}"
2613
+ + (f", merged into {done['merged_into']}" if done.get("merged_into") else ""))
2614
+ if into and cfg.get("project_id") == project_id:
2615
+ cfg_path = root / project.CONFIG_DIR / project.CONFIG_FILE
2616
+ current = project.load_config(root)
2617
+ current["project_id"], current["homes"] = into, []
2618
+ cfg_path.write_text(json.dumps(current, indent=2) + "\n", encoding="utf-8")
2619
+ _note_home(root, _identity(root))
2620
+ _say(f"Saved .imprint/config.json now names {into} (commit it)")
2621
+ if done.get("github_repositories"):
2622
+ _say("Next run `imprint github link` in the repository: your developer key "
2623
+ f"authorises the App's key on {into}")
2624
+ return 0
2625
+
2626
+
2569
2627
  GITHUB_MODES = {
2570
2628
  "upgrade": "The App made this project with a key CodeImprint holds. Your developer key "
2571
2629
  "becomes its key too, and authorises the App's key to keep sealing pushes: "
@@ -3108,17 +3166,24 @@ def build_parser() -> argparse.ArgumentParser:
3108
3166
  tk.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3109
3167
  tk.set_defaults(func=cmd_token)
3110
3168
 
3111
- pj = sub.add_parser("project", help="the project: rename it, or record that its "
3112
- "repository moved")
3113
- pj.add_argument("action", choices=["rename", "move"],
3169
+ pj = sub.add_parser("project", help="the project: rename it, record that its "
3170
+ "repository moved, or archive a duplicate")
3171
+ pj.add_argument("action", choices=["rename", "move", "archive"],
3114
3172
  help="rename: a new display name. move: this repository was renamed, "
3115
- "transferred or moved to another host and is still the same project")
3173
+ "transferred or moved to another host and is still the same project. "
3174
+ "archive: a second project for the same repository stops taking "
3175
+ "seals (--into merges it into the one to keep); nothing is deleted")
3116
3176
  pj.add_argument("name", nargs="?", help="rename: the new name (1-100 characters); "
3117
- "move: the project's folder (default: here)")
3177
+ "move, archive: the project's folder (default: "
3178
+ "here)")
3118
3179
  pj.add_argument("path", nargs="?", default=".")
3119
3180
  pj.add_argument("--private", action="store_true",
3120
3181
  help="show the name to you only, not on the public project page")
3121
3182
  pj.add_argument("--project", help="project ID (default: .imprint/config.json)")
3183
+ pj.add_argument("--into", help="archive: the project to keep; this project's repository "
3184
+ "and GitHub App connection move there")
3185
+ pj.add_argument("--reason", help="archive: a note for you (at most 200 characters)")
3186
+ pj.add_argument("--yes", action="store_true", help="archive: do not ask")
3122
3187
  pj.add_argument("--url", help="server URL (overrides login and CODEIMPRINT_URL)")
3123
3188
  pj.set_defaults(func=cmd_project)
3124
3189
 
File without changes
File without changes