Skip to content

timeout defaults to 1200 #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ test = [
dev = [
"ruff>=0.3.0",
"pip-tools>=7.4.0", # for pip-compile
"twine"
]

[project.scripts]
Expand Down
2 changes: 1 addition & 1 deletion socketsecurity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__author__ = 'socket.dev'
__version__ = '2.0.4'
__version__ = '2.0.5'
7 changes: 7 additions & 0 deletions socketsecurity/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CliConfig:
integration_org_slug: Optional[str] = None
pending_head: bool = False
timeout: Optional[int] = 1200
timeout: Optional[int] = 1200
@classmethod
def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig':
parser = create_argument_parser()
Expand Down Expand Up @@ -265,6 +266,12 @@ def create_argument_parser() -> argparse.ArgumentParser:
action="store_true",
help="Output in JSON format"
)
output_group.add_argument(
"--enable_json",
dest="enable_json",
action="store_true",
help=argparse.SUPPRESS
)
output_group.add_argument(
"--enable-sarif",
dest="enable_sarif",
Expand Down
290 changes: 160 additions & 130 deletions socketsecurity/core/__init__.py

Large diffs are not rendered by default.

81 changes: 41 additions & 40 deletions socketsecurity/core/classes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
from dataclasses import dataclass, field
from typing import Dict, List, TypedDict, Any, Optional
from typing import Dict, List, TypedDict, Any, Optional, Tuple

from socketdev.fullscans import FullScanMetadata, SocketArtifact, SocketArtifactLink, DiffType, SocketManifestReference, SocketScore, SocketAlert
from socketdev.fullscans import FullScanMetadata, SocketArtifact, SocketArtifactLink, SocketScore, SocketAlert, DiffArtifact

__all__ = [
"Report",
Expand Down Expand Up @@ -121,42 +121,43 @@ class Package(SocketArtifactLink):
purl: str = ""
transitives: int = 0
url: str = ""
introduced_by: List[Tuple[str, str]] = field(default_factory=list)

@classmethod
def from_socket_artifact(cls, data: dict) -> "Package":
def from_socket_artifact(cls, artifact: SocketArtifact) -> "Package":
"""
Create a Package from a SocketArtifact dictionary.
Create a Package from a SocketArtifact.

Args:
data: Dictionary containing SocketArtifact data
artifact: SocketArtifact instance from scan results

Returns:
New Package instance
"""
return cls(
id=data["id"],
name=data["name"],
version=data["version"],
type=data["type"],
score=data["score"],
alerts=data["alerts"],
author=data.get("author", []),
size=data.get("size"),
license=data.get("license"),
topLevelAncestors=data["topLevelAncestors"],
direct=data.get("direct", False),
manifestFiles=data.get("manifestFiles", []),
dependencies=data.get("dependencies"),
artifact=data.get("artifact")
id=artifact.id,
name=artifact.name,
version=artifact.version,
type=artifact.type,
score=artifact.score,
alerts=artifact.alerts,
author=artifact.author or [],
size=artifact.size,
license=artifact.license,
topLevelAncestors=artifact.topLevelAncestors,
direct=artifact.direct,
manifestFiles=artifact.manifestFiles,
dependencies=artifact.dependencies,
artifact=artifact.artifact
)

@classmethod
def from_diff_artifact(cls, data: dict) -> "Package":
def from_diff_artifact(cls, artifact: DiffArtifact) -> "Package":
"""
Create a Package from a DiffArtifact dictionary.
Create a Package from a DiffArtifact.

Args:
data: Dictionary containing DiffArtifact data
artifact: DiffArtifact instance from diff results

Returns:
New Package instance
Expand All @@ -165,29 +166,29 @@ def from_diff_artifact(cls, data: dict) -> "Package":
ValueError: If reference data cannot be found in DiffArtifact
"""
ref = None
if data["diffType"] in ["added", "updated"] and data.get("head"):
ref = data["head"][0]
elif data["diffType"] in ["removed", "replaced"] and data.get("base"):
ref = data["base"][0]
if artifact.diffType in ["added", "updated"] and artifact.head:
ref = artifact.head[0]
elif artifact.diffType in ["removed", "replaced"] and artifact.base:
ref = artifact.base[0]

if not ref:
raise ValueError("Could not find reference data in DiffArtifact")

return cls(
id=data["id"],
name=data["name"],
version=data["version"],
type=data["type"],
score=data["score"],
alerts=data["alerts"],
author=data.get("author", []),
size=data.get("size"),
license=data.get("license"),
topLevelAncestors=ref["topLevelAncestors"],
direct=ref.get("direct", False),
manifestFiles=ref.get("manifestFiles", []),
dependencies=ref.get("dependencies"),
artifact=ref.get("artifact")
id=artifact.id,
name=artifact.name,
version=artifact.version,
type=artifact.type,
score=artifact.score,
alerts=artifact.alerts,
author=artifact.author or [],
size=artifact.size,
license=artifact.license,
topLevelAncestors=ref.topLevelAncestors,
direct=ref.direct,
manifestFiles=ref.manifestFiles,
dependencies=ref.dependencies,
artifact=ref.artifact
)

class Issue:
Expand Down
5 changes: 4 additions & 1 deletion socketsecurity/core/scm/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def from_env(cls, pr_number: Optional[str] = None) -> 'GithubConfig':
owner = repository.split('/')[0]
repository = repository.split('/')[1]

is_default = os.getenv('DEFAULT_BRANCH', '').lower() == 'true'
default_branch_env = os.getenv('DEFAULT_BRANCH')
# Consider the variable truthy if it exists and isn't explicitly 'false'
is_default = default_branch_env is not None and default_branch_env.lower() != 'false'

return cls(
sha=os.getenv('GITHUB_SHA', ''),
api_url=os.getenv('GITHUB_API_URL', ''),
Expand Down
23 changes: 23 additions & 0 deletions socketsecurity/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,28 @@
"pom.xml": {
"pattern": "pom.xml"
}
},
".net": {
"proj": {
"pattern": "*.*proj"
},
"props": {
"pattern": "*.props"
},
"targets": {
"pattern": "*.targets"
},
"nuspec": {
"pattern": "*.nuspec"
},
"nugetConfig": {
"pattern": "nuget.config"
},
"packagesConfig": {
"pattern": "packages.config"
},
"packagesLock": {
"pattern": "packages.lock.json"
}
}
}
4 changes: 3 additions & 1 deletion socketsecurity/socketcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def main_code():
log.debug(f"config: {config.to_dict()}")
output_handler = OutputHandler(config)

sdk = socketdev(token=config.api_token)
sdk = socketdev(token=config.api_token, timeout=config.timeout)
log.debug("sdk loaded")

if config.enable_debug:
Expand Down Expand Up @@ -146,6 +146,7 @@ def main_code():
integration_type = config.integration_type
integration_org_slug = config.integration_org_slug or org_slug

log.debug(f"config: {config.to_dict()}")
params = FullScanParams(
org_slug=org_slug,
integration_type=integration_type,
Expand All @@ -159,6 +160,7 @@ def main_code():
make_default_branch=config.default_branch,
set_as_pending_head=True
)
log.debug(f"Params initially set to: {params}")

# Initialize diff
diff = Diff()
Expand Down
Loading