summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2016-08-03 21:30:08 -0300
committerdrebs <drebs@leap.se>2016-08-03 21:31:33 -0300
commit9084597674130682d84cd1884c8dbd24b866096e (patch)
treec0a04b57df2a4f2d6ba03a0ea21fb20cdbdb612a /scripts
parent1c8b39b808a5d5b56f5463d29ad1a7e901bf84d5 (diff)
[pkg] support netrc couch access in migrate script
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/migration/0.8.2/migrate.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/scripts/migration/0.8.2/migrate.py b/scripts/migration/0.8.2/migrate.py
index 159905ef..adc0f7d9 100755
--- a/scripts/migration/0.8.2/migrate.py
+++ b/scripts/migration/0.8.2/migrate.py
@@ -22,15 +22,20 @@ See the README.md file for more information.
import datetime
import logging
+import netrc
import os
from argparse import ArgumentParser
+from leap.soledad.server import load_configuration
+
from migrate_couch_schema import migrate
TARGET_VERSION = '0.8.2'
DEFAULT_COUCH_URL = 'http://127.0.0.1:5984'
+CONF = load_configuration('/etc/soledad/soledad-server.conf')
+NETRC_PATH = CONF['soledad-server']['admin_netrc']
#
@@ -54,12 +59,24 @@ def _configure_logger(log_file):
level=logging.DEBUG)
+def _default_couch_url():
+ if not os.path.exists(NETRC_PATH):
+ return DEFAULT_COUCH_URL
+ parsed_netrc = netrc.netrc(NETRC_PATH)
+ host, (login, _, password) = parsed_netrc.hosts.items()[0]
+ url = ('http://%(login)s:%(password)s@%(host)s:5984' % {
+ 'login': login,
+ 'password': password,
+ 'host': host})
+ return url
+
+
def _parse_args():
parser = ArgumentParser()
parser.add_argument(
'--couch_url',
help='the url for the couch database',
- default=DEFAULT_COUCH_URL)
+ default=_default_couch_url())
parser.add_argument(
'--do-migrate',
help='actually perform the migration (otherwise '