Skip to content

Commit

Permalink
Merge pull request #912 from koordinates/store-region
Browse files Browse the repository at this point in the history
Store S3 region along with S3 URL
  • Loading branch information
olsen232 authored Oct 3, 2023
2 parents 0e556f3 + 522b3d7 commit 544fb98
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion kart/byod/point_cloud_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from kart.cli_util import StringFromFile, MutexOption, KartCommand
from kart.point_cloud.import_ import PointCloudImporter
from kart.point_cloud.metadata_util import extract_pc_tile_metadata
from kart.s3_util import get_hash_and_size_of_s3_object, fetch_from_s3
from kart.s3_util import get_hash_and_size_of_s3_object, fetch_from_s3, get_region_name


L = logging.getLogger(__name__)
Expand Down Expand Up @@ -128,5 +128,6 @@ def extract_tile_metadata(self, tile_location):
)
tmp_downloaded_tile.unlink()
# TODO - format still not definite, we might not put the whole URL in here.
result["tile"]["region"] = get_region_name()
result["tile"]["url"] = tile_location
return result
3 changes: 2 additions & 1 deletion kart/byod/raster_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from kart.cli_util import StringFromFile, MutexOption, KartCommand
from kart.raster.import_ import RasterImporter
from kart.raster.metadata_util import extract_raster_tile_metadata
from kart.s3_util import get_hash_and_size_of_s3_object, fetch_from_s3
from kart.s3_util import get_hash_and_size_of_s3_object, get_region_name


L = logging.getLogger(__name__)
Expand Down Expand Up @@ -123,5 +123,6 @@ def extract_tile_metadata(self, tile_location):
oid_and_size = get_hash_and_size_of_s3_object(tile_location)
result = extract_raster_tile_metadata(tile_location, oid_and_size=oid_and_size)
# TODO - format still not definite, we might not put the whole URL in here.
result["tile"]["region"] = get_region_name()
result["tile"]["url"] = tile_location
return result
5 changes: 5 additions & 0 deletions kart/s3_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def get_s3_resource():
return resource


@functools.lru_cache(maxsize=1)
def get_region_name():
return get_s3_client().meta.config.region_name


@functools.lru_cache()
def get_bucket(name):
return get_s3_resource().Bucket(name)
Expand Down
4 changes: 4 additions & 0 deletions tests/byod/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_byod_point_cloud_import(
{"name": "Blue", "dataType": "integer", "size": 16},
]

tile_region = auckland["tile"][0]["+"]["region"]
tile_0_url = os.path.join(
s3_test_data_point_cloud.split("*")[0], "auckland_0_0.laz"
)
Expand All @@ -62,6 +63,7 @@ def test_byod_point_cloud_import(
"format": "laz-1.2",
"nativeExtent": "1754987.85,1755987.77,5920219.76,5921219.64,-1.66,99.83",
"pointCount": 4231,
"region": tile_region,
"url": tile_0_url,
"oid": "sha256:6b980ce4d7f4978afd3b01e39670e2071a792fba441aca45be69be81cb48b08c",
"size": 51489,
Expand Down Expand Up @@ -114,6 +116,7 @@ def test_byod_raster_import(
"5": "Gully risk",
}

tile_region = erorisk_si["tile"][0]["+"]["region"]
tile_url = os.path.join(
s3_test_data_raster.split("*")[0], "erorisk_silcdb4.tif"
)
Expand All @@ -124,6 +127,7 @@ def test_byod_raster_import(
"dimensions": "762x790",
"format": "geotiff/cog",
"nativeExtent": "POLYGON((1573869.73 5155224.347,1573869.73 5143379.674,1585294.591 5143379.674,1585294.591 5155224.347,1573869.73 5155224.347))",
"region": tile_region,
"url": tile_url,
"oid": "sha256:c4bbea4d7cfd54f4cdbca887a1b358a81710e820a6aed97cdf3337fd3e14f5aa",
"size": 604652,
Expand Down

0 comments on commit 544fb98

Please sign in to comment.