run it with `uv run --script script.py`
#!/usr/bin/env -S uv run --script # /// script # requires-python = ">=3.13" # dependencies = [ # "rich", # ] # /// # run using `./script.py` or `uv run --script script.py` import argparse from rich import print from rich.prompt import Prompt from rich.panel import Panel def print_title(text): print(Panel(f" {text}", style="green")) print("\n") def print_desc(text): print(f"[yellow] {text}[/yellow]") def print_command(text): print(f"[white]{text}[/white]") def user_input(prompt): print("\n") return Prompt.ask(f"\n[red] {prompt}[/red]") def wait_for_enter(dummy_flag): print("\n") print(Panel(f" Press enter to continue", title_align="center", style="blue")) input() class CreateSSHKeypairStep: def run(self, context): print_title("Generating SSH Key Pair") print_desc("Run:") print_command(f"ssh-keygen -t rsa -f {context['key_path']}/{context['username']}.pub") wait_for_enter(True) class GitCommitStep: def run(self, context): print_title("Committing SSH Key to Git Repository") print_desc("Run:") print_command(f"cp {context['key_path']}/{context['username']}.pub user_keys/") print_command(f"git commit {context['username']}") print_command("git push") wait_for_enter(True) class WaitForBuildStep: build_url = "http://example.com/builds/user_keys" def run(self, context): print_title("Waiting for Build Job to Finish") print_desc(f"Wait for the build job at {self.build_url} to finish") wait_for_enter(True) class RetrieveUserEmailStep: dir_url = "http://example.com/directory" def run(self, context): print_title("Retrieving User Email") print_desc(f"Go to {self.dir_url}") print_desc(f"Find the email address for user `{context['username']}`") context["email"] = user_input("Paste the email address and press enter") class SendPrivateKeyStep: def run(self, context): print_title("Sending Private Key") print_desc("Go to 1Password") print_desc(f"Paste the contents of {context['key_path']}/{context['username']} into a new document") print_desc(f"Share the document with {context['email']}") wait_for_enter(True) if __name__ == "__main__": parser = argparse.ArgumentParser(description="Automate SSH key setup and sharing process.") parser.add_argument("username", type=str, help="Username for whom the SSH key will be generated") parser.add_argument("--key-path", type=str, default=".", help="Path where the SSH key will be stored (default: .)") parser.add_argument("--extra-args", nargs="*", help="Additional arguments for future use") args = parser.parse_args() context = { "username": args.username, "key_path": args.key_path, "extra_args": args.extra_args or [] } procedure = [ CreateSSHKeypairStep(), GitCommitStep(), WaitForBuildStep(), RetrieveUserEmailStep(), SendPrivateKeyStep(), ] for step in procedure: step.run(context) print("[green] Done.[/green]")
https://imgur.com/a/MmViG7G
run it with `uv run --script script.py`