1
1
import requests
2
2
import openziti
3
3
import json
4
- import sys
5
4
import os
6
5
7
6
@@ -351,7 +350,6 @@ def dumpJson(self):
351
350
352
351
353
352
if __name__ == '__main__' :
354
- zitiId = os .getenv ("INPUT_ZITIID" )
355
353
url = os .getenv ("INPUT_WEBHOOKURL" )
356
354
eventJsonStr = os .getenv ("INPUT_EVENTJSON" )
357
355
username = os .getenv ("INPUT_SENDERUSERNAME" )
@@ -361,6 +359,16 @@ def dumpJson(self):
361
359
eventName = os .getenv ("GITHUB_EVENT_NAME" )
362
360
363
361
# 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
+
364
372
idFilename = "id.json"
365
373
with open (idFilename , 'w' ) as f :
366
374
f .write (zitiId )
@@ -371,19 +379,20 @@ def dumpJson(self):
371
379
mwb = MattermostWebhookBody (username , icon , channel , eventName , eventJsonStr , actionRepo )
372
380
except Exception as e :
373
381
print (f"Exception creating webhook body: { e } " )
374
- sys . exit ( - 1 )
382
+ raise e
375
383
376
384
# Post the webhook over Ziti
377
385
headers = {'Content-Type' : 'application/json' }
378
386
data = mwb .dumpJson ()
379
- print (f"{ data } " )
380
387
381
388
with openziti .monkeypatch ():
382
389
try :
390
+ print (f"Posting webhook to { url } with headers { headers } and data { data } " )
391
+ # breakpoint()
383
392
r = requests .post (url , headers = headers , data = data )
384
393
print (f"Response Status: { r .status_code } " )
385
394
print (r .headers )
386
395
print (r .content )
387
396
except Exception as e :
388
397
print (f"Exception posting webhook: { e } " )
389
- sys . exit ( - 1 )
398
+ raise e
0 commit comments