Skip to content

Commit

Permalink
Fix git auth prompting and allow config of '.git' auto suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
ogenstad committed Nov 28, 2024
1 parent eb37197 commit fc3911c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions backend/infrahub/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 9 additions & 7 deletions backend/infrahub/graphql/mutations/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions backend/infrahub/workers/infrahub_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions changelog/+ddd89dc2.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Corrected configuration for prefect worker to never prompt for Git credentials on the console
1 change: 1 addition & 0 deletions changelog/5077.added.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fc3911c

Please sign in to comment.