Skip to content

Commit

Permalink
Merge pull request #58 from bird-house/issue-39-public-url
Browse files Browse the repository at this point in the history
added public url (purl)
  • Loading branch information
cehbrecht committed Feb 27, 2019
2 parents f98806b + be26453 commit e6a36b3
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/functional/test_rpcinterface_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_generate_token_and_revoke_it(self):
def test_register_service_and_unregister_it(self):
service = {'url': WPS_TEST_SERVICE, 'name': 'test_emu',
'type': 'wps', 'public': False, 'auth': 'token',
'verify': True}
'verify': True, 'purl': 'http://purl/wps'}
# register
resp = call_FUT(self.app, 'register_service', (
service['url'],
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_wps_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUp(self):
self.wps_path = '/ows/proxy/test_emu'
# register
service = {'url': WPS_TEST_SERVICE, 'name': 'test_emu',
'type': 'wps', 'public': True}
'type': 'wps', 'public': True, 'purl': 'http://purl/wps'}
try:
call_FUT(self.app, 'register_service', (
service['url'],
Expand Down
1 change: 1 addition & 0 deletions tests/store/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MemoryServiceStoreTestCase(unittest.TestCase):
def setUp(self):
self.service_data = {'url': 'http://localhost:5000/wps',
'name': 'emu',
'purl': 'http://myservice/wps',
'public': False,
'auth': 'token',
'type': 'WPS',
Expand Down
8 changes: 4 additions & 4 deletions tests/store/test_mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def test_save_token(self):
class MongodbServiceStoreTestCase(unittest.TestCase):
def setUp(self):
self.service = dict(name="loving_flamingo", url="http://somewhere.over.the/ocean", type="wps",
public=False, auth='token', verify=True)
public=False, auth='token', verify=True, purl="http://purl/wps")
self.service_public = dict(name="open_pingu", url="http://somewhere.in.the/deep_ocean", type="wps",
public=True, auth='token', verify=True)
public=True, auth='token', verify=True, purl="http://purl/wps")
self.service_special = dict(url="http://wonderload", name="A special Name", type='wps',
auth='token', verify=False)
auth='token', verify=False, purl="http://purl/wps")

def test_fetch_by_name(self):
collection_mock = mock.Mock(spec=["find_one"])
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_save_service_with_special_name(self):

collection_mock.insert_one.assert_called_with({
'url': 'http://wonderload', 'type': 'wps', 'name': 'a_special_name', 'public': False, 'auth': 'token',
'verify': False})
'verify': False, 'purl': "http://purl/wps"})

def test_save_service_public(self):
collection_mock = mock.Mock(spec=["insert_one", "find_one", "count_documents"])
Expand Down
3 changes: 2 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def setUp(self):

def test_register_service_and_unregister_it(self):
service = {'url': 'http://localhost/wps', 'name': 'test_emu',
'type': 'wps', 'public': False, 'auth': 'token', 'verify': True}
'type': 'wps', 'public': False, 'auth': 'token', 'verify': True,
'purl': 'http://myservice/wps'}
# register
resp = self.reg.register_service(
service['url'],
Expand Down
8 changes: 6 additions & 2 deletions tests/test_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_service_with_url_only(self):
service = Service(url='http://nowhere/wps')
assert service.url == 'http://nowhere/wps'
assert service.name == 'unknown'
assert service.has_purl() is False

def test_missing_url(self):
with pytest.raises(TypeError) as e_info:
Expand All @@ -51,12 +52,15 @@ def test_service_with_name(self):
service = Service(url='http://nowhere/wps', name="test_wps")
assert service.url == 'http://nowhere/wps'
assert service.name == 'test_wps'
assert service.has_purl() is False

def test_service_params(self):
service = Service(url='http://nowhere/wps', name="test_wps")
service = Service(url='http://nowhere/wps', name="test_wps", purl='http://myservice/wps')
assert service.params == {'name': 'test_wps',
'public': False,
'auth': 'token',
'type': 'WPS',
'url': 'http://nowhere/wps',
'verify': True}
'verify': True,
'purl': 'http://myservice/wps'}
assert service.has_purl() is True
14 changes: 12 additions & 2 deletions twitcher/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import time

from twitcher.utils import now_secs
from twitcher.utils import now_secs, is_valid_url
from twitcher.exceptions import AccessTokenNotFound


class Service(dict):
"""
Dictionary that contains OWS services. It always has ``'url'`` key.
Dictionary that contains OWS services. It always has the ``'url'`` key.
"""
def __init__(self, *args, **kwargs):
super(Service, self).__init__(*args, **kwargs)
Expand All @@ -32,6 +32,15 @@ def type(self):
"""Service type."""
return self.get('type', 'WPS')

@property
def purl(self):
"""Service optional public URL (purl)."""
return self.get('purl', '')

def has_purl(self):
"""Return true if we have a valid public URL (purl)."""
return is_valid_url(self.purl)

@property
def public(self):
"""Flag if service has public access."""
Expand Down Expand Up @@ -63,6 +72,7 @@ def params(self):
'url': self.url,
'name': self.name,
'type': self.type,
'purl': self.purl,
'public': self.public,
'auth': self.auth,
'verify': self.verify}
Expand Down
8 changes: 6 additions & 2 deletions twitcher/owsproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ def _send_request(request, service, extra_path=None, request_params=None):
try:
if ct in ['text/xml', 'application/xml', 'text/xml;charset=ISO-8859-1']:
# replace urls in xml content
proxy_url = request.route_url('owsproxy', service_name=service['name'])
# ... if public URL is not configured use proxy url.
if service.has_purl():
public_url = service.get('purl')
else:
public_url = request.route_url('owsproxy', service_name=service['name'])
# TODO: where do i need to replace urls?
content = replace_caps_url(resp.content, proxy_url, service.get('url'))
content = replace_caps_url(resp.content, public_url, service.get('url'))
else:
# raw content
content = resp.content
Expand Down
1 change: 1 addition & 0 deletions twitcher/store/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def save_service(self, service, overwrite=True):
name=name,
url=baseurl(service.url),
type=service.type,
purl=service.purl,
public=service.public,
auth=service.auth,
verify=service.verify))
Expand Down
1 change: 1 addition & 0 deletions twitcher/store/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def save_service(self, service, overwrite=True):
name=name,
url=baseurl(service.url),
type=service.type,
purl=service.purl,
public=service.public,
auth=service.auth,
verify=service.verify))
Expand Down
12 changes: 10 additions & 2 deletions twitcher/twitcherctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def create_parser(self):
subparser.add_argument('--name', help="Service name. If not set then a name will be generated.")
subparser.add_argument('--type', default='wps',
help="Service type (wps, wms). Default: wps.")
subparser.add_argument('--purl', default='',
help="Service optional public URL.")
subparser.add_argument('--public', action='store_true',
help="If set then service has no access restrictions.")
subparser.add_argument('--auth', default='token',
Expand Down Expand Up @@ -116,10 +118,16 @@ def run(self, args):
if args.cmd == 'list':
result = service.list_services()
elif args.cmd == 'register':
data = {'name': args.name,
'type': args.type,
'purl': args.purl,
'public': args.public,
'auth': args.auth,
'verify': args.verify}
result = service.register_service(
url=args.url,
data={'name': args.name, 'type': args.type, 'public': args.public, 'auth': args.auth,
'verify': args.verify})
data=data,
)
elif args.cmd == 'unregister':
result = service.unregister_service(name=args.name)
elif args.cmd == 'clear':
Expand Down

0 comments on commit e6a36b3

Please sign in to comment.