code: def connect_to_enclave(
      oblv_keys_stash: OblvKeysStash,
      verify_key: SyftVerifyKey,
      oblv_client: OblvClient,
      deployment_id: str,
      connection_port: int,
      oblv_key_name: str,
  ) -> Optional[subprocess.Popen]:
      global OBLV_PROCESS_CACHE
      if deployment_id in OBLV_PROCESS_CACHE:
          process = OBLV_PROCESS_CACHE[deployment_id][0]
          if process.poll() is None:
              return process
          # If the process has been terminated create a new connection
          del OBLV_PROCESS_CACHE[deployment_id]
  
      # Always create key file each time, which ensures consistency when there is key change in database
      create_keys_from_db(
          oblv_keys_stash=oblv_keys_stash,
          verify_key=verify_key,
          oblv_key_name=oblv_key_name,
      )
      oblv_key_path = os.path.expanduser(
          os.getenv("OBLV_KEY_PATH", "~/.oblv")
      )
  
      public_file_name = (
          oblv_key_path + "/" + oblv_key_name + "_public.der"
      )
      private_file_name = (
          oblv_key_path + "/" + oblv_key_name + "_private.der"
      )
  
      depl = oblv_client.deployment_info(deployment_id)
      if depl.is_deleted:
          raise OblvEnclaveError(
              "User cannot connect to this deployment, as it is no longer available."
          )
      if depl.is_dev_env:
          process = subprocess.Popen(  # nosec
              [
                  "oblv",
                  "connect",
                  "--private-key",
                  private_file_name,
                  "--public-key",
                  public_file_name,
                  "--url",
                  depl.instance.service_url,
                  "--pcr0",
                  depl.pcr_codes[0],
                  "--pcr1",
                  depl.pcr_codes[1],
                  "--pcr2",
                  depl.pcr_codes[2],
                  "--port",
                  "443",
                  "--lport",
                  str(connection_port),
                  "--disable-pcr-check",
              ],
              stdout=subprocess.PIPE,
              stderr=subprocess.PIPE,
          )
      else:
          process = subprocess.Popen(  # nosec
              [
                  "oblv",
                  "connect",
                  "--private-key",
                  private_file_name,
                  "--public-key",
                  public_file_name,
                  "--url",
                  depl.instance.service_url,
                  "--pcr0",
                  depl.pcr_codes[0],
                  "--pcr1",
                  depl.pcr_codes[1],
                  "--pcr2",
                  depl.pcr_codes[2],
                  "--port",
                  "443",
                  "--lport",
                  str(connection_port),
              ],
              stdout=subprocess.PIPE,
              stderr=subprocess.PIPE,
          )
      while process.poll() is None:
          log_line = process.stderr.readline().decode()
          if log_line.__contains__("Error:  Invalid PCR Values"):
              raise OblvProxyConnectPCRError()
          elif log_line.lower().__contains__("error"):
              raise OblvEnclaveError(message=log_line)
          elif log_line.__contains__("listening on"):
              break
  
      OBLV_PROCESS_CACHE[deployment_id] = [process, connection_port]
      return None
  
imports: from base64 import encodebytes
  import os
  import random
  import subprocess
  from typing import Any
  from typing import Callable
  from typing import Dict
  from typing import List
  from typing import Optional
  from typing import Tuple
  from typing import cast
  from oblv_ctl import OblvClient
  import requests
  from result import Err
  from result import Ok
  from result import Result
  from ...client.api import SyftAPI
  from ...client.client import HTTPConnection
  from ...client.client import Routes
  from ...node.credentials import SyftSigningKey
  from ...node.credentials import SyftVerifyKey
  from ...serde.deserialize import _deserialize
  from ...serde.serializable import serializable
  from ...service.action.action_object import ActionObject
  from ...service.code.user_code import UserCodeStatus
  from ...service.context import AuthedServiceContext
  from ...service.response import SyftError
  from ...service.service import AbstractService
  from ...service.service import service_method
  from ...service.user.user_roles import GUEST_ROLE_LEVEL
  from ...store.document_store import DocumentStore
  from ...types.uid import UID
  from ...util.util import find_available_port
  from .constants import DOMAIN_CONNECTION_PORT
  from .constants import LOCAL_MODE
  from .deployment_client import OblvMetadata
  from .exceptions import OblvEnclaveError
  from .exceptions import OblvProxyConnectPCRError
  from .oblv_keys import OblvKeys
  from .oblv_keys_stash import OblvKeysStash
label_desc: Use image node_id 1 for calling a global function with example usage: connect_to_enclave(oblv_keys_stash, verify_key, oblv_client, deployment_id, connection_port, oblv_key_name) and returns: None, process