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

Url prefix #85

Merged
merged 4 commits into from
Apr 30, 2021
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
14 changes: 9 additions & 5 deletions src/openeo_grass_gis_driver/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
from flask_restful import Api
from werkzeug.middleware.proxy_fix import ProxyFix

__author__ = "Sören Gebbert"
__copyright__ = "Copyright 2018, Sören Gebbert, mundialis"
__maintainer__ = "Soeren Gebbert"
__email__ = "[email protected]"
from openeo_grass_gis_driver.well_known import URL_PREFIX


__license__ = "Apache License, Version 2.0"
__author__ = "Sören Gebbert, Carmen Tawalika"
__copyright__ = "Copyright 2018-2021, Sören Gebbert, mundialis"
__maintainer__ = "mundialis"


flask_app = Flask(__name__)
flask_app.wsgi_app = ProxyFix(flask_app.wsgi_app, x_for=1, x_host=1, x_proto=1)
# as flask CORS lead to unforeseen behaviour in certain cases, we configure
# headers with nginx and outcomment here.
# CORS(flask_app, supports_credentials=True)
flask_api = Api(flask_app)
flask_api = Api(flask_app, prefix=URL_PREFIX)
33 changes: 26 additions & 7 deletions src/openeo_grass_gis_driver/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from flask import make_response, jsonify

from openeo_grass_gis_driver.app import flask_api
from openeo_grass_gis_driver.authentication import \
Authentication, OIDCAuthentication
from openeo_grass_gis_driver.authentication import UserInfo
from openeo_grass_gis_driver.capabilities import \
Capabilities, ServiceTypes, Services
Capabilities, ServiceTypes, Services, CAPABILITIES
from openeo_grass_gis_driver.collections import Collections
from openeo_grass_gis_driver.collection_information import \
CollectionInformationResource
Expand All @@ -24,18 +26,35 @@
from openeo_grass_gis_driver.well_known import WellKnown

__license__ = "Apache License, Version 2.0"
__author__ = "Sören Gebbert"
__copyright__ = "Copyright 2018, Sören Gebbert, mundialis"
__maintainer__ = "Soeren Gebbert"
__email__ = "[email protected]"
__author__ = "Sören Gebbert, Carmen Tawalika"
__copyright__ = "Copyright 2018-2021, Sören Gebbert, mundialis GmbH & Co. KG"
__maintainer__ = "mundialis"


def add_discovery_endpoints():
""" Add endpoints to "app" instead of flask_api to bypass URL_PREFIX for
basic discovery endpoints
"""

app = flask_api.app

@app.route('/')
def index():
return make_response(jsonify(CAPABILITIES), 200)

@app.route('/.well-known/openeo')
def well_known():
return WellKnown.get(flask_api)


