diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 3abcf1a..f8090cb 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -15,4 +15,4 @@ jobs: - name: Lint run: | pip install flake8 - flake8 --ignore E111,E114,E121,E501 zhook.py \ No newline at end of file + flake8 --ignore E111,E114,E121,E501 zhook.py diff --git a/.github/workflows/zhook.yml b/.github/workflows/zhook.yml index 39f022e..95a9c38 100644 --- a/.github/workflows/zhook.yml +++ b/.github/workflows/zhook.yml @@ -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: | diff --git a/.gitignore b/.gitignore index b6e4761..51d510b 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# tmp file created by zhook.py +/id.json diff --git a/Dockerfile b/Dockerfile index 5589ccb..64f6e94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/action.yml b/action.yml index fe105c0..4930fd8 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/zhook.py b/zhook.py index 92a2418..44bc9bd 100644 --- a/zhook.py +++ b/zhook.py @@ -1,7 +1,6 @@ import requests import openziti import json -import sys import os @@ -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") @@ -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) @@ -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