Skip to content

Commit

Permalink
Merge pull request #48 from UniversityRadioYork/marks/dont-log-api-keys
Browse files Browse the repository at this point in the history
Don't log MyRadio API keys
  • Loading branch information
mstratford authored Oct 17, 2022
2 parents 7912b2c + 92dbd19 commit d6ee435
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions helpers/myradio_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,30 @@ async def async_api_call(
self._logException("Invalid API version. Request not sent.")
return None

url_without_api_key = url

if "?" in url:
url += "&api_key={}".format(self.config.get()["myradio_api_key"])
url_without_api_key += "&api_key=REDACTED"
else:
url += "?api_key={}".format(self.config.get()["myradio_api_key"])
url_without_api_key += "?api_key=REDACTED"

self._log("Requesting API V2 URL with method {}: {}".format(method, url))
self._log(
"Requesting API V2 URL with method {}: {}".format(
method, url_without_api_key
)
)

request = None
try:
if method == "GET":
request = await self.async_call(url, method="GET", timeout=timeout)
elif method == "POST":
self._log("POST data: {}".format(data))
request = await self.async_call(url, data=data, method="POST", timeout=timeout)
request = await self.async_call(
url, data=data, method="POST", timeout=timeout
)
elif method == "PUT":
request = await self.async_call(url, method="PUT", timeout=timeout)
else:
Expand All @@ -131,12 +141,20 @@ def api_call(self, url, api_version="v2", method="GET", data=None, timeout=10):
self._logException("Invalid API version. Request not sent.")
return None

url_without_api_key = url

if "?" in url:
url += "&api_key={}".format(self.config.get()["myradio_api_key"])
url_without_api_key += "&api_key=REDACTED"
else:
url += "?api_key={}".format(self.config.get()["myradio_api_key"])
url_without_api_key += "?api_key=REDACTED"

self._log("Requesting API V2 URL with method {}: {}".format(method, url))
self._log(
"Requesting API V2 URL with method {}: {}".format(
method, url_without_api_key
)
)

request = None
if method == "GET":
Expand Down Expand Up @@ -209,7 +227,9 @@ async def get_showplan(self, timeslotid: int):

# Audio Library

async def get_filename(self, item: PlanItem, did_download: bool = False, redownload=False):
async def get_filename(
self, item: PlanItem, did_download: bool = False, redownload=False
):
format = "mp3" # TODO: Maybe we want this customisable?
if item.trackid:
itemType = "track"
Expand Down

0 comments on commit d6ee435

Please sign in to comment.