Skip to content

Commit 4672706

Browse files
authored
Updated readme and updated sdk requirements (#121)
* Updated readme and updated sdk requirements * feat: enhance monorepo support with multiple --sub-path options - Add support for multiple --sub-path arguments to scan different directories within a single workspace - Require --workspace-name when using --sub-path for proper workspace identification - Optimize base_paths parameter to pass target_path for simplified SDK integration - Update argument validation to enforce sub_paths and workspace_name pairing - Add comprehensive README documentation with monorepo examples and usage patterns - Include GitHub Actions workflow examples for monorepo CI/CD scenarios - Extend parameter table with detailed descriptions of new CLI options This enhancement enables scanning multiple directories (e.g., frontend, backend, services/api) as a single workspace while preserving git context from the repository root, making it ideal for organizations with monorepo structures.
1 parent 40fc69e commit 4672706

File tree

6 files changed

+150
-78
lines changed

6 files changed

+150
-78
lines changed

README.md

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,60 @@ Pre-configured workflow examples are available in the [`workflows/`](workflows/)
4141

4242
These examples are production-ready and include best practices for each platform.
4343

44+
## Monorepo Workspace Support
45+
46+
The Socket CLI supports scanning specific workspaces within monorepo structures while preserving git context from the repository root. This is useful for organizations that maintain multiple applications or services in a single repository.
47+
48+
### Key Features
49+
50+
- **Multiple Sub-paths**: Specify multiple `--sub-path` options to scan different directories within your monorepo
51+
- **Combined Workspace**: All sub-paths are scanned together as a single workspace in Socket
52+
- **Git Context Preserved**: Repository metadata (commits, branches, etc.) comes from the main target-path
53+
- **Workspace Naming**: Use `--workspace-name` to differentiate scans from different parts of your monorepo
54+
55+
### Usage Examples
56+
57+
**Scan multiple frontend and backend workspaces:**
58+
```bash
59+
socketcli --target-path /path/to/monorepo \
60+
--sub-path frontend \
61+
--sub-path backend \
62+
--sub-path services/api \
63+
--workspace-name main-app
64+
```
65+
66+
**GitHub Actions for monorepo workspace:**
67+
```bash
68+
socketcli --target-path $GITHUB_WORKSPACE \
69+
--sub-path packages/web \
70+
--sub-path packages/mobile \
71+
--workspace-name mobile-web \
72+
--scm github \
73+
--pr-number $PR_NUMBER
74+
```
75+
76+
This will:
77+
- Scan manifest files in `./packages/web/` and `./packages/mobile/`
78+
- Combine them into a single workspace scan
79+
- Create a repository in Socket named like `my-repo-mobile-web`
80+
- Preserve git context (commits, branch info) from the repository root
81+
82+
### Requirements
83+
84+
- Both `--sub-path` and `--workspace-name` must be specified together
85+
- `--sub-path` can be used multiple times to include multiple directories
86+
- All specified sub-paths must exist within the target-path
87+
4488
## Usage
4589

4690
```` shell
47-
socketcli [-h] [--api-token API_TOKEN] [--repo REPO] [--integration {api,github,gitlab}] [--owner OWNER] [--branch BRANCH]
48-
[--committers [COMMITTERS ...]] [--pr-number PR_NUMBER] [--commit-message COMMIT_MESSAGE] [--commit-sha COMMIT_SHA]
49-
[--target-path TARGET_PATH] [--sbom-file SBOM_FILE] [--files FILES] [--save-submitted-files-list SAVE_SUBMITTED_FILES_LIST]
50-
[--default-branch] [--pending-head] [--generate-license] [--enable-debug] [--enable-json] [--enable-sarif]
51-
[--disable-overview] [--disable-security-issue] [--allow-unverified] [--ignore-commit-files] [--disable-blocking]
52-
[--scm SCM] [--timeout TIMEOUT] [--exclude-license-details]
91+
socketcli [-h] [--api-token API_TOKEN] [--repo REPO] [--repo-is-public] [--branch BRANCH] [--integration {api,github,gitlab,azure,bitbucket}]
92+
[--owner OWNER] [--pr-number PR_NUMBER] [--commit-message COMMIT_MESSAGE] [--commit-sha COMMIT_SHA] [--committers [COMMITTERS ...]]
93+
[--target-path TARGET_PATH] [--sbom-file SBOM_FILE] [--license-file-name LICENSE_FILE_NAME] [--save-submitted-files-list SAVE_SUBMITTED_FILES_LIST]
94+
[--save-manifest-tar SAVE_MANIFEST_TAR] [--files FILES] [--sub-path SUB_PATH] [--workspace-name WORKSPACE_NAME]
95+
[--excluded-ecosystems EXCLUDED_ECOSYSTEMS] [--default-branch] [--pending-head] [--generate-license] [--enable-debug]
96+
[--enable-json] [--enable-sarif] [--disable-overview] [--exclude-license-details] [--allow-unverified] [--disable-security-issue]
97+
[--ignore-commit-files] [--disable-blocking] [--enable-diff] [--scm SCM] [--timeout TIMEOUT] [--include-module-folders] [--version]
5398
````
5499

55100
If you don't want to provide the Socket API Token every time then you can use the environment variable `SOCKET_SECURITY_API_KEY`
@@ -65,11 +110,11 @@ If you don't want to provide the Socket API Token every time then you can use th
65110
| Parameter | Required | Default | Description |
66111
|:-----------------|:---------|:--------|:------------------------------------------------------------------------|
67112
| --repo | False | *auto* | Repository name in owner/repo format (auto-detected from git remote) |
68-
| --integration | False | api | Integration type (api, github, gitlab) |
113+
| --repo-is-public | False | False | If set, flags a new repository creation as public. Defaults to false. |
114+
| --integration | False | api | Integration type (api, github, gitlab, azure, bitbucket) |
69115
| --owner | False | | Name of the integration owner, defaults to the socket organization slug |
70116
| --branch | False | *auto* | Branch name (auto-detected from git) |
71117
| --committers | False | *auto* | Committer(s) to filter by (auto-detected from git commit) |
72-
| --repo-is-public | False | False | If set, flags a new repository creation as public. Defaults to false. |
73118
74119
#### Pull Request and Commit
75120
| Parameter | Required | Default | Description |
@@ -83,17 +128,20 @@ If you don't want to provide the Socket API Token every time then you can use th
83128
|:----------------------------|:---------|:----------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
84129
| --target-path | False | ./ | Target path for analysis |
85130
| --sbom-file | False | | SBOM file path |
86-
| --files | False | *auto* | Files to analyze (JSON array string). Auto-detected from git commit changes when not specified |
87-
| --excluded-ecosystems | False | [] | List of ecosystems to exclude from analysis (JSON array string). You can get supported files from the [Supported Files API](https://docs.socket.dev/reference/getsupportedfiles) |
88131
| --license-file-name | False | `license_output.json` | Name of the file to save the license details to if enabled |
89132
| --save-submitted-files-list | False | | Save list of submitted file names to JSON file for debugging purposes |
90133
| --save-manifest-tar | False | | Save all manifest files to a compressed tar.gz archive with original directory structure |
134+
| --files | False | *auto* | Files to analyze (JSON array string). Auto-detected from git commit changes when not specified |
135+
| --sub-path | False | | Sub-path within target-path for manifest file scanning (can be specified multiple times). All sub-paths are combined into a single workspace scan while preserving git context from target-path. Must be used with --workspace-name |
136+
| --workspace-name | False | | Workspace name suffix to append to repository name (repo-name-workspace_name). Must be used with --sub-path |
137+
| --excluded-ecosystems | False | [] | List of ecosystems to exclude from analysis (JSON array string). You can get supported files from the [Supported Files API](https://docs.socket.dev/reference/getsupportedfiles) |
91138
92139
#### Branch and Scan Configuration
93-
| Parameter | Required | Default | Description |
94-
|:-----------------|:---------|:--------|:------------------------------------------------------------------------------------------------------|
95-
| --default-branch | False | *auto* | Make this branch the default branch (auto-detected from git and CI environment when not specified) |
96-
| --pending-head | False | *auto* | If true, the new scan will be set as the branch's head scan (automatically synced with default-branch) |
140+
| Parameter | Required | Default | Description |
141+
|:-------------------------|:---------|:--------|:------------------------------------------------------------------------------------------------------|
142+
| --default-branch | False | *auto* | Make this branch the default branch (auto-detected from git and CI environment when not specified) |
143+
| --pending-head | False | *auto* | If true, the new scan will be set as the branch's head scan (automatically synced with default-branch) |
144+
| --include-module-folders | False | False | If enabled will include manifest files from folders like node_modules |
97145

98146
#### Output Configuration
99147
| Parameter | Required | Default | Description |
@@ -104,6 +152,7 @@ If you don't want to provide the Socket API Token every time then you can use th
104152
| --enable-sarif | False | False | Enable SARIF output of results instead of table or JSON format |
105153
| --disable-overview | False | False | Disable overview output |
106154
| --exclude-license-details | False | False | Exclude license details from the diff report (boosts performance for large repos) |
155+
| --version | False | False | Show program's version number and exit |
107156
108157
#### Security Configuration
109158
| Parameter | Required | Default | Description |
@@ -119,7 +168,6 @@ If you don't want to provide the Socket API Token every time then you can use th
119168
| --enable-diff | False | False | Enable diff mode even when using --integration api (forces diff mode without SCM integration) |
120169
| --scm | False | api | Source control management type |
121170
| --timeout | False | | Timeout in seconds for API requests |
122-
| --include-module-folders | False | False | If enabled will include manifest files from folders like node_modules |
123171
124172
#### Plugins
125173

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.9"
9+
version = "2.2.11"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [
@@ -16,7 +16,7 @@ dependencies = [
1616
'GitPython',
1717
'packaging',
1818
'python-dotenv',
19-
'socketdev>=3.0.5,<4.0.0'
19+
'socketdev>=3.0.6,<4.0.0'
2020
]
2121
readme = "README.md"
2222
description = "Socket Security CLI for CI/CD"

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.9'
2+
__version__ = '2.2.11'

socketsecurity/config.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class CliConfig:
6060
license_file_name: str = "license_output.json"
6161
save_submitted_files_list: Optional[str] = None
6262
save_manifest_tar: Optional[str] = None
63-
sub_path: Optional[str] = None
63+
sub_paths: List[str] = field(default_factory=list)
6464
workspace_name: Optional[str] = None
6565

6666
@classmethod
@@ -108,7 +108,7 @@ def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig':
108108
'license_file_name': args.license_file_name,
109109
'save_submitted_files_list': args.save_submitted_files_list,
110110
'save_manifest_tar': args.save_manifest_tar,
111-
'sub_path': args.sub_path,
111+
'sub_paths': args.sub_paths or [],
112112
'workspace_name': args.workspace_name,
113113
'version': __version__
114114
}
@@ -133,11 +133,11 @@ def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig':
133133
if args.owner:
134134
config_args['integration_org_slug'] = args.owner
135135

136-
# Validate that sub_path and workspace_name are used together
137-
if args.sub_path and not args.workspace_name:
136+
# Validate that sub_paths and workspace_name are used together
137+
if args.sub_paths and not args.workspace_name:
138138
logging.error("--sub-path requires --workspace-name to be specified")
139139
exit(1)
140-
if args.workspace_name and not args.sub_path:
140+
if args.workspace_name and not args.sub_paths:
141141
logging.error("--workspace-name requires --sub-path to be specified")
142142
exit(1)
143143

@@ -299,9 +299,10 @@ def create_argument_parser() -> argparse.ArgumentParser:
299299
)
300300
path_group.add_argument(
301301
"--sub-path",
302-
dest="sub_path",
302+
dest="sub_paths",
303303
metavar="<path>",
304-
help="Sub-path within target-path for manifest file scanning (while preserving git context from target-path)"
304+
action="append",
305+
help="Sub-path within target-path for manifest file scanning (can be specified multiple times). All sub-paths will be combined into a single workspace scan while preserving git context from target-path"
305306
)
306307
path_group.add_argument(
307308
"--workspace-name",

0 commit comments

Comments
 (0)