From 13f7c88ed872008cba7b3bdfcecb0543efadd590 Mon Sep 17 00:00:00 2001 From: Linuro Date: Fri, 31 Jul 2020 21:34:12 +0200 Subject: [PATCH] Moving config to secret.txt --- .gitignore | 1 + docker-compose.yml | 3 ++- files/main.py | 44 +++++++++++++++++++------------------------- secret.txt.example | 20 ++++++++++++++++++++ 4 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 .gitignore create mode 100644 secret.txt.example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d9d0f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +secret.txt diff --git a/docker-compose.yml b/docker-compose.yml index 46a30fe..cc3b49a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,5 @@ -version: '2.0' +version: '3.0' services: assemblybot: build: . + env_file: secret.txt diff --git a/files/main.py b/files/main.py index 3f252eb..fc190ac 100755 --- a/files/main.py +++ b/files/main.py @@ -34,40 +34,34 @@ # # -import sys, requests, datetime, smtplib +import sys, requests, datetime, smtplib, os, re from email.mime.text import MIMEText from email.utils import formatdate # Redmine config -redmine_url = 'https://tickets.zom.bi' -redmine_api_key = '' +redmine_url = os.getenv('REDMINE_URL') +redmine_api_key = os.getenv('REDMINE_API_KEY') ## Mediawiki config -mediawiki_url = 'https://w.zom.bi' +mediawiki_url = os.getenv('MEDIAWIKI_URL') # should be Bot credentials, that can be created on Special:BotPasswords -mediawiki_username = 'Assemblybot@assemblybot' -mediawiki_botpassword='' - +mediawiki_username = os.getenv('MEDIAWIKI_USERNAME') +mediawiki_botpassword=os.getenv('MEDIAWIKI_BOTPASSWORD') +smtp_recipients = re.split(' ',os.getenv('SMTP_RECIPIENTS')) # smtp config -smtp_host = 'mail.zom.bi' -smtp_port = 465 -smtp_from = 'assembly_noreply@zom.bi' -smtp_recipients = [['']] -smtp_user = 'assemblybot' -smtp_password = '' -mail_subject = '☣ The undead assemble' -mail_header = "Greetings fellow undead,\nthere are some open \ -issues that require a decision from an assembly. You'll find a list \ -of said issues at the end of this mail. If you wonna know more about \ -those topics, please head to our issue tracker at https://tickets.zom.bi\ -\n----\n\n\n" -mail_footer = "\n----\n beep, boop. I'm a bot.\n If you wonna\ -complain about me, write a mail to cpp or create a ticket at https://tickets.zom.bi" +smtp_host = os.getenv('SMTP_HOST') +smtp_port = os.getenv('SMTP_PORT') +smtp_from = os.getenv('SMTP_FROM') +smtp_user = os.getenv('SMTP_USER') +smtp_password = os.getenv('SMTP_PASSWORD') +mail_subject = os.getenv('MAIL_SUBJECT') +mail_header = os.getenv('MAIL_HEADER') +mail_footer = os.getenv('MAIL_FOOTER') def main(args): assembly_date = str(datetime.date.today() +\ - datetime.timedelta((6-datetime.date.today().weekday()) % 7)) + datetime.timedelta((datetime.date.today().weekday()) % 7)) requires_assembly = redmine_get_requires_assembly_id() log(1,"Assembly topics:\n") issues = redmine_get_issues(requires_assembly) @@ -95,17 +89,17 @@ def main(args): if '--no-mail' in args: log(1,"'--no-mail' argument given, so no mails have been sent.") else: - smtp_send() + smtp_send(mediawiki_page['content']) return 0 -def smtp_send() +def smtp_send(content): smtp_server = smtplib.SMTP_SSL(host=smtp_host,port=smtp_port) if loglevel == 2: smtp_server.set_debuglevel(1) smtp_server.connect(host=smtp_host) smtp_server.login(user=smtp_user,password=smtp_password) mail_message = MIMEText(mail_header + \ - mediawiki_page['content'] + mail_footer) + content + mail_footer) mail_message['Subject'] = mail_subject mail_message['From'] = smtp_from mail_message['Date'] = formatdate() diff --git a/secret.txt.example b/secret.txt.example new file mode 100644 index 0000000..cd6510e --- /dev/null +++ b/secret.txt.example @@ -0,0 +1,20 @@ +# Redmine config +REDMINE_URL=https://tickets.example.com +REDMINE_API_KEY=1337 + +## Mediawiki config +MEDIAWIKI_URL=https://wiki.example.com +# should be Bot credentials, that can be created on Special:BotPasswords +MEDIAWIKI_USERNAME=Assemblybot@assemblybot +MEDIAWIKI_BOTPASSWORD=1337 + +# smtp config +SMTP_HOST=mail.example.com +SMTP_PORT=465 +SMTP_FROM=assembly_noreply@example.com +SMTP_USER=assemblybot +SMTP_PASSWORD=1337 +SMTP_RECIPIENTS=john.doe@example.com max.mustermann@example.com +MAIL_SUBJECT=Put subject here +MAIL_HEADER=This text comes before the tickets +MAIL_FOOTER=This text comes after the tickets