Skip to content

Commit 98c9a8b

Browse files
committed
fixed test merge conflicts
2 parents 1e1b267 + d7da221 commit 98c9a8b

13 files changed

Lines changed: 135 additions & 44 deletions

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Removed
1313
### Fixed
1414
### Security
15+
- [issues/151](https://github.com/podaac/bignbit/issues/151): Added ExpectedBucketOwner parameter when making S3 requests.
16+
17+
## [0.7.2]
18+
### Added
19+
### Changed
20+
- increased timeout for "Handle BIG Result" lambda
21+
### Deprecated
22+
### Removed
23+
### Fixed
24+
- [issues/168](https://github.com/podaac/bignbit/issues/164): Added `reprojection` keyword to allow overriding default behavior for EPSG:4326
25+
### Security
1526

1627
## [0.7.1]
1728
### Added

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ The contents of the configuration file should be a valid json object with the fo
175175
| singleDayNumber | string | [OPTIONAL] (Default: "") If using the "dataDayStrategy" keyword, all granules in this dataset will use the day of year specified in this keyword. ex: "001" for January 1st |
176176
| subdaily | boolean | [OPTIONAL] (Default: False) Set to true if granules contain subdaily data. This will send `DataDateTime` metadata to GIBS as described in the GIBS ICD |
177177
| outputCrs | list(string) | [OPTIONAL] (Default: ["EPSG:4326"]) Specifies a list of output projections or coordinate reference systems for which to produce browse images. Applies to all variables in granule. GIBS-compatible values are EPSG:4326, EPSG:3413, or EPSG:3031 |
178+
| reprojection | boolean | [OPTIONAL] (Default: False) Set to true to force Harmony jobs to use the outputCrs parameter. If the service (chain) used by the job does not support reprojection, then the job will fail. |
178179
| concept_id | string | [OPTIONAL] (Default: "") Overrides the concept id derived from the granule metadata with this value. ex: "C1996881146-POCLOUD" |
179180

180181
A few example configurations can be found in the [podaac/bignbit-config](https://github.com/podaac/bignbit-config) repository. NOTE: some of the example configurations have other options specified (e.g. `variables`, `latVar`, `lonVar`, etc...) that are no longer supported by this module. The table above are the attributes that are still in use.

bignbit/get_dataset_configuration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from cumulus_logger import CumulusLogger
1010
from cumulus_process import Process
1111

12+
from bignbit import utils
13+
1214
CUMULUS_LOGGER = CumulusLogger('get_dataset_configuration')
1315

1416

@@ -69,7 +71,8 @@ def get_collection_config(config_bucket_name: str, config_key_name: str) -> dict
6971
s3_client = boto3.client('s3')
7072

7173
try:
72-
object_result = s3_client.get_object(Bucket=config_bucket_name, Key=config_key_name)
74+
object_result = s3_client.get_object(Bucket=config_bucket_name, Key=config_key_name,
75+
ExpectedBucketOwner=utils.get_aws_account_id())
7376
except s3_client.exceptions.NoSuchKey as ex:
7477
raise MissingDatasetConfiguration(
7578
f"Dataset configuration not found s3://{config_bucket_name}/{config_key_name}") from ex

bignbit/handle_big_result.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ def process_harmony_results(harmony_job: dict[str, str], cmr_env: str) -> list[d
216216
for url in result_urls:
217217
bucket, key = urlparse(url).netloc, urlparse(url).path.lstrip('/')
218218

219-
response = s3_client.get_object(Bucket=bucket, Key=key)
219+
response = s3_client.get_object(Bucket=bucket, Key=key,
220+
ExpectedBucketOwner=utils.get_aws_account_id())
220221
md5_hash = hashlib.new('md5')
221222
for chunk in response['Body'].iter_chunks(chunk_size=100 * 1024 * 1024): # 100 MB chunk size
222223
md5_hash.update(chunk)

bignbit/send_to_gitc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from cumulus_logger import CumulusLogger
1010
from cumulus_process import Process
1111

12+
from bignbit import utils
13+
1214
CUMULUS_LOGGER = CumulusLogger('send_to_gitc')
1315

1416
GIBS_REGION_ENV_NAME = "GIBS_REGION"
@@ -72,7 +74,8 @@ def read_cnm(cnm_bucket: str, cnm_key: str) -> str:
7274
Key within the bucket pointing to CNM JSON
7375
"""
7476
s3_client = boto3.client('s3')
75-
response = s3_client.get_object(Bucket=cnm_bucket, Key=cnm_key)
77+
response = s3_client.get_object(Bucket=cnm_bucket, Key=cnm_key,
78+
ExpectedBucketOwner=utils.get_aws_account_id())
7679
return response['Body'].read().decode('utf-8')
7780

7881

bignbit/submit_harmony_job.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def generate_harmony_request(collection_concept_id, granule_concept_id, variable
111111
# equirectangular projection through the reproject service.
112112
# Avoids unnecessary processing and errors for some collections
113113
# that do not support reprojection.
114-
if output_crs.upper() != 'EPSG:4326':
114+
if output_crs.upper() != 'EPSG:4326' or big_config['config'].get('reprojection', False):
115115
kwargs['crs'] = output_crs
116116
# Use the scaleExtent either from datasetConfig or use the
117117
# default values from GIBS
@@ -152,7 +152,7 @@ def lambda_handler(event, context):
152152
}
153153

154154
logging_level = os.environ.get('LOGGING_LEVEL', 'info')
155-
CUMULUS_LOGGER.logger.level = levels.get(logging_level, 'info')
155+
CUMULUS_LOGGER.logger.setLevel(levels.get(logging_level, 'info'))
156156
CUMULUS_LOGGER.setMetadata(event, context)
157157

158158
return CMA.cumulus_handler(event, context=context)

bignbit/utils.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,27 @@
1616
ED_USER = ED_PASS = None
1717
EDL_USER_TOKEN: dict[str, str] = {}
1818
HARMONY_CLIENT: Client | None = None
19+
AWS_ACCOUNT_ID: str | None = None
1920

2021
HARMONY_SHOULD_VALIDATE_AUTH = os.environ.get('HARMONY_SHOULD_VALIDATE_AUTH', default='False').upper() == 'TRUE'
2122

2223

24+
def get_aws_account_id() -> str:
25+
"""
26+
Get and cache the current AWS account ID via STS.
27+
28+
Returns
29+
-------
30+
str
31+
The AWS account ID for the current caller identity
32+
"""
33+
global AWS_ACCOUNT_ID # pylint: disable=W0603
34+
if not AWS_ACCOUNT_ID:
35+
sts_client = boto3.client('sts')
36+
AWS_ACCOUNT_ID = sts_client.get_caller_identity()['Account']
37+
return AWS_ACCOUNT_ID
38+
39+
2340
def get_edl_creds() -> tuple[str, str]:
2441
"""
2542
Get EDL username and password from SSM.
@@ -216,7 +233,8 @@ def upload_string_as_object(bucket_name: str, key_name: str, object_content: str
216233
s3_client.put_object(
217234
Body=object_content.encode(),
218235
Bucket=bucket_name,
219-
Key=key_name
236+
Key=key_name,
237+
ExpectedBucketOwner=get_aws_account_id()
220238
)
221239
return f's3://{bucket_name}/{key_name}'
222240

@@ -236,6 +254,7 @@ def upload_object(
236254
Key=key,
237255
Body=body_content,
238256
ContentType=content_type,
257+
ExpectedBucketOwner=get_aws_account_id()
239258
)
240259
return f's3://{bucket}/{key}'
241260

@@ -259,7 +278,8 @@ def upload_to_s3(filepath: pathlib.Path, bucket_name: str, object_key: str):
259278
s3 uri of new object
260279
"""
261280
s3_client = boto3.client('s3')
262-
s3_client.upload_file(str(filepath), bucket_name, object_key)
281+
s3_client.upload_file(str(filepath), bucket_name, object_key,
282+
ExtraArgs={'ExpectedBucketOwner': get_aws_account_id()})
263283

264284
return f's3://{bucket_name}/{object_key}'
265285

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "bignbit"
3-
version = "0.8.0a4"
3+
version = "0.8.0a7"
44
description = "Browse image generation and transfer"
55
authors = ["PO.DAAC <podaac@jpl.nasa.gov>"]
66
license = "Apache 2.0"

scripts/create_dataset_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,15 @@ def cli() -> argparse.Namespace:
399399
'EPSG:4326, EPSG:3413, or EPSG:3031'
400400
)
401401
)
402+
parser.add_argument(
403+
'--reprojection',
404+
action='store_true',
405+
help=(
406+
'Set to true to force reprojection for all granules. This will send the `outputCrs` '
407+
'parameter in Harmony API calls unconditionally. Warning: if the Harmony service used '
408+
'to generate browse images does not support reprojection, jobs will fail.'
409+
)
410+
)
402411
parser.add_argument(
403412
'--s3Destination',
404413
type=str,

terraform/lambda_functions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ resource "aws_lambda_function" "handle_big_result" {
244244
}
245245
function_name = local.handle_big_result_function_name
246246
role = aws_iam_role.bignbit_lambda_role.arn
247-
timeout = 180
248-
memory_size = 512
247+
timeout = 300
248+
memory_size = 1024
249249

250250
environment {
251251
variables = {

0 commit comments

Comments
 (0)