Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Nov 2, 2023
1 parent fbcd143 commit 1ef0cf1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/cli/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_project_load_config(
req_mocks.append(
requests_mock.get(
(
f"{host}/project/api/retrieve/{project_uuid}?app_name=cases_import"
f"{host}/project/api/settings/retrieve/{project_uuid}?app_name=cases_import"
f"&setting_name={setting_name}"
),
request_headers={"Authorization": f"Token {token}"},
Expand Down
5 changes: 2 additions & 3 deletions varfish_cli/api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#: End point for retrieving projects.
ENDPOINT_PROJECT_RETRIEVE = "/project/api/retrieve/{project_uuid}"
#: End point for retrieving projects settings.
ENDPOINT_PROJECT_RETRIEVE = "/project/api/settings/retrieve/{project_uuid}"
ENDPOINT_PROJECT_SETTING_RETRIEVE = "/project/api/settings/retrieve/{project_uuid}"


def project_list(
Expand Down Expand Up @@ -69,10 +69,9 @@ def project_settings_retrieve(
query = "&".join(queries)
if query:
query = f"?{query}"
endpoint = f"{server_url}{ENDPOINT_PROJECT_RETRIEVE}{query}".format(project_uuid=project_uuid)
endpoint = f"{server_url}{ENDPOINT_PROJECT_SETTING_RETRIEVE}{query}".format(project_uuid=project_uuid)
logger.debug("Sending GET request to end point %s", endpoint)
headers = {"Authorization": "Token %s" % api_token}
result = requests.get(endpoint, headers=headers, verify=verify_ssl)
raise_for_status(result)
print(result.json())
return pydantic.TypeAdapter(SettingsEntry).validate_python(result.json())
26 changes: 26 additions & 0 deletions varfish_cli/cli/projects.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
"""Implementation of varfish-cli subcommand "projects *"."""

import os

try:
import tomllib
from tomllib import TOMLDecodeError
except ImportError:
import toml as tomllib
from toml import TomlDecodeError as TOMLDecodeError

import typing
import uuid

from logzero import logger
import typer

from varfish_cli import api, common
from varfish_cli.cli import DEFAULT_PATH_VARFISHRC
from varfish_cli.cli.common import ListObjects, RetrieveObject
from varfish_cli.common import OutputFormat
from varfish_cli.config import CommonOptions
Expand Down Expand Up @@ -86,6 +96,10 @@ def cli_project_load_config(
project_uuid: typing.Annotated[
uuid.UUID, typer.Argument(..., help="UUID of the object to retrieve")
],
config_path: typing.Annotated[
str,
typer.Option("--config-path", help="Path to configuration file", envvar="VARFISH_RC_PATH"),
] = DEFAULT_PATH_VARFISHRC,
output_file: typing.Annotated[
str, typer.Option("--output-file", help="Path to file to write to")
] = "-",
Expand Down Expand Up @@ -121,4 +135,16 @@ def cli_project_load_config(

logger.info("... all data retrieved, updating config...")

if not os.path.exists(config_path):
with open(config_path, "rt") as tomlf:
try:
config_toml = tomllib.loads(tomlf.read())
except TOMLDecodeError as e:
logger.error("could not parse configuration file %s: %s", config_path, e)
raise typer.Exit(1)
else:
config_toml = {}

config_toml.setdefault("paths", [])

print(kwargs)
2 changes: 1 addition & 1 deletion varfish_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def load_config(config_path: str) -> typing.Tuple[typing.Optional[str], typing.O
logger.debug("global/varfish_server_url not set in %s", config_path)
toml_varfish_api_token = config_toml.get("global", {}).get("varfish_api_token")
if toml_varfish_api_token:
logger.debug("using global/varfish_server_url from %s", config_path)
logger.debug("using global/varfish_api_token from %s", config_path)
else:
logger.debug("global/varfish_api_token not set in %s", config_path)

Expand Down

0 comments on commit 1ef0cf1

Please sign in to comment.