Skip to content

Commit 4853755

Browse files
committed
chore: migrate appsec/_iast to _get_env
1 parent 2c76546 commit 4853755

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

ddtrace/_trace/apm_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import os
21
from typing import List
32
from typing import Optional
43

54
from ddtrace._trace.processor import TraceProcessor
65
from ddtrace._trace.span import Span
76
from ddtrace.internal.utils.formats import asbool
7+
from ddtrace.settings._env import get_env as _get_env
88

99

1010
class APMTracingEnabledFilter(TraceProcessor):
@@ -14,7 +14,7 @@ class APMTracingEnabledFilter(TraceProcessor):
1414

1515
def __init__(self) -> None:
1616
super().__init__()
17-
self._apm_tracing_enabled = asbool(os.getenv("DD_APM_TRACING_ENABLED", "true"))
17+
self._apm_tracing_enabled = asbool(_get_env("DD_APM_TRACING_ENABLED", "true"))
1818

1919
def process_trace(self, trace: List[Span]) -> Optional[List[Span]]:
2020
if not self._apm_tracing_enabled:

ddtrace/_trace/product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import enum
22
import json
3-
import os
43
import typing as t
54

65
from envier import En
@@ -9,6 +8,7 @@
98
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
109
from ddtrace.internal.utils.formats import asbool
1110
from ddtrace.internal.utils.formats import parse_tags_str
11+
from ddtrace.settings._env import get_env as _get_env
1212
from ddtrace.settings.http import HttpConfig
1313
from ddtrace.vendor.debtcollector import deprecate
1414

@@ -32,7 +32,7 @@ def post_preload():
3232
if _config.enabled:
3333
from ddtrace._monkey import _patch_all
3434

35-
modules_to_patch = os.getenv("DD_PATCH_MODULES")
35+
modules_to_patch = _get_env("DD_PATCH_MODULES")
3636
modules_to_str = parse_tags_str(modules_to_patch)
3737
modules_to_bool = {k: asbool(v) for k, v in modules_to_str.items()}
3838
_patch_all(**modules_to_bool)

