Download copilot/platform/catalog.py from Wardline/cloak-api: direct link, hf CLI and curl.
- Browser
- Download file 3.82 kB
-
https://huggingface.co/spaces/Wardline/cloak-api/resolve/main/copilot/platform/catalog.py
- Command line
-
hf download hf://spaces/Wardline/cloak-api/copilot/platform/catalog.py
-
curl -L -o catalog.py https://huggingface.co/spaces/Wardline/cloak-api/resolve/main/copilot/platform/catalog.py
3.82 kB
| """Read-only access to the platform snapshot (synced from cloakv2 by tools/sync_platform.mjs). | |
| Everything here is a fact about the product, not about a tenant: built-in presets, AI sites, | |
| entity keys, form defaults. Tenant facts (groups, custom rules, connectors) arrive per request | |
| in a PlatformContext. | |
| """ | |
| from __future__ import annotations | |
| import copy | |
| import json | |
| from functools import lru_cache | |
| from pathlib import Path | |
| HERE = Path(__file__).parent | |
| # Every policy type the dashboard can create, keyed as NewPolicyPage.tsx keys them. | |
| # 'endpoint' is the agent/extension form (saved with channels: {}). | |
| POLICY_TYPES = ('endpoint', 'email', 'slack', 'teams', 'chat', 'drive', 'm365files', 's3', 'gcs', 'azure', 'github') | |
| CHANNEL_TYPES = POLICY_TYPES[1:] | |
| TYPE_LABEL = { | |
| 'endpoint': 'Devices & Browsers', | |
| 'email': 'Email', 'slack': 'Slack', 'teams': 'Microsoft Teams', 'chat': 'Google Chat', | |
| 'drive': 'Google Drive', 'm365files': 'OneDrive / SharePoint', 's3': 'Amazon S3', | |
| 'gcs': 'Google Cloud Storage', 'azure': 'Azure Blob Storage', 'github': 'GitHub', | |
| } | |
| # Display names for entity keys, matching the dashboard's ENTITY_GROUPS where it has one. | |
| _EXTRA_LABELS = { | |
| 'GSTIN': 'GSTIN', 'ITIN': 'US ITIN', 'EIN': 'US EIN', 'IBAN': 'IBAN', 'IFSC': 'IFSC Code', | |
| 'SWIFT_CODE': 'SWIFT Code', 'ROUTING_NUMBER': 'Routing Number', 'AWS_ACCESS_KEY': 'AWS Access Key', | |
| 'GITHUB_TOKEN': 'GitHub Token', 'OPENAI_KEY': 'OpenAI Key', 'ANTHROPIC_KEY': 'Anthropic Key', | |
| 'GOOGLE_API_KEY': 'Google API Key', 'SLACK_TOKEN': 'Slack Token', 'STRIPE_KEY': 'Stripe Key', | |
| 'HUGGINGFACE_TOKEN': 'Hugging Face Token', 'AZURE_KEY': 'Azure Key', 'PRIVATE_KEY': 'Private Key', | |
| 'JWT': 'JWT', 'BEARER_TOKEN': 'Bearer Token', 'DB_CONNECTION_STRING': 'Database Connection String', | |
| 'MEDICAL_RECORD_NUMBER': 'Medical Record Number', 'HEALTH_INSURANCE_ID': 'Health Insurance ID', | |
| 'MAC_ADDRESS': 'MAC Address', 'ZIP_CODE': 'ZIP / PIN Code', 'VIN': 'Vehicle Number (VIN)', | |
| 'CONFIDENTIAL': 'Confidential Marking', | |
| } | |
| def snapshot() -> dict: | |
| return json.loads((HERE / 'snapshot.json').read_text(encoding='utf-8')) | |
| def _default(policy_type: str) -> dict: | |
| return json.loads((HERE / 'defaults' / f'{policy_type}.json').read_text(encoding='utf-8'))['body'] | |
| def default_body(policy_type: str) -> dict: | |
| """A fresh copy of the body the form would send for this type, untouched.""" | |
| return copy.deepcopy(_default(policy_type)) | |
| def entity_labels() -> dict[str, str]: | |
| labels = dict(_EXTRA_LABELS) | |
| for g in snapshot()['entityGroupsUi']: | |
| for e in g['entities']: | |
| labels[e['key']] = e['label'] | |
| return labels | |
| def entity_keys() -> frozenset[str]: | |
| """Every key the platform can detect: regex patterns, dashboard detectors and preset entities.""" | |
| keys = set(snapshot()['patternLabels']) | set(entity_labels()) | |
| for r in snapshot()['detectionRules']: | |
| keys |= set(r['entities']) | |
| return frozenset(keys) | |
| def entity_label(key: str) -> str: | |
| return entity_labels().get(key) or key.replace('_', ' ').title() | |
| def high_risk() -> frozenset[str]: | |
| return frozenset(snapshot()['highRisk']) | |
| def file_types() -> tuple[str, ...]: | |
| return tuple(snapshot()['fileTypes']) | |
| def ai_sites() -> list[dict]: | |
| return snapshot()['aiSites'] | |
| def ai_hosts() -> list[str]: | |
| return [s['host'] for s in ai_sites()] | |
| def builtin_rules() -> list[dict]: | |
| return [dict(r, builtin=True) for r in snapshot()['detectionRules']] | |
| def builtin_block_lists() -> list[dict]: | |
| return [dict(b, builtin=True) for b in snapshot()['blockLists']] | |
| def ide() -> dict: | |
| return snapshot()['ide'] | |
| def action_rank() -> dict[str, int]: | |
| return snapshot()['actionRank'] | |