Skip to content

Commit fe61ffd

Browse files
authored
Add s3 compatible delivery option for Orders and Subscriptions (#1117)
1 parent 0d51904 commit fe61ffd

File tree

4 files changed

+118
-5
lines changed

4 files changed

+118
-5
lines changed

planet/order_request.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,40 @@ def oracle_cloud_storage(customer_access_key_id: str,
358358
return {'oracle_cloud_storage': cloud_details}
359359

360360

361+
def s3_compatible(endpoint: str,
362+
bucket: str,
363+
region: str,
364+
access_key_id: str,
365+
secret_access_key: str,
366+
use_path_style: bool = False,
367+
path_prefix: Optional[str] = None) -> dict:
368+
"""S3 Compatible configuration.
369+
370+
Parameters:
371+
endpoint: S3 compatible endpoint.
372+
bucket: S3-compatible bucket that will receive the order output.
373+
region: Region where the bucket lives in the s3 compatible service.
374+
access_key_id: Access key for authentication.
375+
secret_access_key: Secret key for authentication.
376+
use_path_style: Use path-style addressing with bucket name in URL
377+
(default is False).
378+
path_prefix: Custom string to prepend to the files delivered to the
379+
bucket. A slash (/) character will be treated as a "folder".
380+
Any other characters will be added as a prefix to the files.
381+
"""
382+
parameters = {
383+
'endpoint': endpoint,
384+
'bucket': bucket,
385+
'region': region,
386+
'access_key_id': access_key_id,
387+
'secret_access_key': secret_access_key,
388+
'use_path_style': use_path_style,
389+
}
390+
if path_prefix:
391+
parameters['path_prefix'] = path_prefix
392+
return {'s3_compatible': parameters}
393+
394+
361395
def _tool(name: str, parameters: dict) -> dict:
362396
"""Create the API spec representation of a tool.
363397
@@ -575,7 +609,7 @@ def band_math_tool(b1: str,
575609
For each band expression, the bandmath tool supports normal arithmetic
576610
operations and simple math operators offered in the Python numpy package.
577611
(For a list of supported mathematical functions, see
578-
[Bandmath supported numpy math routines](https://developers.planet.com/apis/orders/bandmath-numpy-routines/)).
612+
[Band Math documentation](https://docs.planet.com/develop/apis/orders/tools/#band-math)).
579613
580614
One bandmath imagery output file is produced for each product bundle, with
581615
output bands derived from the band math expressions. nodata pixels are

planet/subscription_request.py

+38-4
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def amazon_s3(aws_access_key_id: str,
399399
Parameters:
400400
aws_access_key_id: S3 account access key.
401401
aws_secret_access_key: S3 account secret key.
402-
bucket: The name of the bucket that will receive the order output.
402+
bucket: The name of the bucket that will receive the subscription output.
403403
aws_region: The region where the bucket lives in AWS.
404404
path_prefix: Path prefix for deliveries.
405405
"""
@@ -428,7 +428,7 @@ def azure_blob_storage(account: str,
428428
container: ABS container name.
429429
sas_token: Shared-Access Signature token. Token should be specified
430430
without a leading '?'.
431-
storage_endpoint_suffix: Deliver order to a sovereign cloud. The
431+
storage_endpoint_suffix: Deliver subscription to a sovereign cloud. The
432432
default is "core.windows.net".
433433
path_prefix: Path prefix for deliveries.
434434
"""
@@ -496,7 +496,7 @@ def oracle_cloud_storage(customer_access_key_id: str,
496496
Parameters:
497497
customer_access_key_id: Customer Secret Key credentials.
498498
customer_secret_key: Customer Secret Key credentials.
499-
bucket: The name of the bucket that will receive the order output.
499+
bucket: The name of the bucket that will receive the subscription output.
500500
region: The region where the bucket lives in Oracle.
501501
namespace: Object Storage namespace name.
502502
path_prefix: Path prefix for deliveries.
@@ -515,6 +515,40 @@ def oracle_cloud_storage(customer_access_key_id: str,
515515
return _delivery('oracle_cloud_storage', parameters)
516516

517517

518+
def s3_compatible(endpoint: str,
519+
bucket: str,
520+
region: str,
521+
access_key_id: str,
522+
secret_access_key: str,
523+
use_path_style: bool = False,
524+
path_prefix: Optional[str] = None) -> dict:
525+
"""S3 Compatible configuration.
526+
527+
Parameters:
528+
endpoint: S3 compatible endpoint.
529+
bucket: S3-compatible bucket that will receive the subscription output.
530+
region: Region where the bucket lives in the s3 compatible service.
531+
access_key_id: Access key for authentication.
532+
secret_access_key: Secret key for authentication.
533+
use_path_style: Use path-style addressing with bucket name in URL
534+
(default is False).
535+
path_prefix: Custom string to prepend to the files delivered to the
536+
bucket. A slash (/) character will be treated as a "folder".
537+
Any other characters will be added as a prefix to the files.
538+
"""
539+
parameters = {
540+
'endpoint': endpoint,
541+
'bucket': bucket,
542+
'region': region,
543+
'access_key_id': access_key_id,
544+
'secret_access_key': secret_access_key,
545+
'use_path_style': use_path_style,
546+
}
547+
if path_prefix:
548+
parameters['path_prefix'] = path_prefix
549+
return _delivery('s3_compatible', parameters)
550+
551+
518552
def notifications(url: str, topics: List[str]) -> dict:
519553
"""Specify a subscriptions API notification.
520554
@@ -568,7 +602,7 @@ def band_math_tool(b1: str,
568602
For each band expression, the bandmath tool supports normal arithmetic
569603
operations and simple math operators offered in the Python numpy package.
570604
(For a list of supported mathematical functions, see
571-
[Bandmath supported numpy math routines](https://developers.planet.com/apis/orders/bandmath-numpy-routines/)).
605+
[Band Math documentation](https://docs.planet.com/develop/apis/subscriptions/tools/#band-math)).
572606
573607
One bandmath imagery output file is produced for each product bundle, with
574608
output bands derived from the band math expressions. nodata pixels are

tests/unit/test_order_request.py

+23
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,29 @@ def test_oracle_cloud_storage():
262262
assert ocs_config == expected
263263

264264

265+
def test_s3_compatible():
266+
s3c_config = order_request.s3_compatible('https://test.endpoint.com',
267+
'test-bucket',
268+
'us-central-1',
269+
'test-key-id',
270+
'test-secret-key',
271+
use_path_style=True,
272+
path_prefix='test/path/prefix')
273+
274+
expected = {
275+
's3_compatible': {
276+
'endpoint': 'https://test.endpoint.com',
277+
'bucket': 'test-bucket',
278+
'region': 'us-central-1',
279+
'access_key_id': 'test-key-id',
280+
'secret_access_key': 'test-secret-key',
281+
'use_path_style': True,
282+
'path_prefix': 'test/path/prefix'
283+
}
284+
}
285+
assert s3c_config == expected
286+
287+
265288
def test__tool():
266289
test_tool = order_request._tool('bandmath', 'jsonstring')
267290
assert test_tool == {'bandmath': 'jsonstring'}

tests/unit/test_subscription_request.py

+22
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,28 @@ def test_oracle_cloud_storage_path_prefix_success():
442442
}
443443

444444

445+
def test_s3_compatible():
446+
s3c_config = subscription_request.s3_compatible(
447+
'https://test.endpoint.com',
448+
'test-bucket',
449+
'us-central-1',
450+
'test-key-id',
451+
'test-secret-key')
452+
453+
expected = {
454+
'type': 's3_compatible',
455+
'parameters': {
456+
'endpoint': 'https://test.endpoint.com',
457+
'bucket': 'test-bucket',
458+
'region': 'us-central-1',
459+
'access_key_id': 'test-key-id',
460+
'secret_access_key': 'test-secret-key',
461+
'use_path_style': False,
462+
}
463+
}
464+
assert s3c_config == expected
465+
466+
445467
def test_notifications_success():
446468
topics = ['delivery.success']
447469
notifications_config = subscription_request.notifications(url='url',

0 commit comments

Comments
 (0)