Skip to content

Commit

Permalink
Quick fix for thread not holding the settings registry...
Browse files Browse the repository at this point in the history
  • Loading branch information
kenneaal committed Aug 12, 2019
1 parent 1326868 commit b8c7e1b
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 33 deletions.
8 changes: 4 additions & 4 deletions jiraannouncer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def logprint(string):
graylogger.debug(str(string).encode('ascii', 'ignore').decode())


def devsay(string):
def devsay(string, request):
"""Sends a message to the Announcer dev channel for debugging/reporting purposes."""
send("#announcerdev", string, '')
send("#announcerdev", string, '', request)


def jsondump(string):
Expand All @@ -45,10 +45,10 @@ def demarkdown(string):
return string[:300] + ('...' if len(string) > 300 else '')


def send(channel, message, msgshort):
def send(channel, message, msgshort, request):
"""Send resulting message to IRC over XMLRPC."""
message = message.replace('\n', ' ').replace('\r', '')
serverurl = registry.settings['xml_proxy']
serverurl = request.registry.settings['xml_proxy']
proxy = ServerProxy(serverurl)
try:
messagesplit = [message[i:i + 475] for i in range(0, len(message), 475)]
Expand Down
6 changes: 3 additions & 3 deletions jiraannouncer/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def api(request):
header_signature = request.headers['X-Api-Signature']
if header_signature is None:
log.error("No signature sent by API, aborting message")
devsay("No signature sent by API for botserv message!")
devsay("No signature sent by API for botserv message!", request)
sha_name, signature = header_signature.split('=')
if sha_name != 'sha1':
log.error(f"Invalid signature format in API message, was {sha_name}")
Expand All @@ -32,14 +32,14 @@ def api(request):
if not str(mac.hexdigest()) == str(signature):
log.critical("Signature mismatch! API event ignored.")
log.critical(f"{mac.hexdigest()} vs {str(signature)}")
devsay(f"Invalid MAC in API message: {str(signature)}")
devsay(f"Invalid MAC in API message: {str(signature)}", request)

try:
data = request.jsonbody
channel = data['channel']
if not channel:
log.error("No channel specified in API message, aborting.")
return
send(channel, data['message'], "")
send(channel, data['message'], "", request)
except:
log.critical("Well, something done fucked up, exception in body parsing/sending.")
4 changes: 2 additions & 2 deletions jiraannouncer/views/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def circle(request):
log.debug(message2)
else:
for channel in channels:
send(channel, message1, msgshort1)
send(channel, message1, msgshort1, request)
time.sleep(0.5)
for channel in channels:
send(channel, message2, msgshort2)
send(channel, message2, msgshort2, request)
11 changes: 6 additions & 5 deletions jiraannouncer/views/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ def client(request):
if not str(mac.hexdigest()) == str(signature):
log.error("Signature mismatch! GitHub event not parsed.")
log.error(f"{mac.hexdigest()} vs {str(signature)}")
devsay(f"Invalid MAC in Client message: {str(signature)}")
devsay(f"Invalid MAC in Client message: {str(signature)}", request)
possiblefake = True
elif referer != "https://clients.fuelrats.com:7778/":
log.error(f"Client announcer called with invalid referer: {referer}")
devsay(f"Someone tried to call the client announcer with an invalid referer '{referer}'! Absolver!")
devsay(f"Someone tried to call the client announcer with an invalid referer '{referer}'! Absolver!",
request)
possiblefake = True
else:
log.warn("Non-signed request from valid referer.")
Expand All @@ -49,17 +50,17 @@ def client(request):
o2status = request.params['EO2']
except NameError:
log.critical("Missing parameters to Client announcement call.")
devsay("Parameters were missing in a Client announcement call!")
devsay("Parameters were missing in a Client announcement call!", request)

if 'extradata' not in request.params:
message = f"Incoming Client: {cmdrname} - System: {system} - Platform: {platform} - O2: {o2status}"
else:
extradata = request.params['extradata']
message = f"Incoming Client: {cmdrname} - System: {system} - Platform: {platform} - O2: {o2status} - {extradata}"

send("#fuelrats", message, "No Short for you!")
send("#fuelrats", message, "No Short for you!", request)
if possiblefake:
send("#ratchat",
f"[Client Announcer] Warning! The arriving case is not passing validation information!",
"")
"", request)
return
14 changes: 8 additions & 6 deletions jiraannouncer/views/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def github(prequest):
if 'X-GitHub-Event' not in prequest.headers:
log.error("Malformed request to GitHub webhook handler (Missing X-Github-Event)")
devsay(
"[\x0315GitHub\x03] Malformed request to GitHub webhook handler (Missing X-GitHub-Event header)")
"[\x0315GitHub\x03] Malformed request to GitHub webhook handler (Missing X-GitHub-Event header)",
prequest)
return

if github_secret is not None:
Expand All @@ -52,7 +53,7 @@ def github(prequest):
if not str(mac.hexdigest()) == str(signature):
log.critical("Signature mismatch! GitHub event not parsed.")
log.debug(f"{mac.hexdigest()} vs {str(signature)}")
devsay(f"Invalid MAC in GitHub message: {str(signature)}")
devsay(f"Invalid MAC in GitHub message: {str(signature)}", prequest)
return

event = prequest.headers['X-GitHub-Event']
Expand All @@ -61,7 +62,7 @@ def github(prequest):
except JSONDecodeError:
log.error("Error loading GitHub payload:")
log.debug(data)
devsay("A GitHub payload failed to decode to JSON!")
devsay("A GitHub payload failed to decode to JSON!", prequest)
return
domessage = True

