Skip to content

Commit

Permalink
small apisec refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-papazian committed Jun 13, 2024
1 parent 9967778 commit 2c07867
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 1 addition & 3 deletions ddtrace/appsec/_api_security/api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ def _should_collect_schema(self, env, priority: int) -> bool:
return True

def _schema_callback(self, env):
from ddtrace.appsec._utils import _appsec_apisec_features_is_active

if env.span is None or not _appsec_apisec_features_is_active():
if env.span is None or not asm_config._api_security_feature_active:
return
root = env.span._local_root or env.span
if not root or any(meta_name in root._meta for _, meta_name, _ in self.COLLECTED):
Expand Down
4 changes: 1 addition & 3 deletions ddtrace/appsec/_asm_request_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,7 @@ def _set_headers_and_response(response, headers, *_):
if not asm_config._asm_enabled:
return

from ddtrace.appsec._utils import _appsec_apisec_features_is_active

if _appsec_apisec_features_is_active():
if asm_config._api_security_feature_active:
if headers:
# start_response was not called yet, set the HTTP response headers earlier
if isinstance(headers, dict):
Expand Down
4 changes: 0 additions & 4 deletions ddtrace/appsec/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ def access_body(bd):
return req_body


def _appsec_apisec_features_is_active() -> bool:
return asm_config._asm_libddwaf_available and asm_config._asm_enabled and asm_config._api_security_enabled


def _safe_userid(user_id):
try:
_ = int(user_id)
Expand Down
4 changes: 4 additions & 0 deletions ddtrace/settings/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def reset(self):
"""For testing puposes, reset the configuration to its default values given current environment variables."""
self.__init__()

@property
def _api_security_feature_active(self) -> bool:
return self._asm_libddwaf_available and self._asm_enabled and self._api_security_enabled


config = ASMConfig()

Expand Down

0 comments on commit 2c07867

Please sign in to comment.