from typing import Optional
from typing import Dict
from typing import Any


def _cloud_sql_proxy_entry(
    user_id: int,
    user_group: int,
    caliban_config: Optional[Dict[str, Any]] = None,
) -> str:
  """returns dockerfile entry to fetch cloud_sql_proxy, installing in /usr/bin.

  Args:
  user_id: id of non-root user
  user_group: id of non-root group for user
  caliban_config: dictionary of caliban configuration options

  Returns:
  string with Dockerfile directives to install cloud_sql_proxy as root
  and reset the user to the specified user_id:user_group.

  """
  caliban_config = caliban_config or {}
  mlflow_cfg = caliban_config.get('mlflow_config')

  if mlflow_cfg is None:
    return ""

  return f"""
USER root

RUN wget \
  -q https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 \
  -O /usr/bin/cloud_sql_proxy \
  && chmod 755 /usr/bin/cloud_sql_proxy

USER {user_id}:{user_group}
"""