diff --git a/README.md b/README.md index bde4048..802ac54 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ INSTALLATION nb: you can find your API key on your Redmine account page (/my/account) when logged in, on the right-hand pane of the default layout. You'll have to enable Redmine REST API in Administration -> Settings -> Authentication + You can also use an user/password to login but it will ask you for the password each time it tries to sync your activities. To do so, you need to add the following to the config file: + + - auth_type: password + - user: your username + USAGE ----- diff --git a/redminetimesync.config.tpl b/redminetimesync.config.tpl index 5200909..79b8d38 100644 --- a/redminetimesync.config.tpl +++ b/redminetimesync.config.tpl @@ -1,6 +1,10 @@ [redmine] url: https://your.redmine.url -key: +# KEY +key: +# OR LOGIN (and optionally password) +login: +password: [default] # Default Hamster local SQLite file diff --git a/redminetimesync.py b/redminetimesync.py index 444b8d7..d2a9394 100755 --- a/redminetimesync.py +++ b/redminetimesync.py @@ -3,6 +3,7 @@ from ConfigParser import RawConfigParser from requests import ConnectionError import datetime +import getpass import sqlite3 import math import os @@ -263,9 +264,27 @@ def parse_date_or_days_ahead(datestr, config, quit_if_none=False): print "\n" sys.exit() + # Check that api_key or username (and eventually password) are given in config file + api_key = login = password = None + if config.has_option('redmine', 'key'): + api_key = config.get('redmine', 'key') + if config.has_option('redmine', 'login'): + login = config.get('redmine', 'login') + if config.has_option('redmine', 'password'): + password = config.get('redmine', 'Password') + if not api_key and not login: + print('No API key nor Redmine login found in config file.\nPlease Edit your config file.') + sys.exit(-1) + # Connects to Redmine + if api_key: + redmine = Redmine(config.get('redmine', 'url'), key=api_key) + else: + if not password: + password = getpass.getpass('{}\'s password: '.format(login)) + redmine = Redmine(config.get('redmine', 'url'), username=login, password=password) print_('-> Connecting to Redmine...') - redmine = Redmine(config.get('redmine', 'url'), key=config.get('redmine', 'key')) + try: redmine.auth() except (AuthError, ConnectionError) as e: