Skip to content

Commit 3430cf0

Browse files
committed
🚧 more configuration options supported for config command
- proxy support (using the gitconfig http configuration) - custom certificate CA bundle setting - support of scheme/port settings - custom SSH URI setup - and even a setting to define private repository upon creation kudos to @pyhedgehog to force me into implementing that ☺ Fixes: #107 Fixes: #106 Fixes: #81 Fixes: #88 Signed-off-by: Guyzmo <[email protected]>
1 parent 0e68b1e commit 3430cf0

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

git_repo/services/ext/gitlab.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def __init__(self, *args, **kwarg):
2323
super().__init__(*args, **kwarg)
2424

2525
def connect(self):
26-
self.gl.ssl_verify = not self.insecure
26+
self.gl.ssl_verify = self.session_certificate or not self.session_insecure
27+
if self.session_proxy:
28+
self.gl.session.proxies.update(self.session_proxy)
29+
2730
self.gl.set_url(self.url_ro)
2831
self.gl.set_token(self._privatekey)
2932
self.gl.token_auth()

git_repo/services/service.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ class RepositoryService:
5959
# this symbol is made available for testing purposes
6060
_current = None
6161

62-
config_options = ['type', 'token', 'alias', 'fqdn']
62+
config_options = [
63+
'type', 'token', 'alias', 'fqdn', 'remote',
64+
'port', 'scheme', 'insecure',
65+
]
6366

6467
@classmethod
6568
def get_config_path(cls):
@@ -89,7 +92,8 @@ def store_config(cls, config, **kwarg):
8992
for option, value in kwarg.items():
9093
if option not in cls.config_options:
9194
raise ArgumentError('Option {} is invalid and cannot be setup.'.format(option))
92-
config.set_value(section, option, value)
95+
if value != None:
96+
config.set_value(section, option, value)
9397

9498
@classmethod
9599
def set_alias(cls, config):
@@ -111,6 +115,8 @@ def get_service(cls, repository, command):
111115
target = cls.command_map.get(command, command)
112116
conf_section = list(filter(lambda n: 'gitrepo' in n and target in n, config.sections()))
113117

118+
http_section = [config._sections[scheme] for scheme in ('http', 'https')]
119+
114120
# check configuration constraints
115121
if len(conf_section) == 0:
116122
if not target:
@@ -133,25 +139,15 @@ def get_service(cls, repository, command):
133139
raise ValueError('Service type {} does not exists.'.format(config['type']))
134140
service = cls.service_map.get(config['type'], cls)
135141

136-
cls._current = service(repository, config)
142+
cls._current = service(repository, config, http_section)
137143
return cls._current
138144

139145
@classmethod
140146
def get_auth_token(cls, login, password, prompt=None):
141147
raise NotImplementedError
142148

143-
def __init__(self, r=None, c=None):
144-
'''
145-
:param r: git-python repository instance
146-
:param c: configuration data
147-
148-
Build a repository service instance, store configuration and parameters
149-
And launch the connection to the service
150-
'''
151-
152-
self.repository = r
153-
self.config = c
154-
149+
def load_configuration(self, c, hc):
150+
CONFIG_TRUE=('on', 'true', 'yes', '1')
155151
# if there's a configuration file, update the names accordingly
156152
if c:
157153
name = ' '.join(c['__name__'].replace('"', '').split(' ')[1:])
@@ -170,8 +166,32 @@ def __init__(self, r=None, c=None):
170166
c.get('private_token',
171167
c.get('privatekey', None))))
172168
self._alias = c.get('alias', self.name)
173-
self.fqdn = c.get('fqdn', self.fqdn)
174-
self.insecure = c.get('insecure', 'false').lower() in ('on', 'true', 'yes', '1')
169+
170+
self.fqdn, port = c.get('fqdn', self.fqdn).split(':')
171+
self.port = port or None
172+
173+
self.default_create_private = c.get('default-create-private', 'false').lower() in CONFIG_TRUE
174+
self.ssh_url = c.get('ssh-url', None) or self.fqdn
175+
176+
self.session_insecure = c.get('insecure', 'false').lower() in CONFIG_TRUE
177+
self.session_certificate = c.get('certificate', None)
178+
self.session_proxy = {cf['__name__']: cf['proxy'] for cf in hc if cf.get('proxy', None)}
179+
180+
181+
182+
def __init__(self, r=None, c=None, hc=None):
183+
'''
184+
:param r: git-python repository instance
185+
:param c: configuration data
186+
187+
Build a repository service instance, store configuration and parameters
188+
And launch the connection to the service
189+
'''
190+
191+
self.repository = r
192+
self.config = c
193+
194+
self.load_configuration(c, hc)
175195

176196
# if service has a repository configured, connect
177197
if r:

0 commit comments

Comments
 (0)