diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index 79e701b..f3039fd 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -1 +1,4 @@ # Unreleased + +## Features + - #55 Added publicly callable function finding the database id from its name. diff --git a/exasol/saas/client/api_access.py b/exasol/saas/client/api_access.py index 9f2e776..048fee4 100644 --- a/exasol/saas/client/api_access.py +++ b/exasol/saas/client/api_access.py @@ -83,9 +83,7 @@ def _get_database_id( database_name: str, ) -> str: """ - Finds the database id, given an optional database name. If the name is not - provided returns an id of any non-deleted database. The latter option may be - useful for testing. + Finds the database id, given the database name. """ dbs = list_databases.sync(account_id, client=client) dbs = list(filter(lambda db: (db.name == database_name) and # type: ignore @@ -96,6 +94,25 @@ def _get_database_id( return dbs[0].id +def get_database_id( + host: str, + account_id: str, + pat: str, + database_name: str, +) -> str: + """ + Finds the database id, given the database name. + + Args: + host: SaaS service URL. + account_id: User account ID + pat: Personal Access Token. + database_name: Database name. + """ + with create_saas_client(host, pat) as client: + return _get_database_id(account_id, client, database_name) + + def get_connection_params( host: str, account_id: str,