Skip to content

Commit 4fcf125

Browse files
Review feedback
1 parent d1c2e33 commit 4fcf125

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

mip_api/__init__.py

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

1010

1111
def lambda_handler(event, context):
12-
"""Sample pure Lambda function
12+
"""Entry Point for Lambda
13+
14+
The Python process will continue to run for the entire lifecycle of
15+
the Lambda execution environment (15 minutes). Subsequent Lambda
16+
runs will re-enter this function.
1317
1418
Parameters
1519
----------

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: 15 additions & 1 deletion
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]
@@ -37,10 +47,14 @@ def param_no_program_bool(params):
3747
def param_limit_int(params):
3848
if params and "limit" in params:
3949
try:
40-
return int(params["limit"])
50+
number = int(params["limit"])
4151
except ValueError as exc:
4252
err_str = "QueryStringParameter 'limit' must be an Integer"
4353
raise ValueError(err_str) from exc
54+
55+
if number < 0:
56+
raise ValueError("QueryStringParameter 'limit' must be a positive Integer")
57+
return number
4458
return 0
4559

4660

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)