Skip to content

Commit e0d5fe4

Browse files
committed
update py webhook action to use a channel-specific url; add debug
logging to self-tests
1 parent eb07272 commit e0d5fe4

File tree

4 files changed

+86
-33
lines changed

4 files changed

+86
-33
lines changed

.github/workflows/zhook.yml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,40 @@ jobs:
2020
runs-on: ubuntu-latest
2121
name: POST Webhook
2222
steps:
23-
- uses: actions/checkout@v4
24-
- name: run hook directly
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Run Python Script Directly
2527
if: |
26-
github.repository_owner == 'openziti'
28+
github.repository_owner == 'qrkourier'
2729
&& ((github.event_name != 'pull_request_review')
2830
|| (github.event_name == 'pull_request_review' && github.event.review.state == 'approved'))
2931
env:
3032
INPUT_ZITIID: ${{ secrets.ZITI_MATTERMOST_IDENTITY }}
31-
INPUT_WEBHOOKURL: ${{ secrets.ZHOOK_URL }}
33+
INPUT_WEBHOOKURL: ${{ secrets.ZHOOK_URL_DEV_NOTIFICATIONS }}
3234
INPUT_EVENTJSON: ${{ toJson(github.event) }}
3335
INPUT_SENDERUSERNAME: GitHubZ
3436
INPUT_DESTCHANNEL: dev-notifications
3537
INPUT_SENDERICONURL: https://github.com/fluidicon.png
38+
ZITI_LOG: 6
39+
TLSUV_DEBUG: 6
40+
shell: bash
3641
run: |
37-
pip install --upgrade requests openziti
42+
set -o pipefail
43+
set -o xtrace
44+
pip install --user --upgrade requests openziti==1.2.0
45+
echo "DEBUG: PYTHONPATH=${PYTHONPATH:-}"
3846
python ./zhook.py
39-
40-
- uses: ./ # use self to bring the pain forward
41-
name: run action
47+
48+
- uses: ./
49+
name: Run as a GH Action from the Local Checkout
4250
if: |
43-
github.repository_owner == 'openziti'
51+
github.repository_owner == 'qrkourier'
4452
&& ((github.event_name != 'pull_request_review')
4553
|| (github.event_name == 'pull_request_review' && github.event.review.state == 'approved'))
4654
with:
4755
zitiId: ${{ secrets.ZITI_MATTERMOST_IDENTITY }}
48-
webhookUrl: ${{ secrets.ZHOOK_URL }}
56+
webhookUrl: ${{ secrets.ZHOOK_URL_DEV_NOTIFICATIONS }}
4957
eventJson: ${{ toJson(github.event) }}
50-
senderUsername: "GitHubZ"
51-
destChannel: "dev-notifications"
58+
senderUsername: GitHubZ
59+
destChannel: dev-notifications

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3-slim AS builder
22

3-
RUN pip install --target=/app requests openziti
3+
RUN pip install --target=/app requests openziti==1.2.0
44

55
# https://github.com/GoogleContainerTools/distroless
66
FROM gcr.io/distroless/python3-debian12

action.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
name: 'Ziti Mattermost Action - Python'
2-
description: 'POST to Mattermost Webhook endpoint over a Ziti network'
1+
name: Ziti Mattermost Action - Python
2+
description: POST to Mattermost Webhook endpoint over a Ziti network
33
branding:
4-
icon: 'zap'
5-
color: 'red'
4+
icon: zap
5+
color: red
66
inputs:
77
zitiId:
8-
description: 'Identity JSON for an enrolled Ziti endpoint'
8+
description: Identity JSON for an enrolled Ziti endpoint
99
required: true
1010
webhookUrl:
11-
description: 'URL for posting the payload'
11+
description: URL for posting the payload
1212
required: true
1313
eventJson:
14-
description: 'GitHub event JSON (github.event)'
14+
description: GitHub event JSON (github.event)
1515
required: true
1616
senderUsername:
17-
description: 'Mattermost username'
17+
description: Mattermost username
1818
required: false
19-
default: "GithubZ"
19+
default: GithubZ
2020
senderIconUrl:
21-
description: 'Mattermost user icon URL'
21+
description: Mattermost user icon URL
2222
required: false
23-
default: "https://github.com/fluidicon.png"
23+
default: https://github.com/fluidicon.png
2424
destChannel:
25-
description: 'Mattermost channel'
25+
description: Mattermost channel
2626
required: false
27-
default: "dev-notifications"
27+
default: dev-notifications
2828
runs:
29-
using: "docker"
30-
image: "Dockerfile"
29+
using: docker
30+
image: Dockerfile