def create_endpoints():
"""Create all endpoints for the openEO Core API wrapper
"""Create all endpoints for the openEO Core API wrapper
"""

add_discovery_endpoints()

# Capabilities
flask_api.add_resource(Capabilities, '/')
flask_api.add_resource(WellKnown, '/.well-known/openeo')
flask_api.add_resource(OutputFormats, '/file_formats')
# /conformance
flask_api.add_resource(Udf, '/udf_runtimes')
Expand Down
4 changes: 3 additions & 1 deletion src/openeo_grass_gis_driver/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ class TestBase(unittest.TestCase):

def setUp(self):
self.app = flask_api.app.test_client()
self.prefix = flask_api.prefix
self.gconf = ActiniaConfig()
self.gconf.PORT = "443"
self.auth = Headers()
auth = bytes(self.gconf.USER + ':' + self.gconf.PASSWORD, "utf-8")
encodeAuth = base64.b64encode(auth).decode()
self.auth.add('Authorization', 'Basic ' + encodeAuth)
response = self.app.get('/credentials/basic', headers=self.auth)
response = self.app.get(
self.prefix + '/credentials/basic', headers=self.auth)
resp_data = json.loads(response.data.decode())
self.auth.set(
'Authorization',
Expand Down
15 changes: 11 additions & 4 deletions src/openeo_grass_gis_driver/well_known.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@

__license__ = "Apache License, Version 2.0"
__author__ = "Carmen Tawalika"
__copyright__ = "2018-present mundialis GmbH & Co. KG"
__copyright__ = "2018-2021 mundialis GmbH & Co. KG"


API_VERSION = "1.0.1"
API_SHORT_VERSION = "v%s.%s" % (
API_VERSION.split('.')[0], API_VERSION.split('.')[1])
# This is the URL prefix that is used by app.py and must be used in the tests
URL_PREFIX = "/api/%s" % API_SHORT_VERSION


class WellKnown(Resource):
Expand All @@ -15,11 +22,11 @@ def __init__(self):

def get(self):

host_url = request.host_url
url = '%s%s/' % (request.host_url.strip('/'), URL_PREFIX)

version_list = list()
version_list.append({"url": host_url + "api/v1.0/",
"api_version": "1.0.1",
version_list.append({"url": url,
"api_version": API_VERSION,
"production": False})

resp = dict()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_actinia_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ def test_layer_exists_2(self):

def test_layer_exists_2_error(self):
iface = ActiniaInterface(self.gconf)
layer_name = "latlong_wgs84.modis_ndvi_global.strds.ndvi_16_5600m_nope"
status = iface.check_layer_exists(
layer_name="latlong_wgs84.modis_ndvi_global.strds.ndvi_16_5600m_nope")
layer_name=layer_name)
self.assertFalse(status)

def test_async_persistent_processing(self):
Expand Down
9 changes: 6 additions & 3 deletions tests/test_capabilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from flask import json
import unittest

from openeo_grass_gis_driver.capabilities import CAPABILITIES, SERVICE_TYPES
from openeo_grass_gis_driver.jobs import OUTPUT_FORMATS
from openeo_grass_gis_driver.test_base import TestBase
Expand All @@ -15,21 +16,23 @@
class CapabilitiesTestCase(TestBase):

def test_capabilities(self):
response = self.app.get('/', headers=self.auth)
response = self.app.get(self.prefix + '/', headers=self.auth)
print(response.data)

self.assertEqual(json.loads(response.data.decode()),
CAPABILITIES)

def test_ouput_formats(self):
response = self.app.get('/file_formats', headers=self.auth)
response = self.app.get(
self.prefix + '/file_formats', headers=self.auth)
print(response.data)

self.assertEqual(json.loads(response.data.decode()),
OUTPUT_FORMATS)

def test_service_types(self):
response = self.app.get('/service_types', headers=self.auth)
response = self.app.get(
self.prefix + '/service_types', headers=self.auth)
print(response.data)

self.assertEqual(json.loads(response.data.decode()),
Expand Down
7 changes: 6 additions & 1 deletion tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
from flask import json
from pprint import pprint

from openeo_grass_gis_driver.test_base import TestBase

__license__ = "Apache License, Version 2.0"
Expand All @@ -18,7 +19,8 @@ def test_collections(self):

:return:
"""
response = self.app.get('/collections', headers=self.auth)
response = self.app.get(
self.prefix + '/collections', headers=self.auth)
data = json.loads(response.data.decode())

pprint(data)
Expand All @@ -41,6 +43,7 @@ def test_collections(self):

def test_raster_collections_id_1(self):
response = self.app.get(
self.prefix +
'/collections/nc_spm_08.landsat.raster.lsat5_1987_10',
headers=self.auth)
self.assertEqual(response.status_code, 200)
Expand All @@ -51,6 +54,7 @@ def test_raster_collections_id_1(self):

def test_raster_collections_id_2(self):
response = self.app.get(
self.prefix +
'/collections/nc_spm_08.PERMANENT.raster.elevation',
headers=self.auth)
self.assertEqual(response.status_code, 200)
Expand All @@ -61,6 +65,7 @@ def test_raster_collections_id_2(self):

def test_vector_collections_id_2(self):
response = self.app.get(
self.prefix +
'/collections/nc_spm_08.PERMANENT.raster.elevation',
headers=self.auth)
self.assertEqual(response.status_code, 200)
Expand Down
Loading