diff options
author | Kali Kaneko <kali@leap.se> | 2016-04-18 11:32:18 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2016-04-18 11:32:18 -0400 |
commit | bc465c34afe6e86b7fc8d7c690b76aa5e23d6a13 (patch) | |
tree | bf5bdeb244fe4569336ee48b32cb4db0d727c373 /server/pkg | |
parent | 55548cf947966bcbb9a496e523a3f802b0f0b55f (diff) | |
parent | d5974f61df6ca640dde69903976d4721b6d88007 (diff) |
Merge tag '0.8.0'
Tag soledad version 0.8.0
Diffstat (limited to 'server/pkg')
-rwxr-xr-x | server/pkg/create-user-db | 44 | ||||
-rw-r--r-- | server/pkg/requirements.pip | 2 |
2 files changed, 36 insertions, 10 deletions
diff --git a/server/pkg/create-user-db b/server/pkg/create-user-db index 7eafc945..54856643 100755 --- a/server/pkg/create-user-db +++ b/server/pkg/create-user-db @@ -20,7 +20,8 @@ import sys import netrc import argparse from leap.soledad.common.couch import CouchDatabase -from leap.soledad.common.couch import is_db_name_valid +from leap.soledad.common.couch.state import is_db_name_valid +from leap.soledad.common.couch import list_users_dbs from leap.soledad.server import load_configuration @@ -30,8 +31,12 @@ This is meant to be used by Soledad Server. """ parser = argparse.ArgumentParser(description=description) parser.add_argument('dbname', metavar='user-d34db33f', type=str, + default='', nargs='?', help='database name on the format user-{uuid4}') -NETRC_PATH = load_configuration('/etc/soledad/soledad-server.conf')['admin_netrc'] +parser.add_argument('--migrate-all', action='store_true', + help="recreate all design docs for all existing account") +CONF = load_configuration('/etc/soledad/soledad-server.conf') +NETRC_PATH = CONF['soledad-server']['admin_netrc'] def url_for_db(dbname): @@ -48,13 +53,34 @@ def url_for_db(dbname): return url -if __name__ == '__main__': - args = parser.parse_args() - if not is_db_name_valid(args.dbname): - print ("Invalid name! %s" % args.dbname) +def ensure_database(dbname): + """ + This method will ensure that a database named `dbname` will exist + or created if it doesn't. Calling it twice will ensure that design + documents are present and updated. + The database name has to match this criteria to be considered valid: + user-[a-f0-9]+ + + :param dbname: name of the user database + :type dbname: str + """ + if not is_db_name_valid(dbname): + print ("Invalid name! %s" % dbname) sys.exit(1) - url = url_for_db(args.dbname) + url = url_for_db(dbname) + db_security = CONF['database-security'] db = CouchDatabase.open_database(url=url, create=True, - replica_uid=None, ensure_ddocs=True) - print ('success! Created %s, replica_uid: %s' % + replica_uid=None, ensure_ddocs=True, + database_security=db_security) + print ('success! Ensured that database %s exists, with replica_uid: %s' % (db._dbname, db.replica_uid)) + + +if __name__ == '__main__': + args = parser.parse_args() + if args.migrate_all: + couch_url = url_for_db('') + for dbname in list_users_dbs(couch_url): + ensure_database(dbname) + else: + ensure_database(args.dbname) diff --git a/server/pkg/requirements.pip b/server/pkg/requirements.pip index 58834d0e..f9cce08e 100644 --- a/server/pkg/requirements.pip +++ b/server/pkg/requirements.pip @@ -2,7 +2,7 @@ configparser u1db routes PyOpenSSL -twisted +twisted>=12.3.0 #pinned for wheezy compatibility Beaker==1.6.3 #wheezy couchdb==0.8 #wheezy |