Add agent.force_git_ssh_port to control https to ssh link conversion for non standard ssh port

This commit is contained in:
allegroai 2020-10-04 19:42:44 +03:00
parent 3ff85b7b85
commit 6e54e55c31
3 changed files with 13 additions and 5 deletions

View File

@ -17,9 +17,14 @@ agent {
# leave blank for GIT SSH credentials (set force_git_ssh_protocol=true to force SSH protocol)
git_user=""
git_pass=""
# Limit credentials to a single domain, for example: github.com,
# all other domains will use public access (no user/pass). Default: always send user/pass for any VCS domain
git_domain=""
# Force GIT protocol to use SSH regardless of the git url (Assumes GIT user/pass are blank)
force_git_ssh_protocol: false
# Force a specific SSH port when converting http to ssh links (the domain is kept the same)
# force_git_ssh_port: ""
# unique name of this worker, if None, created based on hostname:process_id
# Overridden with os environment: TRAINS_WORKER_NAME

View File

@ -16,6 +16,8 @@
# Force GIT protocol to use SSH regardless of the git url (Assumes GIT user/pass are blank)
force_git_ssh_protocol: false
# Force a specific SSH port when converting http to ssh links (the domain is kept the same)
# force_git_ssh_port: 0
# Set the python version to use when creating the virtual environment and launching the experiment
# Example values: "/usr/bin/python3" or "/usr/local/bin/python3.6"

View File

@ -5,7 +5,7 @@ import subprocess
from distutils.spawn import find_executable
from hashlib import md5
from os import environ, getenv
from typing import Text, Sequence, Mapping, Iterable, TypeVar, Callable, Tuple
from typing import Text, Sequence, Mapping, Iterable, TypeVar, Callable, Tuple, Optional
import attr
from furl import furl
@ -254,8 +254,8 @@ class VCS(object):
return url
@classmethod
def replace_http_url(cls, url):
# type: (Text) -> Text
def replace_http_url(cls, url, port=None):
# type: (Text, Optional[int]) -> Text
"""
Replace HTTPS URL with SSH URL when applicable
"""
@ -267,7 +267,7 @@ class VCS(object):
# make sure there is no port in the final url (safe_furl support)
# the original port was an https port, and we do not know if there is a different ssh port,
# so we have to clear the original port specified (https) and use the default ssh schema port.
parsed_url.port = None
parsed_url.port = port or None
url = parsed_url.url
return url
@ -279,7 +279,8 @@ class VCS(object):
if self.session.config.get('agent.force_git_ssh_protocol', None) and self.url:
parsed_url = furl(self.url)
if parsed_url.scheme == "https":
new_url = self.replace_http_url(self.url)
new_url = self.replace_http_url(
self.url, port=self.session.config.get('agent.force_git_ssh_port', None))
if new_url != self.url:
print("Using SSH credentials - replacing https url '{}' with ssh url '{}'".format(
self.url, new_url))