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
2 changes: 2 additions & 0 deletions obiba_opal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
)
from obiba_opal.sql import SQLService, SQLHistoryService
from obiba_opal.security import EncryptService, DecryptService
from obiba_opal.datashield import DataSHIELDQuotaService

__all__ = [
"UriBuilder",
Expand Down Expand Up @@ -133,4 +134,5 @@
"SQLHistoryService",
"EncryptService",
"DecryptService",
"DataSHIELDQuotaService",
]
103 changes: 103 additions & 0 deletions obiba_opal/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
)
from obiba_opal.sql import SQLService, SQLHistoryService
from obiba_opal.security import EncryptService, DecryptService
from obiba_opal.datashield import DataSHIELDQuotaService


def _make_args_with_globals(
Expand Down Expand Up @@ -3418,3 +3419,105 @@ def analysis_plugin_command(
json=json_output,
)
AnalysisCommand.do_command(args)


# =============================================================================
# DataSHIELD Commands
# =============================================================================


def datashield_quota_command(
ctx: typer.Context,
opal: str = typer.Option("http://localhost:8080", "--opal", "-o", help="Opal server base url"),
user: str | None = typer.Option(
None, "--user", "-u", help="Credentials auth: user name (password will be requested if not provided)"
),
password: str | None = typer.Option(
None, "--password", "-p", help="Credentials auth: user password (requires a user name)"
),
token: str | None = typer.Option(None, "--token", "-tk", help="Token auth: User access token"),
ssl_cert: str | None = typer.Option(
None, "--ssl-cert", "-sc", help="Two-way SSL auth: certificate/public key file (requires a private key)"
),
ssl_key: str | None = typer.Option(
None, "--ssl-key", "-sk", help="Two-way SSL auth: private key file (requires a certificate)"
),
verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"),
no_ssl_verify: bool = typer.Option(
False, "--no-ssl-verify", "-nv", help="Do not verify SSL certificates for HTTPS."
),
id: str | None = typer.Option(
None,
"--id",
"-id",
help="Quota identifier. Not specifying the quota identifier, will get the list of the DataSHIELD quotas.",
),
type: str | None = typer.Option(
None, "--type", "-ty", help="Subject type: system, group, user. Default is system."
),
subject: str | None = typer.Option(
None,
"--subject",
"-s",
help="Subject name: the user or the group name (required when subject type is user or group).",
),
metric: str | None = typer.Option(
None, "--metric", "-m", help="Usage metric: execution-time, session-time. Default is execution-time."
),
period: str | None = typer.Option(
None, "--period", "-pd", help="Rolling period the usage is summed over: daily, weekly. Default is weekly."
),
limit: float | None = typer.Option(
None, "--limit", "-lm", help="Usage allowance, in minutes (zero forbids DataSHIELD for this subject)."
),
disabled: bool = typer.Option(
False, "--disabled", "-di", help="Disable the quota (on add, if omitted the quota is enabled by default)."
),
enabled: bool = typer.Option(
False,
"--enabled",
"-en",
help="Enable the quota (on update, when neither --enabled nor --disabled is specified, the quota is left "
"as it is).",
),
fetch: bool = typer.Option(
False, "--fetch", "-fe", help="Fetch one or multiple quota(s). This is the default action."
),
add: bool = typer.Option(False, "--add", "-a", help="Add a quota."),
update: bool = typer.Option(False, "--update", "-ud", help="Update a quota (requires a quota identifier)."),
delete: bool = typer.Option(False, "--delete", "-de", help="Delete a quota (requires a quota identifier)."),
usage: bool = typer.Option(
False,
"--usage",
"-us",
help="Get the quota usage of the user specified by --subject, or of the current user when omitted.",
),
json_output: bool = typer.Option(False, "--json", "-j", help="Pretty JSON formatting of the response"),
):
"""Manage DataSHIELD usage quotas."""
args = _make_args_with_globals(
ctx,
opal=opal,
user=user,
password=password,
token=token,
ssl_cert=ssl_cert,
ssl_key=ssl_key,
verbose=verbose,
no_ssl_verify=no_ssl_verify,
id=id,
type=type,
subject=subject,
metric=metric,
period=period,
limit=limit,
disabled=disabled,
enabled=enabled,
fetch=fetch,
add=add,
update=update,
delete=delete,
usage=usage,
json=json_output,
)
DataSHIELDQuotaService.do_command(args)
5 changes: 5 additions & 0 deletions obiba_opal/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ def wrapper(*args, **kwargs) -> None:
help="Analyses a project variables using external R plugins.",
)(handle_exceptions(cmd.analysis_plugin_command))

# DataSHIELD commands
app.command(name="datashield-quota", help="Manage DataSHIELD usage quotas.")(
handle_exceptions(cmd.datashield_quota_command)
)


# =============================================================================
# Global options callback
Expand Down
8 changes: 8 additions & 0 deletions obiba_opal/console_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
)
from obiba_opal.sql import SQLService, SQLHistoryService
from obiba_opal.security import EncryptService, DecryptService
from obiba_opal.datashield import DataSHIELDQuotaService


def prompt_password():
Expand Down Expand Up @@ -546,6 +547,13 @@ def run():
SQLHistoryService.add_arguments,
SQLHistoryService.do_command,
)
add_subcommand(
subparsers,
"datashield-quota",
"Manage DataSHIELD usage quotas.",
DataSHIELDQuotaService.add_arguments,
DataSHIELDQuotaService.do_command,
)

# Execute selected command
args = parser.parse_args()
Expand Down
Loading
Loading