Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print error when conf not found #33

Merged
merged 2 commits into from
Nov 4, 2024
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
3 changes: 3 additions & 0 deletions arlas/cli/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
@collections.callback()
def configuration(config: str = typer.Option(help="Name of the ARLAS configuration to use from your configuration file ({}).".format(variables["configuration_file"]))):
variables["arlas"] = config
if Configuration.settings.arlas.get(config, None) is None:
print("Error: arlas configuration {} not found among [{}]".format(config, ", ".join(Configuration.settings.arlas.keys())), file=sys.stderr)
exit(1)


@collections.command(help="List collections", name="list")
Expand Down
18 changes: 9 additions & 9 deletions arlas/cli/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ def create_configuration(

@configurations.command(help="Delete a configuration", name="delete")
def delete_configuration(
name: str = typer.Argument(help="Name of the configuration"),
config: str = typer.Argument(help="Name of the configuration"),
):
if Configuration.settings.arlas.get(name) is None:
print("Error: no configuration found for {}.".format(name), file=sys.stderr)
if Configuration.settings.arlas.get(config, None) is None:
print("Error: arlas configuration {} not found among [{}]".format(config, ", ".join(Configuration.settings.arlas.keys())), file=sys.stderr)
exit(1)
Configuration.settings.arlas.pop(name)
Configuration.settings.arlas.pop(config)
Configuration.save(variables["configuration_file"])
Configuration.init(variables["configuration_file"])
print("Configuration {} deleted.".format(name))
print("Configuration {} deleted.".format(config))


@configurations.command(help="Describe a configuration", name="describe")
def describe_configuration(
name: str = typer.Argument(help="Name of the configuration"),
config: str = typer.Argument(help="Name of the configuration"),
):
if Configuration.settings.arlas.get(name) is None:
print("Error: no configuration found for {}.".format(name), file=sys.stderr)
if Configuration.settings.arlas.get(config, None) is None:
print("Error: arlas configuration {} not found among [{}]".format(config, ", ".join(Configuration.settings.arlas.keys())), file=sys.stderr)
exit(1)
print(yaml.dump(Configuration.settings.arlas[name].model_dump()))
print(yaml.dump(Configuration.settings.arlas[config].model_dump()))
5 changes: 5 additions & 0 deletions arlas/cli/iam.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import sys
import typer

from arlas.cli.settings import Configuration
from arlas.cli.variables import variables

iam = typer.Typer()
Expand All @@ -9,3 +11,6 @@
@iam.callback()
def configuration(config: str = typer.Option(help="Name of the ARLAS configuration to use from your configuration file ({}).".format(variables["configuration_file"]))):
variables["arlas"] = config
if Configuration.settings.arlas.get(config, None) is None:
print("Error: arlas configuration {} not found among [{}]".format(config, ", ".join(Configuration.settings.arlas.keys())), file=sys.stderr)
exit(1)
3 changes: 3 additions & 0 deletions arlas/cli/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
@indices.callback()
def configuration(config: str = typer.Option(help="Name of the ARLAS configuration to use from your configuration file ({}).".format(variables["configuration_file"]))):
variables["arlas"] = config
if Configuration.settings.arlas.get(config, None) is None:
print("Error: arlas configuration {} not found among [{}]".format(config, ", ".join(Configuration.settings.arlas.keys())), file=sys.stderr)
exit(1)


@indices.command(help="List indices", name="list")
Expand Down
3 changes: 3 additions & 0 deletions arlas/cli/persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
@persist.callback()
def configuration(config: str = typer.Option(help="Name of the ARLAS configuration to use from your configuration file ({}).".format(variables["configuration_file"]))):
variables["arlas"] = config
if Configuration.settings.arlas.get(config, None) is None:
print("Error: arlas configuration {} not found among [{}]".format(config, ", ".join(Configuration.settings.arlas.keys())), file=sys.stderr)
exit(1)


@persist.command(help="Add an entry, returns its ID", name="add")
Expand Down
6 changes: 3 additions & 3 deletions arlas/cli/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def __get_fields__(origin: list[str], properties: dict[str:dict]):
def __arlas__(arlas: str, suffix, post=None, put=None, patch=None, delete=None, service=Services.arlas_server):
configuration: ARLAS = Configuration.settings.arlas.get(arlas, None)
if configuration is None:
print("Error: arlas configuration ({}) not found among [{}] for {}.".format(arlas, ", ".join(Configuration.settings.arlas.keys()), service.name), file=sys.stderr)
print("Error: arlas configuration {} not found among [{}] for {}.".format(arlas, ", ".join(Configuration.settings.arlas.keys()), service.name), file=sys.stderr)
exit(1)
if service == Services.arlas_server:
__headers__ = configuration.server.headers.copy()
Expand Down Expand Up @@ -476,10 +476,10 @@ def __arlas__(arlas: str, suffix, post=None, put=None, patch=None, delete=None,
def __es__(arlas: str, suffix, post=None, put=None, delete=None, exit_on_failure: bool = True, headers: dict[str, str] = {}):
endpoint = Configuration.settings.arlas.get(arlas)
if endpoint is None:
print("Error: arlas configuration ({}) not found among [{}].".format(arlas, ", ".join(Configuration.settings.arlas.keys())), file=sys.stderr)
print("Error: arlas configuration {} not found among [{}].".format(arlas, ", ".join(Configuration.settings.arlas.keys())), file=sys.stderr)
exit(1)
if endpoint.elastic is None:
print("Error: arlas configuration ({}) misses an elasticsearch configuration.".format(arlas), file=sys.stderr)
print("Error: arlas configuration {} misses an elasticsearch configuration.".format(arlas), file=sys.stderr)
exit(1)
url = "/".join([endpoint.elastic.location, suffix])
__headers = endpoint.elastic.headers
Expand Down
2 changes: 0 additions & 2 deletions arlas/cli/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import typer
from prettytable import PrettyTable

from arlas.cli.service import Service
from arlas.cli.variables import variables
Expand Down Expand Up @@ -29,4 +28,3 @@ def activate(id: str = typer.Argument(help="User's identifier")):
def deactivate(id: str = typer.Argument(help="User's identifier")):
config = variables["arlas"]
print(Service.deactivate(config, id).get("message"))

Loading