Skip to content

Commit e7a1cbd

Browse files
committed
fix typing
1 parent c8af1df commit e7a1cbd

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

cloudsplaining/command/create_multi_account_config_file.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ def create_multi_account_config_file(output_file: str, verbosity: int) -> None:
4242
"""
4343
set_log_level(verbosity)
4444

45-
output_file = Path(output_file)
46-
if output_file.exists():
47-
logger.debug("%s exists. Removing the file and replacing its contents.", output_file)
48-
output_file.unlink()
45+
output_file_path = Path(output_file)
46+
if output_file_path.exists():
47+
logger.debug("%s exists. Removing the file and replacing its contents.", output_file_path)
48+
output_file_path.unlink()
4949

50-
with output_file.open("a", encoding="utf-8") as file_obj:
50+
with output_file_path.open("a", encoding="utf-8") as file_obj:
5151
file_obj.write(MULTI_ACCOUNT_CONFIG_TEMPLATE)
5252

53-
utils.print_green(f"Success! Multi-account config file written to: {output_file}")
54-
print(f"\nMake sure you edit the {output_file} file and then run the scan-multi-account command, as shown below.")
55-
print(f"\n\tcloudsplaining scan-multi-account --exclusions-file exclusions.yml -c {output_file} -o ./")
53+
utils.print_green(f"Success! Multi-account config file written to: {output_file_path}")
54+
print(
55+
f"\nMake sure you edit the {output_file_path} file and then run the scan-multi-account command, as shown below."
56+
)
57+
print(f"\n\tcloudsplaining scan-multi-account --exclusions-file exclusions.yml -c {output_file_path} -o ./")

cloudsplaining/command/download.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ def download(profile: str, output: str, include_non_default_policy_versions: boo
6262
default_region = "us-east-1"
6363
session_data = {"region_name": default_region}
6464

65-
output = Path(output)
65+
output_path = Path(output)
6666
if profile:
6767
session_data["profile_name"] = profile
68-
output_filename = output / f"{profile}.json"
68+
output_filename = output_path / f"{profile}.json"
6969
else:
70-
output_filename = output / "default.json"
70+
output_filename = output_path / "default.json"
7171

7272
results = get_account_authorization_details(session_data, include_non_default_policy_versions)
7373
with output_filename.open("w", encoding="utf-8") as f:

cloudsplaining/command/scan.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,24 @@ def scan(
139139
flag_conditional_statements = False
140140
flag_resource_arn_statements = False
141141

142-
output = Path(output)
143-
input_file = Path(input_file)
144-
if input_file.is_file():
145-
account_name = input_file.stem
146-
account_authorization_details_cfg = json.loads(input_file.read_text(encoding="utf-8"))
142+
output_path = Path(output)
143+
input_file_path = Path(input_file)
144+
if input_file_path.is_file():
145+
account_name = input_file_path.stem
146+
account_authorization_details_cfg = json.loads(input_file_path.read_text(encoding="utf-8"))
147147
rendered_html_report = scan_account_authorization_details(
148148
account_authorization_details_cfg,
149149
exclusions,
150150
account_name,
151-
output,
151+
output_path,
152152
write_data_files=True,
153153
minimize=minimize,
154154
flag_conditional_statements=flag_conditional_statements,
155155
flag_resource_arn_statements=flag_resource_arn_statements,
156156
flag_trust_policies=flag_trust_policies,
157157
severity=severity,
158158
)
159-
html_output_file = output / f"iam-report-{account_name}.html"
159+
html_output_file = output_path / f"iam-report-{account_name}.html"
160160
logger.info("Saving the report to %s", html_output_file)
161161
if html_output_file.exists():
162162
html_output_file.unlink()
@@ -171,25 +171,25 @@ def scan(
171171
url = f"file://{html_output_file.absolute()}"
172172
webbrowser.open(url, new=2)
173173

174-
if input_file.is_dir():
174+
if input_file_path.is_dir():
175175
logger.info("The path given is a directory. Scanning for account authorization files and generating report.")
176-
input_files = get_authorization_files_in_directory(input_file)
176+
input_files = get_authorization_files_in_directory(input_file_path)
177177
for file in input_files:
178178
logger.info(f"Scanning file: {file}")
179179
account_authorization_details_cfg = json.loads(Path(file).read_text(encoding="utf-8"))
180180

181-
account_name = input_file.parent.stem
181+
account_name = input_file_path.parent.stem
182182
# Scan the Account Authorization Details config
183183
rendered_html_report = scan_account_authorization_details(
184184
account_authorization_details_cfg,
185185
exclusions,
186186
account_name,
187-
output,
187+
output_path,
188188
write_data_files=True,
189189
minimize=minimize,
190190
severity=severity,
191191
)
192-
html_output_file = output / f"iam-report-{account_name}.html"
192+
html_output_file = output_path / f"iam-report-{account_name}.html"
193193
logger.info("Saving the report to %s", html_output_file)
194194
if html_output_file.exists():
195195
html_output_file.unlink()

cloudsplaining/command/scan_multi_account.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ def scan_accounts(
227227
utils.print_green(f"Saved the JSON data to: s3://{output_bucket}/{output_file}")
228228
if output_directory:
229229
# Write the HTML file
230-
output_directory = Path(output_directory)
231-
html_output_file = output_directory / f"{target_account_name}.html"
230+
output_dir_path = Path(output_directory)
231+
html_output_file = output_dir_path / f"{target_account_name}.html"
232232
utils.write_file(html_output_file, rendered_report)
233233
utils.print_green(f"Saved the HTML report to: {html_output_file}")
234234
# Write the JSON data file
235235
if write_data_file:
236-
results_data_file = output_directory / f"{target_account_name}.json"
236+
results_data_file = output_dir_path / f"{target_account_name}.json"
237237
results_data_filepath = utils.write_results_data_file(results, results_data_file)
238238
utils.print_green(f"Saved the JSON data to: {results_data_filepath}")
239239

cloudsplaining/shared/template_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ def _get_custom_content(self, filename: str) -> str:
2626
if not filename or "/" in filename or "\\" in filename or ".." in filename:
2727
return "default"
2828

29-
filename = Path(filename)
30-
if not filename.exists():
29+
file_path = Path(filename)
30+
if not file_path.exists():
3131
return "default"
3232

3333
try:
34-
content = filename.read_text(encoding="utf-8").strip()
34+
content = file_path.read_text(encoding="utf-8").strip()
3535
if content:
3636
json_str = json.dumps(content)
3737
return json_str[1:-1]

cloudsplaining/shared/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def is_aws_managed(arn: str) -> bool:
119119

120120

121121
# pragma: no cover
122-
def write_results_data_file(results: dict[str, dict[str, Any]], raw_data_file: Path) -> str:
122+
def write_results_data_file(results: dict[str, dict[str, Any]], raw_data_file: Path) -> Path:
123123
"""
124124
Writes the raw data file containing all the results for an AWS account
125125

0 commit comments

Comments
 (0)