EOX GitLab Instance

Skip to content
Snippets Groups Projects
Commit bdedd34c authored by Fabian Schindler's avatar Fabian Schindler
Browse files

Adding HTTP source

parent faf9e1ed
No related branches found
No related tags found
No related merge requests found
Pipeline #22812 failed
...@@ -22,7 +22,7 @@ if TYPE_CHECKING: ...@@ -22,7 +22,7 @@ if TYPE_CHECKING:
from pystac import Item from pystac import Item
from ..exceptions import RegistrationError from ..exceptions import RegistrationError
from ..source import Source, LocalSource, S3Source, SwiftSource from ..source import HTTPSource, Source, LocalSource, S3Source, SwiftSource
from .abc import ItemBackend from .abc import ItemBackend
...@@ -206,6 +206,15 @@ class EOxServerBackend(ItemBackend): ...@@ -206,6 +206,15 @@ class EOxServerBackend(ItemBackend):
) )
storage_name = storage.name storage_name = storage.name
elif isinstance(source, HTTPSource):
storage, created_storage = backends.Storage.objects.get_or_create(
name=source.name,
url=source.endpoint_url,
storage_type="http",
# TODO: maybe add storage auth at some point
)
storage_name = storage.name
if created_storage_auth: if created_storage_auth:
logger.info("Created storage auth", source=source.name) logger.info("Created storage auth", source=source.name)
if created_storage: if created_storage:
......
...@@ -11,10 +11,12 @@ from os.path import normpath, join, isabs ...@@ -11,10 +11,12 @@ from os.path import normpath, join, isabs
import shutil import shutil
from glob import glob from glob import glob
from fnmatch import fnmatch from fnmatch import fnmatch
import requests
import structlog import structlog
from typing import TYPE_CHECKING, Optional from typing import TYPE_CHECKING, Optional
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from urllib.parse import urlparse from urllib.parse import urljoin, urlparse
import boto3 import boto3
import boto3.session import boto3.session
...@@ -369,10 +371,29 @@ class LocalSource(Source): ...@@ -369,10 +371,29 @@ class LocalSource(Source):
return {}, self._join_path(path) return {}, self._join_path(path)
class HTTPSource(Source):
def get_container_and_path(self, path: str):
return (self.endpoint_url, path)
def list_files(self, path: str, glob_pattern: list = None):
raise NotImplementedError()
def get_file(self, path: str, target_path: str):
url = urljoin(self.endpoint_url, path)
response = requests.get(url, allow_redirects=True)
with open(target_path, "w") as f:
f.write(response.content)
@abstractmethod
def get_vsi_env_and_path(self, path: str):
return {}, f"/vsicurl/{urljoin(self.endpoint_url, path)}"
SOURCE_TYPES = { SOURCE_TYPES = {
"swift": SwiftSource, "swift": SwiftSource,
"s3": S3Source, "s3": S3Source,
"local": LocalSource, "local": LocalSource,
"http": HTTPSource,
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment