1313
1414def build_parser () -> argparse .ArgumentParser :
1515 p = argparse .ArgumentParser (description = "Deploy request client" )
16- p .add_argument (
17- "--cid" ,
18- required = True ,
19- help = "IPFS CID of the build tarball"
20- )
21- p .add_argument (
22- "--app" ,
23- required = True ,
24- help = "Application name on the server"
25- )
26- p .add_argument (
27- "--url" ,
28- required = True ,
29- help = "Deploy service URL" ,
30- )
31- p .add_argument (
32- "--key" ,
33- required = True ,
34- help = "Base64-encoded Ed25519 private key" ,
35- )
16+ p .add_argument ("--cid" , required = True , help = "IPFS CID" )
17+ p .add_argument ("--app" , required = True , help = "Application name on the server" )
18+ p .add_argument ("--url" , required = True , help = "Deploy service URL" )
19+ p .add_argument ("--key" , required = True , help = "Base64-encoded Ed25519 private key" )
3620 return p
3721
3822
3923def main (argv : list [str ] | None = None ) -> None :
4024 args = build_parser ().parse_args (argv )
4125
42- key_b64 = args .key
43-
4426 try :
45- signing_key = SigningKey (base64 .b64decode (key_b64 ))
27+ signing_key = SigningKey (base64 .b64decode (args . key ))
4628 except Exception as exc :
4729 print ("Invalid private key (must be base64-encoded)" , file = sys .stderr )
48- raise SystemExit (1 ) from exc
30+ sys . exit (1 )
4931
5032 payload : Dict [str , Any ] = {"cid" : args .cid , "app" : args .app }
51-
52- # Use separators to eliminate whitespace – the server verifies the raw bytes
5333 body : bytes = json .dumps (payload , separators = ("," , ":" )).encode ()
5434
5535 signature : bytes = signing_key .sign (body ).signature
@@ -59,10 +39,20 @@ def main(argv: list[str] | None = None) -> None:
5939 }
6040
6141 resp = requests .post (args .url , headers = headers , data = body , timeout = 60 )
42+
43+ # Fail the workflow on HTTP error codes
44+ if not resp .ok :
45+ print (f"HTTP { resp .status_code } : { resp .text } " , file = sys .stderr )
46+ sys .exit (1 )
47+
6248 try :
63- print (resp .json ())
49+ # JSON body
50+ print (json .dumps (resp .json (), indent = 2 ))
51+ return
6452 except ValueError :
53+ # Plain-text body
6554 print (resp .text )
55+ return
6656
6757
6858if __name__ == "__main__" :
0 commit comments