code: def get_ssh_keypair(
      key_path: Optional[PathLike], dstack_key_path: Path
  ) -> str:
      """Returns a path to the private key"""
      if key_path is not None:
          key_path = Path(key_path).expanduser().resolve()
          pub_key = (
              key_path
              if key_path.suffix == ".pub"
              else key_path.with_suffix(key_path.suffix + ".pub")
          )
          private_key = pub_key.with_suffix("")
          if pub_key.exists() and private_key.exists():
              return str(private_key)
          raise ConfigurationError(
              f"Make sure valid keypair exists: {private_key}(.pub)"
          )
  
      if not dstack_key_path.exists():
          generate_rsa_key_pair(private_key_path=dstack_key_path)
      return str(dstack_key_path)
  
file_path: dstack/src/dstack/api/_public/repos.py
imports: from pathlib import Path
  from typing import Optional, Union
  import giturlparse
  import requests
  from git import InvalidGitRepositoryError
  from dstack._internal.core.errors import ConfigurationError
  from dstack._internal.core.models.repos import LocalRepo, RemoteRepo
  from dstack._internal.core.models.repos.base import Repo, RepoType
  from dstack._internal.core.services.configs import ConfigManager
  from dstack._internal.core.services.repos import InvalidRepoCredentialsError, get_local_repo_credentials, load_repo
  from dstack._internal.utils.crypto import generate_rsa_key_pair
  from dstack._internal.utils.logging import get_logger
  from dstack._internal.utils.path import PathLike
  from dstack.api.server import APIClient
label_desc: Use image node_id 1 for calling a global function with example usage: get_ssh_keypair(key_path, dstack_key_path) and returns: str, str