Skip to content

Commit 1469410

Browse files
authored
Merge pull request #16 from openziti/bump-actions
raise exceptions; enhance docker image; bump versions
2 parents 3a705e7 + 73306cc commit 1469410

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

.github/workflows/python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
- name: Lint
1616
run: |
1717
pip install flake8
18-
flake8 --ignore E111,E114,E121,E501 zhook.py
18+
flake8 --ignore E111,E114,E121,E501 zhook.py

.github/workflows/zhook.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ jobs:
3737
pip install --upgrade requests openziti
3838
python ./zhook.py
3939
40-
4140
- uses: ./ # use self to bring the pain forward
4241
name: run action
4342
if: |

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# tmp file created by zhook.py
132+
/id.json

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
FROM python:3-slim AS builder
2-
ADD . /app
3-
WORKDIR /app
42

53
RUN pip install --target=/app requests openziti
64

75
# https://github.com/GoogleContainerTools/distroless
86
FROM gcr.io/distroless/python3-debian12
97
COPY --from=builder /app /app
8+
COPY ./zhook.py /app/zhook.py
109
WORKDIR /app
11-
ENV PYTHONPATH /app
10+
ENV PYTHONPATH=/app
11+
ENV ZITI_LOG=6
12+
ENV TLSUV_DEBUG=6
1213
CMD ["/app/zhook.py"]

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Ziti Mattermost Action - Python'
2-
description: 'POST to Mattermost wWebhook endpoint over a Ziti network'
2+
description: 'POST to Mattermost Webhook endpoint over a Ziti network'
33
branding:
44
icon: 'zap'
55
color: 'red'

zhook.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import requests
22
import openziti
33
import json
4-
import sys
54
import os
65

76

@@ -351,7 +350,6 @@ def dumpJson(self):
351350

352351

353352
if __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

Comments
 (0)