Skip to content

Commit

Permalink
Merge branch 'password_auth'
Browse files Browse the repository at this point in the history
  • Loading branch information
brunetton committed Jan 19, 2015
2 parents 57273ac + e33fc2c commit 9cea3a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
6 changes: 5 additions & 1 deletion redminetimesync.config.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[redmine]
url: https://your.redmine.url
key: <your_redmine_api_key_here>
# KEY
key: <your_redmine_api_key>
# OR LOGIN (and optionally password)
login: <your_redmine_login>
password: <your_redmine_password>

[default]
# Default Hamster local SQLite file
Expand Down
21 changes: 20 additions & 1 deletion redminetimesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ConfigParser import RawConfigParser
from requests import ConnectionError
import datetime
import getpass
import sqlite3
import math
import os
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 9cea3a3

Please sign in to comment.