Trun on/off git via settings/environment

This commit is contained in:
Daniel Perna 2018-07-12 21:34:04 +02:00
parent f287de77b8
commit 39b567845a
3 changed files with 20 additions and 8 deletions

View file

@ -68,7 +68,7 @@ Ban IPs after n failed login attempts. Restart service to reset banning. The def
Files and folders to ignore in the UI, e.g. `IGNORE_PATTERN = [".*", "*.log", "__pycache__"]` Files and folders to ignore in the UI, e.g. `IGNORE_PATTERN = [".*", "*.log", "__pycache__"]`
#### GIT (bool) #### GIT (bool)
Set this variable to `True` to enable Git integration. This feature requires [GitPython](https://gitpython.readthedocs.io) Set this variable to `True` to enable Git integration. This feature requires [GitPython](https://gitpython.readthedocs.io)
to be installed on the system that is running the configurator. For thechnical reasons this feature can't be enabled with a static configuration file. to be installed on the system that is running the configurator.
To push local commits to a remote repository, you have to add the remote manually: `git remote add origin ssh://somehost:/user/repo.git` To push local commits to a remote repository, you have to add the remote manually: `git remote add origin ssh://somehost:/user/repo.git`
Verify, that the user that is running the configurator is allowed to push without any interaction (by using SSH PubKey authentication for example). Verify, that the user that is running the configurator is allowed to push without any interaction (by using SSH PubKey authentication for example).
#### DIRSFIRST (bool) #### DIRSFIRST (bool)

View file

@ -97,12 +97,7 @@ DEV = False
TOTP = None TOTP = None
HTTPD = None HTTPD = None
FAIL2BAN_IPS = {} FAIL2BAN_IPS = {}
REPO = False REPO = None
if GIT:
try:
from git import Repo as REPO
except ImportError:
LOG.warning("Unable to import Git module")
INDEX = Template(r"""<!DOCTYPE html> INDEX = Template(r"""<!DOCTYPE html>
<html lang="en"> <html lang="en">
@ -3428,7 +3423,8 @@ def load_settings(settingsfile):
global LISTENIP, LISTENPORT, BASEPATH, SSL_CERTIFICATE, SSL_KEY, HASS_API, \ global LISTENIP, LISTENPORT, BASEPATH, SSL_CERTIFICATE, SSL_KEY, HASS_API, \
HASS_API_PASSWORD, CREDENTIALS, ALLOWED_NETWORKS, BANNED_IPS, BANLIMIT, \ HASS_API_PASSWORD, CREDENTIALS, ALLOWED_NETWORKS, BANNED_IPS, BANLIMIT, \
DEV, IGNORE_PATTERN, DIRSFIRST, SESAME, VERIFY_HOSTNAME, ENFORCE_BASEPATH, \ DEV, IGNORE_PATTERN, DIRSFIRST, SESAME, VERIFY_HOSTNAME, ENFORCE_BASEPATH, \
ENV_PREFIX, NOTIFY_SERVICE, USERNAME, PASSWORD, SESAME_TOTP_SECRET, TOTP ENV_PREFIX, NOTIFY_SERVICE, USERNAME, PASSWORD, SESAME_TOTP_SECRET, TOTP, \
GIT, REPO
settings = {} settings = {}
if settingsfile: if settingsfile:
try: try:
@ -3454,6 +3450,13 @@ def load_settings(settingsfile):
elif key[len(ENV_PREFIX):] in ["ALLOWED_NETWORKS", "BANNED_IPS", "IGNORE_PATTERN"]: elif key[len(ENV_PREFIX):] in ["ALLOWED_NETWORKS", "BANNED_IPS", "IGNORE_PATTERN"]:
value = value.split(',') value = value.split(',')
settings[key[len(ENV_PREFIX):]] = value settings[key[len(ENV_PREFIX):]] = value
GIT = settings.get("GIT", GIT)
if GIT:
try:
# pylint: disable=redefined-outer-name
from git import Repo as REPO
except ImportError:
LOG.warning("Unable to import Git module")
LISTENIP = settings.get("LISTENIP", LISTENIP) LISTENIP = settings.get("LISTENIP", LISTENIP)
LISTENPORT = settings.get("LISTENPORT", LISTENPORT) LISTENPORT = settings.get("LISTENPORT", LISTENPORT)
BASEPATH = settings.get("BASEPATH", BASEPATH) BASEPATH = settings.get("BASEPATH", BASEPATH)
@ -3715,6 +3718,7 @@ class RequestHandler(BaseHTTPRequestHandler):
branches = [] branches = []
if REPO: if REPO:
try: try:
# pylint: disable=not-callable
repo = REPO(dirpath.decode('utf-8'), repo = REPO(dirpath.decode('utf-8'),
search_parent_directories=True) search_parent_directories=True)
activebranch = repo.active_branch.name activebranch = repo.active_branch.name
@ -4149,6 +4153,7 @@ class RequestHandler(BaseHTTPRequestHandler):
if postvars['path']: if postvars['path']:
try: try:
addpath = unquote(postvars['path'][0]) addpath = unquote(postvars['path'][0])
# pylint: disable=not-callable
repo = REPO(addpath, repo = REPO(addpath,
search_parent_directories=True) search_parent_directories=True)
filepath = "/".join(addpath.split(os.sep)[len(repo.working_dir.split(os.sep)):]) filepath = "/".join(addpath.split(os.sep)[len(repo.working_dir.split(os.sep)):])
@ -4184,6 +4189,7 @@ class RequestHandler(BaseHTTPRequestHandler):
if postvars['path']: if postvars['path']:
try: try:
diffpath = unquote(postvars['path'][0]) diffpath = unquote(postvars['path'][0])
# pylint: disable=not-callable
repo = REPO(diffpath, repo = REPO(diffpath,
search_parent_directories=True) search_parent_directories=True)
filepath = "/".join(diffpath.split(os.sep)[len(repo.working_dir.split(os.sep)):]) filepath = "/".join(diffpath.split(os.sep)[len(repo.working_dir.split(os.sep)):])
@ -4221,6 +4227,7 @@ class RequestHandler(BaseHTTPRequestHandler):
commitpath = unquote(postvars['path'][0]) commitpath = unquote(postvars['path'][0])
response['path'] = commitpath response['path'] = commitpath
message = unquote(postvars['message'][0]) message = unquote(postvars['message'][0])
# pylint: disable=not-callable
repo = REPO(commitpath, repo = REPO(commitpath,
search_parent_directories=True) search_parent_directories=True)
try: try:
@ -4256,6 +4263,7 @@ class RequestHandler(BaseHTTPRequestHandler):
branchpath = unquote(postvars['path'][0]) branchpath = unquote(postvars['path'][0])
response['path'] = branchpath response['path'] = branchpath
branch = unquote(postvars['branch'][0]) branch = unquote(postvars['branch'][0])
# pylint: disable=not-callable
repo = REPO(branchpath, repo = REPO(branchpath,
search_parent_directories=True) search_parent_directories=True)
try: try:
@ -4292,6 +4300,7 @@ class RequestHandler(BaseHTTPRequestHandler):
branchpath = unquote(postvars['path'][0]) branchpath = unquote(postvars['path'][0])
response['path'] = branchpath response['path'] = branchpath
branch = unquote(postvars['branch'][0]) branch = unquote(postvars['branch'][0])
# pylint: disable=not-callable
repo = REPO(branchpath, repo = REPO(branchpath,
search_parent_directories=True) search_parent_directories=True)
try: try:
@ -4359,6 +4368,7 @@ class RequestHandler(BaseHTTPRequestHandler):
repopath = unquote(postvars['path'][0]) repopath = unquote(postvars['path'][0])
response['path'] = repopath response['path'] = repopath
try: try:
# pylint: disable=not-callable
repo = REPO(repopath) repo = REPO(repopath)
urls = [] urls = []
if repo.remotes: if repo.remotes:
@ -4400,6 +4410,7 @@ class RequestHandler(BaseHTTPRequestHandler):
repopath = unquote(postvars['path'][0]) repopath = unquote(postvars['path'][0])
response['path'] = repopath response['path'] = repopath
try: try:
# pylint: disable=not-callable
repo = REPO(repopath) repo = REPO(repopath)
returnvalue = repo.git.stash() returnvalue = repo.git.stash()
response['error'] = False response['error'] = False

View file

@ -1,6 +1,7 @@
{ {
"LISTENIP": "0.0.0.0", "LISTENIP": "0.0.0.0",
"LISTENPORT": 3218, "LISTENPORT": 3218,
"GIT": false,
"BASEPATH": null, "BASEPATH": null,
"ENFORCE_BASEPATH": false, "ENFORCE_BASEPATH": false,
"SSL_CERTIFICATE": null, "SSL_CERTIFICATE": null,