Skip to content

Add path_prefix to Subscriptions API request builder #1018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions planet/subscription_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,16 @@ def _delivery(type: str, parameters: dict) -> dict:
def amazon_s3(aws_access_key_id: str,
aws_secret_access_key: str,
bucket: str,
aws_region: str) -> dict:
aws_region: str,
path_prefix: Optional[str] = None) -> dict:
"""Delivery to Amazon S3.

Parameters:
aws_access_key_id: S3 account access key.
aws_secret_access_key: S3 account secret key.
bucket: The name of the bucket that will receive the order output.
aws_region: The region where the bucket lives in AWS.
path_prefix: Path prefix for deliveries.
"""
parameters = {
'aws_access_key_id': aws_access_key_id,
Expand All @@ -387,13 +389,17 @@ def amazon_s3(aws_access_key_id: str,
'aws_region': aws_region,
}

if path_prefix:
parameters['path_prefix'] = path_prefix

return _delivery('amazon_s3', parameters)


def azure_blob_storage(account: str,
container: str,
sas_token: str,
storage_endpoint_suffix: Optional[str] = None) -> dict:
storage_endpoint_suffix: Optional[str] = None,
path_prefix: Optional[str] = None) -> dict:
"""Delivery to Azure Blob Storage.

Parameters:
Expand All @@ -403,6 +409,7 @@ def azure_blob_storage(account: str,
without a leading '?'.
storage_endpoint_suffix: Deliver order to a sovereign cloud. The
default is "core.windows.net".
path_prefix: Path prefix for deliveries.
"""
parameters = {
'account': account,
Expand All @@ -413,29 +420,39 @@ def azure_blob_storage(account: str,
if storage_endpoint_suffix:
parameters['storage_endpoint_suffix'] = storage_endpoint_suffix

if path_prefix:
parameters['path_prefix'] = path_prefix

return _delivery('azure_blob_storage', parameters)


def google_cloud_storage(credentials: str, bucket: str) -> dict:
def google_cloud_storage(credentials: str,
bucket: str,
path_prefix: Optional[str] = None) -> dict:
"""Delivery to Google Cloud Storage.

Parameters:
credentials: JSON-string of service account for bucket.
bucket: GCS bucket name.
path_prefix: Path prefix for deliveries.
"""
parameters = {
'bucket': bucket,
'credentials': credentials,
}

if path_prefix:
parameters['path_prefix'] = path_prefix

return _delivery('google_cloud_storage', parameters)


def oracle_cloud_storage(customer_access_key_id: str,
customer_secret_key: str,
bucket: str,
region: str,
namespace: str) -> dict:
namespace: str,
path_prefix: Optional[str] = None) -> dict:
"""Delivery to Oracle Cloud Storage.

Parameters:
Expand All @@ -444,6 +461,7 @@ def oracle_cloud_storage(customer_access_key_id: str,
bucket: The name of the bucket that will receive the order output.
region: The region where the bucket lives in Oracle.
namespace: Object Storage namespace name.
path_prefix: Path prefix for deliveries.
"""
parameters = {
'customer_access_key_id': customer_access_key_id,
Expand All @@ -453,6 +471,9 @@ def oracle_cloud_storage(customer_access_key_id: str,
'namespace': namespace
}

if path_prefix:
parameters['path_prefix'] = path_prefix

return _delivery('oracle_cloud_storage', parameters)


Expand Down
74 changes: 74 additions & 0 deletions tests/unit/test_subscription_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ def test_amazon_s3_success():
}


def test_amazon_s3_path_prefix_success():
res = subscription_request.amazon_s3(aws_access_key_id='keyid',
aws_secret_access_key='accesskey',
bucket='bucket',
aws_region='region',
path_prefix="prefix")

assert res == {
"type": "amazon_s3",
"parameters": {
"aws_access_key_id": "keyid",
"aws_secret_access_key": "accesskey",
"bucket": "bucket",
"aws_region": "region",
"path_prefix": "prefix"
}
}


def test_azure_blob_storage_success():
res = subscription_request.azure_blob_storage(
account='act',
Expand All @@ -215,6 +234,26 @@ def test_azure_blob_storage_success():
}


def test_azure_blob_storage_path_prefix_success():
res = subscription_request.azure_blob_storage(
account='act',
container='container',
sas_token='sastoken',
storage_endpoint_suffix='suffix',
path_prefix="prefix")

assert res == {
"type": "azure_blob_storage",
"parameters": {
"account": "act",
"container": "container",
"sas_token": "sastoken",
"storage_endpoint_suffix": "suffix",
"path_prefix": "prefix"
}
}


def test_google_cloud_storage_success():
res = subscription_request.google_cloud_storage(credentials='cred',
bucket='bucket')
Expand All @@ -227,6 +266,19 @@ def test_google_cloud_storage_success():
}


def test_google_cloud_storage_path_prefix_success():
res = subscription_request.google_cloud_storage(credentials='cred',
bucket='bucket',
path_prefix="prefix")

assert res == {
"type": "google_cloud_storage",
"parameters": {
"bucket": "bucket", "credentials": "cred", "path_prefix": "prefix"
}
}


def test_oracle_cloud_storage_success():
res = subscription_request.oracle_cloud_storage(
customer_access_key_id='keyid',
Expand All @@ -247,6 +299,28 @@ def test_oracle_cloud_storage_success():
}


def test_oracle_cloud_storage_path_prefix_success():
res = subscription_request.oracle_cloud_storage(
customer_access_key_id='keyid',
customer_secret_key='secretkey',
bucket='bucket',
region='region',
namespace='namespace',
path_prefix="prefix")

assert res == {
"type": "oracle_cloud_storage",
"parameters": {
"customer_access_key_id": "keyid",
"customer_secret_key": "secretkey",
"bucket": "bucket",
"region": "region",
"namespace": "namespace",
"path_prefix": "prefix"
}
}


def test_notifications_success():
topics = ['delivery.success']
notifications_config = subscription_request.notifications(url='url',
Expand Down