-
Notifications
You must be signed in to change notification settings - Fork 15
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
Showing
14 changed files
with
39,985 additions
and
27 deletions.
There are no files selected for viewing
Empty file.
52 changes: 52 additions & 0 deletions
52
cloud_governance/common/clouds/aws/resource_explorer/resource_explorer_operations.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,52 @@ | ||
import boto3 | ||
|
||
from cloud_governance.common.logger.init_logger import logger | ||
|
||
# @Todo, This class will be used in the feature releases. | ||
# @Todo, it helps in find the resource data like tags by using search query | ||
|
||
|
||
class ResourceExplorerOperations: | ||
""" | ||
This class performs the resource explorer operations | ||
""" | ||
|
||
def __init__(self): | ||
self.__client = self.__set_client() | ||
|
||
def __set_client(self): | ||
view = self.list_views() | ||
region = 'us-east-1' | ||
if view: | ||
region = view.split(':')[3] | ||
return boto3.client('resource-explorer-2', region_name=region) | ||
|
||
def __search(self, search_string: str): | ||
try: | ||
response = self.__client.search(QueryString=search_string) | ||
return response.get('Resources', []) | ||
except Exception as err: | ||
logger.error(err) | ||
return [] | ||
|
||
def find_resource_tags(self, resource_id: str): | ||
search_results = self.__search(search_string=f'"{resource_id}"') | ||
tags = [] | ||
for resource in search_results: | ||
if resource_id in resource.get('Arn'): | ||
if resource.get('Properties'): | ||
tags = resource.get('Properties', {})[0].get('Data') | ||
return tags | ||
|
||
def list_views(self): | ||
""" | ||
This method returns list the views | ||
:return: | ||
:rtype: | ||
""" | ||
client = boto3.client('resource-explorer-2', region_name='us-east-1') | ||
views = client.list_views()['Views'] | ||
if views: | ||
return views[0] | ||
else: | ||
raise Exception("No Resource Explorer view found in Region: us-east-1, create one on Free of Charge") |
Empty file.
44 changes: 44 additions & 0 deletions
44
cloud_governance/common/clouds/aws/support/support_operations.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,44 @@ | ||
import boto3 | ||
|
||
from cloud_governance.common.logger.init_logger import logger | ||
|
||
|
||
class SupportOperations: | ||
""" | ||
This class performs the support operations | ||
""" | ||
|
||
def __init__(self): | ||
self.__client = boto3.client('support', region_name='us-east-1') | ||
|
||
def get_describe_trusted_advisor_checks(self): | ||
""" | ||
This method returns the trusted advisor check results | ||
:return: | ||
:rtype: | ||
""" | ||
try: | ||
response = self.__client.describe_trusted_advisor_checks(language='en') | ||
return response.get('checks', []) | ||
except Exception as err: | ||
logger.error(err) | ||
return [] | ||
|
||
def get_trusted_advisor_reports(self): | ||
""" | ||
This method returns the reports of the checks | ||
:return: | ||
:rtype: | ||
""" | ||
result = {} | ||
try: | ||
advisor_checks_list = self.get_describe_trusted_advisor_checks() | ||
for check in advisor_checks_list: | ||
response = self.__client.describe_trusted_advisor_check_result(checkId=check.get('id')) | ||
result.setdefault(check.get('category'), {}).setdefault(check.get('id'), { | ||
'metadata': check, | ||
'reports': response.get('result', []) | ||
}) | ||
except Exception as err: | ||
logger.err(err) | ||
return result |
28 changes: 28 additions & 0 deletions
28
cloud_governance/common/clouds/aws/utils/common_methods.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,28 @@ | ||
def get_tag_value_from_tags(tags: list, tag_name: str, cast_type: str = 'str', | ||
default_value: any = '') -> any: | ||
""" | ||
This method return the tag value inputted by tag_name | ||
:param tags: | ||
:type tags: | ||
:param tag_name: | ||
:type tag_name: | ||
:param cast_type: | ||
:type cast_type: | ||
:param default_value: | ||
:type default_value: | ||
:return: | ||
:rtype: | ||
""" | ||
if tags: | ||
for tag in tags: | ||
key = tag.get('Key').lower().replace("_", '').replace("-", '').strip() | ||
if key == tag_name.lower(): | ||
if cast_type: | ||
if cast_type == 'int': | ||
return int(tag.get('Value').split()[0].strip()) | ||
elif cast_type == 'float': | ||
return float(tag.get('Value').strip()) | ||
else: | ||
return str(tag.get('Value').strip()) | ||
return tag.get('Value').strip() | ||
return default_value |
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
Oops, something went wrong.