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

Add https support #248

Closed
wants to merge 1 commit 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
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:18.04
RUN apt-get update && apt-get install \
-y build-essential git python3-dev python3-virtualenv

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m virtualenv --python=/usr/bin/python3 $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Install dependencies:
COPY setup.py marge-bot/setup.py
COPY requirements.txt marge-bot/requirements.txt
COPY requirements_frozen.txt marge-bot/requirements_frozen.txt
COPY version marge-bot/version
COPY marge marge-bot/marge
COPY marge.app marge-bot/marge.app

WORKDIR /marge-bot

RUN python3 setup.py install
RUN pip3 install -r requirements.txt

ENTRYPOINT ["./marge.app"]
12 changes: 7 additions & 5 deletions marge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def regexp(str_regex):
metavar='URL',
help='Your GitLab instance, e.g. "https://gitlab.example.com".\n',
)
ssh_key_group = parser.add_mutually_exclusive_group(required=True)
ssh_key_group = parser.add_mutually_exclusive_group(required=False)
ssh_key_group.add_argument(
'--ssh-key',
type=str,
Expand All @@ -89,8 +89,9 @@ def regexp(str_regex):
)
ssh_key_group.add_argument(
'--ssh-key-file',
type=str, # because we want a file location, not the content
# type=str, # because we want a file location, not the content
metavar='FILE',
default='marge-bot-ssh-key', # give it a default to stop complaining
help='Path to the private ssh key for marge so it can clone/push.\n',
)
parser.add_argument(
Expand Down Expand Up @@ -229,9 +230,9 @@ def regexp(str_regex):
# pylint: disable=protected-access
for _, (_, value) in parser._source_to_settings.get(configargparse._COMMAND_LINE_SOURCE_KEY, {}).items():
cli_args.extend(value)
for bad_arg in ['--auth-token', '--ssh-key']:
if bad_arg in cli_args:
raise MargeBotCliArgError('"%s" can only be set via ENV var or config file.' % bad_arg)
# for bad_arg in ['--auth-token', '--ssh-key']:
# if bad_arg in cli_args:
# raise MargeBotCliArgError('"%s" can only be set via ENV var or config file.' % bad_arg)
return config


Expand Down Expand Up @@ -290,6 +291,7 @@ def main(args=None):

config = bot.BotConfig(
user=user,
auth_token=auth_token,
ssh_key_file=ssh_key_file,
project_regexp=options.project_regexp,
git_timeout=options.git_timeout,
Expand Down
3 changes: 2 additions & 1 deletion marge/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def start(self):
with TemporaryDirectory() as root_dir:
repo_manager = store.RepoManager(
user=self.user,
auth_token=self._config.auth_token,
root_dir=root_dir,
ssh_key_file=self._config.ssh_key_file,
timeout=self._config.git_timeout,
Expand Down Expand Up @@ -186,7 +187,7 @@ def _get_single_job(self, project, merge_request, repo, options):


class BotConfig(namedtuple('BotConfig',
'user ssh_key_file project_regexp merge_order merge_opts git_timeout ' +
'user auth_token ssh_key_file project_regexp merge_order merge_opts git_timeout ' +
'git_reference_repo branch_regexp source_branch_regexp batch')):
pass

Expand Down
9 changes: 7 additions & 2 deletions marge/store.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import tempfile
import re

from . import git


class RepoManager:

def __init__(self, user, root_dir, ssh_key_file=None, timeout=None, reference=None):
def __init__(self, user, auth_token, root_dir, ssh_key_file=None, timeout=None, reference=None):
self._root_dir = root_dir
self._user = user
self._ssh_key_file = ssh_key_file
self._auth_token = auth_token
self._repos = {}
self._timeout = timeout
self._reference = reference

def repo_for_project(self, project):
repo = self._repos.get(project.id)
if not repo or repo.remote_url != project.ssh_url_to_repo:
repo_url = project.ssh_url_to_repo
credentials = self._user.username + ":" + self._auth_token
repo_url = re.sub(":", "/", project.ssh_url_to_repo, 1)
repo_url = re.sub("git", "https://" + credentials, repo_url, 1)

local_repo_dir = tempfile.mkdtemp(dir=self._root_dir)

repo = git.Repo(repo_url, local_repo_dir, ssh_key_file=self._ssh_key_file,
Expand Down