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
1 change: 1 addition & 0 deletions changelog/+storage-encrypt.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `infrahubctl storage encrypt`, which encrypts the files that an Infrahub server stored before storage encryption was enabled. Before it encrypts, the command lists the files still to process, so the progress line shows the number done out of the total, the percentage, the remaining time at the recent rate and the bytes done out of the total; `--no-count` skips that listing on very large installations. The command pages through the stored files, asks the server to encrypt them in batches, adapts the number of requests in flight to the server and waits when the server answers HTTP 429, and logs in again when a login with a username and password expires during a long run. It saves its position, so that a run stopped with Ctrl-C (exit code 130), SIGTERM (exit code 143) or an error can resume, and it writes a report of the files the server left unchanged.
2 changes: 1 addition & 1 deletion dev/knowledge/cli-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The main Typer app lives in `infrahub_sdk/ctl/cli_commands.py`. It is re-exporte
Commands are organized in two tiers:

- **Root commands** are registered directly on the main app with `app.command()`. These are standalone operations that don't belong to a logical group (e.g. `dump`, `load`, `check`, `render`, `run`, `transform`, `protocols`, `version`, `info`).
- **Subcommand groups** are separate `AsyncTyper()` instances registered with `app.add_typer(sub_app, name="group")`. Each group lives in its own module under `infrahub_sdk/ctl/`. Current groups: `branch`, `schema`, `validate`, `repository`, `menu`, `object`, `graphql`, `task`.
- **Subcommand groups** are separate `AsyncTyper()` instances registered with `app.add_typer(sub_app, name="group")`. Each group lives in its own module under `infrahub_sdk/ctl/`. Current groups: `branch`, `schema`, `validate`, `repository`, `menu`, `object`, `graphql`, `task`, `marketplace`, `storage`, `telemetry`, `troubleshooting`.

## Adding a new command

Expand Down
75 changes: 75 additions & 0 deletions docs/docs/infrahubctl/infrahubctl-storage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# `infrahubctl storage`

Manage the files that an Infrahub server stores.

**Usage**:

```console
$ infrahubctl storage [OPTIONS] COMMAND [ARGS]...
```

**Options**:

* `--install-completion`: Install completion for the current shell.
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
* `--help`: Show this message and exit.

**Commands**:

* `encrypt`: Encrypt the stored files that were written...

## `infrahubctl storage encrypt`

Encrypt the stored files that were written before storage encryption was enabled.

The command lists the stored objects page by page and asks the server, which holds the storage key, to encrypt them.

It keeps several batches in flight, and halves that number when the server answers HTTP 429, 503 or 504 or a request times out.
It waits when the server answers HTTP 429.

The token needs the super admin permission, and storage encryption must be enabled on the server.

The command does its own retries, not those of the SDK client: network errors and HTTP 500, 502, 503 and 504, up to --max-retries.

Before it encrypts, the command lists the objects still to process, to show the total, the percent done and the remaining time.
Use --no-count to skip this pass on a very large installation; the progress then shows no total.

The state file records the position after every page. After an error, Ctrl-C or SIGTERM, run the same command again to resume.

Objects that the server leaves unchanged are listed in the report file, which every run appends to.
A run that resumes does not retry them, nor the objects that failed, because the saved position is past them.
A new full pass, which starts after a pass has finished, or --restart, tries them again.

Exit codes:
0 Every object is encrypted, was already encrypted, or was skipped by the server
1 The server could not encrypt at least one object, or the command failed before the run
(for example on a login error or an unexpected error)
2 The run stopped on an error from the server or on a state file or report that cannot be used
130 The run stopped on Ctrl-C (SIGINT)
143 The run stopped on SIGTERM

**Usage**:

```console
$ infrahubctl storage encrypt [OPTIONS]
```

**Options**:

* `--concurrency INTEGER RANGE`: Most batches in flight at once (at most 64); the command starts lower and adapts [default: 8; 1<=x<=64]
* `--batch-size INTEGER RANGE`: Stored objects in each request to encrypt [default: 50; 1<=x<=500]
* `--page-size INTEGER RANGE`: Stored objects in each listing request [default: 5000; 1<=x<=5000]
* `--rate FLOAT RANGE`: Most requests per second (default: no maximum) [x>=0.001]
* `--priority TEXT`: Priority of the requests: high, medium or low [default: low]
* `--before [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%dT%H:%M:%S%z]`: Leave the objects modified after this time (ISO 8601; no offset means UTC)
* `--dry-run`: Only list: count the objects and their size
* `--limit INTEGER RANGE`: Stop after this number of objects [x>=1]
* `--allow-unverified`: Also encrypt the objects that no node records a checksum for
* `--state-file PATH`: Keeps the position in the listing, so a rerun resumes [default: infrahub-storage-encrypt.state.json]
* `--report PATH`: Receives one JSON line for each object that was not encrypted [default: infrahub-storage-encrypt.report.jsonl]
* `--max-retries INTEGER RANGE`: Retries of one request after a network error or HTTP 500, 502, 503, 504 [default: 10; x>=0]
* `--timeout INTEGER RANGE`: Seconds before one request times out [default: 300; x>=1]
* `--restart`: Ignore the state file and list from the first object
* `--no-count`: Do not list the objects first to count them; the progress shows no total, percent or remaining time
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
* `--help`: Show this message and exit.
2 changes: 2 additions & 0 deletions infrahub_sdk/ctl/cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from ..ctl.repository import app as repository_app
from ..ctl.repository import find_repository_config_file, get_repository_config
from ..ctl.schema import app as schema_app
from ..ctl.storage import app as storage_app
from ..ctl.task import app as task_app
from ..ctl.telemetry import app as telemetry_app
from ..ctl.transform import list_transforms
Expand Down Expand Up @@ -81,6 +82,7 @@
app.add_typer(graphql_app, name="graphql")
app.add_typer(task_app, name="task")
app.add_typer(marketplace_app, name="marketplace")
app.add_typer(storage_app, name="storage")
app.add_typer(telemetry_app, name="telemetry")
app.add_typer(troubleshooting_app, name="troubleshooting")

Expand Down
11 changes: 11 additions & 0 deletions infrahub_sdk/ctl/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from infrahub_sdk.async_typer import AsyncTyper
from infrahub_sdk.ctl.storage.encrypt import encrypt_command

app = AsyncTyper()

app.command(name="encrypt")(encrypt_command)


@app.callback()
def callback() -> None:
"""Manage the files that an Infrahub server stores."""
Loading