Skip to content

Commit 6973c2e

Browse files
committed
switch to ruff for linting
1 parent 930ccc0 commit 6973c2e

37 files changed

+446
-364
lines changed

.github/dependabot.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"

.github/workflows/publish.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@ jobs:
2626
run: |
2727
make install
2828
29-
# TODO: fix all pylint issues first
30-
# - name: Pylint
31-
# run: |
32-
# make lint
33-
34-
- name: Run pytest (unit tests) and bandit (security test)
29+
- name: Run pytest (unit tests)
3530
run: |
36-
make security-test
3731
make test
3832
3933

.github/workflows/test.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ jobs:
3838
run: |
3939
make install
4040
41-
- name: Run pytest (unit tests) and bandit (security test)
41+
- name: Run pytest (unit tests)
4242
run: |
43-
make security-test
4443
make test
4544
4645
- name: Run mypy (static type check)
@@ -71,6 +70,6 @@ jobs:
7170
run: |
7271
make install
7372
74-
- name: Run pytest (unit tests) and bandit (security test)
73+
- name: Run pytest (unit tests)
7574
run: |
7675
make test

.pre-commit-config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ repos:
66
- repo: https://github.com/astral-sh/ruff-pre-commit
77
rev: v0.5.3
88
hooks:
9+
- id: ruff
10+
files: ^(cloudsplaining/|setup.py)
911
- id: ruff-format

Makefile

-8
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ test: setup-dev
5353
python3 -m coverage run -m pytest -v
5454
python3 -m coverage report -m
5555

56-
# Run python security tests
57-
security-test: setup-dev
58-
bandit -r ./${PROJECT_UNDERSCORE}/
59-
60-
# Run Pylint to lint your code
61-
lint: setup-dev
62-
pylint ${PROJECT_UNDERSCORE}/
63-
6456
type-check: setup-dev
6557
mypy
6658

cloudsplaining/__init__.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import sys
44

55
# Set default logging handler to avoid "No handler found" warnings.
6-
from logging import NullHandler
7-
6+
# from logging import NullHandler
87
# logging.getLogger(__name__).addHandler(NullHandler())
98
# Uncomment to get the full debug logs.
109
# 2020-10-06 10:04:17,200 - root - DEBUG - Leveraging the bundled IAM Definition.
1110
# Need to figure out how to get click_log to do this for me.
12-
from typing import Union, Optional
11+
from typing import Optional, Union
1312

1413
logger = logging.getLogger(__name__)
1514
logger.setLevel(logging.WARNING)
@@ -71,10 +70,10 @@ def set_log_level(verbose: int) -> None:
7170
:return:
7271
"""
7372
if verbose == 1:
74-
set_stream_logger(level=getattr(logging, "WARNING"))
73+
set_stream_logger(level=logging.WARNING)
7574
elif verbose == 2:
76-
set_stream_logger(level=getattr(logging, "INFO"))
75+
set_stream_logger(level=logging.INFO)
7776
elif verbose >= 3:
78-
set_stream_logger(level=getattr(logging, "DEBUG"))
77+
set_stream_logger(level=logging.DEBUG)
7978
else:
80-
set_stream_logger(level=getattr(logging, "CRITICAL"))
79+
set_stream_logger(level=logging.CRITICAL)

cloudsplaining/bin/cli.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import click
12+
1213
from cloudsplaining import command
1314
from cloudsplaining.bin.version import __version__
1415

cloudsplaining/command/__init__.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# ruff: noqa: F401
12
# pylint: disable=missing-module-docstring
2-
from cloudsplaining.command import create_exclusions_file
3-
from cloudsplaining.command import create_multi_account_config_file
4-
from cloudsplaining.command import expand_policy
5-
from cloudsplaining.command import download
6-
from cloudsplaining.command import scan
7-
from cloudsplaining.command import scan_multi_account
8-
from cloudsplaining.command import scan_policy_file
3+
from cloudsplaining.command import (
4+
create_exclusions_file,
5+
create_multi_account_config_file,
6+
download,
7+
expand_policy,
8+
scan,
9+
scan_multi_account,
10+
scan_policy_file,
11+
)

cloudsplaining/command/create_exclusions_file.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
# Licensed under the BSD 3-Clause license.
99
# For full license text, see the LICENSE file in the repo root
1010
# or https://opensource.org/licenses/BSD-3-Clause
11-
import os
1211
import logging
12+
import os
13+
1314
import click
14-
from cloudsplaining.shared.constants import EXCLUSIONS_TEMPLATE
15+
1516
from cloudsplaining import set_log_level
1617
from cloudsplaining.shared import utils
18+
from cloudsplaining.shared.constants import EXCLUSIONS_TEMPLATE
1719

1820
logger = logging.getLogger(__name__)
1921

@@ -38,7 +40,7 @@ def create_exclusions_file(output_file: str, verbosity: int) -> None:
3840
"""
3941
set_log_level(verbosity)
4042

