From fc3911cdaaa5c323fce5034cad256f8fc2b21120 Mon Sep 17 00:00:00 2001 From: Patrick Ogenstad Date: Thu, 28 Nov 2024 08:41:07 +0100 Subject: [PATCH] Fix git auth prompting and allow config of '.git' auto suffix --- backend/infrahub/config.py | 1 + backend/infrahub/graphql/mutations/repository.py | 16 +++++++++------- backend/infrahub/workers/infrahub_async.py | 3 +++ changelog/+ddd89dc2.fixed.md | 1 + changelog/5077.added.md | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 changelog/+ddd89dc2.fixed.md create mode 100644 changelog/5077.added.md diff --git a/backend/infrahub/config.py b/backend/infrahub/config.py index 38f73f426c..4cd12a7d34 100644 --- a/backend/infrahub/config.py +++ b/backend/infrahub/config.py @@ -337,6 +337,7 @@ class GitSettings(BaseSettings): description="Time (in seconds) between git repositories synchronizations", deprecated="This setting is deprecated and not currently in use.", ) + append_git_suffix: bool = Field(default=True, description="Automatically append '.git' to HTTP URLs if missing.") class HTTPSettings(BaseSettings): diff --git a/backend/infrahub/graphql/mutations/repository.py b/backend/infrahub/graphql/mutations/repository.py index 2a5612d27b..e3302b02d4 100644 --- a/backend/infrahub/graphql/mutations/repository.py +++ b/backend/infrahub/graphql/mutations/repository.py @@ -5,6 +5,7 @@ from graphene import Boolean, InputObjectType, Mutation, String +from infrahub import config from infrahub.core.constants import InfrahubKind, RepositoryInternalStatus from infrahub.core.manager import NodeManager from infrahub.core.protocols import CoreGenericRepository, CoreReadOnlyRepository, CoreRepository @@ -181,13 +182,14 @@ async def mutate_update( def cleanup_payload(data: InputObjectType | dict[str, Any]) -> None: """If the input payload contains an http URL that doesn't end in .git it will be added to the payload""" - http_without_dotgit = r"^(https?://)(?!.*\.git$).*" - if ( - data.get("location") - and data["location"].get("value") - and re.match(http_without_dotgit, data["location"]["value"]) - ): - data["location"]["value"] = f'{data["location"]["value"]}.git' + if config.SETTINGS.git.append_git_suffix: + http_without_dotgit = r"^(https?://)(?!.*\.git$).*" + if ( + data.get("location") + and data["location"].get("value") + and re.match(http_without_dotgit, data["location"]["value"]) + ): + data["location"]["value"] = f'{data["location"]["value"]}.git' class ProcessRepository(Mutation): diff --git a/backend/infrahub/workers/infrahub_async.py b/backend/infrahub/workers/infrahub_async.py index 2ffe2ca11d..e1fbb5e204 100644 --- a/backend/infrahub/workers/infrahub_async.py +++ b/backend/infrahub/workers/infrahub_async.py @@ -79,6 +79,9 @@ async def setup( logging.getLogger("aio_pika").setLevel(logging.ERROR) logging.getLogger("aiormq").setLevel(logging.ERROR) logging.getLogger("git").setLevel(logging.ERROR) + # Prevent git from interactively prompting the user for passwords if the credentials provided + # by the credential helper is failing. + os.environ["GIT_TERMINAL_PROMPT"] = "0" if not config.SETTINGS.settings: config_file = os.environ.get("INFRAHUB_CONFIG", "infrahub.toml") diff --git a/changelog/+ddd89dc2.fixed.md b/changelog/+ddd89dc2.fixed.md new file mode 100644 index 0000000000..80b47c4a7c --- /dev/null +++ b/changelog/+ddd89dc2.fixed.md @@ -0,0 +1 @@ +Corrected configuration for prefect worker to never prompt for Git credentials on the console diff --git a/changelog/5077.added.md b/changelog/5077.added.md new file mode 100644 index 0000000000..f8e8be1ff7 --- /dev/null +++ b/changelog/5077.added.md @@ -0,0 +1 @@ +Added a 'append_git_suffix' configuration setting for Git repositories that allows you to disable auto appending '.git' to repositories defined with an HTTP URL