From e4b2902bcfe916f7ef4df180bc95cb6701958548 Mon Sep 17 00:00:00 2001 From: Iakov Gan Date: Sat, 30 Dec 2023 14:44:13 +0100 Subject: [PATCH] lint --- cid/common.py | 4 ++-- cid/export.py | 7 +++---- cid/helpers/cur.py | 21 ++++++++------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/cid/common.py b/cid/common.py index 28056d3d..e8d789bc 100644 --- a/cid/common.py +++ b/cid/common.py @@ -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: @@ -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 """ diff --git a/cid/export.py b/cid/export.py index bdd3bd47..c41cb5b9 100644 --- a/cid/export.py +++ b/cid/export.py @@ -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 """ @@ -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 = [] @@ -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() diff --git a/cid/helpers/cur.py b/cid/helpers/cur.py index 856570ca..3f75c9aa 100644 --- a/cid/helpers/cur.py +++ b/cid/helpers/cur.py @@ -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: @@ -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() @@ -182,7 +180,7 @@ 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', @@ -190,10 +188,8 @@ def metadata(self) -> dict: choices=choices + [''], ) if answer == '': - raise CidCritical('') - 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 @@ -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_')] -