Skip to content

Commit

Permalink
Merge branch 'magpie_adapter_interface_update' into magpie_adapter
Browse files Browse the repository at this point in the history
Conflicts:
	magpie/adapter/__init__.py
	magpie/adapter/magpieservice.py
	requirements.txt
  • Loading branch information
dbyrns committed Jul 19, 2018
2 parents 05f2c73 + 68cbcad commit 901daca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
7 changes: 2 additions & 5 deletions magpie/adapter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@

class MagpieAdapter(AdapterInterface):

def servicestore_factory(self, registry, database=None, headers=None):
return MagpieServiceStore(registry=registry, headers=headers)
def servicestore_factory(self, registry, database=None):
return MagpieServiceStore(registry=registry)

def owssecurity_factory(self, registry):
# TODO For magpie we cannot store the servicestore object since the constructor need a header with token
# taken from the request... maybe we should check for that?!?
#return MagpieOWSSecurity(tokenstore_factory(registry), servicestore_factory(registry))
return MagpieOWSSecurity()

def configurator_factory(self, settings):
Expand Down
25 changes: 14 additions & 11 deletions magpie/adapter/magpieservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@ class MagpieServiceStore(ServiceStore):
"""
Registry for OWS services. Uses magpie to fetch service url and attributes.
"""
def __init__(self, registry, headers=None):
self.headers = headers
def __init__(self, registry):
try:
self.magpie_url = registry.settings.get('magpie.url').strip('/')
except AttributeError:
#If magpie.url does not exist, calling strip fct over None will raise this issue
raise ConfigurationError('magpie.url config cannot be found')

def save_service(self, service, overwrite=True):
def save_service(self, service, overwrite=True, request=None):
"""
Magpie store is read-only, use magpie api to add services
"""
raise NotImplementedError

def delete_service(self, name):
def delete_service(self, name, request=None):
"""
Magpie store is read-only, use magpie api to delete services
"""
raise NotImplementedError

def list_services(self):
#TODO Now only wps are returned as well as fetch_by_ulr... fetch_by_name has been patched to support other service_type
def list_services(self, request=None):
"""
Lists all services registered in magpie.
"""
my_services = []
response = requests.get('{url}/services/types/wps'.format(url=self.magpie_url), headers=self.headers)
response = requests.get('{url}/services/types/wps'.format(url=self.magpie_url),
cookies=request.cookies)
if response.status_code != 200:
raise response.raise_for_status()
services = json.loads(response.text)
Expand All @@ -51,11 +52,12 @@ def list_services(self):
type=service['service_type']))
return my_services

def fetch_by_name(self, name):
def fetch_by_name(self, name, request=None):
"""
Gets service for given ``name`` from magpie.
"""
response = requests.get('{url}/services/{name}'.format(url=self.magpie_url, name=name), headers=self.headers)
response = requests.get('{url}/services/{name}'.format(url=self.magpie_url, name=name),
cookies=request.cookies)
if response.status_code == 404:
raise ServiceNotFound
if response.status_code != 200:
Expand All @@ -67,17 +69,18 @@ def fetch_by_name(self, name):
type=services[name]['service_type'])
raise ServiceNotFound

def fetch_by_url(self, url):
def fetch_by_url(self, url, request=None):
"""
Gets service for given ``url`` from mongodb storage.
"""
services = self.list_services()
services = self.list_services(request=request)
for service in services:
if service.url == url:
return service
raise ServiceNotFound

def clear_services(self):

def clear_services(self, request=None):
"""
Magpie store is read-only, use magpie api to delete services
"""
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ paste
cornice_swagger
cornice
colander
git+https://github.com/Ouranosinc/twitcher.git@issue-24-rest-api-with-magpie#egg=pyramid_twitcher

0 comments on commit 901daca

Please sign in to comment.