Skip to content

Commit

Permalink
Merge pull request buildbot#7543 from tdesveaux/git/http-credentials
Browse files Browse the repository at this point in the history
Git steps: implement auth by user/password
  • Loading branch information
p12tic authored May 14, 2024
2 parents e298cb7 + f7982af commit 97fb9c3
Show file tree
Hide file tree
Showing 12 changed files with 832 additions and 55 deletions.
42 changes: 40 additions & 2 deletions master/buildbot/steps/source/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#
# Copyright Buildbot Team Members

from __future__ import annotations

from typing import TYPE_CHECKING

from twisted.internet import defer
from twisted.internet import reactor
from twisted.python import log
Expand All @@ -25,6 +29,12 @@
from buildbot.steps.worker import CompositeStepMixin
from buildbot.util.git import RC_SUCCESS
from buildbot.util.git import GitStepMixin
from buildbot.util.git_credential import GitCredentialOptions
from buildbot.util.git_credential import add_user_password_to_credentials

if TYPE_CHECKING:
from buildbot.interfaces import IRenderable


GIT_HASH_LENGTH = 40

Expand Down Expand Up @@ -89,6 +99,8 @@ def __init__(
sshPrivateKey=None,
sshHostKey=None,
sshKnownHosts=None,
auth_credentials: tuple[IRenderable | str, IRenderable | str] | None = None,
git_credentials: GitCredentialOptions | None = None,
**kwargs,
):
if not getDescription and not isinstance(getDescription, dict):
Expand All @@ -115,7 +127,19 @@ def __init__(
super().__init__(**kwargs)

self.setupGitStep()
self.setup_git_auth(sshPrivateKey, sshHostKey, sshKnownHosts)
if auth_credentials is not None:
git_credentials = add_user_password_to_credentials(
auth_credentials,
repourl,
git_credentials,
)

self.setup_git_auth(
sshPrivateKey,
sshHostKey,
sshKnownHosts,
git_credentials,
)

if isinstance(self.mode, str):
if not self._hasAttrGroupMember('mode', self.mode):
Expand Down Expand Up @@ -596,6 +620,8 @@ def __init__(
sshPrivateKey=None,
sshHostKey=None,
sshKnownHosts=None,
auth_credentials: tuple[IRenderable | str, IRenderable | str] | None = None,
git_credentials: GitCredentialOptions | None = None,
config=None,
**kwargs,
):
Expand All @@ -611,7 +637,19 @@ def __init__(
super().__init__(**kwargs)

self.setupGitStep()
self.setup_git_auth(sshPrivateKey, sshHostKey, sshKnownHosts)
if auth_credentials is not None:
git_credentials = add_user_password_to_credentials(
auth_credentials,
repourl,
git_credentials,
)

self.setup_git_auth(
sshPrivateKey,
sshHostKey,
sshKnownHosts,
git_credentials,
)

if not self.branch:
bbconfig.error('GitPush: must provide branch')
Expand Down
Loading

0 comments on commit 97fb9c3

Please sign in to comment.