From eb797a945dfa775c07b12c6d088dba8b5d3248da Mon Sep 17 00:00:00 2001 From: Matthias Bilger Date: Fri, 27 Sep 2019 22:00:54 +0200 Subject: [PATCH] simplified docker usage --- Dockerfile | 4 ++-- README.md | 41 ++++++++++------------------------------- entrypoint.sh | 3 +++ infomentor/__main__.py | 19 ++++++++++++++++--- setup.py | 3 --- 5 files changed, 31 insertions(+), 39 deletions(-) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index d86fc01..6e6d4a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM python:3.7.3-stretch COPY requirements.txt /tmp/ +COPY entrypoint.sh / RUN pip install -r /tmp/requirements.txt COPY . /tmp/infomentor @@ -10,5 +11,4 @@ RUN useradd --create-home appuser WORKDIR /home/appuser USER appuser VOLUME ["/home/appuser"] - -CMD [ "python", "-m", "infomentor" ] +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 50ce4c0..803ce45 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ # Infomentor Tool This tool is designed to check the infomentor portal and send notifications using mail or pushover api. +It is also capable of sending Calendar invitations/entries. ## Usage +You could install it locally but using the docker image is preferred. + ``` python3 -m venv venv source venv/bin/activate @@ -13,53 +16,29 @@ infomentor After the first run a `infomentor.ini` file is available which has a few values to be entered. - ## Docker This could be run within docker. You it has a volume `/home/appuser` where all the data is stored. In favour of accessing it from a webserver you should bindmount it. -There also the infomentor.ini should be placed. +There also the infomentor.ini would be placed. Build the container by `docker build -t infomentor:latest .` and run it like this: +### Notify Users / First Run + ``` docker run -v '/var/docker/infomentor/:/home/appuser' infomentor:latest ``` -for adding an user or all the commands run it adding -it to it, like: +### Adding a user ``` -docker run -it -v '/var/docker/infomentor/:/home/appuser' infomentor:latest adduser +docker run -v '/var/docker/infomentor/:/home/appuser' infomentor:latest --username --password --pushover --invitationmail ``` -## Manage Users - - -### Step 1 create a user - -Provide the username and password for infomentor. -``` -docker run -it -v '/var/docker/infomentor/:/home/appuser' infomentor:latest adduser --username -``` -### Step 2 add notification mechanism -``` -docker run -it -v '/var/docker/infomentor/:/home/appuser' infomentor:latest addmail --username -``` - -or +### See all options ``` -docker run -it -v '/var/docker/infomentor/:/home/appuser' infomentor:latest pushover --username -``` - -### Step 3 (optional) Add iCloud calendar - -*NB:* This is currently not working. You could add it, but it won't work. - -It is capable of syncing all the infomentor calendar elements to icloud calendar - -``` -source venv/bin/activate -addcalendar --username +docker run -v '/var/docker/infomentor/:/home/appuser' infomentor:latest --help ``` ## NB diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..e809cbf --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +infomentor $* diff --git a/infomentor/__main__.py b/infomentor/__main__.py index ba09a49..58bafbc 100644 --- a/infomentor/__main__.py +++ b/infomentor/__main__.py @@ -34,6 +34,7 @@ def parse_args(arglist): parser.add_argument("--username", type=str, nargs="?", help="infomentor username") parser.add_argument("--password", type=str, nargs="?", help="infomentor password") parser.add_argument("--fake", action="store_true", help="add fake") + parser.add_argument("--notifyerrors", action="store_true", help="add fake") parser.add_argument("--pushover", type=str, nargs="?", help="pushover user id") parser.add_argument("--mail", type=str, nargs="?", help="e-mail for notification") parser.add_argument( @@ -59,13 +60,13 @@ def perform_user_update(args): session.query(model.User).filter(model.User.name == username).one_or_none() ) if existing_user is not None: - print("user exists, changing pw") + logger.info("Updating user {}", username) else: - print(f"Adding user: {username}") + logger.info("Creating User user {}", username) if args.password is None: + logger.info("No password provided, asking for it") import getpass - password = getpass.getpass(prompt="Password: ") else: password = args.password @@ -76,15 +77,23 @@ def perform_user_update(args): user = model.User(name=username, password=password) session.add(user) + if args.notifyerrors: + user.wantstatus = True + else: + user.wantstatus = False + if args.pushover is not None: + logger.info("Adding pushover notification") user.notification = model.Notification( ntype=model.Notification.Types.PUSHOVER, info=args.pushover ) elif args.mail: + logger.info("Adding email notification") user.notification = model.Notification( ntype=model.Notification.Types.EMAIL, info=args.mail ) elif args.fake: + logger.info("Adding fake notification") user.notification = model.Notification( ntype=model.Notification.Types.FAKE, info="" ) @@ -94,6 +103,7 @@ def perform_user_update(args): and args.icloudpwd is not None and args.icloudcalendar is not None ): + logger.info("Adding icloud calendar") user.icalendar = model.ICloudCalendar( icloud_user=args.iclouduser, password=args.icloudpwd, @@ -101,6 +111,7 @@ def perform_user_update(args): ) if args.invitationmail: + logger.info("Activating sending of calendar entries per mail") user.invitation = model.Invitation(email=mail) session.commit() @@ -111,6 +122,7 @@ def notify_users(): session = db.get_db() cfg = config.load() if cfg["healthchecks"]["url"] != "": + logger.info("Triggering Healthcheck Start") requests.get(cfg["healthchecks"]["url"] + "/start") for user in session.query(model.User): @@ -161,6 +173,7 @@ def notify_users(): session.commit() if cfg["healthchecks"]["url"] != "": + logger.info("Triggering Healthcheck Stop") requests.get(cfg["healthchecks"]["url"]) diff --git a/setup.py b/setup.py index 91ef732..2cc6cc8 100644 --- a/setup.py +++ b/setup.py @@ -11,9 +11,6 @@ setup( entry_points = { 'console_scripts': [ 'infomentor=infomentor:main', - 'adduser=infomentor:run_adduser', - 'addmail=infomentor:run_addmail', - 'addpushover=infomentor:run_addpushover', ], }, install_requires=[