Skip to content

Commit

Permalink
fix(client): move payload to GCClient
Browse files Browse the repository at this point in the history
  • Loading branch information
fnareoh committed Jan 9, 2024
1 parent 7c53cc9 commit 3052fd4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
15 changes: 10 additions & 5 deletions pygitguardian/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
import requests
from requests import Response, Session, codes

from .config import DEFAULT_API_VERSION, DEFAULT_BASE_URI, DEFAULT_TIMEOUT
from .config import (
DEFAULT_API_VERSION,
DEFAULT_BASE_URI,
DEFAULT_TIMEOUT,
MAXIMUM_PAYLOAD_SIZE,
)
from .iac_models import (
IaCDiffScanResult,
IaCScanParameters,
Expand Down Expand Up @@ -190,6 +195,7 @@ def __init__(
"Authorization": f"Token {api_key}",
},
)
self.maximum_payload_size = MAXIMUM_PAYLOAD_SIZE
self.secret_scan_preferences = SecretScanPreferences()

def request(
Expand Down Expand Up @@ -584,10 +590,9 @@ def read_metadata(self) -> Optional[Detail]:
result.status_code = resp.status_code
return result
metadata = ServerMetadata.from_dict(resp.json())
if "general__maximum_payload_size" in metadata.preferences:
metadata.secret_scan_preferences.general__maximum_payload_size = (
metadata.preferences["general__maximum_payload_size"]
)
self.maximum_payload_size = metadata.preferences.get(
"general__maximum_payload_size", MAXIMUM_PAYLOAD_SIZE
)
self.secret_scan_preferences = metadata.secret_scan_preferences
return None

Expand Down
2 changes: 1 addition & 1 deletion pygitguardian/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

MULTI_DOCUMENT_LIMIT = 20
DOCUMENT_SIZE_THRESHOLD_BYTES = 1048576 # 1MB
GENERAL_MAXIMUM_PAYLOAD = 2621440 # 25MB
MAXIMUM_PAYLOAD_SIZE = 2621440 # 25MB
7 changes: 1 addition & 6 deletions pygitguardian/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
)
from typing_extensions import Self

from .config import (
DOCUMENT_SIZE_THRESHOLD_BYTES,
GENERAL_MAXIMUM_PAYLOAD,
MULTI_DOCUMENT_LIMIT,
)
from .config import DOCUMENT_SIZE_THRESHOLD_BYTES, MULTI_DOCUMENT_LIMIT


class ToDictMixin:
Expand Down Expand Up @@ -662,7 +658,6 @@ def __repr__(self) -> str:
class SecretScanPreferences:
maximum_document_size: int = DOCUMENT_SIZE_THRESHOLD_BYTES
maximum_documents_per_scan: int = MULTI_DOCUMENT_LIMIT
general__maximum_payload_size: int = GENERAL_MAXIMUM_PAYLOAD


@dataclass
Expand Down

0 comments on commit 3052fd4

Please sign in to comment.