name: "workspace_zulip_bridge"
description: "Workspace bridge for personal Zulip accounts"
schema_version: 1
version: "0.0.35-rc+20260824140142.f6c5d5d9"
api_version: "v1"

requirements:
  core:
    from_version: "0.0.0"
  workspace:
    from_version: "0.0.0"

imports:
  core_local_domain:
    element: "$core"
    kind: "resource"
    link: "$core.dns.domains.$local_domain"
  workspace_backend_node:
    element: "$workspace"
    kind: "resource"
    link: "$core.compute.nodes.$workspace_backend"
  workspace_zulip_bridge_enrollment_secret:
    element: "$workspace"
    kind: "resource"
    link: "$core.secret.passwords.$workspace_zulip_bridge_enrollment_secret"
  profile_develop:
    element: "$core"
    kind: "resource"
    link: "$core.vs.profiles.$develop"
  profile_small:
    element: "$core"
    kind: "resource"
    link: "$core.vs.profiles.$small"
  profile_medium:
    element: "$core"
    kind: "resource"
    link: "$core.vs.profiles.$medium"
  profile_large:
    element: "$core"
    kind: "resource"
    link: "$core.vs.profiles.$large"
  profile_legacy:
    element: "$core"
    kind: "resource"
    link: "$core.vs.profiles.$legacy"

