Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Features

* #146: Add interface for text_ai_extension_wrapper
* #169: Added a function that creates a bucket-fs PathLike object

## Security Issues

Expand Down
55 changes: 43 additions & 12 deletions exasol/nb_connector/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ def open_sqlalchemy_connection(conf: Secrets):
return sqlalchemy.create_engine(websocket_url)


def _get_onprem_bucketfs_url(conf: Secrets) -> str:
bucketfs_url_prefix = ("https" if _optional_encryption(conf, CKey.bfs_encryption)
else "http")
bucketfs_host = conf.get(CKey.bfs_host_name, conf.get(CKey.db_host_name))
return f"{bucketfs_url_prefix}://{bucketfs_host}:{conf.get(CKey.bfs_port)}"


def _get_ca_cert_verification(conf: Secrets) -> Any:
sslopt = _extract_ssl_options(conf)
verify = sslopt.get("cert_reqs") == ssl.CERT_REQUIRED
return sslopt.get("ca_certs") or sslopt.get("ca_cert_path") or verify


def open_bucketfs_connection(conf: Secrets) -> bfs.BucketLike:
"""
Connects to a BucketFS service using provided configuration parameters.
Expand All @@ -247,25 +260,19 @@ def open_bucketfs_connection(conf: Secrets) -> bfs.BucketLike:
"""

if get_backend(conf) == StorageBackend.onprem:
# Set up the connection parameters.
buckfs_url_prefix = "https" if _optional_encryption(conf, CKey.bfs_encryption) else "http"
buckfs_host = conf.get(CKey.bfs_host_name, conf.get(CKey.db_host_name))
buckfs_url = f"{buckfs_url_prefix}://{buckfs_host}:{conf.get(CKey.bfs_port)}"

sslopt = _extract_ssl_options(conf)
verify = sslopt.get("cert_reqs") == ssl.CERT_REQUIRED
verify = sslopt.get("ca_certs") or sslopt.get("ca_cert_path") or verify

buckfs_credentials = {
bucketfs_url = _get_onprem_bucketfs_url(conf)
verify = _get_ca_cert_verification(conf)
bucketfs_credentials = {
conf.get(CKey.bfs_bucket): {
"username": conf.get(CKey.bfs_user),
"password": conf.get(CKey.bfs_password),
}
}

# Connect to the BucketFS service and navigate to the bucket of choice.
bucketfs = bfs.Service(buckfs_url, buckfs_credentials, verify, conf.get(CKey.bfs_service)) # type: ignore
return bucketfs[conf.get(CKey.bfs_bucket)] # type: ignore
bucketfs = bfs.Service(bucketfs_url, bucketfs_credentials, verify, # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the type ignore still needed, I think, Bucketfs provides now py.typed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we define bucketfs_credentials here as a dictionary, but in the interface it's Mapping.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that they are not compatible

conf.get(CKey.bfs_service))
return bucketfs[conf.get(CKey.bfs_bucket)] # type: ignore

else:
saas_url, saas_token, saas_account_id = [
Expand All @@ -278,6 +285,30 @@ def open_bucketfs_connection(conf: Secrets) -> bfs.BucketLike:
pat=saas_token) # type: ignore


def open_bucketfs_location(conf: Secrets) -> bfs.path.PathLike:
"""
Similar to `open_buckets_connection`, but returns a PathLike interface.
"""
if get_backend(conf) == StorageBackend.onprem:
return bfs.path.build_path(
backend=bfs.path.StorageBackend.onprem,
url=_get_onprem_bucketfs_url(conf),
username=conf.get(CKey.bfs_user),
password=conf.get(CKey.bfs_password),
verify=_get_ca_cert_verification(conf),
bucket_name=conf.get(CKey.bfs_bucket),
service_name=conf.get(CKey.bfs_service)
)
else:
return bfs.path.build_path(
backend=bfs.path.StorageBackend.saas,
url=conf.get(CKey.saas_url),
account_id=conf.get(CKey.saas_account_id),
database_id=get_saas_database_id(conf),
pat=conf.get(CKey.saas_token)
)


def open_ibis_connection(conf: Secrets, **kwargs):
"""
Creates a connection to Ibis with Exasol backend.
Expand Down
Loading
Loading