Skip to content

Commit 8f87a69

Browse files
committed
Merge branch 'main' into doc/#50-Added_section_Add_how_to_release_to_Developer_Guide
2 parents 0f68bc8 + 7d4a78a commit 8f87a69

File tree

10 files changed

+601
-265
lines changed

10 files changed

+601
-265
lines changed

doc/changes/changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changes
22

33
* [unreleased](unreleased.md)
4+
* [0.6.0](changes_0.6.0.md)
45
* [0.5.0](changes_0.5.0.md)
56
* [0.4.0](changes_0.4.0.md)
67
* [0.3.0](changes_0.3.0.md)
@@ -13,6 +14,7 @@
1314
hidden:
1415
---
1516
unreleased
17+
changes_0.6.0
1618
changes_0.5.0
1719
changes_0.4.0
1820
changes_0.3.0

doc/changes/changes_0.5.0.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 0.5.0 - 2024-05-16
22

3-
# Bugfixes
3+
## Bugfixes
44

55
* Fixed typehint for optional argument to enable usage with python 3.9

doc/changes/changes_0.6.0.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# 0.6.0 - 2024-05-22
2+
3+
## Feature
4+
5+
* #45 Added a helper function to assemble DB connection parameters.
6+
7+
## Documentation
8+
9+
* #50: Described release process in Developer Guide
10+
11+
## Bugfixes
12+
13+
* #44 Fixed the return value of the operational_saas_database_id fixture.
14+
15+
## Refactoring
16+
17+
* #19: Removed slack notifications for events other than `schedule`

doc/changes/unreleased.md

-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
11
# Unreleased
2-
3-
This release removes slack notifications for events other than `schedule`.
4-
5-
## Refactoring
6-
7-
* #19: Removed slack notifications for events other than `schedule`
8-
9-
## Doc
10-
11-
* #50: Described release process in Developer Guide

exasol/saas/client/api_access.py

+71-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import time
55

6-
from typing import Iterable, List, Optional
6+
from typing import Iterable, List, Optional, Any
77
from contextlib import contextmanager
88
import datetime as dt
99
from datetime import datetime, timedelta
@@ -32,6 +32,7 @@
3232
add_allowed_ip,
3333
delete_allowed_ip,
3434
)
35+
from exasol.saas.client.openapi.types import UNSET
3536

3637

3738
LOG = logging.getLogger(__name__)
@@ -76,6 +77,75 @@ def create_saas_client(
7677
)
7778

7879

80+
def _get_database_id(
81+
account_id: str,
82+
client: openapi.AuthenticatedClient,
83+
database_name: str,
84+
) -> str:
85+
"""
86+
Finds the database id, given an optional database name. If the name is not
87+
provided returns an id of any non-deleted database. The latter option may be
88+
useful for testing.
89+
"""
90+
dbs = list_databases.sync(account_id, client=client)
91+
dbs = list(filter(lambda db: (db.name == database_name) and # type: ignore
92+
(db.deleted_at is UNSET) and # type: ignore
93+
(db.deleted_by is UNSET), dbs)) # type: ignore
94+
if not dbs:
95+
raise RuntimeError(f'SaaS database {database_name} was not found.')
96+
return dbs[0].id
97+
98+
99+
def get_connection_params(
100+
host: str,
101+
account_id: str,
102+
pat: str,
103+
database_id: str | None = None,
104+
database_name: str | None = None,
105+
) -> dict[str, Any]:
106+
"""
107+
Gets the database connection parameters, such as those required by pyexasol:
108+
- dns
109+
- user
110+
- password.
111+
Returns the parameters in a dictionary that can be used as kwargs when
112+
creating a connection, like in the code below:
113+
114+
connection_params = get_connection_params(...)
115+
connection = pyexasol.connect(**connection_params)
116+
117+
Args:
118+
host: SaaS service URL.
119+
account_id: User account ID
120+
pat: Personal Access Token.
121+
database_id: Database ID, id known.
122+
database_name: Database name, in case the id is unknown.
123+
"""
124+
125+
with create_saas_client(host, pat) as client:
126+
if not database_id:
127+
if not database_name:
128+
raise ValueError(('To get SaaS connection parameters, '
129+
'either database name or database id must be provided.'))
130+
database_id = _get_database_id(account_id, client, database_name=database_name)
131+
clusters = list_clusters.sync(account_id,
132+
database_id,
133+
client=client)
134+
cluster_id = next(filter(lambda cl: cl.main_cluster, clusters)).id # type: ignore
135+
connections = get_cluster_connection.sync(account_id,
136+
database_id,
137+
cluster_id,
138+
client=client)
139+
if connections is None:
140+
raise RuntimeError('Failed to get the SaaS connection data.')
141+
connection_params = {
142+
'dsn': f'{connections.dns}:{connections.port}',
143+
'user': connections.db_username,
144+
'password': pat
145+
}
146+
return connection_params
147+
148+
79149
class OpenApiAccess:
80150
"""
81151
This class is meant to be used only in the context of the API
@@ -190,7 +260,6 @@ def poll_status():
190260
if poll_status() not in success:
191261
raise DatabaseStartupFailure()
192262

193-
194263
def clusters(
195264
self,
196265
database_id: str,

0 commit comments

Comments
 (0)