-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Basic Api and Client classes (#5)
* accept reformatting * accept reformatting * edit readme * accept reformatting * remove unused imports * accept reformatting * accept reformatting --------- Co-authored-by: sean <sean.hoyal@external.eodc.eu>
- Loading branch information
1 parent
590018f
commit f9ec761
Showing
10 changed files
with
485 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from attrs import Factory, define, field | ||
from fastapi import FastAPI, Response | ||
|
||
from openeo_fastapi.client import models | ||
|
||
|
||
@define | ||
class OpenEOApi: | ||
"""Factory for creating FastApi applications conformant to the OpenEO Api specification.""" | ||
|
||
client: field() | ||
app: field(default=Factory(lambda self: FastAPI)) | ||
|
||
def _route_filter(self): | ||
""" """ | ||
pass | ||
|
||
def register_get_capabilities(self): | ||
"""Register landing page (GET /). | ||
Returns: | ||
None | ||
""" | ||
self.app.add_api_route( | ||
name="capabilities", | ||
path="/", | ||
response_model=models.Capabilities, | ||
response_model_exclude_unset=False, | ||
response_model_exclude_none=True, | ||
methods=["GET"], | ||
endpoint=self.client.get_capabilities, | ||
) | ||
|
||
def register_get_conformance(self): | ||
"""Register conformance page (GET /). | ||
Returns: | ||
None | ||
""" | ||
self.app.add_api_route( | ||
name="conformance", | ||
path="/", | ||
response_model=models.ConformanceGetResponse, | ||
response_model_exclude_unset=False, | ||
response_model_exclude_none=True, | ||
methods=["GET"], | ||
endpoint=self.client.get_conformance, | ||
) | ||
|
||
def register_well_known(self): | ||
"""Register well known page (GET /). | ||
Returns: | ||
None | ||
""" | ||
self.app.add_api_route( | ||
name=".well-known", | ||
path="/.well-known/openeo", | ||
response_model=models.WellKnownOpeneoGetResponse, | ||
response_model_exclude_unset=False, | ||
response_model_exclude_none=True, | ||
methods=["GET"], | ||
endpoint=self.client.get_well_know, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Conformance Classes.""" | ||
from enum import Enum | ||
|
||
|
||
class STACConformanceClasses(str, Enum): | ||
"""STAC Api conformance classes.""" | ||
|
||
CORE = "https://api.stacspec.org/v1.0.0/core" | ||
COLLECTIONS = "https://api.stacspec.org/v1.0.0/collections" | ||
|
||
|
||
class OGCConformanceClasses(str, Enum): | ||
"""OGC compliant conformance classes.""" | ||
|
||
pass | ||
|
||
|
||
BASIC_CONFORMANCE_CLASSES = [ | ||
STACConformanceClasses.CORE, | ||
STACConformanceClasses.COLLECTIONS, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import abc | ||
from collections import namedtuple | ||
from urllib.parse import urlunparse | ||
|
||
from attrs import define, field | ||
|
||
from openeo_fastapi.client import conformance, models | ||
|
||
|
||
@define | ||
class OpenEOCore: | ||
"""Base client for the OpenEO Api.""" | ||
|
||
# TODO. Improve. Not quite sure about setting these here. | ||
api_dns: str = field() | ||
backend_version: str = field() | ||
billing: str = field() | ||
endpoints: list = field() | ||
links: list = field() | ||
api_tls: bool = field(default=True) | ||
_id: str = field(default="OpenEOApi") | ||
title: str = field(default="OpenEO FastApi") | ||
description: str = field(default="Implemented from the OpenEO FastAPi package.") | ||
stac_version: str = field(default="1.0.0") | ||
api_version: str = field(default="1.1.0") | ||
|
||
@abc.abstractmethod | ||
def get_well_know(self) -> models.WellKnownOpeneoGetResponse: | ||
""" """ | ||
|
||
prefix = "https" if self.api_tls else "http" | ||
|
||
Components = namedtuple( | ||
typename="Components", | ||
field_names=["scheme", "netloc", "url", "path", "query", "fragment"], | ||
) | ||
|
||
# TODO Supporting multiple versions should be possible here. But would change how we get the api version. | ||
url = urlunparse( | ||
Components( | ||
scheme=prefix, | ||
netloc=self.api_dns, | ||
query=None, | ||
path="", | ||
url=f"/openeo/{self.api_version}/", | ||
fragment=None, | ||
) | ||
) | ||
|
||
return models.WellKnownOpeneoGetResponse( | ||
versions=[ | ||
models.Version(url=url, production=False, api_version=self.api_version) | ||
] | ||
) | ||
|
||
@abc.abstractmethod | ||
def get_capabilities(self) -> models.Capabilities: | ||
""" """ | ||
return models.Capabilities( | ||
id=self._id, | ||
title=self.title, | ||
stac_version=self.stac_version, | ||
api_version=self.api_version, | ||
description=self.description, | ||
backend_version=self.backend_version, | ||
billing=self.billing, | ||
links=self.links, | ||
endpoints=self.endpoints, | ||
) | ||
|
||
@abc.abstractmethod | ||
def get_conformance(self) -> models.ConformanceGetResponse: | ||
""" """ | ||
return models.ConformanceGetResponse( | ||
conformsTo=conformance.BASIC_CONFORMANCE_CLASSES | ||
) |
Oops, something went wrong.