SPB Git

Repository Public

asc.py 3.6 KB 78 lines python

1#!/usr/bin/env python32# =============================================================================3#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project          : MacLustr Vision iOS8# File             : Scripts/asc.py9# Description      : Minimal App Store Connect API client (JWT ES256 with the10#                    team key already on this Mac). Usage: asc.py GET11#                    /v1/apps?filter[bundleId]=…12# Module           : Scripts13# Repository       : https://git.spboucher.ai/maclustr-vision-ios14# Project Website  : https://camera.spboucher.ai15# Created          : 2026-11-3016# Last Modified    : 2026-11-3017#18# Author           : Simon-Pierre Boucher19# Position         : Professor of Finance20# Institution      : Université du Québec en Outaouais (UQO)21# Organization     : SP Boucher22# Website          : https://spboucher.ai23# Git              : https://git.spboucher.ai24#25# Preferred Contact: admin@spboucher.ai26# Technical Contact: dev@spboucher.ai27# Security/Admin   : admin@spboucher.ai28#29# Copyright (c) 202630# Simon-Pierre Boucher31# All rights reserved where applicable. This file is governed by the32# applicable project license, copyright notices and relevant law.33# Existing third-party rights and notices remain unaffected.34#35# License          : None specified (no license file in this repository)36#37# Do not embed credentials, private keys, access tokens,38# certificates or confidential personal information.39#40# =============================================================================41# END OF SP BOUCHER SOURCE HEADER42# =============================================================================4344import base64, json, os, subprocess, sys, tempfile, time, urllib.request, urllib.error4546KEY_ID = os.environ.get("ASC_KEY_ID", "L379BDKR69")47ISSUER = os.environ.get("ASC_ISSUER_ID", "013e761f-e05c-4d93-a50b-f3d960adae4a")48KEY = os.path.expanduser(f"~/.appstoreconnect/private_keys/AuthKey_{KEY_ID}.p8")4950def b64(b): return base64.urlsafe_b64encode(b).rstrip(b"=")5152def token():53    head = b64(json.dumps({"alg": "ES256", "kid": KEY_ID, "typ": "JWT"}).encode())54    now = int(time.time())55    body = b64(json.dumps({"iss": ISSUER, "iat": now, "exp": now + 900, "aud": "appstoreconnect-v1"}).encode())56    msg = head + b"." + body57    with tempfile.NamedTemporaryFile() as f:58        f.write(msg); f.flush()59        der = subprocess.check_output(["openssl", "dgst", "-sha256", "-sign", KEY, f.name])60    # DER ECDSA signature -> raw r||s (JOSE)61    i = 2 if der[1] < 0x80 else 2 + (der[1] & 0x7F)62    rl = der[i + 1]; r = der[i + 2:i + 2 + rl]; i += 2 + rl63    sl = der[i + 1]; s = der[i + 2:i + 2 + sl]64    raw = r[-32:].rjust(32, b"\0") + s[-32:].rjust(32, b"\0")65    return (msg + b"." + b64(raw)).decode()6667def call(method, path, payload=None):68    req = urllib.request.Request("https://api.appstoreconnect.apple.com" + path, method=method, data=json.dumps(payload).encode() if payload is not None else None,69                                 headers={"Authorization": "Bearer " + token(), "Content-Type": "application/json"})70    try:71        with urllib.request.urlopen(req, timeout=60) as r: return r.status, json.loads(r.read() or b"{}")72    except urllib.error.HTTPError as e:73        return e.code, json.loads(e.read() or b"{}")7475if __name__ == "__main__":76    status, data = call(sys.argv[1], sys.argv[2], json.loads(sys.argv[3]) if len(sys.argv) > 3 else None)77    print(status); print(json.dumps(data, indent=1, ensure_ascii=False)[:6000])78
Files main
Menu

Theme