From 131d974913da191169a050cbe8e4c1e6061f9073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Rubinstein?= Date: Mon, 1 Jun 2026 15:06:45 +0200 Subject: [PATCH] Read the GitHub App private key from the environment Reverts #34. Reading GH_APP_PRIVATE_KEY from the environment instead of a .gh-app-private-key.pem file lets the token generator run in Claude Code web, where the key is provided as an environment variable rather than a file. Co-Authored-By: Claude Opus 4.8 --- tests/get_github_app_token.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tests/get_github_app_token.py b/tests/get_github_app_token.py index 44bdd53..4eacd03 100755 --- a/tests/get_github_app_token.py +++ b/tests/get_github_app_token.py @@ -10,14 +10,12 @@ """ GitHub App Token Generator with caching -Generates an installation access token from GitHub App credentials. +Generates an installation access token from GitHub App credentials in environment. Caches tokens and reuses them until they expire (with 5-minute buffer). Environment variables required: - GH_APP_ID: GitHub App ID - -Files required: -- .gh-app-private-key.pem: PEM private key +- GH_APP_PRIVATE_KEY: PEM private key Usage: # Run with uv (automatically installs dependencies) @@ -42,7 +40,6 @@ # Cache file location CACHE_FILE = Path("/tmp/gh_app_token_cache.json") -PRIVATE_KEY_FILE = Path(__file__).resolve().parents[1] / ".gh-app-private-key.pem" # Buffer time before expiration (5 minutes) EXPIRATION_BUFFER_SECONDS = 300 @@ -99,18 +96,14 @@ def save_token_to_cache(token, expires_at): def generate_installation_token(): """Generate a new installation access token for the GitHub App.""" + # Get credentials from environment app_id = os.getenv("GH_APP_ID") + private_key = os.getenv("GH_APP_PRIVATE_KEY") - if not app_id: - print("Error: Missing GH_APP_ID", file=sys.stderr) - sys.exit(1) - - if not PRIVATE_KEY_FILE.exists(): - print(f"Error: Missing private key file: {PRIVATE_KEY_FILE}", file=sys.stderr) + if not all([app_id, private_key]): + print("Error: Missing GH_APP_ID or GH_APP_PRIVATE_KEY", file=sys.stderr) sys.exit(1) - private_key = PRIVATE_KEY_FILE.read_text() - # Generate JWT now = int(time.time()) payload = {