41-
with open(output_file, "a") as file_obj:
43+
with open(output_file, "a", encoding="utf-8") as file_obj:
4244
for line in EXCLUSIONS_TEMPLATE:
4345
file_obj.write(line)
4446
utils.print_green(f"Success! Exclusions template file written to: {output_file}")

cloudsplaining/command/create_multi_account_config_file.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
# Licensed under the BSD 3-Clause license.
99
# For full license text, see the LICENSE file in the repo root
1010
# or https://opensource.org/licenses/BSD-3-Clause
11-
import os
1211
import logging
12+
import os
13+
1314
import click
14-
from cloudsplaining.shared.constants import MULTI_ACCOUNT_CONFIG_TEMPLATE
15+
1516
from cloudsplaining import set_log_level
1617
from cloudsplaining.shared import utils
18+
from cloudsplaining.shared.constants import MULTI_ACCOUNT_CONFIG_TEMPLATE
1719

1820
logger = logging.getLogger(__name__)
1921
OK_GREEN = "\033[92m"
@@ -44,7 +46,7 @@ def create_multi_account_config_file(output_file: str, verbosity: int) -> None:
4446
logger.debug("%s exists. Removing the file and replacing its contents.", output_file)
4547
os.remove(output_file)
4648

47-
with open(output_file, "a") as file_obj:
49+
with open(output_file, "a", encoding="utf-8") as file_obj:
4850
for line in MULTI_ACCOUNT_CONFIG_TEMPLATE:
4951
file_obj.write(line)
5052
utils.print_green(f"Success! Multi-account config file written to: {os.path.relpath(output_file)}")

cloudsplaining/command/download.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import json
1212
import logging
1313
import os
14-
from typing import Dict, List, Any, TYPE_CHECKING
14+
from typing import TYPE_CHECKING, Any, Dict, List
1515

1616
import boto3
1717
import click
@@ -68,7 +68,7 @@ def download(profile: str, output: str, include_non_default_policy_versions: boo
6868
output_filename = os.path.join(output, "default.json")
6969

7070
results = get_account_authorization_details(session_data, include_non_default_policy_versions)
71-
with open(output_filename, "w") as f:
71+
with open(output_filename, "w", encoding="utf-8") as f:
7272
json.dump(results, f, indent=4, default=str)
7373
# output_filename.write_text(json.dumps(results, indent=4, default=str))
7474
print(f"Saved results to {output_filename}")

cloudsplaining/command/expand_policy.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
# Licensed under the BSD 3-Clause license.
88
# For full license text, see the LICENSE file in the repo rootgit pus
99
# or https://opensource.org/licenses/BSD-3-Clause
10-
import logging
1110
import json
11+
import logging
12+
1213
import click
1314
from policy_sentry.analysis.expand import get_expanded_policy
15+
1416
from cloudsplaining import set_log_level
1517

1618
logger = logging.getLogger(__name__)
@@ -31,7 +33,7 @@ def expand_policy(input_file: str, verbosity: int) -> None:
3133
"""
3234
set_log_level(verbosity)
3335

34-
with open(input_file) as json_file:
36+
with open(input_file, encoding="utf-8") as json_file:
3537
logger.debug(f"Opening {input_file}")
3638
data = json.load(json_file)
3739
policy = get_expanded_policy(data)

0 commit comments

Comments
 (0)