MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _max_graph_file_bytes

Function _max_graph_file_bytes

graphify/security.py:35–65  ·  view source on GitHub ↗

Return the graph.json size cap in bytes. Honors the ``GRAPHIFY_MAX_GRAPH_BYTES`` environment variable so users with large codebases can raise the limit without editing source. The value may be plain bytes (``671088640``) or carry an ``MB`` / ``GB`` suffix (``640MB``, ``2GB`` — case-

()

Source from the content-addressed store, hash-verified

33
34
35def _max_graph_file_bytes() -> int:
36 """Return the graph.json size cap in bytes.
37
38 Honors the ``GRAPHIFY_MAX_GRAPH_BYTES`` environment variable so users with
39 large codebases can raise the limit without editing source. The value may
40 be plain bytes (``671088640``) or carry an ``MB`` / ``GB`` suffix
41 (``640MB``, ``2GB`` — case-insensitive, decimal multipliers of 1024).
42 Falls back to ``_MAX_GRAPH_FILE_BYTES`` (512 MiB) when the env var is unset,
43 blank, or unparseable.
44
45 Read fresh on every call so the env var can be set before import and still
46 take effect.
47 """
48 raw = os.environ.get("GRAPHIFY_MAX_GRAPH_BYTES", "").strip()
49 if not raw:
50 return _MAX_GRAPH_FILE_BYTES
51 text = raw.upper()
52 multiplier = 1
53 if text.endswith("GB"):
54 multiplier = 1024 * 1024 * 1024
55 text = text[:-2].strip()
56 elif text.endswith("MB"):
57 multiplier = 1024 * 1024
58 text = text[:-2].strip()
59 try:
60 value = int(text)
61 except ValueError:
62 return _MAX_GRAPH_FILE_BYTES
63 if value <= 0:
64 return _MAX_GRAPH_FILE_BYTES
65 return value * multiplier
66
67# AWS metadata, link-local, and common cloud metadata endpoints
68_BLOCKED_HOSTS = {"metadata.google.internal", "metadata.google.com"}

Callers 1

Calls 1

getMethod · 0.45

Tested by

no test coverage detected