Skip to content

Commit

Permalink
Merge pull request #1395 from opsmill/develop
Browse files Browse the repository at this point in the history
Version 0.8.2
  • Loading branch information
ogenstad authored Nov 10, 2023
2 parents 846bff6 + 6818a8c commit baeb591
Show file tree
Hide file tree
Showing 103 changed files with 1,669 additions and 1,909 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/onCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

poetry config virtualenvs.create true
poetry install --no-interaction --no-ansi --no-root
poetry install --no-interaction --no-ansi

invoke demo.build
2 changes: 1 addition & 1 deletion .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

invoke demo.init demo.start
invoke demo.start
12 changes: 0 additions & 12 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ sdk_files: &sdk_files
- "pyproject.toml"
- "poetry.lock"

nornir_files: &nornir_files
- "nornir_plugin/**"
- "pyproject.toml"
- "poetry.lock"

sync_files: &sync_files
- "sync/**"
- "pyproject.toml"
Expand Down Expand Up @@ -54,13 +49,6 @@ sdk_all:
- *ci_config
- *development_files

nornir_all:
- *nornir_files
- *sdk_files
- *backend_files
- *ci_config
- *development_files

sync_all:
- *sync_files
- *sdk_files
Expand Down
3 changes: 0 additions & 3 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
"group/infrahubctl":
- ctl/**

"group/nornir":
- nornir_plugin/**

"group/python-sdk":
- python_sdk/**

Expand Down
23 changes: 4 additions & 19 deletions .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
description: "Issue related to the Python SDK"
color: "56e8e1"

- name: "group/nornir"
description: "Issue related to the Nornir Plugin"
color: "41ba21"

- name: "group/sync-engine"
description: "Issue related to the Synchronization engine"
color: "56e8e1"
Expand Down Expand Up @@ -81,21 +77,6 @@
description: "Maintenance task related to the infrahubctl command line"
color: "fef2c0"

# ----------------------------------
# TYPE NORNIR
# ----------------------------------
- name: "type/feature/nornir"
description: "New feature or request related to the Nornir plugin"
color: "a2eeef"

- name: "type/bug/nornir"
description: "Something isn't working as expected related to the Nornir plugin"
color: "d73a4a"

- name: "type/housekeeping/nornir"
description: "Maintenance task related to the Nornir plugin"
color: "fef2c0"

# ----------------------------------
# TYPE ALL
# ----------------------------------
Expand Down Expand Up @@ -161,6 +142,10 @@
description: "The redaction of the issue is still a work in progress"
color: "dcb518"

- name: "state/referenced"
description: "This issue is referenced in our internal tooling"
color: "c9510c"

# ----------------------------------
# CI
# ----------------------------------
Expand Down
60 changes: 17 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
backend: ${{ steps.changes.outputs.backend_all }}
frontend: ${{ steps.changes.outputs.frontend_all }}
sdk: ${{ steps.changes.outputs.sdk_all }}
nornir: ${{ steps.changes.outputs.nornir_all }}
sync: ${{ steps.changes.outputs.sync_all }}
e2e: ${{ steps.changes.outputs.e2e_all }}
python: ${{ steps.changes.outputs.python_all }}
Expand Down Expand Up @@ -175,43 +174,6 @@ jobs:
flag-name: python-sdk-integration
parallel: true

nornir-plugin-tests:
if: |
always() && !cancelled() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
needs.files-changed.outputs.nornir == 'true'
needs: ["files-changed", "yaml-lint", "python-lint"]
runs-on: "ubuntu-20.04"
timeout-minutes: 30
steps:
- name: "Check out repository code"
uses: "actions/checkout@v3"
- name: "Install Invoke"
run: "pip install toml invoke"
- name: "Build Test Image"
run: "invoke test.build"
- name: "Black Tests"
run: "invoke nornir.black --docker"
- name: "Isort Tests"
run: "invoke nornir.isort --docker"
- name: "Pylint Tests"
run: "invoke nornir.pylint --docker"
- name: "Mypy Tests"
run: "invoke nornir.mypy --docker"
- name: "Unit Tests"
run: "invoke nornir.test-unit"
env:
BUILDKITE_ANALYTICS_TOKEN: ${{ secrets.BUILDKITE_NORNIR_UNIT }}
- name: "Coveralls : Unit Tests"
uses: coverallsapp/[email protected]
env:
COVERALLS_SERVICE_NUMBER: ${{ github.sha }}
with:
flag-name: nornir-plugin-unit
parallel: true


infrahub-sync-tests:
if: |
always() && !cancelled() &&
Expand Down Expand Up @@ -338,6 +300,18 @@ jobs:
- name: "Run integration tests"
working-directory: ./frontend
run: "npm run cypress:run"
- name: Upload cypress screenshots
if: failure()
uses: actions/upload-artifact@v3
with:
name: screenshots
path: docs/media/*
- name: Upload cypress videos
if: failure()
uses: actions/upload-artifact@v3
with:
name: screenshots
path: frontend/cypress/videos/*
- name: "Coveralls : Unit Tests"
uses: coverallsapp/[email protected]
env:
Expand Down Expand Up @@ -375,7 +349,7 @@ jobs:
# run: "invoke demo.pull"
# - name: Initialize Demo
# id: init-demo
# run: "invoke demo.init demo.start demo.load-infra-schema"
# run: "invoke demo.start demo.load-infra-schema"
# - name: Check Demo Status
# run: "invoke demo.status"
# - name: Load Data
Expand Down Expand Up @@ -417,7 +391,7 @@ jobs:
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
runs-on: "runner-ubuntu-8-32"
timeout-minutes: 30
timeout-minutes: 40
env:
INFRAHUB_DB_TYPE: neo4j
steps:
Expand All @@ -440,7 +414,7 @@ jobs:
run: "invoke demo.pull"
- name: Initialize Demo
id: init-demo
run: "invoke demo.init demo.start demo.load-infra-schema"
run: "invoke demo.start demo.load-infra-schema"
- name: Check Demo Status
run: "invoke demo.status"
- name: Load Data
Expand Down Expand Up @@ -476,7 +450,7 @@ jobs:
run: invoke demo.status

coverall-report:
needs: ["frontend-tests", "backend-tests-default", "python-sdk-tests", "nornir-plugin-tests"]
needs: ["frontend-tests", "backend-tests-default", "python-sdk-tests"]
if: |
always() && !cancelled()
runs-on: ubuntu-latest
Expand Down Expand Up @@ -508,5 +482,5 @@ jobs:
env:
COVERALLS_SERVICE_NUMBER: ${{ github.sha }}
with:
carryforward: "backend-unit,backend-integration,frontend-unit,python-sdk-unit,python-sdk-integration,nornir-plugin-unit"
carryforward: "backend-unit,backend-integration,frontend-unit,python-sdk-unit,python-sdk-integration"
parallel-finished: true
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ coverage.xml
*.env
script.py
.vscode/settings.json
.retype/*
node_modules/*
development/docker-compose.override.yml
development/docker-compose.dev-override.yml
Expand All @@ -15,6 +14,11 @@ development/docker-compose.dev-override.yml
.direnv/
.envrc

# Retype App
.retype/*
docs/.retype
retype.manifest

storage/*
.coverage.*
python_sdk/dist/*
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tasks:
command: |
cd /workspace/infrahub
source $HOME/.bashrc
poetry run invoke demo.destroy demo.init demo.start demo.load-infra-schema demo.load-infra-data
poetry run invoke demo.destroy demo.start demo.load-infra-schema demo.load-infra-data
# Ports to expose on workspace startup
ports:
Expand Down
2 changes: 2 additions & 0 deletions backend/infrahub/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
diff,
file,
internal,
menu,
query,
schema,
storage,
Expand All @@ -19,6 +20,7 @@
router.include_router(diff.router)
router.include_router(file.router)
router.include_router(internal.router)
router.include_router(menu.router)
router.include_router(query.router)
router.include_router(schema.router)
router.include_router(storage.router)
Expand Down
125 changes: 125 additions & 0 deletions backend/infrahub/api/menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
from __future__ import annotations

from typing import Dict, List

from fastapi import APIRouter, Depends
from pydantic import BaseModel, Field

from infrahub.api.dependencies import get_branch_dep
from infrahub.core import registry
from infrahub.core.branch import Branch # noqa: TCH001
from infrahub.core.schema import GroupSchema, NodeSchema
from infrahub.log import get_logger

log = get_logger()
router = APIRouter(prefix="/menu")


class InterfaceMenu(BaseModel):
title: str = Field(..., description="Title of the menu item")
path: str = Field(default="", description="URL endpoint if applicable")
icon: str = Field(default="", description="The icon to show for the current view")
children: List[InterfaceMenu] = Field(default_factory=list, description="Child objects")
kind: str = Field(default="")

def __lt__(self, other: object) -> bool:
if not isinstance(other, InterfaceMenu):
raise NotImplementedError
return self.title < other.title

def list_title(self) -> str:
return f"All {self.title}(s)"


def add_to_menu(structure: Dict[str, List[InterfaceMenu]], menu_item: InterfaceMenu) -> None:
all_items = InterfaceMenu(title=menu_item.list_title(), path=menu_item.path, icon=menu_item.icon)
menu_item.path = ""
menu_item.icon = ""
for child in structure[menu_item.kind]:
menu_item.children.append(child)
if child.kind in structure:
add_to_menu(structure, child)
menu_item.children.sort()
menu_item.children.insert(0, all_items)


@router.get("")
async def get_menu(
branch: Branch = Depends(get_branch_dep),
) -> List[InterfaceMenu]:
log.info("menu_request", branch=branch.name)

full_schema = registry.schema.get_full(branch=branch)
objects = InterfaceMenu(
title="Objects",
children=[],
)

structure: Dict[str, List[InterfaceMenu]] = {}

groups = InterfaceMenu(
title="Groups",
)
for key in full_schema.keys():
model = full_schema[key]

if isinstance(model, GroupSchema) or not model.include_in_menu:
continue

if isinstance(model, NodeSchema) and "CoreGroup" in model.inherit_from:
groups.children.append(InterfaceMenu(title=model.label or model.name, path=f"/groups/{model.kind}"))
continue

menu_name = model.menu_placement or "base"
if menu_name not in structure:
structure[menu_name] = []

structure[menu_name].append(
InterfaceMenu(
title=model.label or model.name, path=f"/objects/{model.kind}", icon=model.icon or "", kind=model.kind
)
)

for menu_item in structure["base"]:
if menu_item.kind in structure:
add_to_menu(structure, menu_item)

objects.children.append(menu_item)

objects.children.sort()
groups.children.sort()
groups.children.insert(0, InterfaceMenu(title="All Groups", path="/groups"))
unified_storage = InterfaceMenu(
title="Unified Storage",
children=[
InterfaceMenu(title="Schema", path="/schema", icon="mdi:file-code"),
InterfaceMenu(title="Repository", path="/objects/CoreRepository", icon="mdi:source-repository"),
InterfaceMenu(title="GraphQL Query", path="/objects/CoreGraphQLQuery", icon="mdi:graphql"),
],
)

change_control = InterfaceMenu(
title="Change Control",
children=[
InterfaceMenu(title="Branches", path="/branches", icon="mdi:layers-triple"),
InterfaceMenu(title="Proposed Changes", path="/proposed-changes", icon="mdi:file-replace-outline"),
InterfaceMenu(title="Check Definition", path="/objects/CoreCheckDefinition", icon="mdi:check-all"),
],
)
deployment = InterfaceMenu(
title="Deployment",
children=[
InterfaceMenu(title="Artifact", path="/objects/CoreArtifact", icon="mdi:file-document-outline"),
InterfaceMenu(
title="Artifact Definition",
path="/objects/CoreArtifactDefinition",
icon="mdi:file-document-multiple-outline",
),
InterfaceMenu(title="Transformation", path="/objects/CoreTransformation", icon="mdi:cog-transfer"),
],
)
admin = InterfaceMenu(
title="Admin", children=[InterfaceMenu(title="Accounts", path="/objects/CoreAccount", icon="mdi:account")]
)

return [objects, groups, unified_storage, change_control, deployment, admin]
Loading

0 comments on commit baeb591

Please sign in to comment.