Skip to content

Commit

Permalink
🚧 more configuration options supported for config command
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
guyzmo committed Feb 2, 2017
1 parent 0e68b1e commit 3430cf0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
5 changes: 4 additions & 1 deletion git_repo/services/ext/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def __init__(self, *args, **kwarg):
super().__init__(*args, **kwarg)

def connect(self):
self.gl.ssl_verify = not self.insecure
self.gl.ssl_verify = self.session_certificate or not self.session_insecure
if self.session_proxy:
self.gl.session.proxies.update(self.session_proxy)

self.gl.set_url(self.url_ro)
self.gl.set_token(self._privatekey)
self.gl.token_auth()
Expand Down
54 changes: 37 additions & 17 deletions git_repo/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class RepositoryService:
# this symbol is made available for testing purposes
_current = None

config_options = ['type', 'token', 'alias', 'fqdn']
config_options = [
'type', 'token', 'alias', 'fqdn', 'remote',
'port', 'scheme', 'insecure',
]

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

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

http_section = [config._sections[scheme] for scheme in ('http', 'https')]

# check configuration constraints
if len(conf_section) == 0:
if not target:
Expand All @@ -133,25 +139,15 @@ def get_service(cls, repository, command):
raise ValueError('Service type {} does not exists.'.format(config['type']))
service = cls.service_map.get(config['type'], cls)

cls._current = service(repository, config)
cls._current = service(repository, config, http_section)
return cls._current

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

def __init__(self, r=None, c=None):
'''
:param r: git-python repository instance
:param c: configuration data
Build a repository service instance, store configuration and parameters
And launch the connection to the service
'''

self.repository = r
self.config = c

def load_configuration(self, c, hc):
CONFIG_TRUE=('on', 'true', 'yes', '1')
# if there's a configuration file, update the names accordingly
if c:
name = ' '.join(c['__name__'].replace('"', '').split(' ')[1:])
Expand All @@ -170,8 +166,32 @@ def __init__(self, r=None, c=None):
c.get('private_token',
c.get('privatekey', None))))
self._alias = c.get('alias', self.name)
self.fqdn = c.get('fqdn', self.fqdn)
self.insecure = c.get('insecure', 'false').lower() in ('on', 'true', 'yes', '1')

self.fqdn, port = c.get('fqdn', self.fqdn).split(':')
self.port = port or None

self.default_create_private = c.get('default-create-private', 'false').lower() in CONFIG_TRUE
self.ssh_url = c.get('ssh-url', None) or self.fqdn

self.session_insecure = c.get('insecure', 'false').lower() in CONFIG_TRUE
self.session_certificate = c.get('certificate', None)
self.session_proxy = {cf['__name__']: cf['proxy'] for cf in hc if cf.get('proxy', None)}



def __init__(self, r=None, c=None, hc=None):
'''
:param r: git-python repository instance
:param c: configuration data
Build a repository service instance, store configuration and parameters
And launch the connection to the service
'''

self.repository = r
self.config = c

self.load_configuration(c, hc)

# if service has a repository configured, connect
if r:
Expand Down

0 comments on commit 3430cf0

Please sign in to comment.