Skip to content

Commit 4a5dd2c

Browse files
authored
allow currency selection (#1174)
1 parent e860fac commit 4a5dd2c

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

cfn-templates/cid-cfn.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AWSTemplateFormatVersion: '2010-09-09'
2-
Description: Deployment of Cloud Intelligence Dashboards v4.1.3
2+
Description: Deployment of Cloud Intelligence Dashboards v4.1.4
33
Metadata:
44
AWS::CloudFormation::Interface:
55
ParameterGroups:
@@ -104,6 +104,8 @@ Metadata:
104104
default: "Create Local Assets Bucket"
105105
ReferenceAssetsBucket:
106106
default: "Reference Assets Bucket Name"
107+
CurrencySymbol:
108+
default: "Currency Symbol"
107109
cfn-lint:
108110
config:
109111
ignore_checks:
@@ -256,6 +258,20 @@ Parameters:
256258
Type: String
257259
Description: Source bucket for CID Assets to sync from.
258260
Default: 'aws-managed-cost-intelligence-dashboards-us-east-1'
261+
CurrencySymbol:
262+
Type: String
263+
Description: 'Currency Symbol. Please align with Currency of your CUR. Only supported for China region.'
264+
Default: "USD"
265+
AllowedValues:
266+
# Only currency symbols supported by QS
267+
- "USD" # US Dollar $
268+
- "GBP" # British Pound £
269+
- "EUR" # Euro €
270+
- "JPY" # Japanese Yen ¥
271+
- "KRW" # South Korean Won ₩
272+
- "DKK" # Danish Krone kr
273+
- "TWD" # Taiwan Dollar NT
274+
- "INR" # Indian Rupee ₹
259275

260276
Conditions:
261277
NeedCUDOSDashboard: !Equals [ !Ref DeployCUDOSDashboard, "yes" ]
@@ -1789,7 +1805,7 @@ Resources:
17891805
try:
17901806
dashboard = properties['Dashboard']
17911807
# set additional parameters from environment variables
1792-
for par in 'athena_workgroup quicksight_datasource_id quicksight_datasource_role_arn athena_database glue_data_catalog cur_table_name cur_database quicksight_user account_map_source share_with_account account_map_database_name'.split():
1808+
for par in 'athena_workgroup quicksight_datasource_id quicksight_datasource_role_arn athena_database glue_data_catalog cur_table_name cur_database quicksight_user account_map_source share_with_account account_map_database_name currency_symbol'.split():
17931809
dashboard[par.replace('_', '-')] = dashboard.get(par.replace('_', '-'), os.environ.get(par))
17941810
if request_type == 'Create':
17951811
dash_url = deploy_dash(dashboard)
@@ -1864,6 +1880,7 @@ Resources:
18641880
account_map_source: 'dummy' #initial
18651881
share_with_account: !Ref ShareDashboard
18661882
account_map_database_name: !If [NeedDatabase, !Ref CidDatabase, !Ref DatabaseName ]
1883+
currency_symbol: !Ref CurrencySymbol
18671884
Metadata:
18681885
cfn_nag:
18691886
rules_to_suppress:
@@ -2052,7 +2069,7 @@ Resources:
20522069
SourceBucket: !Ref ReferenceAssetsBucket
20532070
DestinationBucket: !Ref LocalAssetsBucket
20542071
Keys:
2055-
- 'cid-resource-lambda-layer/cid-4.1.3.zip' #replace version here if needed
2072+
- 'cid-resource-lambda-layer/cid-4.1.4.zip' #replace version here if needed
20562073

20572074
CidResourceLambdaLayer:
20582075
Type: AWS::Lambda::LayerVersion
@@ -2067,7 +2084,7 @@ Resources:
20672084
- LambdaLayerBucketPrefixIsManaged
20682085
- !FindInMap [RegionMap, !Ref 'AWS::Region', BucketName]
20692086
- !Sub '${LambdaLayerBucketPrefix}-${AWS::Region}' # Region added for backward compatibility
2070-
S3Key: 'cid-resource-lambda-layer/cid-4.1.3.zip' #replace version here if needed
2087+
S3Key: 'cid-resource-lambda-layer/cid-4.1.4.zip' #replace version here if needed
20712088
CompatibleRuntimes:
20722089
- python3.10
20732090
- python3.11

cid/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = '4.1.3'
1+
__version__ = '4.1.4'
22

cid/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def deploy(ctx, **kwargs):
140140
--category TEXT Comma separated list of categories of dashboards (ex: foundational,advanced )
141141
--catalog TEXT Comma separated list of catalog files or urls (ex: foundational,advanced )
142142
--theme TEXT A QuickSight Theme (CLASSIC|MIDNIGHT|SEASIDE|RAINIER)
143+
--currency TEXT A currency symbol instead of default USD (USD|GBP|EUR|JPY|KRW|DKK|TWD|INR)
143144
--share-with-account (yes|no) Make dashboard visible to other users in the same account by default.
144145
"""
145146
ctx.obj.deploy(**kwargs)
@@ -206,6 +207,7 @@ def update(ctx, dashboard_id, force, recursive, **kwargs):
206207
\b
207208
--on-drift (show|override) Action if a drift of view and dataset is discovered. 'override' = override drift(will destroy customization) or 'show' (default) = show a diff. In Unattended mode (without terminal on-drift will have allways override behaviour)
208209
--theme TEXT A QuickSight Theme (CLASSIC|MIDNIGHT|SEASIDE|RAINIER)
210+
--currency TEXT A currency symbol instead of default USD (USD|GBP|EUR|JPY|KRW|DKK|TWD|INR)
209211
210212
"""
211213
ctx.obj.update(dashboard_id, force=force, recursive=recursive, **kwargs)

cid/helpers/quicksight/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,21 @@ def _build_params_for_create_update_dash(self, definition: dict, permissions: bo
13011301
}
13021302
elif definition.get('definition'):
13031303
create_parameters['Definition'] = definition.get('definition')
1304+
currency = get_parameters().get('currency-symbol', 'USD')
1305+
if currency != 'USD' and currency:
1306+
if currency not in "USD|GBP|EUR|JPY|KRW|DKK|TWD|INR".split('|'):
1307+
raise CidCritical(f'Currency {currency} is not supported. USD|GBP|EUR|JPY|KRW|DKK|TWD|INR')
1308+
cid_print(f'Setting currency = <BOLD>{currency}<END>')
1309+
def _set_currency(data):
1310+
"""Recursively set currency"""
1311+
if isinstance(data, dict):
1312+
if 'CurrencyDisplayFormatConfiguration' in data:
1313+
data['CurrencyDisplayFormatConfiguration']['Symbol'] = currency
1314+
return {k: _set_currency(v) for k, v in data.items()}
1315+
elif isinstance(data, list):
1316+
return [_set_currency(item) for item in data]
1317+
return data
1318+
create_parameters['Definition'] = _set_currency(create_parameters['Definition'])
13041319
dataset_references = []
13051320
for identifier, arn in definition.get('datasets', {}).items():
13061321
# Fetch dataset by name (preferably) OR by id

0 commit comments

Comments
 (0)