From f8705537b57780457b7997484c338ec2f6c5c7b6 Mon Sep 17 00:00:00 2001 From: Iakov GAN <82834333+iakov-aws@users.noreply.github.com> Date: Thu, 6 Jul 2023 17:48:48 +0200 Subject: [PATCH] Better timezone management (#575) --- cfn-templates/cid-cfn.yml | 2 +- cid/_version.py | 2 +- cid/helpers/quicksight/__init__.py | 10 +++++++--- cid/helpers/randtime.py | 2 +- cid/helpers/timezone.py | 5 ++++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cfn-templates/cid-cfn.yml b/cfn-templates/cid-cfn.yml index a8f69a5f..c144a0e3 100644 --- a/cfn-templates/cid-cfn.yml +++ b/cfn-templates/cid-cfn.yml @@ -136,7 +136,7 @@ Parameters: CidVersion: Type: String MinLength: 5 - Default: 0.2.21 + Default: 0.2.22 Description: A version of CID package Suffix: Type: String diff --git a/cid/_version.py b/cid/_version.py index 4c14317b..2c7b5623 100644 --- a/cid/_version.py +++ b/cid/_version.py @@ -1,2 +1,2 @@ -__version__ = '0.2.21' +__version__ = '0.2.22' diff --git a/cid/helpers/quicksight/__init__.py b/cid/helpers/quicksight/__init__.py index b45838ef..c5150c02 100644 --- a/cid/helpers/quicksight/__init__.py +++ b/cid/helpers/quicksight/__init__.py @@ -1067,11 +1067,15 @@ def ensure_dataset_refresh_schedule(self, dataset_id, schedules: list): if exec_env()['terminal'] in ('lambda'): schedule_frequency_timezone = get_parameters().get("timezone", timezone.get_default_timezone()) else: + default_timezone = timezone.get_default_timezone() schedule_frequency_timezone = get_parameter("timezone", - message='Please select timezone for datasets scheduled refresh time', - choices=timezone.get_all_timezones(), - default=timezone.get_default_timezone() + message='Please select timezone for datasets scheduled refresh.', + choices=sorted(list(set(timezone.get_all_timezones() + [default_timezone]))), + default=default_timezone ) + if not schedule_frequency_timezone: + logger.warning(f'Cannot get timezone. Please provide --timezone parameter. Please make sure scheduled refresh is configured manualy.') + return for schedule in schedules: diff --git a/cid/helpers/randtime.py b/cid/helpers/randtime.py index 897b2068..1cabbc5d 100644 --- a/cid/helpers/randtime.py +++ b/cid/helpers/randtime.py @@ -5,7 +5,7 @@ def pseudo_random_generator(hashable_string: str, maximum: int=100) -> int: """Gernerate a pseudo random integer number, but the same for any given hashable_string identifier """ - hash_hex = hashlib.md5(bytes(hashable_string, "utf-8"), usedforsecurity=False).hexdigest()[:16] # nosec B303 - not used for security + hash_hex = hashlib.md5(bytes(hashable_string, "utf-8")).hexdigest()[:16] # nosec B303, B324 - not used for security bigint_value = int.from_bytes(bytes.fromhex(hash_hex), 'little', signed=True) return bigint_value % int(maximum) diff --git a/cid/helpers/timezone.py b/cid/helpers/timezone.py index f0225908..4a10822d 100644 --- a/cid/helpers/timezone.py +++ b/cid/helpers/timezone.py @@ -65,4 +65,7 @@ def get_default_timezone(): def get_all_timezones(): """Get all zones""" # zoneinfo is not working with 3.7, 3.8 - return sorted(list(win_tz.values())) + + return sorted(list(set( + list(win_tz.values()) + list(MAPPING_REGION_2_TIMEZONE.values()) + )))