Store auth secrets in persistent volume (fixes #1)
This commit is contained in:
parent
ad58ad9eaf
commit
756aa14e7f
2 changed files with 18 additions and 14 deletions
|
@ -36,7 +36,10 @@
|
||||||
file: path=/tmp/communistquotes state=absent
|
file: path=/tmp/communistquotes state=absent
|
||||||
|
|
||||||
- name: create config folder
|
- name: create config folder
|
||||||
file: path=/etc/communistquotes state=directory mode=700
|
file: path={{ item.path }} state=directory mode=700
|
||||||
|
with_items:
|
||||||
|
- { path: '/etc/communistquotes/' }
|
||||||
|
- { path: '/etc/communistquotes/secrets/' }
|
||||||
|
|
||||||
- name: add env file
|
- name: add env file
|
||||||
copy: src=env dest=/etc/communistquotes/env mode=600
|
copy: src=env dest=/etc/communistquotes/env mode=600
|
||||||
|
@ -46,4 +49,4 @@
|
||||||
name: "communist-quotes"
|
name: "communist-quotes"
|
||||||
hour: "*/3"
|
hour: "*/3"
|
||||||
minute: "0"
|
minute: "0"
|
||||||
job: "perl -le 'sleep rand 10800' && docker run --rm --name communistquotes --env-file /etc/communistquotes/env communistquotes >> /var/log/communistquotes.log 2>&1"
|
job: "perl -le 'sleep rand 10800' && docker run --rm --name communistquotes -v /etc/communistquotes/secrets/:/etc/communistquotes/secrets/ --env-file /etc/communistquotes/env communistquotes >> /var/log/communistquotes.log 2>&1"
|
||||||
|
|
|
@ -7,6 +7,8 @@ import random
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
secrets_path = '/etc/communistquotes/secrets/'
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Parse quotes from .csv files, and post a random quote to Mastodon API')
|
parser = argparse.ArgumentParser(description='Parse quotes from .csv files, and post a random quote to Mastodon API')
|
||||||
parser.add_argument('--debug', action='store_true', help='Dont actually login or post to the remote API')
|
parser.add_argument('--debug', action='store_true', help='Dont actually login or post to the remote API')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -19,27 +21,26 @@ if not args.debug:
|
||||||
username = os.environ['MASTODON_USERNAME']
|
username = os.environ['MASTODON_USERNAME']
|
||||||
|
|
||||||
# Create application if it does not exist
|
# Create application if it does not exist
|
||||||
# TODO: store this file in volume
|
if not os.path.isfile(secrets_path + instance + '.secret'):
|
||||||
if not os.path.isfile(instance+'.secret'):
|
|
||||||
if Mastodon.create_app(
|
if Mastodon.create_app(
|
||||||
'tootbot',
|
'tootbot',
|
||||||
api_base_url='https://'+instance,
|
api_base_url = 'https://' + instance,
|
||||||
to_file = instance+'.secret'
|
to_file = secrets_path + instance + '.secret'
|
||||||
):
|
):
|
||||||
print('tootbot app created on instance '+instance)
|
print('tootbot app created on instance ' + instance)
|
||||||
else:
|
else:
|
||||||
print('failed to create app on instance '+instance)
|
print('failed to create app on instance ' + instance)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
mastodon_api = Mastodon(
|
mastodon_api = Mastodon(
|
||||||
client_id=instance+'.secret',
|
client_id = secrets_path + instance + '.secret',
|
||||||
api_base_url='https://'+instance
|
api_base_url = 'https://' + instance
|
||||||
)
|
)
|
||||||
mastodon_api.log_in(
|
mastodon_api.log_in(
|
||||||
username=username,
|
username = username,
|
||||||
password=os.environ['MASTODON_PASSWORD'],
|
password = os.environ['MASTODON_PASSWORD'],
|
||||||
scopes=['read', 'write'],
|
scopes = ['read', 'write'],
|
||||||
to_file=username+".secret"
|
to_file = secrets_path + username + ".secret"
|
||||||
)
|
)
|
||||||
|
|
||||||
quotes = []
|
quotes = []
|
||||||
|
|
Loading…
Reference in a new issue