Skip to content

Commit 9686cfa

Browse files
committed
add VULNERABLECODE_USER_AGENT
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 1102d93 commit 9686cfa

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

dejacode/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ def get_fake_redis_connection(config, use_strict_redis):
717717

718718
# Default to 5 seconds.
719719
DEJACODE_INTEGRATION_REQUESTS_TIMEOUT = env.int("DEJACODE_INTEGRATION_REQUESTS_TIMEOUT", default=5)
720+
VULNERABLECODE_USER_AGENT = env.str("VULNERABLECODE_USER_AGENT", default="VCIO_API_AGENT")
720721

721722
if IS_TESTS:
722723
# Silent the django-axes logging during tests

dejacode_toolkit/vulnerablecode.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.core.cache import caches
1010

1111
from dejacode_toolkit import BaseService
12+
from dejacode_toolkit import get_settings
1213
from dejacode_toolkit import logger
1314

1415
cache = caches["vulnerabilities"]
@@ -20,6 +21,12 @@ class VulnerableCode(BaseService):
2021
url_field_name = "vulnerablecode_url"
2122
api_key_field_name = "vulnerablecode_api_key"
2223
api_version = "v3"
24+
user_agent = get_settings("VULNERABLECODE_USER_AGENT", default="VCIO_API_AGENT")
25+
26+
def get_session(self):
27+
session = super().get_session()
28+
session.headers.update({"User-Agent": self.user_agent})
29+
return session
2330

2431
def get_vulnerabilities_by_purl(
2532
self,

0 commit comments

Comments
 (0)