Skip to content

Commit 476dc22

Browse files
authored
Dashboard tag fix (#1351)
* add fix for incorrect version * refactor initial version for readability
1 parent 0e8f9dc commit 476dc22

File tree

5 files changed

+64
-23
lines changed

5 files changed

+64
-23
lines changed

cid/helpers/quicksight/dashboard.py

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
from cid.utils import cid_print, get_yesno_parameter
1212
from cid.helpers.quicksight.resource import CidQsResource
1313
from cid.helpers.quicksight.dataset import Dataset
14-
from cid.helpers.quicksight.version import CidVersion
14+
from cid.helpers.quicksight.version import CidVersion, DEFAULT_VERSION
1515

1616

1717
logger = logging.getLogger(__name__)
1818

1919

2020
class Dashboard(CidQsResource):
21+
# Dashboards with known invalid v1.0.0 tags
22+
DASHBOARDS_WITH_INVALID_V1_TAGS = {'ta-organizational-view', 'resiliencevue'}
23+
2124
def __init__(self, raw: dict, qs=None) -> None:
2225
super().__init__(raw)
2326
# Initialize properties
@@ -212,22 +215,57 @@ def health(self) -> bool:
212215

213216
@property
214217
def deployed_cid_version(self):
218+
"""Get the deployed CID version from tags, template, or definition."""
215219
if self._cid_version:
216-
return self._cid_version
217-
tag_version = (self.qs.get_tags(self.arn) or {}).get('cid_version_tag')
218-
#print(f'{self.id}: {tag_version}')
219-
if tag_version:
220-
logger.trace(f'version of {self.arn} from tag = {tag_version}')
221-
self._cid_version = CidVersion(tag_version)
222-
else:
223-
if self.deployed_template:
224-
self._cid_version = self.deployed_template.cid_version
225-
elif self.deployed_definition:
226-
self._cid_version = self.deployed_definition.cid_version
227-
if self._cid_version:
228-
logger.trace(f'setting tag of {self.arn} to cid_version_tag = {self._cid_version}')
229-
self.qs.set_tags(self.arn, cid_version_tag=self._cid_version)
220+
return self._cid_version
221+
222+
try:
223+
tag_version = self._get_version_from_tags()
224+
if self._is_valid_tag_version(tag_version):
225+
logger.debug(f'Using version from tag for {self.id}: {tag_version}')
226+
self._cid_version = CidVersion(tag_version)
227+
else:
228+
self._cid_version = self._get_version_from_sources()
229+
if self._cid_version:
230+
self._update_version_tag()
231+
except Exception as exc:
232+
logger.warning(f'Failed to determine CID version for {self.id}: {exc}')
233+
self._cid_version = None
234+
230235
return self._cid_version
236+
237+
def _get_version_from_tags(self):
238+
"""Extract version from dashboard tags."""
239+
tags = self.qs.get_tags(self.arn) or {}
240+
return tags.get('cid_version_tag')
241+
242+
def _is_valid_tag_version(self, tag_version):
243+
"""Check if tag version is valid and not a known invalid default."""
244+
if not tag_version or tag_version == DEFAULT_VERSION:
245+
return False
246+
247+
# v1.0.0 is invalid only for specific dashboards with incorrect defaults
248+
if tag_version == 'v1.0.0' and self.id in self.DASHBOARDS_WITH_INVALID_V1_TAGS:
249+
logger.debug(f'Ignoring invalid v1.0.0 tag for dashboard {self.id}')
250+
return False
251+
252+
return True
253+
254+
def _get_version_from_sources(self):
255+
"""Get version from template or definition as fallback."""
256+
if self.deployed_template:
257+
return self.deployed_template.cid_version
258+
elif self.deployed_definition:
259+
return self.deployed_definition.cid_version
260+
return None
261+
262+
def _update_version_tag(self):
263+
"""Update the version tag if we found a version from other sources."""
264+
try:
265+
logger.debug(f'Setting version tag for {self.arn}: {self._cid_version}')
266+
self.qs.set_tags(self.arn, cid_version_tag=self._cid_version)
267+
except Exception as exc:
268+
logger.warning(f'Failed to update version tag for {self.id}: {exc}')
231269

232270

233271
@property

cid/helpers/quicksight/definition.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33
from typing import Dict
44
from cid.helpers.quicksight.resource import CidQsResource
5-
from cid.helpers.quicksight.version import CidVersion
5+
from cid.helpers.quicksight.version import CidVersion, DEFAULT_VERSION
66

77
logger = logging.getLogger(__name__)
88

@@ -21,7 +21,7 @@ def cid_version(self) -> CidVersion:
2121
except TypeError as e:
2222
logger.debug(f"Could not resolve CID version. Raw version value '{self._raw_version}' does not conform to CID version format vmajor.minor.build e.g. v.1.0.1")
2323

24-
return CidVersion("v1.0.0")
24+
return CidVersion(DEFAULT_VERSION)
2525

2626
def resolve_version(self, raw: dict):
2727
about_content = []
@@ -38,13 +38,13 @@ def resolve_version(self, raw: dict):
3838
if about_content:
3939
all_about_content = " | ".join(about_content)
4040
# find first string that looks like vx.y.z using a regular expression where x, y and z are numbers
41-
version_matches = re.findall(r"(v\d+?\.\d+?\.\d+?)", all_about_content)
41+
version_matches = re.findall(r"([vV]\d+?\.\d+?\.\d+?)", all_about_content)
4242
if version_matches:
43-
return version_matches[0]
43+
return version_matches[0].lower() # normalize to lowercase
4444
else:
45-
version_matches = re.findall(r"(v\d+?\.\d+?)", all_about_content)
45+
version_matches = re.findall(r"([vV]\d+?\.\d+?)", all_about_content)
4646
if version_matches:
47-
return f"{version_matches[0]}.0"
47+
return f"{version_matches[0].lower()}.0" # normalize to lowercase
4848

4949
return None
5050

cid/helpers/quicksight/version.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
logger = logging.getLogger(__name__)
88

9+
# Default version used when version cannot be determined
10+
DEFAULT_VERSION = "v0.0.0"
11+
912
class CidVersion:
1013
""" Semantic version of dashboards in CID
1114
"""

dashboards/resilience-vue/resilience-vue-definition.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4176,7 +4176,7 @@ Sheets:
41764176
- Content: "<text-box>\n <block align=\"center\">\n <inline color=\"#23dae6\"\
41774177
\ font-size=\"48px\">\n <b>ResilienceVue\_</b>\n </inline>\n </block>\n\
41784178
\ <br/>\n <block align=\"center\">\n <inline color=\"PrimaryForeground\"\
4179-
\ font-size=\"48px\">\n <b>V 0.1.0</b>\n </inline>\n </block>\n <br/>\n\
4179+
\ font-size=\"48px\">\n <b>v0.1.0</b>\n </inline>\n </block>\n <br/>\n\
41804180
\ <block align=\"center\"/>\n <br/>\n <block align=\"center\">\n <inline\
41814181
\ color=\"PrimaryForeground\" font-size=\"24px\">\n <b>Centralized AWS\
41824182
\ Resilience Assessment Solution</b>\n </inline>\n </block>\n <br/>\n \

dashboards/tao/tao-definition.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17188,7 +17188,7 @@ Sheets:
1718817188
\ </a>\n </inline>\n </block>\n <br/>\n <block align=\"center\">\n\
1718917189
\ <inline font-size=\"60px\">Trusted Advisor Organizational View\_</inline>\n\
1719017190
\ </block>\n <br/>\n <block align=\"center\">\n <inline font-size=\"54.88px\"\
17191-
>\n <b>V4.0.0</b>\n </inline>\n </block>\n <br/>\n <br/>\n <block\
17191+
>\n <b>v4.0.0</b>\n </inline>\n </block>\n <br/>\n <br/>\n <block\
1719217192
\ align=\"right\"/>\n <br/>\n <block align=\"right\"/>\n <br/>\n <block\
1719317193
\ align=\"right\">Built by: Yuriy Prykhodko, Timur Tulyaganov, Sumit Dhuwalia\_\
1719417194
</block>\n <br/>\n <block align=\"right\"/>\n <br/>\n <block align=\"right\"\

0 commit comments

Comments
 (0)