Skip to content
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

Git steps: implement auth by user/password #7543

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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