ddtrace/appsec/_iast/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ def wrapped_function(wrapped, instance, args, kwargs):
2828
return wrapped(*args, **kwargs)
2929
"""
3030

31-
import os
3231
import sys
3332
import types
3433

3534
from ddtrace.internal import forksafe
3635
from ddtrace.internal.logger import get_logger
3736
from ddtrace.internal.module import ModuleWatchdog
38-
from ddtrace.settings._config import _get_env
37+
from ddtrace.settings._env import environ as _env
3938
from ddtrace.settings.asm import config as asm_config
4039

4140
from ._listener import iast_listen
@@ -187,11 +186,11 @@ def _iast_pytest_activation():
187186
global _iast_propagation_enabled
188187
if _iast_propagation_enabled:
189188
return
190-
os.environ["DD_IAST_ENABLED"] = _get_env("DD_IAST_ENABLED", "1")
191-
os.environ["DD_IAST_REQUEST_SAMPLING"] = _get_env("DD_IAST_REQUEST_SAMPLING", "100.0")
192-
os.environ["_DD_APPSEC_DEDUPLICATION_ENABLED"] = _get_env("_DD_APPSEC_DEDUPLICATION_ENABLED", "false")
193-
os.environ["DD_IAST_VULNERABILITIES_PER_REQUEST"] = _get_env("DD_IAST_VULNERABILITIES_PER_REQUEST", "1000")
194-
os.environ["DD_IAST_MAX_CONCURRENT_REQUESTS"] = _get_env("DD_IAST_MAX_CONCURRENT_REQUESTS", "1000")
189+
_env["DD_IAST_ENABLED"] = _env.get("DD_IAST_ENABLED", "1")
190+
_env["DD_IAST_REQUEST_SAMPLING"] = _env.get("DD_IAST_REQUEST_SAMPLING", "100.0")
191+
_env["_DD_APPSEC_DEDUPLICATION_ENABLED"] = _env.get("_DD_APPSEC_DEDUPLICATION_ENABLED", "false")
192+
_env["DD_IAST_VULNERABILITIES_PER_REQUEST"] = _env.get("DD_IAST_VULNERABILITIES_PER_REQUEST", "1000")
193+
_env["DD_IAST_MAX_CONCURRENT_REQUESTS"] = _env.get("DD_IAST_MAX_CONCURRENT_REQUESTS", "1000")
195194

196195
asm_config._iast_request_sampling = 100.0
197196
asm_config._deduplication_enabled = False

ddtrace/appsec/_iast/taint_sinks/weak_cipher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from typing import Any
32
from typing import Callable
43
from typing import Set
@@ -13,6 +12,7 @@
1312
from ddtrace.appsec._iast.constants import RC4_DEF
1413
from ddtrace.appsec._iast.constants import VULN_WEAK_CIPHER_TYPE
1514
from ddtrace.internal.logger import get_logger
15+
from ddtrace.settings._env import get_env as _get_env
1616
from ddtrace.settings.asm import config as asm_config
1717

1818
from .._logs import iast_error
@@ -28,7 +28,7 @@
2828

2929
def get_weak_cipher_algorithms() -> Set:
3030
CONFIGURED_WEAK_CIPHER_ALGORITHMS = None
31-
DD_IAST_WEAK_CIPHER_ALGORITHMS = os.getenv("DD_IAST_WEAK_CIPHER_ALGORITHMS")
31+
DD_IAST_WEAK_CIPHER_ALGORITHMS = _get_env("DD_IAST_WEAK_CIPHER_ALGORITHMS")
3232
if DD_IAST_WEAK_CIPHER_ALGORITHMS:
3333
CONFIGURED_WEAK_CIPHER_ALGORITHMS = set(
3434
algo.strip() for algo in DD_IAST_WEAK_CIPHER_ALGORITHMS.lower().split(",")

ddtrace/appsec/_iast/taint_sinks/weak_hash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import os
21
from typing import Any
32
from typing import Callable
43
from typing import Set
54

65
from ddtrace.internal.logger import get_logger
6+
from ddtrace.settings._env import get_env as _get_env
77
from ddtrace.settings.asm import config as asm_config
88

99
from ..._common_module_patches import try_unwrap
@@ -28,7 +28,7 @@
2828

2929
def get_weak_hash_algorithms() -> Set:
3030
CONFIGURED_WEAK_HASH_ALGORITHMS = None
31-
DD_IAST_WEAK_HASH_ALGORITHMS = os.getenv("DD_IAST_WEAK_HASH_ALGORITHMS")
31+
DD_IAST_WEAK_HASH_ALGORITHMS = _get_env("DD_IAST_WEAK_HASH_ALGORITHMS")
3232
if DD_IAST_WEAK_HASH_ALGORITHMS:
3333
CONFIGURED_WEAK_HASH_ALGORITHMS = set(algo.strip() for algo in DD_IAST_WEAK_HASH_ALGORITHMS.lower().split(","))
3434

ddtrace/appsec/_processor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import dataclasses
22
import errno
33
from json.decoder import JSONDecodeError
4-
import os
5-
import os.path
64
from typing import TYPE_CHECKING
75
from typing import Any
86
from typing import ClassVar
@@ -43,6 +41,7 @@
4341
from ddtrace.internal.logger import get_logger
4442
from ddtrace.internal.rate_limiter import RateLimiter
4543
from ddtrace.internal.remoteconfig import PayloadType
44+
from ddtrace.settings._env import get_env as _get_env
4645
from ddtrace.settings.asm import config as asm_config
4746

4847

@@ -72,7 +71,7 @@ def get_rules() -> str:
7271

7372

7473
def _get_rate_limiter() -> RateLimiter:
75-
return RateLimiter(int(os.getenv("DD_APPSEC_TRACE_RATE_LIMIT", DEFAULT.TRACE_RATE_LIMIT)))
74+
return RateLimiter(int(_get_env("DD_APPSEC_TRACE_RATE_LIMIT", DEFAULT.TRACE_RATE_LIMIT)))
7675

7776

7877
@dataclasses.dataclass(eq=False)

0 commit comments

Comments
 (0)