Skip to content

Commit 49bb9b3

Browse files
Review feedback
1 parent d1c2e33 commit 49bb9b3

File tree

5 files changed

+47
-28
lines changed

5 files changed

+47
-28
lines changed

mip_api/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99

1010

1111
def lambda_handler(event, context):
12-
"""Sample pure Lambda function
12+
"""Entry Point for Lambda
13+
14+
Collect configuration from environment variables and query-string parameters,
15+
determine data requested based on the API endpoint called, and finally
16+
present the requested data in the desired format.
17+
18+
Note: The Python process will continue to run for the entire lifecycle of
19+
the Lambda execution environment (15 minutes). Subsequent Lambda
20+
runs will re-enter this function.
1321
1422
Parameters
1523
----------

mip_api/chart.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,20 @@ def process_chart(params, chart_dict, omit_list, other, no_program):
105105

106106
if priority_codes is not None:
107107
if short in priority_codes:
108-
# Since Python 3.7, python dictionaries preserve insertion
109-
# order, so to prepend an item to the top of the dictionary,
110-
# we create a new dictionary inserting the target code first,
111-
# then add the previous output, and finally save the new
112-
# dictionary as our output dictionary.
113-
new_chart = {short: name}
114-
new_chart.update(out_chart)
115-
out_chart = new_chart
116-
found_codes.append(short)
108+
out_chart = util.dict_prepend(out_chart, short, name)
117109
else:
118110
out_chart[short] = name
119-
found_codes.append(short)
120111
else:
121112
out_chart[short] = name
122-
found_codes.append(short)
113+
found_codes.append(short)
123114

124115
# inject "other" code
125116
if util.param_other_bool(params):
126-
new_chart = {other: "Other"}
127-
new_chart.update(out_chart)
128-
out_chart = new_chart
117+
out_chart = util.dict_prepend(out_chart, other, "Other")
129118

130119
# inject "no program" code
131120
if util.param_no_program_bool(params):
132-
new_chart = {no_program: "No Program"}
133-
new_chart.update(out_chart)
134-
out_chart = new_chart
121+
out_chart = util.dict_prepend(out_chart, no_program, "No Program")
135122

136123
return out_chart
137124

mip_api/ssm.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ def get_secrets(ssm_path):
3838
ssm_secrets[name] = p["Value"]
3939
LOG.info(f"Loaded secret: {name}")
4040
else:
41-
LOG.error(f"Invalid response from SSM client")
42-
raise Exception
41+
msg = "Invalid response from SSM client"
42+
LOG.error(msg)
43+
raise Exception(msg)
4344

4445
for reqkey in ["user", "pass"]:
4546
if reqkey not in ssm_secrets:
46-
raise Exception(f"Missing required secure parameter: {reqkey}")
47+
msg = f"Missing required secure parameter: {reqkey}"
48+
LOG.error(msg)
49+
raise Exception(msg)
4750

4851
return ssm_secrets

mip_api/util.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import os
22

33

4+
def dict_prepend(original, key, value):
5+
# Since Python 3.7, python dictionaries preserve insertion
6+
# order, so to prepend an item to the top of the dictionary,
7+
# we create a new dictionary inserting the new key first,
8+
# then add the previous output
9+
new_dict = {key: value}
10+
new_dict.update(original)
11+
return new_dict
12+
13+
414
def get_os_var(varnam):
515
try:
616
return os.environ[varnam]
@@ -22,6 +32,17 @@ def _param_bool(params, param):
2232
return False
2333

2434

35+
def _param_int(params, param):
36+
number = 0
37+
if params and param in params:
38+
try:
39+
number = int(params[param])
40+
except ValueError as exc:
41+
msg = f"The parameter '{param}' must be an integer"
42+
raise ValueError(msg) from exc
43+
return number
44+
45+
2546
def param_inactive_bool(params):
2647
return not _param_bool(params, "show_inactive_codes")
2748

@@ -35,13 +56,10 @@ def param_no_program_bool(params):
3556

3657

3758
def param_limit_int(params):
38-
if params and "limit" in params:
39-
try:
40-
return int(params["limit"])
41-
except ValueError as exc:
42-
err_str = "QueryStringParameter 'limit' must be an Integer"
43-
raise ValueError(err_str) from exc
44-
return 0
59+
limit = _param_int(params, "limit")
60+
if limit < 0:
61+
raise ValueError("The parameter 'limit' must be a positive Integer")
62+
return limit
4563

4664

4765
def param_priority_list(params):

template.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Resources:
6767
Transitions:
6868
- TransitionInDays: 3
6969
StorageClass: INTELLIGENT_TIERING
70+
- Id: ExpireOldObjectVersions
71+
Status: Enabled
72+
NoncurrentVersionExpirationInDays: 365
7073

7174
CacheBucketPolicy:
7275
Type: AWS::S3::BucketPolicy

0 commit comments

Comments
 (0)