-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c074e50
commit 7b08c6c
Showing
10 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
servicecatalog_puppet/commands/task_reference_helpers/generators/s3_parameter_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from servicecatalog_puppet import constants, task_reference_constants | ||
|
||
|
||
def s3_parameter_handler( | ||
all_tasks, home_region, new_tasks, parameter_details, puppet_account_id, task | ||
): | ||
if parameter_details.get("s3"): | ||
s3_parameter_details = parameter_details.get("s3") | ||
key = s3_parameter_details.get("key") | ||
jmespath = s3_parameter_details.get("jmespath") | ||
|
||
task_account_id = task.get("account_id") | ||
task_region = task.get("region") | ||
|
||
key = ( | ||
key.replace("${AWS::Region}", task_region) | ||
.replace("${AWS::AccountId}", task_account_id) | ||
.replace("${AWS::PuppetAccountId}", puppet_account_id) | ||
) | ||
jmespath = ( | ||
jmespath.replace("${AWS::Region}", task_region) | ||
.replace("${AWS::AccountId}", task_account_id) | ||
.replace("${AWS::PuppetAccountId}", puppet_account_id) | ||
) | ||
|
||
parameter_task_reference = f"{constants.S3_PARAMETERS}-{key}-{jmespath}" | ||
|
||
if all_tasks.get(parameter_task_reference): | ||
s3_task_params = all_tasks.get(parameter_task_reference) | ||
else: | ||
s3_task_params = { | ||
"task_reference": parameter_task_reference, | ||
"account_id": puppet_account_id, | ||
"region": home_region, | ||
"key": key, | ||
"jmespath": jmespath, | ||
task_reference_constants.MANIFEST_SECTION_NAMES: dict(), | ||
task_reference_constants.MANIFEST_ITEM_NAMES: dict(), | ||
task_reference_constants.MANIFEST_ACCOUNT_IDS: dict(), | ||
"dependencies": [], | ||
"dependencies_by_reference": [], | ||
"execution": constants.EXECUTION_MODE_HUB, | ||
"section_name": constants.S3_PARAMETERS, | ||
} | ||
new_tasks[parameter_task_reference] = s3_task_params | ||
|
||
s3_task_params[task_reference_constants.MANIFEST_SECTION_NAMES].update( | ||
**task.get(task_reference_constants.MANIFEST_SECTION_NAMES) | ||
) | ||
s3_task_params[task_reference_constants.MANIFEST_ITEM_NAMES].update( | ||
**task.get(task_reference_constants.MANIFEST_ITEM_NAMES) | ||
) | ||
s3_task_params[task_reference_constants.MANIFEST_ACCOUNT_IDS].update( | ||
**task.get(task_reference_constants.MANIFEST_ACCOUNT_IDS) | ||
) | ||
|
||
task["dependencies_by_reference"].append(parameter_task_reference) | ||
|
||
if not task.get("s3_parameters_tasks_references"): | ||
task["s3_parameters_tasks_references"] = dict() | ||
|
||
parameter_name = ( | ||
str(s3_parameter_details.get("name")) | ||
.replace("${AWS::Region}", task_region) | ||
.replace("${AWS::AccountId}", task_account_id) | ||
.replace("${AWS::PuppetAccountId}", puppet_account_id) | ||
) | ||
|
||
task["s3_parameters_tasks_references"][ | ||
parameter_name | ||
] = parameter_task_reference |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
servicecatalog_puppet/workflow/s3/get_s3_parameter_task.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import json | ||
from copy import deepcopy | ||
|
||
import luigi | ||
|
||
from servicecatalog_puppet import constants | ||
from servicecatalog_puppet.workflow.dependencies import tasks | ||
import jmespath | ||
|
||
|
||
class GetS3ParameterTask(tasks.TaskWithReference): | ||
account_id = luigi.Parameter() | ||
key = luigi.Parameter() | ||
jmespath_location = luigi.Parameter() | ||
region = luigi.Parameter() | ||
cachable_level = constants.CACHE_LEVEL_RUN | ||
|
||
def params_for_results_display(self): | ||
return { | ||
"task_reference": self.task_reference, | ||
"account_id": self.account_id, | ||
"region": self.region, | ||
"key": self.key, | ||
"jmespath_location": self.jmespath_location, | ||
} | ||
|
||
def run(self): | ||
with self.spoke_regional_client("s3") as s3: | ||
object = ( | ||
s3.get_object( | ||
Bucket=f"sc-puppet-parameters-{self.account_id}", Key=self.key | ||
) | ||
.get("Body") | ||
.read() | ||
) | ||
result = jmespath.search(self.jmespath_location, json.loads(object)) | ||
self.write_output(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters