SPB Git

Repository Public MIT

asc.py 5.4 KB 126 lines python

1#!/usr/bin/env python32# =============================================================================3#                  SP BOUCHER | SOFTWARE & RESEARCH4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project          : ORIX Astra10# File             : Scripts/asc.py11# Description      : Minimal App Store Connect API client (JWT ES256 with the12#                    team key already on this Mac). Usage: asc.py GET13#                    /v1/apps?filter[bundleId]=…14# Module           : Scripts15# Repository       : https://git.spboucher.ai/orix-astra16# Created          : 2026-11-2117# Last Modified    : 2026-11-2118#19# =============================================================================20# AUTHOR & PROFESSIONAL AFFILIATION21# =============================================================================22#23# Author           : Simon-Pierre Boucher24# Position         : Professor of Finance25# Institution      : Université du Québec en Outaouais (UQO)26# Department       : Département des sciences administratives27# Organization     : SP Boucher28#29# Website          : https://spboucher.ai30# Git              : https://git.spboucher.ai31#32# =============================================================================33# OFFICIAL CONTACT DIRECTORY34# =============================================================================35#36# General          : info@spboucher.ai37# Professional     : contact@spboucher.ai38# Direct           : simon@spboucher.ai39# Research         : research@spboucher.ai40# Development      : dev@spboucher.ai41# Support          : support@spboucher.ai42# Security/Admin   : admin@spboucher.ai43# Notifications    : notifications@spboucher.ai44#45# Preferred Contact: support@spboucher.ai46#47# =============================================================================48# COPYRIGHT & INTELLECTUAL PROPERTY49# =============================================================================50#51# Copyright (c) 202652# Simon-Pierre Boucher53#54# All rights reserved where applicable.55#56# This file is governed by the applicable project license,57# copyright notices, institutional agreements and relevant law.58#59# Unless expressly authorized by the applicable license or60# rights holder, copying, redistribution, sublicensing,61# publication and commercial exploitation are not permitted.62#63# Existing third-party rights and notices remain unaffected.64#65# =============================================================================66# CONFIDENTIALITY & SECURITY67# =============================================================================68#69# Classification   : Public70# Distribution     : Public repository; use is governed by the project license71# Security Contact : admin@spboucher.ai72#73# Access to this source does not independently grant permission74# to redistribute or disclose confidential materials.75#76# Do not embed credentials, private keys, access tokens,77# certificates or confidential personal information.78#79# =============================================================================80# LICENSE & MAINTENANCE81# =============================================================================82#83# License          : Proprietary, all rights reserved (see license file)84# License File     : LICENSE85# Maintainer       : Simon-Pierre Boucher86# Technical Contact: dev@spboucher.ai87#88# =============================================================================89# END OF SP BOUCHER SOURCE HEADER90# =============================================================================9192import base64, json, os, subprocess, sys, tempfile, time, urllib.request, urllib.error9394KEY_ID = os.environ.get("ASC_KEY_ID", "L379BDKR69")95ISSUER = os.environ.get("ASC_ISSUER_ID", "013e761f-e05c-4d93-a50b-f3d960adae4a")96KEY = os.path.expanduser(f"~/.appstoreconnect/private_keys/AuthKey_{KEY_ID}.p8")9798def b64(b): return base64.urlsafe_b64encode(b).rstrip(b"=")99100def token():101    head = b64(json.dumps({"alg": "ES256", "kid": KEY_ID, "typ": "JWT"}).encode())102    now = int(time.time())103    body = b64(json.dumps({"iss": ISSUER, "iat": now, "exp": now + 900, "aud": "appstoreconnect-v1"}).encode())104    msg = head + b"." + body105    with tempfile.NamedTemporaryFile() as f:106        f.write(msg); f.flush()107        der = subprocess.check_output(["openssl", "dgst", "-sha256", "-sign", KEY, f.name])108    # DER ECDSA signature -> raw r||s (JOSE)109    i = 2 if der[1] < 0x80 else 2 + (der[1] & 0x7F)110    rl = der[i + 1]; r = der[i + 2:i + 2 + rl]; i += 2 + rl111    sl = der[i + 1]; s = der[i + 2:i + 2 + sl]112    raw = r[-32:].rjust(32, b"\0") + s[-32:].rjust(32, b"\0")113    return (msg + b"." + b64(raw)).decode()114115def call(method, path, payload=None):116    req = urllib.request.Request("https://api.appstoreconnect.apple.com" + path, method=method, data=json.dumps(payload).encode() if payload is not None else None,117                                 headers={"Authorization": "Bearer " + token(), "Content-Type": "application/json"})118    try:119        with urllib.request.urlopen(req, timeout=60) as r: return r.status, json.loads(r.read() or b"{}")120    except urllib.error.HTTPError as e:121        return e.code, json.loads(e.read() or b"{}")122123if __name__ == "__main__":124    status, data = call(sys.argv[1], sys.argv[2], json.loads(sys.argv[3]) if len(sys.argv) > 3 else None)125    print(status); print(json.dumps(data, indent=1, ensure_ascii=False)[:6000])126
Files main
Menu

Theme