aboutsummaryrefslogtreecommitdiffstats
path: root/arthur/exts/kubernetes/certificates.py
diff options
context:
space:
mode:
Diffstat (limited to 'arthur/exts/kubernetes/certificates.py')
-rw-r--r--arthur/exts/kubernetes/certificates.py42
1 files changed, 22 insertions, 20 deletions
diff --git a/arthur/exts/kubernetes/certificates.py b/arthur/exts/kubernetes/certificates.py
index bb08655..951a968 100644
--- a/arthur/exts/kubernetes/certificates.py
+++ b/arthur/exts/kubernetes/certificates.py
@@ -1,13 +1,11 @@
"""The Certificates cog helps with managing TLS certificates."""
-from datetime import datetime
from textwrap import dedent
-from discord import Embed
from discord.ext import commands
+from tabulate import tabulate
from arthur.apis.kubernetes import certificates
from arthur.bot import KingArthur
-from arthur.utils import datetime_to_discord
class Certificates(commands.Cog):
@@ -26,28 +24,32 @@ class Certificates(commands.Cog):
"""List TLS certificates in the selected namespace (defaults to default)."""
certs = await certificates.list_certificates(namespace)
- return_embed = Embed(title=f"Certificates in namespace {namespace}")
+ table_data = []
for certificate in certs["items"]:
- expiry = datetime.fromisoformat(
- certificate["status"]["notAfter"].rstrip("Z") + "+00:00"
- )
- renews = datetime.fromisoformat(
- certificate["status"]["renewalTime"].rstrip("Z") + "+00:00"
- )
- body = dedent(
- f"""
- **Subjects:** {", ".join(certificate["spec"]["dnsNames"])}
- **Issuer:** {certificate["spec"]["issuerRef"]["name"]}
- **Status:** {certificate["status"]["conditions"][0]["message"]}
- **Expires:** {datetime_to_discord(expiry)} ({datetime_to_discord(expiry, "R")})
- **Renews:** {datetime_to_discord(renews)} ({datetime_to_discord(renews, "R")})
- """
+ table_data.append(
+ [
+ certificate["metadata"]["name"],
+ ", ".join(certificate["spec"]["dnsNames"]),
+ certificate["spec"]["issuerRef"]["name"],
+ certificate["status"]["conditions"][0]["message"],
+ ]
)
- return_embed.add_field(name=certificate["metadata"]["name"], value=body.strip())
+ table = tabulate(
+ table_data, headers=["Name", "DNS Names", "Issuer", "Status"], tablefmt="psql"
+ )
+
+ return_message = dedent(
+ f"""
+ **Certificates in namespace `{namespace}`**
+ ```
+ {table}
+ ```
+ """
+ )
- await ctx.send(embed=return_embed)
+ await ctx.send(return_message)
def setup(bot: KingArthur) -> None: