Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iakov-aws committed Nov 14, 2023
1 parent 647f612 commit ee9dc4b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions cid/helpers/account_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def cur(self, client) -> CUR:

@property
def accounts(self) -> dict:
""" Get Accoutns with the right mapping """
""" Get Accounts with the right mapping """
if self._accounts:
# Required keys mapping, used in renaming below
key_mapping = {
Expand All @@ -106,7 +106,7 @@ def accounts(self) -> dict:

@lru_cache(1000)
def detect_metadata_table(self, name):
""" detect metatable with the list of accounts """
""" detect meta table with the list of accounts """
cid_print('Autodiscovering metadata table')

# FIXME: This will only work for current Athena Database. We might want to check optimization_data base as well
Expand Down Expand Up @@ -148,11 +148,13 @@ def create(self, name) -> bool:

# Query path
view_definition = self.athena._resources.get('views').get(name, {})
view_file = view_definition.get('File')
template = Template(resource_string(
package_or_requirement='cid.builtin.core',
resource_name=f'data/queries/{view_file}',
).decode('utf-8'))
if view_definition.get('File'):
view_file = view_definition.get('File')
template = Template(resource_string(view_definition.get('providedBy'), f'data/queries/{view_file}').decode('utf-8'))
elif view_definition.get('data'):
template = Template(str(view_definition.get('data')))
else:
raise CidError(f'{name} definition does not contain File or data: {view_definition}')

# Fill in TPLs
columns_tpl = {
Expand Down Expand Up @@ -189,7 +191,7 @@ def get_dummy_account_mapping_sql(self, name) -> list:
return compiled_query

def get_organization_accounts(self) -> list:
""" Retreive AWS Organization account """
""" Retrieve AWS Organization account """
# Init clients
accounts = []
orgs = self.session.client('organizations')
Expand All @@ -212,14 +214,14 @@ def get_organization_accounts(self) -> list:
return accounts

def check_file_exists(self, file_path) -> bool:
""" Checks if the givven file exists """
""" Checks if the given file exists """
# Set base paths
abs_path = Path().absolute()

return Path.is_file(abs_path / file_path)

def get_csv_accounts(self, file_path) -> list:
""" Retreive accounts from CSV file """
""" Retrieve accounts from CSV file """
accounts = [
{str(k).lower().replace(" ", "_"): str(v) for k, v in row.items()}
for row in read_csv(file_path)
Expand All @@ -231,7 +233,7 @@ def get_csv_accounts(self, file_path) -> list:
def select_metadata_collection_method(self) -> str:
""" Selects the method to collect metadata """
logger.info('Metadata source selection')
# Ask user which method to use to retreive account list
# Ask user which method to use to retrieve account list
account_map_sources = {
'Dummy (CUR account data, no names)': 'dummy',
'AWS Organizations (one time account listing)': 'organization',
Expand Down

0 comments on commit ee9dc4b

Please sign in to comment.