Skip to content
Open
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
45 changes: 45 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,51 @@ on:

jobs:

Experimental-iTests:
name: Exp.iTests
runs-on: ubuntu-24.04
permissions:
contents: read

steps:

- name: Free disk space
uses: jlumbroso/free-disk-space@main
with:
tool-cache: true
large-packages: false
haskell: true

- name: Free disk space by removing large directories
run: |
sudo rm -rf /usr/local/graalvm/
sudo rm -rf /usr/local/share/powershell
sudo rm -rf /usr/local/share/chromium
sudo rm -rf /usr/local/lib/node_modules

- name: SCM Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python & Poetry Environment
uses: exasol/python-toolbox/.github/actions/python-environment@v1

- name: Install All Optional Dependencies (aka. "extras")
run: poetry install --all-extras

- name: Run Experimental iTests
run: >
poetry run --
pytest test/integration/ordinary/itest_cli_onprem.py
-rA --setup-show
--backend=all
--itde-nameserver 8.8.8.8
env:
SAAS_HOST: ${{ secrets.INTEGRATION_TEAM_SAAS_STAGING_HOST }}
SAAS_ACCOUNT_ID: ${{ secrets.INTEGRATION_TEAM_SAAS_STAGING_ACCOUNT_ID }}
SAAS_PAT: ${{ secrets.INTEGRATION_TEAM_SAAS_STAGING_PAT }}

Version-Check:
name: Version
runs-on: ubuntu-24.04
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/merge-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
fast-checks:
name: Fast
uses: ./.github/workflows/checks.yml
secrets: inherit
permissions:
contents: read

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests-ordinary-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
extra_param: "--package-manager conda --compression-strategy gzip"
- file: itest_slc.py
extra_param: "--package-manager pip --compression-strategy none"
- file: itest_cli_onprem.py
extra_param: "--backend=onprem --itde-nameserver 8.8.8.8"

steps:

Expand Down
1 change: 1 addition & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Additionally the release includes a CLI for populating the Secure Configuration
* #263: Added functions for handling a set of options for SCS CLI
* #267: Implemented modify operations for the SCS
* #269: Implemented showing SCS content
* #271: Implemented checking SCS content

## Refactorings

Expand Down
9 changes: 8 additions & 1 deletion exasol/nb_connector/cli/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

import click

from exasol.nb_connector.cli import reporting as report
from exasol.nb_connector.cli.groups import cli
from exasol.nb_connector.cli.options import SCS_OPTIONS
from exasol.nb_connector.cli.param_wrappers import add_params
from exasol.nb_connector.cli.processing import processing
from exasol.nb_connector.cli.processing.option_set import ScsCliError


