Skip to content

Commit ef4fa4b

Browse files
committed
migrate infrahubctl
1 parent 5603263 commit ef4fa4b

21 files changed

+867
-0
lines changed

.github/file-filters.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ documentation_all:
3838
- *development_files
3939
- *doc_files
4040
- *markdown_all
41+
42+
infrahub_reference_generated: &infrahub_reference_generated
43+
- "docs/docs/python-sdk/reference/config.mdx"

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
timeout-minutes: 5
3737
outputs:
3838
documentation: ${{ steps.changes.outputs.documentation_all }}
39+
documentation_generated: ${{ steps.changes.outputs.documentation_generated_all }}
3940
helm: ${{ steps.changes.outputs.helm_all }}
4041
python: ${{ steps.changes.outputs.python_all }}
4142
yaml: ${{ steps.changes.outputs.yaml_all }}
@@ -145,6 +146,35 @@ jobs:
145146
- name: "Build docs website"
146147
run: "invoke docs"
147148

149+
validate-generated-documentation:
150+
if: |
151+
always() && !cancelled() &&
152+
!contains(needs.*.result, 'failure') &&
153+
!contains(needs.*.result, 'cancelled') &&
154+
(needs.files-changed.outputs.python == 'true') || (needs.files-changed.outputs.documentation_generated == 'true')
155+
needs: ["files-changed", "yaml-lint", "python-lint"]
156+
runs-on: "ubuntu-22.04"
157+
timeout-minutes: 5
158+
steps:
159+
- name: "Check out repository code"
160+
uses: "actions/checkout@v4"
161+
with:
162+
submodules: true
163+
- name: Set up Python
164+
uses: actions/setup-python@v5
165+
with:
166+
python-version: "3.12"
167+
- name: "Setup Python environment"
168+
run: |
169+
pipx install poetry==1.8.5
170+
poetry config virtualenvs.create true --local
171+
poetry env use 3.12
172+
- name: "Install dependencies"
173+
run: "poetry install --no-interaction --no-ansi"
174+
- name: "Setup environment"
175+
run: "pip install invoke toml"
176+
- name: "Validate generated documentation"
177+
run: "poetry run invoke docs-validate"
148178

149179
validate-documentation-style:
150180
if: |

