Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
iakov-aws committed Dec 30, 2023
1 parent 30f623b commit e4b2902
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cid/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def cur(self) -> CUR:
if not self._clients.get('cur'):
while True:
try:
_cur = CUR(self.athena, self.glue, self.s3)
_cur = CUR(self.athena, self.glue)
print('Checking if CUR is enabled and available...')

if not _cur.metadata:
Expand Down Expand Up @@ -256,7 +256,7 @@ def get_definition(self, type: str, name: str=None, id: str=None, noparams: bool

@command
def export(self, **kwargs):
export_analysis(self.qs, self.athena, glue=self.glue, s3=self.s3)
export_analysis(self.qs, self.athena, glue=self.glue)

def track(self, action, dashboard_id):
""" Send dashboard_id and account_id to adoption tracker """
Expand Down
7 changes: 3 additions & 4 deletions cid/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def choose_analysis(qs):
return choices[choice]['AnalysisId']


def export_analysis(qs, athena, glue, s3):
def export_analysis(qs, athena, glue):
""" Export analysis to yaml resource File
"""

Expand Down Expand Up @@ -98,7 +98,7 @@ def export_analysis(qs, athena, glue, s3):
resources['crawlers'] = {}


cur_helper = CUR(athena=athena, glue=glue, s3=s3)
cur_helper = CUR(athena=athena, glue=glue)

resources_datasets = []

Expand Down Expand Up @@ -435,8 +435,7 @@ def quick_try():
qs = QuickSight(boto3.session.Session(), identity)
athena = Athena(boto3.session.Session())
glue = Glue(boto3.session.Session())
s3 = S3(boto3.session.Session())
export_analysis(qs, athena, glue, s3)
export_analysis(qs, athena, glue)

if __name__ == "__main__": # for testing
quick_try()
21 changes: 8 additions & 13 deletions cid/helpers/cur.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ class CUR():
'savings_plan_offering_type',
'savings_plan_payment_option'
]
_table_name = None
_metadata = None

def __init__(self, athena, glue, s3):
def __init__(self, athena, glue):
self.athena = athena
self.glue = glue
self.s3 = s3

@property
def table_name(self) -> str:
Expand Down Expand Up @@ -161,14 +159,14 @@ def metadata(self) -> dict:
return self._metadata

if get_parameters().get('cur-table-name'):
self._table_name = get_parameters().get('cur-table-name')
table_name = get_parameters().get('cur-table-name')
try:
self._metadata = self.athena.get_table_metadata(self._table_name)
self._metadata = self.athena.get_table_metadata(table_name)
except self.athena.client.exceptions.ResourceNotFoundException as exc:
raise CidCritical('Provided cur-table-name "{self._table_name}" is not found. Please make sure the table exists.') from exc
raise CidCritical(f'Provided cur-table-name "{table_name}" is not found. Please make sure the table exists.') from exc
res, message = self.table_is_cur(table=self._metadata, return_reason=True)
if not res:
raise CidCritical(f'Table {self._table_name} does not look like CUR. {message}')
raise CidCritical(f'Table {table_name} does not look like CUR. {message}')
else:
# Look all tables and filter ones with CUR fields
all_tables = self.athena.list_table_metadata()
Expand All @@ -182,18 +180,16 @@ def metadata(self) -> dict:
if not cur_tables:
raise CidCritical(f'CUR table not found. (scanned {len(all_tables)} tables in Athena Database {self.athena.DatabaseName} in {self.athena.region}). But none has required fields: {self.cur_minimal_required_columns}.')

choices = sorted([v.get('Name') for v in cur_tables], reverse=True)
choices = sorted([tab.get('Name') for tab in cur_tables], reverse=True)

answer = get_parameter(
param_name='cur-table-name',
message="Please select CUR",
choices=choices + ['<CREATE CUR TABLE AND CRAWLER>'],
)
if answer == '<CREATE CUR TABLE AND CRAWLER>':
raise CidCritical('<CREATE CUR TABLE AND CRAWLER>')
else:
self._tableName = answer
self._metadata = self.athena.get_table_metadata(self._tableName)
raise CidCritical('CUR creation was requested') # to be captured in common.py
self._metadata = self.athena.get_table_metadata(answer)
return self._metadata

@property
Expand All @@ -205,4 +201,3 @@ def fields(self) -> list:
def tag_and_cost_category_fields(self) -> list:
""" Returns all tags and cost category fields. """
return [field for field in self.fields if field.startswith('resource_tags_user_') or field.startswith('cost_category_')]

0 comments on commit e4b2902

Please sign in to comment.