11import requests
22import openziti
33import json
4- import sys
54import os
65
76
@@ -351,7 +350,6 @@ def dumpJson(self):
351350
352351
353352if __name__ == '__main__' :
354- zitiId = os .getenv ("INPUT_ZITIID" )
355353 url = os .getenv ("INPUT_WEBHOOKURL" )
356354 eventJsonStr = os .getenv ("INPUT_EVENTJSON" )
357355 username = os .getenv ("INPUT_SENDERUSERNAME" )
@@ -361,6 +359,16 @@ def dumpJson(self):
361359 eventName = os .getenv ("GITHUB_EVENT_NAME" )
362360
363361 # Setup Ziti identity
362+ zitiJwt = os .getenv ("INPUT_ZITIJWT" )
363+ if zitiJwt is not None :
364+ zitiId = openziti .enroll (zitiJwt )
365+ else :
366+ zitiId = os .getenv ("INPUT_ZITIID" )
367+
368+ if zitiId is None :
369+ print ("ERROR: no Ziti identity provided, set INPUT_ZITIID or INPUT_ZITIJWT" )
370+ exit (1 )
371+
364372 idFilename = "id.json"
365373 with open (idFilename , 'w' ) as f :
366374 f .write (zitiId )
@@ -371,19 +379,20 @@ def dumpJson(self):
371379 mwb = MattermostWebhookBody (username , icon , channel , eventName , eventJsonStr , actionRepo )
372380 except Exception as e :
373381 print (f"Exception creating webhook body: { e } " )
374- sys . exit ( - 1 )
382+ raise e
375383
376384 # Post the webhook over Ziti
377385 headers = {'Content-Type' : 'application/json' }
378386 data = mwb .dumpJson ()
379- print (f"{ data } " )
380387
381388 with openziti .monkeypatch ():
382389 try :
390+ print (f"Posting webhook to { url } with headers { headers } and data { data } " )
391+ # breakpoint()
383392 r = requests .post (url , headers = headers , data = data )
384393 print (f"Response Status: { r .status_code } " )
385394 print (r .headers )
386395 print (r .content )
387396 except Exception as e :
388397 print (f"Exception posting webhook: { e } " )
389- sys . exit ( - 1 )
398+ raise e
0 commit comments