docs/_templates/sdk_config.j2

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Python SDK Configuration
3+
---
4+
import Tabs from '@theme/Tabs';
5+
import TabItem from '@theme/TabItem';
6+
7+
The Python SDK (Async or Sync) client can be configured using an instance of the `Config` class.
8+
9+
<Tabs groupId="async-sync">
10+
<TabItem value="Async" default>
11+
12+
```python
13+
from infrahub_sdk import Config, InfrahubClient
14+
config = Config(address="http://infrahub:8080", api_token="123-xyz-invalid-token")
15+
client = InfrahubClient(config=config)
16+
```
17+
18+
</TabItem>
19+
<TabItem value="Sync">
20+
21+
```python
22+
from infrahub_sdk import Config, InfrahubClientSync
23+
config = Config(address="http://infrahub:8080", api_token="123-xyz-invalid-token")
24+
client = InfrahubClientSync(config=config)
25+
```
26+
27+
</TabItem>
28+
</Tabs>
29+
30+
The following settings can be defined in the `Config` class
31+
{% for property in properties %}
32+
<!-- vale off -->
33+
## {{ property.name }}
34+
35+
**Property**: {{ property.name }}<br />
36+
<!-- vale on -->
37+
**Description**: {% if '\n' in property.description %} {% endif %}{{ property.description }}<br />
38+
**Type**: `{{ property.type }}`<br />
39+
{% if "default" in property and property.default is not none and property.default != "" and property.type != "object" %}
40+
**Default value**: {{ property.default }}<br />
41+
{% endif %}
42+
{% if "choices" in property and property.choices | length > 0 %}
43+
**Choices**: {{ property.choices | join(", ") }}<br />
44+
{% endif %}
45+
**Environment variable**: `{{ property.env_vars | join(", ") | upper | default("", true) }}`<br />
46+
{% endfor %}
47+
48+
<!-- vale off -->
49+
## recorder
50+
51+
**Property**: recorder<br />
52+
<!-- vale on -->
53+
**Description**: Select builtin recorder for later replay.<br />
54+
**Type**: `RecorderType`<br />
55+
**Default value**: RecorderType.NONE <br />
56+
57+
<!-- vale off -->
58+
## custom_recorder
59+
60+
**Property**: custom_recorder<br />
61+
<!-- vale on -->
62+
**Description**: Provides a way to record responses from the Infrahub API<br />
63+
**Type**: `Recorder` (protocol) <br />
64+
**Default value**: NoRecorder.default <br />
65+
66+
<!-- vale off -->
67+
## requester
68+
69+
**Property**: requester<br />
70+
<!-- vale on -->
71+
**Type**: `AsyncRequester`<br />
72+
**Default value**: None <br />
73+
74+
<!-- vale off -->
75+
## sync_requester
76+
77+
**Property**: sync_requester<br />
78+
<!-- vale on -->
79+
**Type**: `SyncRequester`<br />
80+
**Default value**: None <br />
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# `infrahubctl branch`
2+
3+
Manage the branches in a remote Infrahub instance.
4+
5+
List, create, merge, rebase ..
6+
7+
**Usage**:
8+
9+
```console
10+
$ infrahubctl branch [OPTIONS] COMMAND [ARGS]...
11+
```
12+
13+
**Options**:
14+
15+
* `--install-completion`: Install completion for the current shell.
16+
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
17+
* `--help`: Show this message and exit.
18+
19+
**Commands**:
20+
21+
* `create`: Create a new branch.
22+
* `delete`: Delete a branch.
23+
* `list`: List all existing branches.
24+
* `merge`: Merge a Branch with main.
25+
* `rebase`: Rebase a Branch with main.
26+
* `validate`: Validate if a branch has some conflict and...
27+
28+
## `infrahubctl branch create`
29+
30+
Create a new branch.
31+
32+
**Usage**:
33+
34+
```console
35+
$ infrahubctl branch create [OPTIONS] BRANCH_NAME
36+
```
37+
38+
**Arguments**:
39+
40+
* `BRANCH_NAME`: Name of the branch to create [required]
41+
42+
**Options**:
43+
44+
* `--description TEXT`: Description of the branch
45+
* `--sync-with-git / --no-sync-with-git`: Extend the branch to Git and have Infrahub create the branch in connected repositories. [default: no-sync-with-git]
46+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
47+
* `--help`: Show this message and exit.
48+
49+
## `infrahubctl branch delete`
50+
51+
Delete a branch.
52+
53+
**Usage**:
54+
55+
```console
56+
$ infrahubctl branch delete [OPTIONS] BRANCH_NAME
57+
```
58+
59+
**Arguments**:
60+
61+
* `BRANCH_NAME`: [required]
62+
63+
**Options**:
64+
65+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
66+
* `--help`: Show this message and exit.
67+
68+
## `infrahubctl branch list`
69+
70+
List all existing branches.
71+
72+
**Usage**:
73+
74+
```console
75+
$ infrahubctl branch list [OPTIONS]
76+
```
77+
78+
**Options**:
79+
80+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
81+
* `--help`: Show this message and exit.
82+
83+
## `infrahubctl branch merge`
84+
85+
Merge a Branch with main.
86+
87+
**Usage**:
88+
89+
```console
90+
$ infrahubctl branch merge [OPTIONS] BRANCH_NAME
91+
```
92+
93+
**Arguments**:
94+
95+
* `BRANCH_NAME`: [required]
96+
97+
**Options**:
98+
99+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
100+
* `--help`: Show this message and exit.
101+
102+
## `infrahubctl branch rebase`
103+
104+
Rebase a Branch with main.
105+
106+
**Usage**:
107+
108+
```console
109+
$ infrahubctl branch rebase [OPTIONS] BRANCH_NAME
110+
```
111+
112+
**Arguments**:
113+
114+
* `BRANCH_NAME`: [required]
115+
116+
**Options**:
117+
118+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
119+
* `--help`: Show this message and exit.
120+
121+
## `infrahubctl branch validate`
122+
123+
Validate if a branch has some conflict and is passing all the tests (NOT IMPLEMENTED YET).
124+
125+
**Usage**:
126+
127+
```console
128+
$ infrahubctl branch validate [OPTIONS] BRANCH_NAME
129+
```
130+
131+
**Arguments**:
132+
133+
* `BRANCH_NAME`: [required]
134+
135+
**Options**:
136+
137+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
138+
* `--help`: Show this message and exit.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# `infrahubctl check`
2+
3+
Execute user-defined checks.
4+
5+
**Usage**:
6+
7+
```console
8+
$ infrahubctl check [OPTIONS] [CHECK_NAME] [VARIABLES]...
9+
```
10+
11+
**Arguments**:
12+
13+
* `[CHECK_NAME]`: Name of the Python check
14+
* `[VARIABLES]...`: Variables to pass along with the query. Format key=value key=value.
15+
16+
**Options**:
17+
18+
* `--branch TEXT`
19+
* `--path TEXT`: Root directory [default: .]
20+
* `--debug / --no-debug`: [default: no-debug]
21+
* `--format-json / --no-format-json`: [default: no-format-json]
22+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
23+
* `--list`: Show available Python checks
24+
* `--install-completion`: Install completion for the current shell.
25+
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
26+
* `--help`: Show this message and exit.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# `infrahubctl dump`
2+
3+
Export nodes and their relationships out of the database.
4+
5+
**Usage**:
6+
7+
```console
8+
$ infrahubctl dump [OPTIONS]
9+
```
10+
11+
**Options**:
12+
13+
* `--namespace TEXT`: Namespace(s) to export
14+
* `--directory PATH`: Directory path to store export [default: (dynamic)]
15+
* `--quiet / --no-quiet`: No console output [default: no-quiet]
16+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
17+
* `--branch TEXT`: Branch from which to export [default: main]
18+
* `--concurrent INTEGER`: Maximum number of requests to execute at the same time. [env var: INFRAHUB_MAX_CONCURRENT_EXECUTION; default: 4]
19+
* `--timeout INTEGER`: Timeout in sec [env var: INFRAHUB_TIMEOUT; default: 60]
20+
* `--exclude TEXT`: Prevent node kind(s) from being exported, CoreAccount is excluded by default [default: CoreAccount]
21+
* `--install-completion`: Install completion for the current shell.
22+
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
23+
* `--help`: Show this message and exit.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `infrahubctl generator`
2+
3+
Run a generator script.
4+
5+
**Usage**:
6+
7+
```console
8+
$ infrahubctl generator [OPTIONS] [GENERATOR_NAME] [VARIABLES]...
9+
```
10+
11+
**Arguments**:
12+
13+
* `[GENERATOR_NAME]`: Name of the Generator
14+
* `[VARIABLES]...`: Variables to pass along with the query. Format key=value key=value.
15+
16+
**Options**:
17+
18+
* `--branch TEXT`
19+
* `--path TEXT`: Root directory [default: .]
20+
* `--debug / --no-debug`: [default: no-debug]
21+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
22+
* `--list`: Show available Generators
23+
* `--install-completion`: Install completion for the current shell.
24+
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
25+
* `--help`: Show this message and exit.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# `infrahubctl info`
2+
3+
Display the status of the Python SDK.
4+
5+
**Usage**:
6+
7+
```console
8+
$ infrahubctl info [OPTIONS]
9+
```
10+
11+
**Options**:
12+
13+
* `--detail / --no-detail`: Display detailed information. [default: no-detail]
14+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
15+
* `--install-completion`: Install completion for the current shell.
16+
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
17+
* `--help`: Show this message and exit.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# `infrahubctl load`
2+
3+
Import nodes and their relationships into the database.
4+
5+
**Usage**:
6+
7+
```console
8+
$ infrahubctl load [OPTIONS]
9+
```
10+
11+
**Options**:
12+
13+
* `--directory PATH`: Directory path of exported data [default: (dynamic)]
14+
* `--continue-on-error / --no-continue-on-error`: Allow exceptions during loading and display them when complete [default: no-continue-on-error]
15+
* `--quiet / --no-quiet`: No console output [default: no-quiet]
16+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
17+
* `--branch TEXT`: Branch from which to export [default: main]
18+
* `--concurrent INTEGER`: Maximum number of requests to execute at the same time. [env var: INFRAHUB_MAX_CONCURRENT_EXECUTION]
19+
* `--timeout INTEGER`: Timeout in sec [env var: INFRAHUB_TIMEOUT; default: 60]
20+
* `--install-completion`: Install completion for the current shell.
21+
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
22+
* `--help`: Show this message and exit.

0 commit comments

Comments
 (0)