Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ cython_debug/
.abstra/

# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/

Expand Down Expand Up @@ -226,4 +226,4 @@ Icon[]
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
.apdisk
3 changes: 0 additions & 3 deletions .graphqlrc.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .graphqlrc.yml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
schema: "{{ infrahub_server_url }}/schema.graphql"
documents: "**/*.gql"
3 changes: 0 additions & 3 deletions .infrahub.yml

This file was deleted.

51 changes: 51 additions & 0 deletions .infrahub.yml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# yaml-language-server: $schema=https://schema.infrahub.app/python-sdk/repository-config/latest.json
---
# https://docs.infrahub.app/reference/dotinfrahub
schemas: # Schema definitions to load (files or directories)
- schemas

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears we generate an schemas/example.yml file. We should update this to include the path to this example.

Suggested change
- schemas
- "schemas/example.yml"


{% if objects %}
objects: # Object definitions to load (files or directories)
- objects

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- objects
- "objects/<file>.yml"


{% endif %}
{% if menus %}
menus: # Menu definitions to load (files or directories)
- menus

{% endif %}
{% if transforms %}
jinja2_transforms:
- name: <string>
query: <string>
template_path: transforms/templates/<string>.j2

python_transforms:
- name: <string>
file_path: transforms/<string>.py

{% endif %}
{% if generators %}
generator_definitions:
- name: <string>
file_path: generators/<string>.py
query: <string>
targets: <string>

{% endif %}
queries:
- name: <string>
file_path: queries/<string>.gql

{% if checks %}
check_definitions:
- name: <string>
file_path: checks/<string>.py

{% endif %}
artifact_definitions:
- name: <string>
parameters: {}
content_type: <string>
targets: <string>
transformation: <string>
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.10
hooks:
# Run the linter.
- id: ruff-check
args: [--fix]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.37.1
hooks:
- id: yamllint
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
exclude: ^\.vscode/|/\.vscode/
- id: mixed-line-ending
- id: trailing-whitespace
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"recommendations": [
"charliermarsh.ruff",
"ms-python.python",
"opsmill.infrahub",
"redhat.vscode-yaml",
]
}
21 changes: 21 additions & 0 deletions .vscode/settings.json.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"python.defaultInterpreterPath": ".venv/bin/python3",
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": true,
"python.testing.pytestEnabled": true,
"infrahub-vscode.servers": [
{
"name": "{{ project_name }}",
"address": "{{ infrahub_server_url }}",
"api_token": "{{ infrahub_api_token }}"
}
],
"[yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml",
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true
}
}
2 changes: 1 addition & 1 deletion .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ rules:
# See https://github.com/prettier/prettier/pull/10926 or https://github.com/redhat-developer/vscode-yaml/issues/433
min-spaces-from-content: 1
line-length:
max: 140
max: 200
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: false
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Infrahub Repository

