Skip to content

Commit dfeafb5

Browse files
authored
Fix the issue with the query command not recognizing the latest IAM definition (#221)
1 parent aa1444e commit dfeafb5

File tree

7 files changed

+21
-11
lines changed

7 files changed

+21
-11
lines changed

policy_sentry/command/create_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import click_log
99
from policy_sentry.writing.template import create_actions_template, create_crud_template
1010

11-
logger = logging.getLogger()
11+
logger = logging.getLogger(__name__)
1212
click_log.basic_config(logger)
1313

1414

policy_sentry/command/initialize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ def create_policy_sentry_config_directory():
120120
"""
121121
print("Creating the database...")
122122
logger.debug(f"We will store the new database here: {DATASTORE_FILE_PATH}")
123-
# If the database file already exists
124-
123+
# If the database file already exists, remove it
125124
if os.path.exists(LOCAL_DATASTORE_FILE_PATH):
125+
logger.debug(f"The database at {DATASTORE_FILE_PATH} already exists. Removing and replacing it.")
126126
os.remove(LOCAL_DATASTORE_FILE_PATH)
127127
elif os.path.exists(CONFIG_DIRECTORY):
128128
pass

policy_sentry/command/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
get_condition_key_details,
2727
)
2828

29-
logger = logging.getLogger()
29+
logger = logging.getLogger(__name__)
3030
click_log.basic_config(logger)
3131

3232

policy_sentry/command/write_policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from policy_sentry.util.file import read_yaml_file
1111
from policy_sentry.writing.sid_group import SidGroup
1212

13-
logger = logging.getLogger()
13+
logger = logging.getLogger(__name__)
1414
click_log.basic_config(logger)
1515

1616

policy_sentry/shared/constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"""
44
from pathlib import Path
55
import os
6+
import logging
7+
8+
logger = logging.getLogger()
69

710
# General Folders
811
HOME = str(Path.home())
@@ -19,13 +22,21 @@
1922
BASE_DOCUMENTATION_URL = "https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_actions-resources-contextkeys.html"
2023

2124
# Data json file
25+
# On initialization, load the IAM data
2226
BUNDLED_DATASTORE_FILE_PATH = os.path.join(
2327
str(Path(os.path.dirname(__file__))), "data", "iam-definition.json"
2428
)
2529
LOCAL_DATASTORE_FILE_PATH = os.path.join(CONFIG_DIRECTORY, "iam-definition.json")
30+
# Check for the existence of the local datastore first.
2631
if os.path.exists(LOCAL_DATASTORE_FILE_PATH):
32+
# If it exists, leverage that datastore instead of the one bundled with the python package
33+
logger.info(f"The IAM definition at {LOCAL_DATASTORE_FILE_PATH} exists. "
34+
f"Leveraging that IAM definition instead of the definition bundled with the python package. "
35+
f"To leverage the bundled definition, remove the folder $HOME/.policy_sentry/")
2736
DATASTORE_FILE_PATH = LOCAL_DATASTORE_FILE_PATH
2837
else:
38+
# Otherwise, leverage the datastore inside the python package
39+
logger.debug("Leveraging the bundled IAM Definition.")
2940
DATASTORE_FILE_PATH = BUNDLED_DATASTORE_FILE_PATH
3041

3142
# Overrides

policy_sentry/shared/iam_data.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
"""Used for loading the IAM data"""
2-
import os
32
import json
43
import logging
54
import functools
5+
from policy_sentry.shared.constants import DATASTORE_FILE_PATH
66

7+
logger = logging.getLogger()
78
# On initialization, load the IAM data
8-
iam_definition_path = os.path.join(
9-
os.path.abspath(os.path.dirname(__file__)), "data", "iam-definition.json"
10-
)
9+
iam_definition_path = DATASTORE_FILE_PATH
10+
logger.info(f"Leveraging the IAM definition at {iam_definition_path}")
1111
iam_definition = json.load(open(iam_definition_path, "r"))
12-
logger = logging.getLogger(__name__)
1312

1413

1514
@functools.lru_cache(maxsize=1024)

policy_sentry/writing/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
from schema import Optional, Schema, And, Use, SchemaError
66

7-
logger = logging.getLogger("__main__." + __name__)
7+
logger = logging.getLogger(__name__)
88

99

1010
def check(conf_schema, conf):

0 commit comments

Comments
 (0)