Programmatically populate host_key in git-gate #335
Reference in New Issue
Block a user
Delete Branch "git-gate-populate-host-key"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #333.
Summary
bot_bottle/git_gate_host_key.pywithpreflight_host_keys()which runs duringBottleBackend.prepare()after manifest validation.host_key, the launch is aborted with a clear error naming the repos.ssh-keyscan(Python stdlib only), displays it to the operator, requests confirmation, and optionally persists it to the bottle.mdconfig file on disk. The key is always applied in-memory for the current launch regardless of persistence choice.headless: bool = FalsetoBottleSpec;--headlesslaunches set it toTrue.fetch_host_key, frontmatter text editing, file scanning/update, and allpreflight_host_keyspaths.@@ -0,0 +85,4 @@# ---------------------------------------------------------------------------def _insert_host_key_in_frontmatter(fm_text: str, repo_name: str, host_key: str) -> str:This is incorrect (
host_keyended up being persisted undergit-gate.repos.bot-bottle.keyinstead ofgit-gate.repos.bot-bottle), and the implementation is overly complicated: should instead parse the yaml into a nested dict, insert thehost_keyin the correct location in the nested dict, and then serialize it as yaml again.@@ -0,0 +85,4 @@# ---------------------------------------------------------------------------def _insert_host_key_in_frontmatter(fm_text: str, repo_name: str, host_key: str) -> str:Confirmed — the bug is that
child_indentis overwritten on every line withindent > repo_indent, including grandchildren, so it ends up at the deepest nesting level (key.provider/key.pathindent) rather than the direct child level. That causeshost_keyto land inside thekey:block.Will replace
_insert_host_key_in_frontmatter(and_update_frontmatter_in_file) with a parse → mutate → re-serialize approach: useyaml_subset.parse_frontmatter()to get the dict, setfm["git-gate"]["repos"][repo_name]["host_key"], then serialize back with a newserialize_yaml_subset()added toyaml_subset.py. Since the project is stdlib-only, the serializer will handle the bounded shape (nested dicts and string scalars) that bot-bottle configs use.@didericis-claude small DX improvement: show the name of the bottle config file that will be changed during the save host key confirmation step
Done.
find_repo_bottle_file()is now called before the save prompt so the filename appears inline:If no bottle file is found the prompt is skipped entirely and a message explains the key is session-only. Also used
find_repo_bottle_file()insidefind_and_update_bottle_file()to eliminate the duplicate scan logic, and renamed all helpers to public names (no underscore prefix) since they are tested via direct import.