@cli.command()
Expand All @@ -24,4 +27,8 @@ def check(scs_file: Path, connect: bool):
Optionally also verify if a connection to the configured Exasol database
instance is successful.
"""
pass
try:
processing.check_scs(scs_file, connect)
except ScsCliError as ex:
report.error(ex)
sys.exit(1)
9 changes: 3 additions & 6 deletions exasol/nb_connector/cli/commands/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ def configure_onprem(scs_file: Path, **kwargs):
"""
Configure connection to an Exasol on-premise instance.
"""
result = processing.save(
processing.save(
scs_file,
StorageBackend.onprem,
use_itde=False,
values=kwargs,
)
sys.exit(result)


@configure.command("saas")
Expand All @@ -46,13 +45,12 @@ def configure_saas(scs_file: Path, **kwargs):
Configuring one of the parameters --saas-database-id and
--saas-database-name is sufficient.
"""
result = processing.save(
processing.save(
scs_file,
StorageBackend.saas,
use_itde=False,
values=kwargs,
)
sys.exit(result)


@configure.command("docker-db")
Expand All @@ -61,10 +59,9 @@ def configure_docker_db(scs_file: Path, **kwargs):
"""
Configure connection to an Exasol Docker instance.
"""
result = processing.save(
processing.save(
scs_file,
StorageBackend.onprem,
use_itde=True,
values=kwargs,
)
sys.exit(result)
9 changes: 7 additions & 2 deletions exasol/nb_connector/cli/commands/show.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import sys
from pathlib import Path

from exasol.nb_connector.cli import reporting as report
from exasol.nb_connector.cli.groups import cli
from exasol.nb_connector.cli.options import SCS_OPTIONS
from exasol.nb_connector.cli.param_wrappers import add_params
from exasol.nb_connector.cli.processing import processing
from exasol.nb_connector.cli.processing.option_set import ScsCliError


@cli.command()
Expand All @@ -14,5 +16,8 @@ def show(scs_file: Path):
Show the configuration currently saved to the Secure Configuration
Storage.
"""
result = processing.show_scs_content(scs_file)
sys.exit(result)
try:
processing.show_scs_content(scs_file)
except ScsCliError as ex:
report.error(ex)
sys.exit(1)
14 changes: 6 additions & 8 deletions exasol/nb_connector/cli/processing/option_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def set_dynamic_defaults(self, values: dict[str, Any]) -> dict[str, Any]:

return values

def check(self) -> bool:
def check(self):
"""
Check if the content of the SCS is complete wrt. the selected
backend as the required options depend on the selected backend.
Expand All @@ -104,12 +104,11 @@ def check(self) -> bool:
"Configuration is complete for an "
f"Exasol {config.backend_name} instance."
)
return True
return
formatted = ", ".join(missing)
n = len(missing)
prefix = "1 option is" if n == 1 else f"{n} options are"
report.error(f"{prefix} not yet configured: {formatted}.")
return False
raise ScsCliError(f"{prefix} not yet configured: {formatted}.")


def get_scs_master_password():
Expand All @@ -128,10 +127,10 @@ def get_scs(scs_file: Path) -> Secrets:
return Secrets(scs_file, scs_password)


def get_option_set(scs_file: Path) -> OptionSet | None:
def get_option_set(scs_file: Path) -> OptionSet:
"""
Return an instance of an OptionSet if the SCS contains a proper
backend selection. Otherwise report an error and return None.
backend selection. Otherwise raise an ScsCliError.

This function is designed to be called only once in the CLI application.
Otherwise it will always ask for the SCS master password and potentially
Expand All @@ -144,6 +143,5 @@ def get_option_set(scs_file: Path) -> OptionSet | None:
scs = get_scs(scs_file)
config = BackendSelector(scs)
if not config.knows_backend:
report.error(f"SCS {scs_file} does not contain any backend.")
return None
raise ScsCliError(f"SCS {scs_file} does not contain any backend.")
return OptionSet(scs, config.backend, config.use_itde)
57 changes: 48 additions & 9 deletions exasol/nb_connector/cli/processing/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
SELECT_BACKEND_OPTION,
USE_ITDE_OPTION,
OptionSet,
ScsCliError,
get_option_set,
get_scs,
)
from exasol.nb_connector.connections import open_pyexasol_connection
from exasol.nb_connector.itde_manager import bring_itde_up
from exasol.nb_connector.secret_store import Secrets

LOG = logging.getLogger(__name__)

Expand All @@ -32,7 +36,7 @@ def save(
backend: StorageBackend,
use_itde: bool,
values: dict[str, Any],
) -> int:
):
"""
Save the provided values to SCS using the keys inferred from backend
and use_itde.
Expand Down Expand Up @@ -60,20 +64,55 @@ def save(
continue
if secret := option.get_secret(interactive=bool(value)):
scs.save(option.scs_key, secret)
return 0


def show_scs_content(scs_file: Path) -> int:
def verify_connection(scs: Secrets) -> None:
"""
Verify if successful connection to the configured backend is possible.
Raise an ScsCliError otherwise.
"""
if BackendSelector(scs).use_itde:
# Question: Is it OK, to let bring_itde_up modify the SCS content, here?
False and bring_itde_up(scs)
report.warning(f"Bring up ITDE currently disabled")
return
try:
open_pyexasol_connection(scs).execute("SELECT 1 FROM DUAL").fetchone()
except Exception as ex:
raise ScsCliError(f"Failed to connect to the configured database {ex}")
report.success("Connection to the configured database instance was successful.")


def check_scs(scs_file: Path, connect: bool) -> None:
"""
Check the SCS content for completeness. Infer the required keys from
backend and use_itde if these are contained in the SCS already.

If parameter `connect` is True then also verify if a connection to the
configured Exasol database instance is successful.

The function raises an ScsCliError in any of the following cases:

* The SCS does not select any backend.

* The options are incomplete for configuring access to the selected backend.

* Connecting to the configured backend was requested but failed.
"""
options = get_option_set(scs_file)
options.check()
if connect:
verify_connection(options.scs)


def show_scs_content(scs_file: Path) -> None:
"""
If the SCS contains a proper backend selection, then show the SCS
content for this context.
"""
option_set = get_option_set(scs_file)
if not option_set:
return 1
for o in option_set.options:
value = o.scs_key and o.displayed_value(option_set.scs)
oset = get_option_set(scs_file)
for o in oset.options:
value = o.scs_key and o.displayed_value(oset.scs)
if value is not None:
value = value or '""'
click.echo(f"{o.cli_option()}: {value}")
return 0
2 changes: 1 addition & 1 deletion exasol/nb_connector/cli/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def success(text: str):
click.echo(click.style(text, fg="green"))


def error(text: str):
def error(text: str | Exception):
click.echo(click.style(f"Error: {text}", fg="bright_red"))


Expand Down
Loading
Loading