Skip to content

Remove refs to InfrahubServices for git ops #6406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
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
39 changes: 17 additions & 22 deletions backend/infrahub/artifacts/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,29 @@
from infrahub.artifacts.models import CheckArtifactCreate
from infrahub.core.constants import InfrahubKind, ValidatorConclusion
from infrahub.core.timestamp import Timestamp
from infrahub.git import InfrahubReadOnlyRepository, InfrahubRepository
from infrahub.services import InfrahubServices
from infrahub.git.repository import get_initialized_repo
from infrahub.tasks.artifact import define_artifact
from infrahub.workers.dependencies import get_client
from infrahub.workflows.utils import add_tags


@flow(name="git-repository-check-artifact-create", flow_run_name="Check artifact creation")
async def create(model: CheckArtifactCreate, service: InfrahubServices) -> ValidatorConclusion:
async def create(model: CheckArtifactCreate) -> ValidatorConclusion:
await add_tags(branches=[model.branch_name], nodes=[model.target_id])
validator = await service.client.get(kind=InfrahubKind.ARTIFACTVALIDATOR, id=model.validator_id, include=["checks"])

repo: InfrahubReadOnlyRepository | InfrahubRepository
if InfrahubKind.READONLYREPOSITORY:
repo = await InfrahubReadOnlyRepository.init(
id=model.repository_id,
name=model.repository_name,
client=service.client,
service=service,
)
else:
repo = await InfrahubRepository.init(
id=model.repository_id,
name=model.repository_name,
client=service.client,
service=service,
)
client = get_client()

validator = await client.get(kind=InfrahubKind.ARTIFACTVALIDATOR, id=model.validator_id, include=["checks"])

repo = await get_initialized_repo(
client=client,
repository_id=model.repository_id,
name=model.repository_name,
repository_kind=model.repository_kind,
commit=model.commit,
)

artifact, artifact_created = await define_artifact(model=model, service=service)
artifact, artifact_created = await define_artifact(model=model)

severity = "info"
artifact_result: dict[str, str | bool | None] = {
Expand Down Expand Up @@ -59,7 +54,7 @@ async def create(model: CheckArtifactCreate, service: InfrahubServices) -> Valid

check = None
check_name = f"{model.artifact_name}: {model.target_name}"
existing_check = await service.client.filters(
existing_check = await client.filters(
kind=InfrahubKind.ARTIFACTCHECK, validator__ids=validator.id, name__value=check_name
)
if existing_check:
Expand All @@ -75,7 +70,7 @@ async def create(model: CheckArtifactCreate, service: InfrahubServices) -> Valid
check.storage_id.value = artifact_result["storage_id"]
await check.save()
else:
check = await service.client.create(
check = await client.create(
kind=InfrahubKind.ARTIFACTCHECK,
data={
"name": check_name,
Expand Down
17 changes: 4 additions & 13 deletions backend/infrahub/cli/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
from infrahub.database.memgraph import IndexManagerMemgraph
from infrahub.database.neo4j import IndexManagerNeo4j
from infrahub.log import get_logger
from infrahub.services import InfrahubServices
from infrahub.services.adapters.message_bus.local import BusSimulator
from infrahub.services.adapters.workflow.local import WorkflowLocalExecution

from .constants import ERROR_BADGE, FAILED_BADGE, SUCCESS_BADGE
from .patch import patch_app
Expand Down Expand Up @@ -187,12 +184,8 @@ async def update_core_schema_cmd(
context: CliContext = ctx.obj
dbdriver = await context.init_db(retry=1)

service = await InfrahubServices.new(
database=dbdriver, message_bus=BusSimulator(), workflow=WorkflowLocalExecution()
)

with prefect_test_harness():
await update_core_schema(db=dbdriver, service=service, initialize=True, debug=debug)
await update_core_schema(db=dbdriver, initialize=True, debug=debug)

await dbdriver.close()

Expand Down Expand Up @@ -342,9 +335,7 @@ async def initialize_internal_schema() -> None:
registry.schema.register_schema(schema=schema)


async def update_core_schema(
db: InfrahubDatabase, service: InfrahubServices, initialize: bool = True, debug: bool = False
) -> None:
async def update_core_schema(db: InfrahubDatabase, initialize: bool = True, debug: bool = False) -> None:
"""Update the core schema of Infrahub to the latest version"""
# ----------------------------------------------------------
# Initialize Schema and Registry
Expand Down Expand Up @@ -393,7 +384,7 @@ async def update_core_schema(
schema_branch=candidate_schema,
constraints=result.constraints,
)
responses = await schema_validate_migrations(message=validate_migration_data, service=service)
responses = await schema_validate_migrations(message=validate_migration_data)
error_messages = [violation.message for response in responses for violation in response.violations]
if error_messages:
rprint(f"{ERROR_BADGE} | Unable to update the schema, due to failed validations")
Expand Down Expand Up @@ -435,7 +426,7 @@ async def update_core_schema(
previous_schema=origin_schema,
migrations=result.migrations,
)
migration_error_msgs = await schema_apply_migrations(message=apply_migration_data, service=service)
migration_error_msgs = await schema_apply_migrations(message=apply_migration_data)

if migration_error_msgs:
rprint(f"{ERROR_BADGE} | Some error(s) happened while running the schema migrations")
Expand Down
10 changes: 2 additions & 8 deletions backend/infrahub/cli/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
from infrahub.menu.models import MenuDict
from infrahub.menu.repository import MenuRepository
from infrahub.menu.utils import create_default_menu
from infrahub.services import InfrahubServices
from infrahub.services.adapters.message_bus.local import BusSimulator
from infrahub.services.adapters.workflow.local import WorkflowLocalExecution
from infrahub.trigger.tasks import trigger_configure_all
from infrahub.workflows.initialization import (
setup_blocks,
Expand Down Expand Up @@ -61,9 +58,6 @@ async def upgrade_cmd(
context: CliContext = ctx.obj
dbdriver = await context.init_db(retry=1)

service = await InfrahubServices.new(
database=dbdriver, message_bus=BusSimulator(), workflow=WorkflowLocalExecution()
)
await initialize_registry(db=dbdriver)

# NOTE add step to validate if the database and the task manager are reachable
Expand All @@ -78,7 +72,7 @@ async def upgrade_cmd(
await migrate_database(db=dbdriver, initialize=False, check=check)

await initialize_internal_schema()
await update_core_schema(db=dbdriver, service=service, initialize=False)
await update_core_schema(db=dbdriver, initialize=False)

# -------------------------------------------
# Upgrade Internal Objects, generated and managed by Infrahub
Expand All @@ -93,7 +87,7 @@ async def upgrade_cmd(
await setup_blocks()
await setup_worker_pools(client=client)
await setup_deployments(client=client)
await trigger_configure_all(service=service)
await trigger_configure_all()

await dbdriver.close()

Expand Down
Loading