Skip to content

Commit 4966365

Browse files
committed
implemented timeout and better blob search changes
1 parent bb5364e commit 4966365

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ The Socket Security CLI was created to enable integrations with other tools like
77
## Usage
88

99
```` shell
10-
socketcli [-h] [--api_token API_TOKEN] [--repo REPO] [--branch BRANCH] [--committer COMMITTER] [--pr_number PR_NUMBER]
11-
[--commit_message COMMIT_MESSAGE] [--default_branch] [--target_path TARGET_PATH] [--scm {api,github,gitlab}] [--sbom-file SBOM_FILE]
10+
socketcli [-h] [--api-token API_TOKEN] [--repo REPO] [--branch BRANCH] [--committer COMMITTER] [--pr-number PR_NUMBER]
11+
[--commit-message COMMIT_MESSAGE] [--default-branch] [--target-path TARGET_PATH] [--scm {api,github,gitlab}] [--sbom-file SBOM_FILE]
1212
[--commit-sha COMMIT_SHA] [--generate-license GENERATE_LICENSE] [-v] [--enable-debug] [--enable-json] [--enable-sarif] [--disable-overview]
1313
[--disable-security-issue] [--files FILES] [--ignore-commit-files] [--timeout]
1414
````
@@ -19,14 +19,14 @@ If you don't want to provide the Socket API Token every time then you can use th
1919
| Parameter | Alternate Name | Required | Default | Description |
2020
|:-------------------------|:---------------|:---------|:--------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2121
| -h | --help | False | | Show the CLI help message |
22-
| --api_token | | False | | Provides the Socket API Token |
22+
| --api-token | | False | | Provides the Socket API Token |
2323
| --repo | | True | | The string name in a git approved name for repositories. |
2424
| --branch | | False | | The string name in a git approved name for branches. |
2525
| --committer | | False | | The string name of the person doing the commit or running the CLI. Can be specified multiple times to have more than one committer |
26-
| --pr_number | | False | 0 | The integer for the PR or MR number |
27-
| --commit_message | | False | | The string for a commit message if there is one |
28-
| --default_branch | | False | False | If the flag is specified this will signal that this is the default branch. This needs to be enabled for a report to update Org Alerts and Org Dependencies |
29-
| --target_path | | False | ./ | This is the path to where the manifest files are location. The tool will recursively search for all supported manifest files |
26+
| --pr-number | | False | 0 | The integer for the PR or MR number |
27+
| --commit-message | | False | | The string for a commit message if there is one |
28+
| --default-branch | | False | False | If the flag is specified this will signal that this is the default branch. This needs to be enabled for a report to update Org Alerts and Org Dependencies |
29+
| --target-path | | False | ./ | This is the path to where the manifest files are location. The tool will recursively search for all supported manifest files |
3030
| --scm | | False | api | This is the mode that the tool is to run in. For local runs `api` would be the mode. Other options are `gitlab` and `github` |
3131
| --generate-license | | False | False | If this flag is specified it will generate a json file with the license per package and license text in the current working directory |
3232
| --version | -v | False | | Prints the version and exits |

socketsecurity/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class CliConfig:
3131
integration_type: IntegrationType = "api"
3232
integration_org_slug: Optional[str] = None
3333
pending_head: bool = False
34+
timeout: Optional[int] = None
3435
@classmethod
3536
def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig':
3637
parser = create_argument_parser()
@@ -62,6 +63,7 @@ def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig':
6263
'disable_blocking': args.disable_blocking,
6364
'integration_type': args.integration,
6465
'pending_head': args.pending_head,
66+
'timeout': args.timeout,
6567
}
6668

6769
if args.owner:
@@ -217,4 +219,11 @@ def create_argument_parser() -> argparse.ArgumentParser:
217219
help="Files to analyze (JSON array string)"
218220
)
219221

222+
parser.add_argument(
223+
"--timeout",
224+
type=int,
225+
help="Timeout in seconds for API requests",
226+
required=False
227+
)
228+
220229
return parser

socketsecurity/core/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ def find_files(path: str) -> List[str]:
167167
log.debug(f"Files found: {list(files)}")
168168
return list(files)
169169

170+
@staticmethod
171+
def to_case_insensitive_regex(input_string: str) -> str:
172+
"""
173+
Converts a string into a case-insensitive regex format.
174+
Example: "pipfile" -> "[Pp][Ii][Pp][Ff][Ii][Ll][Ee]"
175+
:param input_string: The input string to convert.
176+
:return: A case-insensitive regex string.
177+
"""
178+
return ''.join(f'[{char.lower()}{char.upper()}]' if char.isalpha() else char for char in input_string)
179+
170180
@staticmethod
171181
def load_files_for_sending(files: List[str], workspace: str) -> List[Tuple[str, Tuple[str, BinaryIO]]]:
172182
"""Prepares files for sending to the Socket API.

socketsecurity/socketcli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def main_code():
6363
# Initialize Socket core components
6464
socket_config = SocketConfig(
6565
api_key=config.api_token,
66-
allow_unverified_ssl=config.allow_unverified
66+
allow_unverified_ssl=config.allow_unverified,
67+
timeout=config.timeout if config.timeout is not None else 30 # Use CLI timeout if provided
6768
)
6869
print("loaded socket_config")
6970
client = CliClient(socket_config)

0 commit comments

Comments
 (0)