Expand Down Expand Up @@ -218,7 +219,7 @@ def github(prequest):
else:
log.debug(f"Unhandled create ref: {request['ref_type']}")
devsay(f"An unhandled create ref was passed to GitHub: "
f"{request['ref_type']}. Absolver should implement!")
f"{request['ref_type']}. Absolver should implement!", prequest)
return
elif event == 'status':
log.info("Ignored github status event")
Expand All @@ -229,7 +230,8 @@ def github(prequest):
else:
log.debug(f"GitHub unhandled event: {event}")
jsondump(request)
devsay(f"An unhandled GitHub event was passed: {event}. Absolver should implement!")
devsay(f"An unhandled GitHub event was passed: {event}. Absolver should implement!",
prequest)
return
msgshort = {"time": time.time(), "type": event, "key": "GitHub", "full": message}
if gitrecord is not None:
Expand All @@ -250,4 +252,4 @@ def github(prequest):
log.info("Discarding Dependabot message.")
return
for channel in channels:
send(channel, f"[\x0315GitHub\x03] {message}", msgshort)
send(channel, f"[\x0315GitHub\x03] {message}", msgshort, prequest)
8 changes: 5 additions & 3 deletions jiraannouncer/views/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def jira(request):
except:
log.error("Failed to decode JSON from body. Dump:")
log.debug(request.body)
devsay("A JIRA payload couldn't be decoded. Absolver, check the logfile!")
devsay("A JIRA payload couldn't be decoded. Absolver, check the logfile!",
request)
return
request_type = data['webhookEvent']

Expand Down Expand Up @@ -161,7 +162,8 @@ def jira(request):
domessage = False
else:
message = "JIRA unhandled event: " + request_type
devsay(f"An unhandled JIRA event '{request_type}' was passed to webhook. Absolver should implement.")
devsay(f"An unhandled JIRA event '{request_type}' was passed to webhook. Absolver should implement.",
request)
log.debug(f"Unhandled JIRA event: {message}")
return

Expand All @@ -182,5 +184,5 @@ def jira(request):
return
elif domessage:
for channel in channels:
send(channel, f"[\x0315JIRA\x03] {message}", msgshort)
send(channel, f"[\x0315JIRA\x03] {message}", msgshort, request)
return
2 changes: 1 addition & 1 deletion jiraannouncer/views/statuspage.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ def statuspage(request):
)
else:
message = "Something went horribly wrong in Statuspage processing."
send("#ratchat", f"{status_name} {message} {shortlink or ''}", "No shorts today.")
send("#ratchat", f"{status_name} {message} {shortlink or ''}", "No shorts today.", request)
return
8 changes: 4 additions & 4 deletions jiraannouncer/views/teamcity.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ def teamcity(request):
if build['extraParameters']['buildType'] == 'deployment':
message = f"\x0315[\x0306TeamCity\x0315]\x03 {build['projectName']} - " \
f"deploying from {build['agentName']}"
send(channel, message, '')
send(channel, message, '', request)
message = f"\x0315[\x0306TeamCity\x0315]\x03 {build['projectName']} - " \
f"{notifyTypes[notifytype]} on {build['agentName']}: Build #\x0315{build['buildId']}\x03 " \
f"{buildresults[build['buildResult']]} (\x0315{build['buildStatusUrl']}\x03)"
send(channel, message, '')
send(channel, message, '', request)
if build['buildResultDelta'] == 'fixed':
message = f"\0315[\x0306TeamCity\x0315]\x03 Yay! {build['projectName']} builds fixed!"
send(channel, message, '')
send(channel, message, '', request)
elif build['buildResultDelta'] == 'broken':
message = f"\x0315[\x0306TeamCity\x0315]\x03 Alert! Builds for {build['projectName']}" \
f" have started failing!"
send(channel, message, '')
send(channel, message, '', request)
return
6 changes: 3 additions & 3 deletions jiraannouncer/views/travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def travis(request):
request = simplejson.loads(urllib.parse.unquote(data[8:]))
except simplejson.errors.JSONDecodeError:
log.error(f"Error loading Travis payload: {data}")
devsay("Travis couldn't decode a payload! Absolver, check the log.")
devsay("Travis couldn't decode a payload! Absolver, check the log.", request)
return

if "FuelRats/pipsqueak3" in repo:
Expand All @@ -45,7 +45,7 @@ def travis(request):
log.debug(message2)
else:
for channel in channels:
send(channel, message1, msgshort1)
send(channel, message1, msgshort1, request)
time.sleep(0.5)
for channel in channels:
send(channel, message2, msgshort2)
send(channel, message2, msgshort2, request)
4 changes: 2 additions & 2 deletions jiraannouncer/views/upsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def upsource(request):
except simplejson.JSONDecodeError:
log.error("Error loading UpSource JSON data!")
log.error(request.body)
devsay(f"Error loading UpSource JSON data!")
devsay(f"Error loading UpSource JSON data!", request)
return
event = jsonbody['dataType']
if 'data' in jsonbody:
Expand All @@ -38,4 +38,4 @@ def upsource(request):
f" \"{demarkdown(data['message'])}\""
else:
log.warn(f"Unhandled UpSource event: {event}")
send(channel, message, '')
send(channel, message, '', request)

0 comments on commit b8c7e1b

Please sign in to comment.