mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-20 02:06:42 -06:00
parent
2c756873aa
commit
4df517e4da
@ -31,6 +31,7 @@ def register_backend(name):
|
|||||||
"""
|
"""
|
||||||
Decorator for registering a DataBackend class.
|
Decorator for registering a DataBackend class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _wrapper(cls):
|
def _wrapper(cls):
|
||||||
registry['data_backends'][name] = cls
|
registry['data_backends'][name] = cls
|
||||||
return cls
|
return cls
|
||||||
@ -56,7 +57,6 @@ class DataBackend:
|
|||||||
|
|
||||||
@register_backend(DataSourceTypeChoices.LOCAL)
|
@register_backend(DataSourceTypeChoices.LOCAL)
|
||||||
class LocalBackend(DataBackend):
|
class LocalBackend(DataBackend):
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def fetch(self):
|
def fetch(self):
|
||||||
logger.debug(f"Data source type is local; skipping fetch")
|
logger.debug(f"Data source type is local; skipping fetch")
|
||||||
@ -71,12 +71,14 @@ class GitBackend(DataBackend):
|
|||||||
'username': forms.CharField(
|
'username': forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Username'),
|
label=_('Username'),
|
||||||
widget=forms.TextInput(attrs={'class': 'form-control'})
|
widget=forms.TextInput(attrs={'class': 'form-control'}),
|
||||||
|
help_text=_("Only used for cloning with HTTP / HTTPS"),
|
||||||
),
|
),
|
||||||
'password': forms.CharField(
|
'password': forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Password'),
|
label=_('Password'),
|
||||||
widget=forms.TextInput(attrs={'class': 'form-control'})
|
widget=forms.TextInput(attrs={'class': 'form-control'}),
|
||||||
|
help_text=_("Only used for cloning with HTTP / HTTPS"),
|
||||||
),
|
),
|
||||||
'branch': forms.CharField(
|
'branch': forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
@ -89,10 +91,22 @@ class GitBackend(DataBackend):
|
|||||||
def fetch(self):
|
def fetch(self):
|
||||||
local_path = tempfile.TemporaryDirectory()
|
local_path = tempfile.TemporaryDirectory()
|
||||||
|
|
||||||
username = self.params.get('username')
|
|
||||||
password = self.params.get('password')
|
|
||||||
branch = self.params.get('branch')
|
|
||||||
config = StackedConfig.default()
|
config = StackedConfig.default()
|
||||||
|
clone_args = {
|
||||||
|
"branch": self.params.get('branch'),
|
||||||
|
"config": config,
|
||||||
|
"depth": 1,
|
||||||
|
"errstream": porcelain.NoneStream(),
|
||||||
|
"quiet": True,
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.url_scheme in ('http', 'https'):
|
||||||
|
clone_args.update(
|
||||||
|
{
|
||||||
|
"username": self.params.get('username'),
|
||||||
|
"password": self.params.get('password'),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if settings.HTTP_PROXIES and self.url_scheme in ('http', 'https'):
|
if settings.HTTP_PROXIES and self.url_scheme in ('http', 'https'):
|
||||||
if proxy := settings.HTTP_PROXIES.get(self.url_scheme):
|
if proxy := settings.HTTP_PROXIES.get(self.url_scheme):
|
||||||
@ -100,10 +114,7 @@ class GitBackend(DataBackend):
|
|||||||
|
|
||||||
logger.debug(f"Cloning git repo: {self.url}")
|
logger.debug(f"Cloning git repo: {self.url}")
|
||||||
try:
|
try:
|
||||||
porcelain.clone(
|
porcelain.clone(self.url, local_path.name, **clone_args)
|
||||||
self.url, local_path.name, depth=1, branch=branch, username=username, password=password,
|
|
||||||
config=config, quiet=True, errstream=porcelain.NoneStream()
|
|
||||||
)
|
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
raise SyncError(f"Fetching remote data failed ({type(e).__name__}): {e}")
|
raise SyncError(f"Fetching remote data failed ({type(e).__name__}): {e}")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user