From 41b6a7e81c5fe9ee1c26af8084099de5b8a708ca Mon Sep 17 00:00:00 2001 From: golnazads <28757512+golnazads@users.noreply.github.com> Date: Tue, 27 Mar 2018 18:20:23 -0400 Subject: [PATCH 1/2] added /resolver to the endpoint path since this is not API and needs the full path --- resolverway/tests/unittests/test_resolver_gateway.py | 4 ++-- resolverway/views.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/resolverway/tests/unittests/test_resolver_gateway.py b/resolverway/tests/unittests/test_resolver_gateway.py index d206105..b1f21f3 100644 --- a/resolverway/tests/unittests/test_resolver_gateway.py +++ b/resolverway/tests/unittests/test_resolver_gateway.py @@ -24,7 +24,7 @@ def test_route(self): Tests for the existence of a /resolver route, and that it returns properly formatted JSON data when the URL is supplied """ - r= self.client.get('/1987gady.book.....B/ABSTRACT/https://ui.adsabs.harvard.edu/#abs/1987gady.book.....B/ABSTRACT') + r= self.client.get('/resolver/1987gady.book.....B/ABSTRACT/https://ui.adsabs.harvard.edu/#abs/1987gady.book.....B/ABSTRACT') self.assertEqual(r.status_code, 302) def test_single_link(self): @@ -70,7 +70,7 @@ def test_route_error(self): """ Tests for wrong link type """ - r = self.client.get('/1987gady.book.....B/ERROR') + r = self.client.get('/resolver/1987gady.book.....B/ERROR') self.assertEqual(r.status_code, 400) def test_with_header_and_cookie(self): diff --git a/resolverway/views.py b/resolverway/views.py index 05e4326..88b03c9 100644 --- a/resolverway/views.py +++ b/resolverway/views.py @@ -98,9 +98,9 @@ def process_request(self): @advertise(scopes=[], rate_limit=[1000, 3600 * 24]) -@bp.route('/', defaults={'link_type': '', 'url': None}, methods=['GET']) -@bp.route('//', defaults={'url': None}, methods=['GET']) -@bp.route('///', methods=['GET']) +@bp.route('/resolver/', defaults={'link_type': '', 'url': None}, methods=['GET']) +@bp.route('/resolver//', defaults={'url': None}, methods=['GET']) +@bp.route('/resolver///', methods=['GET']) def resolver(bibcode, link_type, url): """ From c1d7809e57c5e4524cd89ab3bf139c3104832458 Mon Sep 17 00:00:00 2001 From: golnazads <28757512+golnazads@users.noreply.github.com> Date: Thu, 29 Mar 2018 07:24:27 -0400 Subject: [PATCH 2/2] added token to communicate with resolver service --- config.py | 5 +++-- resolverway/views.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index a1bb9bb..8eec159 100644 --- a/config.py +++ b/config.py @@ -1,3 +1,4 @@ -# This is the URL to communicate with resolver_service api -RESOLVER_SERVICE_URL = 'http://localhost:5000/%s' +# These are the URL and token for resolver_service api +RESOLVER_SERVICE_URL = 'https://dev.adsabs.harvard.edu/v1/resolver/%s' +RESOLVER_SERVICE_ADSWS_API_TOKEN = 'this is a secret api token!' \ No newline at end of file diff --git a/resolverway/views.py b/resolverway/views.py index 88b03c9..04f9921 100644 --- a/resolverway/views.py +++ b/resolverway/views.py @@ -82,7 +82,8 @@ def process_request(self): try: # if no url then send request to resolver_service to get link(s) params = self.bibcode + '/' + self.link_type - response = requests.get(url=current_app.config['RESOLVER_SERVICE_URL'] %(params), headers=request.headers) + headers = {'Authorization': 'Bearer ' + current_app.config['RESOLVER_SERVICE_ADSWS_API_TOKEN']} + response = requests.get(url=current_app.config['RESOLVER_SERVICE_URL'] %(params), headers=headers) contentType = response.headers.get('content-type')