Welcome! This repository was initialized via the `uv tool run --from 'infrahub-sdk[ctl]' infrahubctl repository init <directory>` command. That bootstraps a repository for use with some example data.
[![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-teal.json)](https://github.com/copier-org/copier)

Welcome! This repository was initialized via the `uv tool run --from 'copier' copier copy https://github.com/opsmill/infrahub-template <directory-path>` command. That bootstraps a repository for use with some example data.

## Installation

Expand Down
88 changes: 75 additions & 13 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,99 @@
---
_envops:
lstrip_blocks: true
trim_blocks: true

project_name:
type: str
help: The name for your new Infrahub repository. This will be used as the package name.
help: Name for this Infrahub repository (also used as the package name).
validator: >-
{% if not (project_name | regex_search('^[a-z][a-z0-9\-]+$')) %}
project_name must start with a letter, followed one or more letters, digits or dashes all lowercase.
{% endif %}
qmark: 📔

is_local_development:
type: bool
default: true
help: Is this repository intended for local development only? If false, additional configuration options will be requested.
qmark: 🏗️

default_infrahub_branch:
# Only ask if not a local development project
when: "{{ not is_local_development }}"
type: str
nullable: true
help: Branch name to use instead of the server default. Leave empty to use the server default.
validator: >-
{% if not default_infrahub_branch and (default_infrahub_branch | regex_search('^[A-Za-z][A-Za-z0-9\-_]+$')) %}
default_infrahub_branch must start with a letter, followed one or more letters, digits or dashes.
{% endif %}
qmark: 🌲

infrahub_server_url:
# Only ask if not a local development project
when: "{{ not is_local_development }}"
type: str
default: http://localhost:8000
help: URL of the Infrahub server (e.g., http://host:port or https://host).
validator: >-
{% if infrahub_server_url and not (infrahub_server_url | regex_search('^https?:\/\/[A-Za-z][A-Za-z0-9\-_]+(?::(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4}))?$')) %}
Invalid url. Must be something like `http://<host>:<port_num>` or `https://<host>`
{% endif %}
qmark: 🖥️

infrahub_api_token:
# Only ask if not a local development project
when: "{{ not is_local_development }}"
type: str
default: 06438eb2-8019-4776-878c-0941b1f1d1ec
help: API token for authentication.
qmark: 🔐

objects:
type: bool
help: >-
Enable support for Infrahub object files.
default: false
help: Include support for object files (preloads data entries).
qmark: 🗃️

generators:
type: bool
help: >-
Enable support for Infrahub data generators.
Generators are plugins that create objects based on input data in Infrahub.
default: false
help: Include support for data generators (plugins that create objects from input data).
qmark: ⚙️

transforms:
type: bool
help: >-
Enable support for Infrahub data transforms.
A Transformation is a generic plugin to transform a dataset into a different format to simplify it's ingestion by third-party systems.
default: false
help: Include support for data transforms (Jinja2 & Python plugins that convert data for third-party systems).
qmark: 🏗️

scripts:
type: bool
help: Include a 'scripts/' directory for custom automation scripts that interact with the Infrahub API.
default: false
help: Include a `scripts/` directory for custom automation scripts."
qmark: 📜

menus:
type: bool
help: Include a 'menus/' directory and configuration to define custom navigation menus in the Infrahub UI.
default: false
help: Include a `menus/` directory for custom UI navigation menus.
qmark: ⚙️

checks:
type: bool
default: false
help: Include a `checks/` directory for custom validation logic.
qmark: ✅

tests:
type: bool
help: Set up a Python testing environment with pytest for integration testing your schemas and data.
default: false
help: Include a pytest environment for integration testing schemas and data.
qmark: 🧪

package_mode:
type: bool
help: Initialize the repository as an installable Python package (with pyproject.toml).
default: false
help: Configure as an installable Python package with pyproject.toml.
qmark: 📦
5 changes: 5 additions & 0 deletions infrahubctl.toml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
server_address="{{ infrahub_server_url }}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this rendered and not sure if there is an option/question for this? Maybe just add this to the README.md? I'd rather than enforce this via the config file by default.

api_token="{{ infrahub_api_token }}"
{% if infrahub_default_branch and infrahub_default_branch not in ["", "main"] %}
default_branch="{{ infrahub_default_branch }}"
{% endif %}
22 changes: 9 additions & 13 deletions pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@ authors = []
readme = "README.md"
requires-python = ">=3.11, <3.14"
dependencies = [
"infrahub-sdk[all]>=1.13.1",
"invoke>=2.2.0",
"httpx>=0.27.2",
"infrahub-sdk[all]>=1.17.0",
"invoke>=2.2.1",
]

[dependency-groups]
dev = [
"infrahub-testcontainers>=1.3.0",
"pytest>=8.4.1",
"pytest-asyncio>=1.0.0",
"ruff>=0.12.0",
"infrahub-testcontainers>=1.6.2",
"pytest>=9.0.2",
"pytest-asyncio>=1.3.0",
"ruff>=0.14.10",
"mypy>=1.17.1",
"pytest>=8.4.1",
"pytest-asyncio>=1.0.0",
"ruff>=0.12.0",
"yamllint>=1.37.1",
"pre-commit>=4.5.1",
]

[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["tests"]


[tool.mypy]
pretty = true
ignore_missing_imports = true
Expand All @@ -47,7 +45,6 @@ exclude = [
"examples",
]


[tool.ruff.lint]
preview = true

Expand All @@ -71,7 +68,6 @@ ignore = [
"PLR",
]


#https://docs.astral.sh/ruff/formatter/black/
[tool.ruff.format]
quote-style = "double"
Expand All @@ -84,4 +80,4 @@ max-line-length = 150

[tool.ruff.lint.mccabe]
# Target max-complexity=10
max-complexity = 17
max-complexity = 17
2 changes: 1 addition & 1 deletion schemas/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: "1.0"
nodes:
- name: Device
namespace: Network
human_friendly_id: ['hostname__value']
human_friendly_id: ["hostname__value"]
attributes:
- name: hostname
kind: Text
Expand Down
Loading