|
11 | 11 | from cid.utils import cid_print, get_yesno_parameter |
12 | 12 | from cid.helpers.quicksight.resource import CidQsResource |
13 | 13 | 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 |
15 | 15 |
|
16 | 16 |
|
17 | 17 | logger = logging.getLogger(__name__) |
18 | 18 |
|
19 | 19 |
|
20 | 20 | class Dashboard(CidQsResource): |
| 21 | + # Dashboards with known invalid v1.0.0 tags |
| 22 | + DASHBOARDS_WITH_INVALID_V1_TAGS = {'ta-organizational-view', 'resiliencevue'} |
| 23 | + |
21 | 24 | def __init__(self, raw: dict, qs=None) -> None: |
22 | 25 | super().__init__(raw) |
23 | 26 | # Initialize properties |
@@ -212,22 +215,57 @@ def health(self) -> bool: |
212 | 215 |
|
213 | 216 | @property |
214 | 217 | def deployed_cid_version(self): |
| 218 | + """Get the deployed CID version from tags, template, or definition.""" |
215 | 219 | 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 | + |
230 | 235 | 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}') |
231 | 269 |
|
232 | 270 |
|
233 | 271 | @property |
|
0 commit comments