Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and simplify api urls #177

Merged
merged 3 commits into from
May 11, 2016
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
19 changes: 10 additions & 9 deletions bin/add_or_update_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
this_script = sys.argv[0]

if len(sys.argv) > 1:
opentree_docstore_url = sys.argv[1]
opentree_docstore_url = sys.argv[1]
else:
print "Please specify the Open Tree doc-store URL as first argument: '%s <repo-URL> <public-API-URL> [<GitHub-OAuth-token-file>]'" % (this_script,)
sys.exit(1) # signal to the caller that something went wrong

if len(sys.argv) > 2:
opentree_api_base_url = sys.argv[2].rstrip("/")
opentree_api_base_url = sys.argv[2].rstrip("/")
nudge_index_url = "%s/phylesystem/search/nudgeIndexOnUpdates" % opentree_api_base_url
else:
print "Please specify the Open Tree API public URL as second argument: '%s <repo-URL> <public-API-URL> [<GitHub-OAuth-token-file>]'" % (this_script,)
sys.exit(1) # signal to the caller that something went wrong

if len(sys.argv) > 3:
oauth_token_file = sys.argv[3]
oauth_token_file = sys.argv[3]
else:
oauth_token_file = None

# To do this automatically via the GitHub API, we need an OAuth token for bot
# user 'opentreeapi' on GitHub, with scope 'public_repo' and permission to
# manage hooks. This is stored in yet another sensitive file.
Expand Down Expand Up @@ -54,7 +55,7 @@
if (hook.get('name') == "web" and
hook.get('active') == True and
hook.get('events') and ("push" in hook['events']) and
hook.get('config') and (hook['config']['url'] == "%s/../search/nudgeIndexOnUpdates" % opentree_api_base_url)
hook.get('config') and (hook['config']['url'] == nudge_index_url)
):
found_matching_webhook = True
except:
Expand All @@ -73,7 +74,7 @@
"push"
],
"config": {
"url": ("%s/../search/nudgeIndexOnUpdates" % opentree_api_base_url),
"url": nudge_index_url,
"content_type": "json"
}
}
Expand Down Expand Up @@ -101,12 +102,12 @@
%s/settings/hooks

Find (or add) a webhook with these properties:
Payload URL: %s/../search/nudgeIndexOnUpdates
Payload URL: %s
Payload version: application/vnd.github.v3+json
Events: push
Active: true

***************************************************************
""" % (opentree_docstore_url, opentree_api_base_url)
""" % (opentree_docstore_url, nudge_index_url)

sys.exit(0)
4 changes: 2 additions & 2 deletions controllers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def __extract_and_validate_collection(request, kwargs):
raise HTTP(404, "Collection '{s}' has no JSON data!".format(s=collection_id))
# add/restore the url field (using the visible fetch URL)
base_url = api_utils.get_collections_api_base_url(request)
collection_json['url'] = '{b}/collection/{i}'.format(b=base_url,
collection_json['url'] = '{b}/v2/collection/{i}'.format(b=base_url,
i=collection_id)
try:
external_url = collections.get_public_url(collection_id)
Expand Down Expand Up @@ -595,7 +595,7 @@ def _fetch_duplicate_study_ids(study_DOI=None, study_ID=None):
# if no DOI exists, there are no known duplicates
return [ ]
oti_base_url = api_utils.get_oti_base_url(request)
fetch_url = '%s/singlePropertySearchForStudies' % oti_base_url
fetch_url = '%s/oti/v1/singlePropertySearchForStudies' % oti_base_url
try:
dupe_lookup_response = fetch(
fetch_url,
Expand Down
10 changes: 4 additions & 6 deletions controllers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def GET(kind, property_name, search_term,jsoncallback=None,callback=None,_=None,
conf.read("%s/applications/%s/private/config" % (os.path.abspath('.'), app_name,))

oti_base_url = conf.get("apis", "oti_base_url")
api_base_url = "%s/ext/QueryServices/graphdb/" % (oti_base_url,)
api_base_url = "%s/oti/ext/QueryServices/graphdb/" % (oti_base_url,)

opentree_docstore_url = conf.get("apis", "opentree_docstore_url")

Expand Down Expand Up @@ -73,7 +73,7 @@ def nudgeIndexOnUpdates():
conf.read("%s/applications/%s/private/config" % (os.path.abspath('.'), app_name,))

oti_base_url = conf.get("apis", "oti_base_url")
api_base_url = "%s/ext/QueryServices/graphdb/" % (oti_base_url,)
api_base_url = "%s/oti/ext/QueryServices/graphdb/" % (oti_base_url,)

opentree_docstore_url = conf.get("apis", "opentree_docstore_url")
payload = request.vars
Expand Down Expand Up @@ -124,8 +124,7 @@ def nudgeIndexOnUpdates():
add_or_update_ids = list(set(add_or_update_ids)) # remove any duplicates

if len(add_or_update_ids) > 0:
# N.B. The indexing service lives outside of the v1/ space, so we "back out" these URLs with ".."
nudge_url = "%s/../ext/IndexServices/graphdb/indexNexsons" % (oti_base_url,)
nudge_url = "%s/oti/ext/IndexServices/graphdb/indexNexsons" % (oti_base_url,)
nexson_urls = [ (nexson_url_template % (study_id,)) for study_id in add_or_update_ids ]

# N.B. that gluon.tools.fetch() can't be used here, since it won't send
Expand Down Expand Up @@ -153,8 +152,7 @@ def nudgeIndexOnUpdates():

if len(removed_study_ids) > 0:
# Un-index the studies that were removed from docstore
# N.B. The indexing service lives outside of the v1/ space, so we "back out" these URLs with ".."
remove_url = "%s/../ext/IndexServices/graphdb/unindexNexsons" % (oti_base_url,)
remove_url = "%s/oti/ext/IndexServices/graphdb/unindexNexsons" % (oti_base_url,)
req = urllib2.Request(
url=remove_url,
data=json.dumps({
Expand Down