Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some bug risks and code quality issues #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# generated by deepsource.io

version = 1

test_patterns = [
'tests/**'
]

exclude_patterns = [
'deployment/**',
'docs/**'
]

[[ analyzers ]]
name = 'python'
enabled = true

[ analyzers.meta ]
max_line_length = 100
5 changes: 2 additions & 3 deletions hammer/library/aws/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def get_public_acls(acl):
# http://acs.amazonaws.com/groups/global/AuthenticatedUsers
# http://acs.amazonaws.com/groups/global/AllUsers
who = grant["Grantee"]["URI"].split("/")[-1]
if who == "AllUsers" or \
who == "AuthenticatedUsers":
if who in ("AllUsers", "AuthenticatedUsers"):
perm = grant["Permission"]
# group all permissions (READ(_ACP), WRITE(_ACP), FULL_CONTROL) by AWS predefined groups
public_acls.setdefault(who, []).append(perm)
Expand Down Expand Up @@ -259,7 +258,7 @@ def set_bucket_encryption(s3_client, bucket, kms_master_key_id=None):
:return: nothing
"""
if kms_master_key_id:
rules = [
rules = [
{
'ApplyServerSideEncryptionByDefault': {
'SSEAlgorithm': 'aws:kms',
Expand Down
2 changes: 1 addition & 1 deletion hammer/library/ddb_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def __init__(self, *args):


class PublicAMIIssue(Issue):
def __init__(self, *args):
def __init__(self, *args):
super().__init__(*args)


Expand Down
6 changes: 2 additions & 4 deletions hammer/reporting-remediation/bot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ def parse_regions(response):
for region in requested_regions:
if region.strip() not in supported_regions:
raise Exception(f'Wrong region {region}. Allowed values: \n ```{allowed_values}```')
else:
regions.append(region.strip())
regions.append(region.strip())
return regions


Expand All @@ -241,8 +240,7 @@ def parse_security_features(response):
for sec_feature in requested_security_features:
if sec_feature.strip() not in supported_features:
raise Exception(f"Unsupported security feature {sec_feature}. Allowed values: \n ```{allowed_values}```")
else:
security_features.append(sec_feature.strip())
security_features.append(sec_feature.strip())
return security_features


Expand Down
4 changes: 2 additions & 2 deletions hammer/tools/ddb_inject_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
}
}

if args.hammer_api_token != None:
if args.hammer_api_token is not None:
# generate new secret if secret value is not set
creds["api"] = {"token": secrets.token_hex() if args.hammer_api_token == -1 else args.hammer_api_token}

if args.hammer_api_url != None:
if args.hammer_api_url is not None:
creds["api"]["url"] = args.hammer_api_url

if not creds:
Expand Down