Buckets:

download
raw
2.76 kB
#!/usr/bin/env python3
"""
Git Credential Helper für GitHub App Authentication.
Generiert automatisch frische Installation Tokens.
"""
import os
import sys
import time
from pathlib import Path
import jwt
APP_ID = os.environ.get("GITHUB_APP_ID", "2872904")
PRIVATE_KEY_PATH = Path(
os.environ.get(
"GITHUB_APP_PRIVATE_KEY_PATH",
str(Path.home() / "Downloads" / "zen-ai-pentest-kimi-assistant.2026-02-23.private-key.pem"),
)
)
def generate_jwt():
"""Generate JWT from Private Key."""
with open(PRIVATE_KEY_PATH, "r") as f:
private_key = f.read()
payload = {
"iat": int(time.time()) - 60,
"exp": int(time.time()) + (10 * 60),
"iss": APP_ID,
}
return jwt.encode(payload, private_key, algorithm="RS256")
def get_installation_token(jwt_token):
"""Exchange JWT for Installation Access Token via API."""
import json
from urllib.parse import urlparse
import requests
url = "https://api.github.com/app/installations"
if urlparse(url).scheme != "https":
raise ValueError(f"Only HTTPS URLs allowed: {url}")
resp = requests.get(
url,
headers={
"Authorization": f"Bearer {jwt_token}",
"Accept": "application/vnd.github.v3+json",
},
timeout=30,
)
resp.raise_for_status()
installations = resp.json()
if not installations:
return None
installation_id = installations[0]["id"]
url = f"https://api.github.com/app/installations/{installation_id}/access_tokens"
if urlparse(url).scheme != "https":
raise ValueError(f"Only HTTPS URLs allowed: {url}")
resp = requests.post(
url,
headers={
"Authorization": f"Bearer {jwt_token}",
"Accept": "application/vnd.github.v3+json",
},
timeout=30,
)
resp.raise_for_status()
data = resp.json()
return data.get("token")
def main():
"""Git credential helper main loop."""
lines = []
for line in sys.stdin:
line = line.strip()
if not line:
break
lines.append(line)
props = {}
for line in lines:
if "=" in line:
key, value = line.split("=", 1)
props[key] = value
host = props.get("host", "")
if host != "github.com":
sys.exit(0)
try:
jwt_token = generate_jwt()
install_token = get_installation_token(jwt_token)
if install_token:
print("protocol=https")
print("host=github.com")
print("username=x-access-token")
print(f"password={install_token}")
print("")
except Exception:
sys.exit(0)
if __name__ == "__main__":
main()

Xet Storage Details

Size:
2.76 kB
·
Xet hash:
040f4dcb7dbce693c30f4f9a56520c304dbecf47bb0da5a8a6f59a9ea2eb1d13

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.