Skip to content

service

dev_tool.services.portal.service

log = logging.getLogger(__name__) module-attribute

PortalService

Bases: BaseService

A service class for interacting with the portal API.

This class provides high-level methods for database and environment operations, delegating to specialized service classes for specific functionality.

The constructor for the PortalService class.

Parameters:

  • config (PortalServiceConfig | None, default: None ) –

    The portal service configuration. If None, uses default configuration.

Source code in dev_tool/services/portal/service.py
def __init__(self, config: PortalServiceConfig | None = None) -> None:
    """
    The constructor for the PortalService class.

    :param config: The portal service configuration. If None, uses default configuration.
    """

    super().__init__()

    self.config = config or PortalServiceConfig()

    token = CONTEXT.configuration.get_developer_token()
    headers = {'Authorization': f'Bearer {token}'}

    self.client = APIClientService(RequestService(), self.config.base_url, headers)

    self.database = DatabaseService(self.config, self.client)
    self.environment = EnvironmentService(self.config, self.client)

config = config or PortalServiceConfig() instance-attribute

client = APIClientService(RequestService(), self.config.base_url, headers) instance-attribute

database = DatabaseService(self.config, self.client) instance-attribute

environment = EnvironmentService(self.config, self.client) instance-attribute

backup_database

A method that backs up a database to a local .sql file as a background task.

Parameters:

  • project (str) –

    The project name from pyproject.toml.

  • database (str) –

    The name of the database to backup.

Returns:

  • str

    The task ID for tracking the backup progress.

Source code in dev_tool/services/portal/service.py
def backup_database(self, project: str, database: str) -> str:
    """
    A method that backs up a database to a local .sql file as a background task.

    :param project: The project name from pyproject.toml.
    :param database: The name of the database to backup.
    :return: The task ID for tracking the backup progress.
    """

    return self.database.backup_database(project, database)

download_environment_variables

A method that downloads environment variables synchronously.

Parameters:

  • name (str) –

    The name of the environment to download.

Returns:

  • bool

    True if the download was successful.

Source code in dev_tool/services/portal/service.py
def download_environment_variables(self, name: str) -> bool:
    """
    A method that downloads environment variables synchronously.

    :param name: The name of the environment to download.
    :return: True if the download was successful.
    """

    return self.environment.download_environment_variables(name)

get_environment_variables

A method that downloads environment variables as a background task.

Parameters:

  • name (str) –

    The name of the environment to download.

Returns:

  • str

    The task ID for tracking the download progress.

Source code in dev_tool/services/portal/service.py
def get_environment_variables(self, name: str) -> str:
    """
    A method that downloads environment variables as a background task.

    :param name: The name of the environment to download.
    :return: The task ID for tracking the download progress.
    """

    return self.environment.get_environment_variables(name)

get_decrypted_content_from_file

A method that decrypts an encrypted database file.

Parameters:

  • file (Path) –

    The path to the encrypted file.

Returns:

  • str

    The decrypted content as a string.

Source code in dev_tool/services/portal/service.py
def get_decrypted_content_from_file(self, file: Path) -> str:
    """
    A method that decrypts an encrypted database file.

    :param file: The path to the encrypted file.
    :return: The decrypted content as a string.
    """

    stem = file.stem.replace('.sql', '')
    key = self.database.get_decryption_key(stem)

    return self.database.decrypt_content(file, key)

restore_database

A method that restores a database from the portal as a background task.

Parameters:

  • database (str) –

    The name of the database to restore.

Returns:

  • str

    The task ID for tracking the restoration progress.

Source code in dev_tool/services/portal/service.py
def restore_database(self, project: str, database: str) -> str:
    """
    A method that restores a database from the portal as a background task.

    :param database: The name of the database to restore.
    :return: The task ID for tracking the restoration progress.
    """

    return self.database.restore_database(project, database)

set_environment_variables

A method that saves environment variables to a file.

Parameters:

  • variables (str) –

    The environment values string to save.

Source code in dev_tool/services/portal/service.py
def set_environment_variables(self, variables: str) -> None:
    """
    A method that saves environment variables to a file.

    :param variables: The environment values string to save.
    """

    self.environment.set_environment_variables(variables)