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-
()
| 33 | |
| 34 | |
| 35 | def _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, binary multipliers: ``MB`` is |
| 42 | 1024*1024 and ``GB`` is 1024*1024*1024, i.e. MiB / GiB). |
| 43 | Falls back to ``_MAX_GRAPH_FILE_BYTES`` (512 MiB) when the env var is unset, |
| 44 | blank, or unparseable. |
| 45 | |
| 46 | Read fresh on every call so the env var can be set before import and still |
| 47 | take effect. |
| 48 | """ |
| 49 | raw = os.environ.get("GRAPHIFY_MAX_GRAPH_BYTES", "").strip() |
| 50 | if not raw: |
| 51 | return _MAX_GRAPH_FILE_BYTES |
| 52 | text = raw.upper() |
| 53 | multiplier = 1 |
| 54 | if text.endswith("GB"): |
| 55 | multiplier = 1024 * 1024 * 1024 |
| 56 | text = text[:-2].strip() |
| 57 | elif text.endswith("MB"): |
| 58 | multiplier = 1024 * 1024 |
| 59 | text = text[:-2].strip() |
| 60 | try: |
| 61 | value = int(text) |
| 62 | except ValueError: |
| 63 | return _MAX_GRAPH_FILE_BYTES |
| 64 | if value <= 0: |
| 65 | return _MAX_GRAPH_FILE_BYTES |
| 66 | return value * multiplier |
| 67 | |
| 68 | # AWS metadata, link-local, and common cloud metadata endpoints |
| 69 | _BLOCKED_HOSTS = {"metadata.google.internal", "metadata.google.com"} |