Skip to content

Commit

Permalink
Working poke for expiring users
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenlj committed Mar 7, 2024
1 parent b91a406 commit 3098da3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions aiven_poke/slack/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,42 @@

RENEW_DOC = "https://doc.nais.io/how-to-guides/persistence/kafka/renew-credentials-for-non-nais/"

FALLBACK = " ".join(textwrap.dedent("""
FALLBACK = " ".join(textwrap.dedent("""\
Your team has users with expiring credentials in the {main_project} pool.
Consult the nais documentation to find out how to fix these.
The following users needs attention:\n\n
"""))
The following users needs attention:
{usernames}
""").splitlines())
MAIN_HEADER = "Your team has users in Kafka with expiring credentials"
WHAT_IS_THIS = " ".join(textwrap.dedent("""
WHAT_IS_THIS = " ".join(textwrap.dedent("""\
Kafka service users are issued certificates with a limited lifespan.
When the certificates are getting close to expiring, warnings are issued to avoid interruptions in service.
The applications using the affected users needs to get new credentials before the expiry date.
""").splitlines())
USERS_HEADER = "*Found service users in the {main_project} pool belonging to team `{team}` with expiring credentials*"
SOLUTION_HEADER = "*Solution*"
SOLUTION_PROTECTED = " ".join(textwrap.dedent(f"""
SOLUTION_PROTECTED = " ".join(textwrap.dedent(f"""\
For users used by legacy applications not running in the nais platform, consult the documentation on
<{RENEW_DOC}|how to renew credentials for non-nais>.
""").splitlines())
SOLUTION_NAIS_APP = " ".join(textwrap.dedent("""
SOLUTION_NAIS_APP = " ".join(textwrap.dedent("""\
For users used by applications running in the nais platform, a simple redeploy of your application should be enough.
""").splitlines())
NEEDS_HELP = " ".join(textwrap.dedent("""
NEEDS_HELP = " ".join(textwrap.dedent("""\
If you need help, reach out in <#C5KUST8N6|nais>
""").splitlines())


def create_user_payload(team, channel, users, main_project):
users_header = USERS_HEADER.format(main_project=main_project, team=team)
usernames = [user.username for user in users]
fallback_text = FALLBACK.format(main_project=main_project, usernames="\n* ".join(usernames))
return Payload(channel, attachments=[
Attachment(Color.WARNING, FALLBACK + ", ".join(usernames), blocks=[
Attachment(Color.WARNING, fallback_text, blocks=[
Header(Text(TextType.PLAIN, MAIN_HEADER)),
TextSection(Text(TextType.MRKDWN, WHAT_IS_THIS)),
TextSection(Text(TextType.MRKDWN, users_header)),
FieldsSection(usernames),
FieldsSection([Text(TextType.MRKDWN, "`{}`".format(u)) for u in usernames]),
TextSection(Text(TextType.MRKDWN, SOLUTION_HEADER)),
TextSection(Text(TextType.MRKDWN, SOLUTION_PROTECTED.format(team=team))),
TextSection(Text(TextType.MRKDWN, SOLUTION_NAIS_APP.format(team=team))),
Expand Down

0 comments on commit 3098da3

Please sign in to comment.