Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from handlers import grouphandler
from handlers import containerhandler
from handlers import collectionshandler
from handlers import searchhandler

log = config.log

Expand Down Expand Up @@ -130,6 +131,8 @@ def _format(route):

webapp2.Route(_format(r'/api/<par_cont_name:groups>/<par_id:{group_id_re}>/<cont_name:projects>'), containerhandler.ContainerHandler, name='cont_sublist_groups', handler_method='get_all', methods=['GET']),
webapp2.Route(_format(r'/api/<par_cont_name:{cont_name_re}>/<par_id:{cid_re}>/<cont_name:{cont_name_re}>'), containerhandler.ContainerHandler, name='cont_sublist', handler_method='get_all', methods=['GET']),
webapp2.Route(_format(r'/api/search'), searchhandler.SearchHandler, name='es_proxy', methods=['GET']),
webapp2.Route(_format(r'/api/search/<cont_name:{cont_name_re}>'), searchhandler.SearchHandler, name='es_proxy', methods=['GET']),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alignment is a little wonky here.

]


Expand Down
4 changes: 2 additions & 2 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
'id_endpoint': 'https://www.googleapis.com/plus/v1/people/me/openIdConnect',
'auth_endpoint': 'https://accounts.google.com/o/oauth2/auth',
'verify_endpoint': 'https://www.googleapis.com/oauth2/v1/tokeninfo',

},
'persistent': {
'db_uri': 'mongodb://localhost:9001/scitran',
'db_connect_timeout': '2000',
'db_server_selection_timeout': '3000',
'data_path': os.path.join(os.path.dirname(__file__), '../persistent/data'),
},
'elasticsearch_host': 'localhost:9200',
}
}

__config = copy.deepcopy(DEFAULT_CONFIG)
Expand Down
27 changes: 27 additions & 0 deletions api/handlers/searchhandler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import datetime
import elasticsearch
from requests import ConnectionError

from .. import base
from .. import config

log = config.log

es_client = elasticsearch.Elasticsearch([config.get_item('persistent', 'elasticsearch_host')])


class SearchHandler(base.RequestHandler):

def __init__(self, request=None, response=None):
super(SearchHandler, self).__init__(request, response)

def get(self, cont_name=None, **kwargs):
if self.public_request:
self.abort(403, 'search is available only for authenticated users')
size = self.get_param('size')
body = self.request.json_body
try:
results = es_client.search(index='scitran', doc_type=cont_name, body=body, _source=['_id'], size=size or 10)
except elasticsearch.exceptions.ConnectionError as e:
self.abort(503, 'elasticsearch is not available')
return results['hits']['hits']
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ requests==2.9.1
rfc3987==1.3.4
webapp2==2.5.2
WebOb==1.5.1
elasticsearch==1.9.0