Skip to content

Commit

Permalink
List entities in namespace(s) (#111)
Browse files Browse the repository at this point in the history
Add `list` sub-group of commands to the CLI

New '/_api' router with an '/entities' GET endpoint
This endpoint is to return a list of entities from the desired
namespace(s). Namespace(s) can be requested through the `namespace`
query parameter, e.g.,
`/_api/entities?namespace="testing"&namespace="my/project"`.

Redo how backends are initialized.
Avoid adding __init__() for backends, instead use _initialize() (used to
be initialize()).

Fully implement list CLI cmds:

* list namespaces
Will list all the namespaces as a full namespace, valid to be a value in
an entity under the namespace key.

* list entities
Will list all entities for a given namespace or multiple namespaces or
all namespaces depending on the provided arguments (if any) or if the
`-a/--all` option is provided.

This has all been made possible through the (normally hidden) endpoints
`/_api/namespaces` and `/_api/entities`. Both are GET endpoints.

The endpoints will list all namespaces or all entities with a given list
of namespaces (provided through the query parameter 'namespace', may be
supplied multiple times - or no times).

Fully test the new CLI commands.
Fully test the new API endpoints.

Add color to pytest runs in GitHub CI.
  • Loading branch information
CasperWA authored Jul 2, 2024
1 parent d505091 commit 1fd928a
Show file tree
Hide file tree
Showing 22 changed files with 2,135 additions and 70 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
--env ENTITIES_SERVICE_X509_CERTIFICATE_FILE \
--env ENTITIES_SERVICE_CA_FILE \
--env PORT=${ENTITIES_SERVICE_PORT} \
--env RUN_TIME=40 \
--env RUN_TIME=60 \
--env STOP_TIME=3 \
--name "entities-service" \
--network "host" \
Expand All @@ -124,7 +124,7 @@ jobs:
- name: Run tests
run: |
{
pytest -vv --live-backend --cov-report=
pytest -vv --live-backend --cov-report= --color=yes
} || {
echo "Failed! Here's the Docker logs for the service:" &&
docker logs entities-service &&
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
pip install -U -e .[testing]
- name: Run pytest
run: pytest -vv --cov-report=xml
run: pytest -vv --cov-report=xml --color=yes

- name: Upload coverage
if: github.repository_owner == 'SINTEF'
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3"
name: "entities-service"

services:
entities_service:
Expand Down
24 changes: 19 additions & 5 deletions entities_service/cli/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@
from typer import Typer


SUB_TYPER_APPS = ("config",)
SUB_TYPER_APPS = ("config", "list")
NO_ARGS_IS_HELP_COMMANDS = ("upload", "validate")
ALIASED_COMMANDS: dict[str, str] = {}


def get_commands() -> Generator[tuple[Callable, dict[str, Any]], None, None]:
"""Return all CLI commands, along with typer.command() kwargs."""
"""Return all CLI commands, along with typer.command() kwargs.
It is important the command module name matches the command function name.
To have a command with an alias, add the alias to the ALIASED_COMMANDS dict.
To have a command that does not require arguments to show the help message, add
the command name to the NO_ARGS_IS_HELP_COMMANDS tuple.
"""
this_dir = Path(__file__).parent.resolve()

for path in this_dir.glob("*.py"):
Expand All @@ -37,16 +46,21 @@ def get_commands() -> Generator[tuple[Callable, dict[str, Any]], None, None]:
"name."
)

command_kwargs = {}
if path.stem in ("upload", "validate"):
command_kwargs: dict[str, Any] = {}
if path.stem in NO_ARGS_IS_HELP_COMMANDS:
command_kwargs["no_args_is_help"] = True
if path.stem in ALIASED_COMMANDS:
command_kwargs["name"] = ALIASED_COMMANDS[path.stem]

yield getattr(module, path.stem), command_kwargs


def get_subtyper_apps() -> Generator[tuple[Typer, dict[str, Any]], None, None]:
"""Return all CLI Typer apps, which are a group of sub-command groups, along with
typer.add_typer() kwargs."""
typer.add_typer() kwargs.
This is done according to the SUB_TYPER_APPS tuple.
"""
this_dir = Path(__file__).parent.resolve()

for path in this_dir.glob("*.py"):
Expand Down
Loading

0 comments on commit 1fd928a

Please sign in to comment.