From 78d8bde653187cbf23a2f0ef8a6952058ad95bf4 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 26 Aug 2021 16:39:04 +0100 Subject: Use publically available URL when outputting metabase share URL In production we use the internal URL to call the metabase API, to avoid egress but we still want to output the public url when giving the sharing link. Making it a constant like this makes it easier to change/overwrite in future if needed. --- bot/constants.py | 1 + bot/exts/moderation/metabase.py | 2 +- config-default.yml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/constants.py b/bot/constants.py index 80e01b174..4e99df7f3 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -569,6 +569,7 @@ class Metabase(metaclass=YAMLGetter): username: Optional[str] password: Optional[str] base_url: str + public_url: str max_session_age: int diff --git a/bot/exts/moderation/metabase.py b/bot/exts/moderation/metabase.py index 3b454ab18..9eeeec074 100644 --- a/bot/exts/moderation/metabase.py +++ b/bot/exts/moderation/metabase.py @@ -167,7 +167,7 @@ class Metabase(Cog): async with self.bot.http_session.post(url, headers=self.headers, raise_for_status=True) as resp: response_json = await resp.json(encoding="utf-8") - sharing_url = f"{MetabaseConfig.base_url}/public/question/{response_json['uuid']}" + sharing_url = f"{MetabaseConfig.public_url}/public/question/{response_json['uuid']}" await ctx.send(f":+1: {ctx.author.mention} Here's your sharing link: {sharing_url}") # This cannot be static (must have a __func__ attribute). diff --git a/config-default.yml b/config-default.yml index 8e0b97a51..baece5c51 100644 --- a/config-default.yml +++ b/config-default.yml @@ -441,6 +441,7 @@ metabase: username: !ENV "METABASE_USERNAME" password: !ENV "METABASE_PASSWORD" base_url: "http://metabase.default.svc.cluster.local" + public_url: "https://metabase.pythondiscord.com" # 14 days, see https://www.metabase.com/docs/latest/operations-guide/environment-variables.html#max_session_age max_session_age: 20160 -- cgit v1.2.3