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

add a script to generate collection configuration from a remote SDAP #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion analysis/webservice/algorithms/DataSeriesList.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class DataSeriesListCalcHandlerImpl(NexusCalcHandler):
path = "/list"
description = "Lists datasets currently available for analysis"
params = {}
remote_sdaps = RemoteSDAPCache()

def __init__(self, tile_service_factory, remote_collections=None, **kwargs):
super().__init__(tile_service_factory, **kwargs)
self._remote_collections = remote_collections
self.remote_sdaps = RemoteSDAPCache()


@cached(ttl=(60 * 60 * 1000)) # 1 hour cached
Expand Down
3 changes: 2 additions & 1 deletion analysis/webservice/redirect/RemoteSDAPCache.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def _add(self, url, timeout=2, max_age=3600*24):

def get(self, url, short_name):
stripped_url = url.strip('/')
if stripped_url not in self.sdap_lists or self.sdap_lists[stripped_url].outdated_at>datetime.now():
logger.debug("")
if stripped_url not in self.sdap_lists or self.sdap_lists[stripped_url].outdated_at > datetime.now():
self._add(stripped_url)

for collection in self.sdap_lists[stripped_url].list:
Expand Down
Empty file.
46 changes: 46 additions & 0 deletions tools/create-remote-conf/create-conf-from-remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import argparse
import requests
import yaml


def parse_args():
parser = argparse.ArgumentParser(description='Create a collections.yaml config from a remote SDAP',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

parser.add_argument('--remote-nexus-list',
help='The url of the remote SDAP server, list end-point',
required=True
)

parser.add_argument('--prefix',
help='Add prefix to the remote collection id to form the local collection id',
required=False,
default="")

return parser.parse_args()


def main():
the_args = parse_args()
r = requests.get(the_args.remote_nexus_list, verify=False)
collection_config = []
for collection in r.json():
if 'remoteUrl' not in collection:
collection_config.append(
{
'id': the_args.prefix + collection['shortName'],
'path': the_args.remote_nexus_list.removesuffix('/list'),
'remote-id': collection['shortName']
}
)

with open('./collections.yml', 'w') as outfile:
yaml.dump(collection_config, outfile, default_flow_style=False)






if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions tools/create-remote-conf/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests