Skip to content

Commit

Permalink
Merge pull request #16 from openziti/bump-actions
Browse files Browse the repository at this point in the history
raise exceptions; enhance docker image; bump versions
  • Loading branch information
qrkourier authored Sep 18, 2024
2 parents 3a705e7 + 73306cc commit 1469410
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- name: Lint
run: |
pip install flake8
flake8 --ignore E111,E114,E121,E501 zhook.py
flake8 --ignore E111,E114,E121,E501 zhook.py
1 change: 0 additions & 1 deletion .github/workflows/zhook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
pip install --upgrade requests openziti
python ./zhook.py
- uses: ./ # use self to bring the pain forward
name: run action
if: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# tmp file created by zhook.py
/id.json
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
FROM python:3-slim AS builder
ADD . /app
WORKDIR /app

RUN pip install --target=/app requests openziti

# https://github.com/GoogleContainerTools/distroless
FROM gcr.io/distroless/python3-debian12
COPY --from=builder /app /app
COPY ./zhook.py /app/zhook.py
WORKDIR /app
ENV PYTHONPATH /app
ENV PYTHONPATH=/app
ENV ZITI_LOG=6
ENV TLSUV_DEBUG=6
CMD ["/app/zhook.py"]
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Ziti Mattermost Action - Python'
description: 'POST to Mattermost wWebhook endpoint over a Ziti network'
description: 'POST to Mattermost Webhook endpoint over a Ziti network'
branding:
icon: 'zap'
color: 'red'
Expand Down
19 changes: 14 additions & 5 deletions zhook.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import requests
import openziti
import json
import sys
import os


Expand Down Expand Up @@ -351,7 +350,6 @@ def dumpJson(self):


if __name__ == '__main__':
zitiId = os.getenv("INPUT_ZITIID")
url = os.getenv("INPUT_WEBHOOKURL")
eventJsonStr = os.getenv("INPUT_EVENTJSON")
username = os.getenv("INPUT_SENDERUSERNAME")
Expand All @@ -361,6 +359,16 @@ def dumpJson(self):
eventName = os.getenv("GITHUB_EVENT_NAME")

# Setup Ziti identity
zitiJwt = os.getenv("INPUT_ZITIJWT")
if zitiJwt is not None:
zitiId = openziti.enroll(zitiJwt)
else:
zitiId = os.getenv("INPUT_ZITIID")

if zitiId is None:
print("ERROR: no Ziti identity provided, set INPUT_ZITIID or INPUT_ZITIJWT")
exit(1)

idFilename = "id.json"
with open(idFilename, 'w') as f:
f.write(zitiId)
Expand All @@ -371,19 +379,20 @@ def dumpJson(self):
mwb = MattermostWebhookBody(username, icon, channel, eventName, eventJsonStr, actionRepo)
except Exception as e:
print(f"Exception creating webhook body: {e}")
sys.exit(-1)
raise e

# Post the webhook over Ziti
headers = {'Content-Type': 'application/json'}
data = mwb.dumpJson()
print(f"{data}")

with openziti.monkeypatch():
try:
print(f"Posting webhook to {url} with headers {headers} and data {data}")
# breakpoint()
r = requests.post(url, headers=headers, data=data)
print(f"Response Status: {r.status_code}")
print(r.headers)
print(r.content)
except Exception as e:
print(f"Exception posting webhook: {e}")
sys.exit(-1)
raise e

0 comments on commit 1469410

Please sign in to comment.