File tree Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 13
13
14
14
from policy_sentry import set_stream_logger
15
15
from policy_sentry .querying .all import get_all_service_prefixes
16
- from policy_sentry .shared .awsdocs import (
17
- create_database ,
18
- update_html_docs_directory ,
19
- )
20
16
from policy_sentry .shared .constants import (
21
17
BUNDLED_DATA_DIRECTORY ,
22
18
BUNDLED_DATASTORE_FILE_PATH ,
@@ -90,6 +86,13 @@ def initialize(
90
86
Initialize the local data file to store AWS IAM information, which can be used to generate IAM policies, and for
91
87
querying the database.
92
88
"""
89
+
90
+ # importing 'awsdocs' is quite pricey, when it is actually only used for initialize the IAM DB
91
+ from policy_sentry .shared .awsdocs import (
92
+ create_database ,
93
+ update_html_docs_directory ,
94
+ )
95
+
93
96
if not access_level_overrides_file :
94
97
overrides_file = LOCAL_ACCESS_OVERRIDES_FILE
95
98
else :
Original file line number Diff line number Diff line change 3
3
from __future__ import annotations
4
4
5
5
import functools
6
- import json
6
+ import gc
7
7
import logging
8
8
from pathlib import Path
9
9
from typing import Any , cast
10
10
11
+ import orjson
12
+
11
13
from policy_sentry .shared .constants import (
12
14
DATASTORE_FILE_PATH ,
13
15
POLICY_SENTRY_SCHEMA_VERSION_NAME ,
18
20
# On initialization, load the IAM data
19
21
iam_definition_path = DATASTORE_FILE_PATH
20
22
logger .debug (f"Leveraging the IAM definition at { iam_definition_path } " )
21
- iam_definition = json .loads (Path (iam_definition_path ).read_bytes ())
23
+
24
+
25
+ def load_iam_definition () -> dict [str , Any ]:
26
+ gc_enabled = gc .isenabled ()
27
+ if gc_enabled :
28
+ # https://github.com/msgpack/msgpack-python?tab=readme-ov-file#performance-tips
29
+ gc .disable ()
30
+
31
+ data : dict [str , Any ] = orjson .loads (Path (iam_definition_path ).read_bytes ())
32
+
33
+ if gc_enabled :
34
+ gc .enable ()
35
+
36
+ return data
37
+
38
+
39
+ iam_definition = load_iam_definition ()
22
40
23
41
24
42
@functools .lru_cache (maxsize = 1 )
Original file line number Diff line number Diff line change @@ -6,3 +6,5 @@ requests==2.32.3
6
6
# Config files and schema validation
7
7
PyYAML == 6.0.1
8
8
schema == 0.7.7
9
+ # IAM DB
10
+ orjson == 3.10.6
Original file line number Diff line number Diff line change 13
13
"requests" ,
14
14
"schema" ,
15
15
"PyYAML" ,
16
+ "orjson" ,
16
17
]
17
18
PROJECT_URLS = {
18
19
"Documentation" : "https://policy-sentry.readthedocs.io/" ,
You can’t perform that action at this time.
0 commit comments