Skip to content

Commit a96ce20

Browse files
committed
Updated user agent string and fixed url encoding for full scan api
1 parent 109a69a commit a96ce20

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

socketdev/core/api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from socketdev.version import __version__
1717
from requests.exceptions import Timeout, ConnectionError
1818
import time
19-
import urllib.parse
2019

2120

2221
class API:
@@ -45,10 +44,9 @@ def do_request(
4544
if headers is None:
4645
headers = {
4746
"Authorization": f"Basic {self.encoded_key}",
48-
"User-Agent": f"SocketPythonScript/{__version__}",
47+
"User-Agent": f"SocketSDKPython/{__version__}",
4948
"accept": "application/json",
5049
}
51-
path = urllib.parse.quote(path)
5250
url = f"{self.api_url}/{path}"
5351

5452
def format_headers(headers_dict):

socketdev/fullscans/__init__.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from enum import Enum
44
from typing import Any, Dict, List, Optional, Union
55
from dataclasses import dataclass, asdict, field
6-
6+
import urllib.parse
77

88
from ..utils import IntegrationType, Utils
99

@@ -702,24 +702,10 @@ class FullScans:
702702
def __init__(self, api):
703703
self.api = api
704704

705-
def create_params_string(self, params: dict) -> str:
706-
param_str = ""
707-
708-
for name, value in params.items():
709-
if value:
710-
if name == "committers" and isinstance(value, list):
711-
for committer in value:
712-
param_str += f"&{name}={committer}"
713-
else:
714-
param_str += f"&{name}={value}"
715-
716-
param_str = "?" + param_str.lstrip("&")
717-
718-
return param_str
719705

720706
def get(self, org_slug: str, params: dict, use_types: bool = False) -> Union[dict, GetFullScanMetadataResponse]:
721-
params_arg = self.create_params_string(params)
722-
path = "orgs/" + org_slug + "/full-scans" + str(params_arg)
707+
params_arg = urllib.parse.urlencode(params)
708+
path = "orgs/" + org_slug + "/full-scans?" + str(params_arg)
723709
response = self.api.do_request(path=path)
724710

725711
if response.status_code == 200:
@@ -741,10 +727,8 @@ def post(self, files: list, params: FullScanParams, use_types: bool = False) ->
741727
org_slug = str(params.org_slug)
742728
params_dict = params.to_dict()
743729
params_dict.pop("org_slug")
744-
745-
params_arg = self.create_params_string(params_dict)
746-
747-
path = "orgs/" + org_slug + "/full-scans" + str(params_arg)
730+
params_arg = urllib.parse.urlencode(params_dict)
731+
path = "orgs/" + org_slug + "/full-scans?" + str(params_arg)
748732

749733
response = self.api.do_request(path=path, method="POST", files=files)
750734

0 commit comments

Comments
 (0)