Skip to content

Commit 6e88300

Browse files
author
Stewart Wallace
committed
Addressing code review comments
1 parent 889f030 commit 6e88300

2 files changed

Lines changed: 7 additions & 35 deletions

File tree

src/lambda_codebase/account_processing/process_account_files.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tempfile
1313
import logging
1414
from typing import Any, TypedDict
15+
import re
1516
import yaml
1617

1718
from yaml.error import YAMLError
@@ -141,36 +142,7 @@ def process_account_list(all_accounts, accounts_in_file):
141142

142143

143144
def sanitize_account_name_for_snf(account_name):
144-
unsupported_characters = [
145-
"<",
146-
">",
147-
"{",
148-
"}",
149-
"[",
150-
"]",
151-
" ",
152-
"?",
153-
"*",
154-
'"',
155-
"#",
156-
"%",
157-
"\\",
158-
"^",
159-
"|",
160-
"~",
161-
"`",
162-
"$",
163-
"&",
164-
",",
165-
";",
166-
":",
167-
"/",
168-
]
169-
sanitized_name = account_name[:30]
170-
for char in unsupported_characters:
171-
sanitized_name = sanitized_name.replace(char, "")
172-
173-
return sanitized_name
145+
return re.sub("[^a-zA-Z0-9_]", "_", account_name[:30])
174146

175147

176148
def start_executions(

src/lambda_codebase/account_processing/tests/test_account_file_processing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,19 @@ def test_get_sanitize_account_name(self):
7878
sanitize_account_name_for_snf(
7979
"thisIsALongerAccountName ForTestingTruncatedNames"
8080
),
81-
"thisIsALongerAccountNameForTe",
81+
"thisIsALongerAccountName_ForTe",
8282
)
8383
self.assertEqual(
8484
sanitize_account_name_for_snf("this accountname <has illegal> chars"),
85-
"thisaccountnamehasillegal",
85+
"this_accountname__has_illegal_",
8686
)
8787
self.assertEqual(
88-
sanitize_account_name_for_snf("this accountname \\has illegal chars"),
89-
"thisaccountnamehasillegal",
88+
sanitize_account_name_for_snf("this accountname \\has illegal"),
89+
"this_accountname__has_illegal",
9090
)
9191
self.assertEqual(
9292
sanitize_account_name_for_snf("^startswithanillegalchar"),
93-
"startswithanillegalchar",
93+
"_startswithanillegalchar",
9494
)
9595
self.assertEqual(
9696
len(

0 commit comments

Comments
 (0)