-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support for tag options (#312)
* adding support for tag options
- Loading branch information
1 parent
72ec67d
commit f44b9d5
Showing
13 changed files
with
261 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
|
||
CACHE_INVALIDATOR = "SCT_CACHE_INVALIDATOR" | ||
|
||
AWS_URL_SUFFIX = "AWS_URL_SUFFIX" | ||
AWS_URL_SUFFIX = "AWS_URL_SUFFIX" |
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
48 changes: 48 additions & 0 deletions
48
servicecatalog_factory/workflow/portfolios/associate_tag_option_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,48 @@ | ||
# Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import luigi | ||
|
||
from servicecatalog_factory.workflow.tasks import FactoryTask | ||
|
||
|
||
class AssociateTagOptionTask(FactoryTask): | ||
region = luigi.Parameter() | ||
|
||
create_product_task_ref = luigi.Parameter() | ||
create_portfolio_task_ref = luigi.Parameter() | ||
create_tag_option_task_ref = luigi.Parameter() | ||
|
||
def params_for_results_display(self): | ||
return { | ||
"region": self.region, | ||
"create_product_task_ref": self.create_product_task_ref, | ||
"create_portfolio_task_ref": self.create_portfolio_task_ref, | ||
"create_tag_option_task_ref": self.create_tag_option_task_ref, | ||
} | ||
|
||
def run(self): | ||
with self.regional_client("servicecatalog") as servicecatalog: | ||
if self.create_portfolio_task_ref: | ||
portfolio_details = self.get_output_from_reference_dependency( | ||
self.create_portfolio_task_ref | ||
) | ||
resource_id = portfolio_details.get("Id") | ||
elif self.create_product_task_ref: | ||
product_details = self.get_output_from_reference_dependency( | ||
self.create_product_task_ref | ||
) | ||
resource_id = product_details.get("ProductId") | ||
else: | ||
raise Exception("Did not find a resource to associate with") | ||
|
||
tag_option_details = self.get_output_from_reference_dependency( | ||
self.create_tag_option_task_ref | ||
) | ||
|
||
try: | ||
servicecatalog.associate_tag_option_with_resource( | ||
ResourceId=resource_id, TagOptionId=tag_option_details.get("Id"), | ||
) | ||
except servicecatalog.exceptions.DuplicateResourceException: | ||
pass | ||
self.write_output_raw("{}") |
37 changes: 37 additions & 0 deletions
37
servicecatalog_factory/workflow/portfolios/create_tag_option_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,37 @@ | ||
# Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import luigi | ||
|
||
from servicecatalog_factory.workflow.tasks import FactoryTask | ||
|
||
|
||
class CreateTagOptionTask(FactoryTask): | ||
region = luigi.Parameter() | ||
tag_option_key = luigi.Parameter() | ||
tag_option_value = luigi.Parameter() | ||
|
||
def params_for_results_display(self): | ||
return { | ||
"region": self.region, | ||
"tag_option_key": self.tag_option_key, | ||
"tag_option_value": self.tag_option_value, | ||
} | ||
|
||
def run(self): | ||
with self.regional_client("servicecatalog") as servicecatalog: | ||
try: | ||
result = servicecatalog.create_tag_option( | ||
Key=self.tag_option_key, Value=self.tag_option_value | ||
).get("TagOptionDetail") | ||
except servicecatalog.exceptions.DuplicateResourceException: | ||
result = servicecatalog.list_tag_options( | ||
Filters={ | ||
"Key": self.tag_option_key, | ||
"Value": self.tag_option_value, | ||
}, | ||
PageSize=2, | ||
).get("TagOptionDetails") | ||
assert len(result) == 1 | ||
result = result[0] | ||
|
||
self.write_output(result) |
Oops, something went wrong.