zhook.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self, username, icon, channel, eventName, eventJsonStr, actionRepo)
7474
elif eventName == "repository_dispatch":
7575
event_type = self.eventJson.get("action", None)
7676
if event_type == "ziti_release":
77-
self.addFipsReleaseDetails()
77+
self.addFipsPreReleaseDetails()
7878
elif event_type == "ziti_promote_stable":
7979
self.addFipsPromoteStableDetails()
8080
else:
@@ -283,16 +283,16 @@ def addReleaseDetails(self):
283283

284284
self.attachment["text"] = bodyText
285285

286-
def addFipsReleaseDetails(self):
286+
def addFipsPreReleaseDetails(self):
287287
# Pre-release announcement (ziti_release)
288288
payload = self.eventJson.get("client_payload", {})
289289
version = payload.get("version")
290290
if not version:
291291
self.attachment["text"] = "[ziti-fips] Pre-release published, but version not found in event."
292292
return
293293
repo = self.repoJson["full_name"]
294-
release_url = f"https://github.com/{repo}/releases/tag/{version}"
295-
self.body["text"] = f"FIPS Pre-release published by [{repo}](https://github.com/{repo})"
294+
release_url = f"https://github.com/{repo}/releases/tag/v{version}"
295+
self.body["text"] = f"FIPS Pre-release published in [{repo}](https://github.com/{repo})"
296296
self.attachment["color"] = self.releaseColor
297297
self.attachment["thumb_url"] = self.fipsReleaseThumbnail
298298
self.attachment["text"] = f"FIPS Pre-release [{version}]({release_url}) is now available."
@@ -305,7 +305,7 @@ def addFipsPromoteStableDetails(self):
305305
self.attachment["text"] = "[ziti-fips] Stable promotion, but version not found in event."
306306
return
307307
repo = self.repoJson["full_name"]
308-
release_url = f"https://github.com/{repo}/releases/tag/{version}"
308+
release_url = f"https://github.com/{repo}/releases/tag/v{version}"
309309
self.body["text"] = f"FIPS Release promoted to stable in [{repo}](https://github.com/{repo})"
310310
self.attachment["color"] = self.releaseColor
311311
self.attachment["thumb_url"] = self.fipsReleaseThumbnail
@@ -414,10 +414,55 @@ def dumpJson(self):
414414
print("ERROR: no Ziti identity provided, set INPUT_ZITIID or INPUT_ZITIJWT")
415415
exit(1)
416416

417+
def generate_json_schema(obj, max_depth=10, current_depth=0):
418+
"""Generate a schema representation of a JSON object by inferring types from values."""
419+
if current_depth >= max_depth:
420+
return "<max_depth_reached>"
421+
422+
if obj is None:
423+
return "null"
424+
elif isinstance(obj, bool):
425+
return "boolean"
426+
elif isinstance(obj, int):
427+
return "integer"
428+
elif isinstance(obj, float):
429+
return "number"
430+
elif isinstance(obj, str):
431+
return "string"
432+
elif isinstance(obj, list):
433+
if len(obj) == 0:
434+
return "array[]"
435+
# Get schema of first element as representative
436+
element_schema = generate_json_schema(obj[0], max_depth, current_depth + 1)
437+
return f"array[{element_schema}]"
438+
elif isinstance(obj, dict):
439+
schema = {}
440+
for key, value in obj.items():
441+
schema[key] = generate_json_schema(value, max_depth, current_depth + 1)
442+
return schema
443+
else:
444+
return f"unknown_type({type(obj).__name__})"
445+
446+
# Validate zitiId as JSON
447+
try:
448+
zitiIdJson = json.loads(zitiId)
449+
except Exception as e:
450+
print(f"ERROR: zitiId is not valid JSON: {e}")
451+
print(f"zitiId content: {zitiId}")
452+
exit(1)
453+
417454
idFilename = "id.json"
418455
with open(idFilename, 'w') as f:
419456
f.write(zitiId)
457+
458+
# Load the identity file after it's been written and closed
459+
try:
420460
openziti.load(idFilename)
461+
except Exception as e:
462+
print(f"ERROR: Failed to load Ziti identity: {e}")
463+
schema = generate_json_schema(zitiIdJson)
464+
print(f"DEBUG: zitiId schema for troubleshooting: {json.dumps(schema, indent=2)}")
465+
raise e
421466

422467
# Create webhook body
423468
try:

0 commit comments

Comments
 (0)