Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jul 2, 2024
1 parent 297f53f commit b84313d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
24 changes: 1 addition & 23 deletions tilecloud_chain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import c2cwsgiutils.setup_process
import jsonschema_validator
import psycopg2
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient, ContainerClient, ContentSettings
from c2cwsgiutils import sentry
from PIL import Image
from prometheus_client import Counter, Summary
Expand Down Expand Up @@ -381,26 +379,6 @@ def filter(self, record: Any) -> bool:
return True


def get_azure_container_client(container: str) -> ContainerClient:
"""Get the Azure blog storage client."""
if "AZURE_STORAGE_CONNECTION_STRING" in os.environ and os.environ["AZURE_STORAGE_CONNECTION_STRING"]:
return BlobServiceClient.from_connection_string(
os.environ["AZURE_STORAGE_CONNECTION_STRING"]
).get_container_client(container=container)
elif "AZURE_STORAGE_BLOB_CONTAINER_URL" in os.environ:
container_client = ContainerClient.from_container_url(os.environ["AZURE_STORAGE_BLOB_CONTAINER_URL"])
if os.environ.get("AZURE_STORAGE_BLOB_VALIDATE_CONTAINER_NAME", "true").lower() == "true":
assert (
container == container_client.container_name
), f"Container name mismatch: {container} != {container_client.container_name}"
return container_client
else:
return BlobServiceClient(
account_url=os.environ["AZURE_STORAGE_ACCOUNT_URL"],
credential=DefaultAzureCredential(),
).get_container_client(container=container)


class TileGeneration:
"""Base class of all the tile generation."""

Expand Down Expand Up @@ -824,9 +802,9 @@ def get_store(
cache_azure = cast(tilecloud_chain.configuration.CacheAzureTyped, cache)
# on Azure
cache_tilestore = AzureStorageBlobTileStore(
container=cache_azure["container"],
tilelayout=layout,
cache_control=cache_azure.get("cache_control"),
client=get_azure_container_client(cache_azure["container"]),
)
elif cache["type"] == "mbtiles":
metadata = {}
Expand Down
22 changes: 20 additions & 2 deletions tilecloud_chain/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import requests
import ruamel.yaml
from azure.core.exceptions import ResourceNotFoundError
from azure.storage.blob import ContentSettings
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient, ContainerClient, ContentSettings
from bottle import jinja2_template
from PIL import Image
from prometheus_client import Summary
Expand All @@ -31,7 +32,6 @@
TileGeneration,
add_common_options,
configuration,
get_azure_container_client,
get_queue_store,
get_tile_matrix_identifier,
)
Expand Down Expand Up @@ -104,6 +104,24 @@ def main(args: Optional[list[str]] = None, out: Optional[IO[str]] = None) -> Non
sys.exit(1)


def get_azure_container_client(container: str) -> ContainerClient:
"""Get the Azure blog storage client."""
if "AZURE_STORAGE_CONNECTION_STRING" in os.environ and os.environ["AZURE_STORAGE_CONNECTION_STRING"]:
return BlobServiceClient.from_connection_string(
os.environ["AZURE_STORAGE_CONNECTION_STRING"]
).get_container_client(container=container)
elif "AZURE_STORAGE_BLOB_CONTAINER_URL" in os.environ:
container_client = ContainerClient.from_container_url(os.environ["AZURE_STORAGE_BLOB_CONTAINER_URL"])
if os.environ.get("AZURE_STORAGE_BLOB_VALIDATE_CONTAINER_NAME", "true").lower() == "true":
assert container == container_client.container_name
return container_client
else:
return BlobServiceClient(
account_url=os.environ["AZURE_STORAGE_ACCOUNT_URL"],
credential=DefaultAzureCredential(),
).get_container_client(container=container)


def _send(
data: Union[bytes, str], path: str, mime_type: str, cache: tilecloud_chain.configuration.Cache
) -> None:
Expand Down
9 changes: 2 additions & 7 deletions tilecloud_chain/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,8 @@
import tilecloud_chain.configuration
import tilecloud_chain.security
from tilecloud import Tile, TileCoord
from tilecloud_chain import (
TileGeneration,
configuration,
controller,
get_azure_container_client,
internal_mapcache,
)
from tilecloud_chain import TileGeneration, configuration, controller, internal_mapcache
from tilecloud_chain.controller import get_azure_container_client

_LOGGER = logging.getLogger(__name__)

Expand Down

0 comments on commit b84313d

Please sign in to comment.