Skip to content

Commit 03d8c05

Browse files
authored
Agent setup: store pem in file (#34)
1 parent 908602b commit 03d8c05

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ Module.symvers
5151
Mkfile.old
5252
dkms.conf
5353
.aider*
54+
.env
55+
.gh-app-private-key.pem
56+
.envrc

tests/get_github_app_token.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
"""
1111
GitHub App Token Generator with caching
1212
13-
Generates an installation access token from GitHub App credentials in environment.
13+
Generates an installation access token from GitHub App credentials.
1414
Caches tokens and reuses them until they expire (with 5-minute buffer).
1515
1616
Environment variables required:
1717
- GH_APP_ID: GitHub App ID
18-
- GH_APP_PRIVATE_KEY: PEM private key
18+
19+
Files required:
20+
- .gh-app-private-key.pem: PEM private key
1921
2022
Usage:
2123
# Run with uv (automatically installs dependencies)
@@ -40,6 +42,7 @@
4042

4143
# Cache file location
4244
CACHE_FILE = Path("/tmp/gh_app_token_cache.json")
45+
PRIVATE_KEY_FILE = Path(__file__).resolve().parents[1] / ".gh-app-private-key.pem"
4346
# Buffer time before expiration (5 minutes)
4447
EXPIRATION_BUFFER_SECONDS = 300
4548

@@ -96,14 +99,18 @@ def save_token_to_cache(token, expires_at):
9699

97100
def generate_installation_token():
98101
"""Generate a new installation access token for the GitHub App."""
99-
# Get credentials from environment
100102
app_id = os.getenv("GH_APP_ID")
101-
private_key = os.getenv("GH_APP_PRIVATE_KEY")
102103

103-
if not all([app_id, private_key]):
104-
print("Error: Missing GH_APP_ID or GH_APP_PRIVATE_KEY", file=sys.stderr)
104+
if not app_id:
105+
print("Error: Missing GH_APP_ID", file=sys.stderr)
106+
sys.exit(1)
107+
108+
if not PRIVATE_KEY_FILE.exists():
109+
print(f"Error: Missing private key file: {PRIVATE_KEY_FILE}", file=sys.stderr)
105110
sys.exit(1)
106111

112+
private_key = PRIVATE_KEY_FILE.read_text()
113+
107114
# Generate JWT
108115
now = int(time.time())
109116
payload = {

0 commit comments

Comments
 (0)