resources:
  $core.vs.variables:
    workspace_zulip_bridge_cores:
      name: "workspace_zulip_bridge_cores"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      setter:
        kind: profile
        element: null
        fallback_strategy: ignore
        profiles:
          - profile: $workspace_zulip_bridge.imports.$profile_develop:uuid
            value: 8
          - profile: $workspace_zulip_bridge.imports.$profile_small:uuid
            value: 8
          - profile: $workspace_zulip_bridge.imports.$profile_medium:uuid
            value: 8
          - profile: $workspace_zulip_bridge.imports.$profile_large:uuid
            value: 8
          - profile: $workspace_zulip_bridge.imports.$profile_legacy:uuid
            value: 8
    workspace_zulip_bridge_ram:
      name: "workspace_zulip_bridge_ram"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      setter:
        kind: profile
        element: null
        fallback_strategy: ignore
        profiles:
          - profile: $workspace_zulip_bridge.imports.$profile_develop:uuid
            value: 8192
          - profile: $workspace_zulip_bridge.imports.$profile_small:uuid
            value: 8192
          - profile: $workspace_zulip_bridge.imports.$profile_medium:uuid
            value: 8192
          - profile: $workspace_zulip_bridge.imports.$profile_large:uuid
            value: 8192
          - profile: $workspace_zulip_bridge.imports.$profile_legacy:uuid
            value: 8192
    workspace_zulip_bridge_data_disk_size:
      name: "workspace_zulip_bridge_data_disk_size"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      setter:
        kind: profile
        element: null
        fallback_strategy: ignore
        profiles:
          - profile: $workspace_zulip_bridge.imports.$profile_develop:uuid
            value: 20
          - profile: $workspace_zulip_bridge.imports.$profile_small:uuid
            value: 30
          - profile: $workspace_zulip_bridge.imports.$profile_medium:uuid
            value: 100
          - profile: $workspace_zulip_bridge.imports.$profile_large:uuid
            value: 256
          - profile: $workspace_zulip_bridge.imports.$profile_legacy:uuid
            value: 256
    workspace_zulip_bridge_batch_size:
      name: "workspace_zulip_bridge_batch_size"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      setter:
        kind: profile
        element: null
        fallback_strategy: ignore
        profiles:
          - profile: $workspace_zulip_bridge.imports.$profile_develop:uuid
            value: 20
          - profile: $workspace_zulip_bridge.imports.$profile_small:uuid
            value: 20
          - profile: $workspace_zulip_bridge.imports.$profile_medium:uuid
            value: 50
          - profile: $workspace_zulip_bridge.imports.$profile_large:uuid
            value: 100
          - profile: $workspace_zulip_bridge.imports.$profile_legacy:uuid
            value: 100
    workspace_zulip_bridge_event_long_polling:
      name: "workspace_zulip_bridge_event_long_polling"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      setter:
        kind: profile
        element: null
        fallback_strategy: ignore
        profiles:
          - profile: $workspace_zulip_bridge.imports.$profile_develop:uuid
            value: 0
          - profile: $workspace_zulip_bridge.imports.$profile_small:uuid
            value: 0
          - profile: $workspace_zulip_bridge.imports.$profile_medium:uuid
            value: 0
          - profile: $workspace_zulip_bridge.imports.$profile_large:uuid
            value: 1
          - profile: $workspace_zulip_bridge.imports.$profile_legacy:uuid
            value: 1

  $core.compute.nodes:
    workspace_zulip_bridge:
      name: "workspace-zulip-bridge"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      cores: $core.vs.variables.$workspace_zulip_bridge_cores:value
      ram: $core.vs.variables.$workspace_zulip_bridge_ram:value
      disk_spec:
        kind: "disks"
        disks:
          - size: 10
            image: "urn:images:96d0855d-be37-5ce0-9ec4-5284b1b20ff4"
            label: root
          - size: $core.vs.variables.$workspace_zulip_bridge_data_disk_size:value
            label: data

  $core.config.configs:
    workspace_zulip_bridge_config:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      path: /etc/workspace-zulip-bridge/bridge.conf
      mode: "0640"
      owner: root
      group: workspace-zulip
      target:
        kind: node
        node: $core.compute.nodes.$workspace_zulip_bridge:uuid
      on_change:
        kind: shell
        command: /usr/local/bin/workspace-zulip-bridge-restart
      body:
        kind: text
        content: |
          f"
          [db]
          connection_url = postgresql:///workspace_zulip_bridge

          [control]
          base_url = https://workspace-bridge-control.{$workspace_zulip_bridge.imports.$core_local_domain:name}:21443
          bootstrap_url = http://workspace-bridge-control.{$workspace_zulip_bridge.imports.$core_local_domain:name}:21085
          hostname = workspace-bridge-control.{$workspace_zulip_bridge.imports.$core_local_domain:name}
          ca_file = /var/lib/workspace-zulip-bridge/pki/control-ca.crt
          certificate_file = /var/lib/workspace-zulip-bridge/pki/bridge.crt
          private_key_file = /var/lib/workspace-zulip-bridge/pki/bridge.key
          credential_private_key_file = /var/lib/workspace-zulip-bridge/pki/credential-x25519.key
          timeout_seconds = 300
          poll_interval_seconds = 2
          heartbeat_interval_seconds = 10
          retry_base_seconds = 1
          retry_cap_seconds = 30
          retry_after_cap_seconds = 300

          [identity]
          realm_uuid = {$workspace_zulip_bridge.imports.$core_local_domain:uuid}
          bridge_instance_uuid = {$workspace_zulip_bridge.imports.$workspace_zulip_bridge_enrollment_secret:uuid}
          identity_generation = 1
          enrollment_secret_file = /etc/workspace-zulip-bridge/secrets/enrollment-secret

          [provider_api]
          base_url = https://workspace-bridge-control.{$workspace_zulip_bridge.imports.$core_local_domain:name}:21443
          ca_file = /var/lib/workspace-zulip-bridge/pki/control-ca.crt
          certificate_file = /var/lib/workspace-zulip-bridge/pki/bridge.crt
          private_key_file = /var/lib/workspace-zulip-bridge/pki/bridge.key
          poll_interval_seconds = 2
          event_long_polling = {$core.vs.variables.$workspace_zulip_bridge_event_long_polling:value}
          lease_seconds = 300
          batch_size = {$core.vs.variables.$workspace_zulip_bridge_batch_size:value}
          timeout_seconds = 30

          [file_api]
          base_url = https://workspace-bridge-control.{$workspace_zulip_bridge.imports.$core_local_domain:name}:21443
          ca_file = /var/lib/workspace-zulip-bridge/pki/control-ca.crt
          certificate_file = /var/lib/workspace-zulip-bridge/pki/bridge.crt
          private_key_file = /var/lib/workspace-zulip-bridge/pki/bridge.key

          [service]
          health_file = /run/workspace-zulip-bridge/progress
          worker_id = {$core.compute.nodes.$workspace_zulip_bridge:uuid}
          "
    workspace_zulip_bridge_enrollment_secret:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      path: /etc/workspace-zulip-bridge/secrets/enrollment-secret
      mode: "0640"
      owner: root
      group: workspace-zulip
      target:
        kind: node
        node: $core.compute.nodes.$workspace_zulip_bridge:uuid
      body:
        kind: text
        content: 'f"{$workspace_zulip_bridge.imports.$workspace_zulip_bridge_enrollment_secret:value}"'

  $workspace_zulip_bridge.imports.$core_local_domain.records:
    workspace_zulip_bridge:
      domain: $workspace_zulip_bridge.imports.$core_local_domain:uuid
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      type: A
      record:
        kind: A
        name: workspace-zulip-bridge
        address: $core.compute.nodes.$workspace_zulip_bridge:default_network:ipv4
    workspace_bridge_control:
      domain: $workspace_zulip_bridge.imports.$core_local_domain:uuid
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      type: A
      record:
        kind: A
        name: workspace-bridge-control
        address: $workspace_zulip_bridge.imports.$workspace_backend_node:default_network:ipv4

  $core.em.services:
    workspace_zulip_bridge_bootstrap:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      name: "workspace-zulip-bridge-bootstrap"
      path: /usr/local/bin/workspace-zulip-bridge-bootstrap
      user: root
      target:
        kind: node
        node: $core.compute.nodes.$workspace_zulip_bridge:uuid
      service_type:
        kind: oneshot
      target_status: enabled
    workspace_zulip_bridge:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      name: "workspace-zulip-bridge"
      path: /opt/workspace-zulip-bridge-venv/bin/workspace-zulip-bridge --config /etc/workspace-zulip-bridge/bridge.conf
      user: workspace-zulip
      target:
        kind: node
        node: $core.compute.nodes.$workspace_zulip_bridge:uuid
      service_type:
        kind: simple
        count: 1
      target_status: enabled
      before:
        - kind: shell
          command: /usr/local/bin/workspace-zulip-bridge-bootstrap

exports:
  bridge_node:
    link: "$core.compute.nodes.$workspace_zulip_bridge"
    kind: "resource"