Skip to content
Snippets Groups Projects
Commit 58f3250c authored by Kevin S. Hahn's avatar Kevin S. Hahn
Browse files

Merge branch 'new_deploy'

parents e1216faf dacd156e
No related branches found
No related tags found
No related merge requests found
# @author: Gunnar Schaefer, Kevin S. Hahn
import os
import re
import time
import logging
import pymongo
......@@ -19,7 +20,7 @@ ap.add_argument('--data_path', help='path to storage area', required=True)
ap.add_argument('--ssl_cert', help='path to SSL certificate file, containing private key and certificate chain', required=True)
ap.add_argument('--api_uri', help='api uri, with https:// prefix')
ap.add_argument('--site_id', help='site ID for Scitran Central [local]', default='local')
ap.add_argument('--site_name', help='site name')
ap.add_argument('--site_name', help='site name', nargs='*', default=['Local']) # hack for uwsgi --pyargv
ap.add_argument('--oauth2_id_endpoint', help='OAuth2 provider ID endpoint', default='https://www.googleapis.com/plus/v1/people/me/openIdConnect')
ap.add_argument('--demo', help='enable automatic user creation', action='store_true', default=False)
ap.add_argument('--insecure', help='allow user info as urlencoded param', action='store_true', default=False)
......@@ -27,6 +28,9 @@ ap.add_argument('--central_uri', help='scitran central api', default='https://sd
ap.add_argument('--log_level', help='log level [info]', default='info')
args = ap.parse_args()
# HACK to allow setting the --site_name in the same way as api.py
# --site_name 'Example Site' or --site_name "Example Site"
args.site_name = ' '.join(args.site_name).strip('"\'')
args.quarantine_path = os.path.join(args.data_path, 'quarantine')
logging.basicConfig(level=getattr(logging, args.log_level.upper())) #FIXME probably not necessary, because done in api.py
......@@ -56,14 +60,17 @@ for x in range(0, 30):
else:
raise Exception('Could not connect to MongoDB')
# TODO: make api_uri a required arg?
application.db.sites.update({'_id': args.site_id}, {'_id': args.site_id, 'name': args.site_name, 'api_uri': args.api_uri}, upsert=True)
if not args.ssl_cert:
log.warning('SSL certificate not specified, Scitran Central functionality disabled')
elif not args.api_uri:
log.warning('api_uri not configured. scitran central functionality disabled.')
elif not args.site_name:
log.warning('site_name not configured. scitran central functionality disabled.')
elif not args.site_id:
log.warning('site_id not configured. scitran central functionality disabled.')
elif args.site_id == 'local':
log.warning('site_id is local. scitran central functionality disabled.')
elif not args.central_uri:
log.warning('central_uri not configured. scitran central functionality disabled.')
else:
......@@ -79,4 +86,4 @@ else:
if fail_count == 3:
log.debug('scitran central unreachable, purging all remotes info')
centralclient.clean_remotes(application.db)
centralclient.clean_remotes(application.db, args.site_id)
......@@ -75,10 +75,10 @@ def update(db, api_uri, site_name, site_id, ssl_cert, central_url):
return False
def clean_remotes(db):
def clean_remotes(db, site_id):
"""Remove db.sites, and removes remotes field from all db.users."""
log.debug('removing remotes from users, and remotes collection')
db.sites.remove({})
db.sites.remove({'_id': {'$ne': [site_id]}})
db.users.update({'remotes': {'$exists': True}}, {'$unset': {'remotes': ''}}, multi=True)
......
......@@ -185,13 +185,18 @@ class Core(base.RequestHandler):
def sites(self):
"""Return local and remote sites."""
if self.app.config['site_id'] == 'local':
return [{'_id': 'local', 'name': 'Local', 'onload': True}]
projection = ['name', 'onload']
# TODO onload for local is true
if self.public_request or self.request.get('all').lower() in ('1', 'true'):
sites = list(self.app.db.sites.find(None, ['name']))
sites = list(self.app.db.sites.find(None, projection))
else:
# TODO onload based on user prefs
remote_ids = (self.app.db.users.find_one({'_id': self.uid}, ['remotes']) or {}).get('remotes', []) + [self.app.config['site_id']]
sites = list(self.app.db.sites.find({'_id': {'$in': remote_ids}}, ['name']))
sites = list(self.app.db.sites.find({'_id': {'$in': remote_ids}}, projection))
for s in sites: # TODO: this for loop will eventually move to public case
if s['_id'] == self.app.config['site_id']:
s['onload'] = True
break
return sites
search_schema = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment