From deb56f0c7b7bd523038ac63ce2ab6750025e7b65 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Fri, 15 Feb 2019 12:05:12 +0100 Subject: [PATCH] Properly read repository info --- APKBUILD | 2 +- usr/lib/python3.6/vmmgr/appmgr.py | 6 +++--- usr/lib/python3.6/vmmgr/vmmgr.py | 8 ++++---- usr/lib/python3.6/vmmgr/wsgiapp.py | 7 ++++--- usr/share/vmmgr/templates/setup-apps.html | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/APKBUILD b/APKBUILD index 139ebc7..e9f6226 100644 --- a/APKBUILD +++ b/APKBUILD @@ -4,7 +4,7 @@ pkgname=vmmgr pkgver=0.0.1 pkgrel=0 pkgdesc="VM and LXC-packages application Manager" -url="https://linuxcontainers.org/lxc/" +url="https://spotter.vm/" arch="noarch" license="GPL" depends="python3 py3-bcrypt py3-cffi py3-cryptography py3-dnspython py3-jinja2 py3-requests py3-six py3-werkzeug" diff --git a/usr/lib/python3.6/vmmgr/appmgr.py b/usr/lib/python3.6/vmmgr/appmgr.py index 124ff5d..e0a1d21 100644 --- a/usr/lib/python3.6/vmmgr/appmgr.py +++ b/usr/lib/python3.6/vmmgr/appmgr.py @@ -92,10 +92,10 @@ class AppMgr: del self.conf['apps'][name] subprocess.run(['apk', '--no-cache', 'del', 'vm-{}@vm'.format(app)]) - def fetch_online_packages(self): + def fetch_online_packages(self, repo_conf): # Fetches list of online packages - repo = vmmgr.get_repo_settings() - packages = requests.get('{}/packages'.format(repo['url']), auth=(repo['user'], repo['pwd']), timeout=5) + auth = (repo_conf['user'], repo_conf['pwd']) if repo_conf['user'] else None + packages = requests.get('{}/packages.json'.format(repo_conf['url']), auth=auth, timeout=5) if packages.status_code != 200: return packages.status_code self.online_packages = json.loads(packages.content) diff --git a/usr/lib/python3.6/vmmgr/vmmgr.py b/usr/lib/python3.6/vmmgr/vmmgr.py index e9143e7..eea2e94 100644 --- a/usr/lib/python3.6/vmmgr/vmmgr.py +++ b/usr/lib/python3.6/vmmgr/vmmgr.py @@ -57,16 +57,16 @@ class VMMgr: # Save config to file self.conf.save() - def get_repo_settings(self): + def get_repo_conf(self): # Read, parse and return current @vm repository configuration with open(REPO_FILE) as f: url = [l for l in f.read().splitlines() if l.startswith('@vm')][0].split(' ', 2)[1] url = urllib.parse.urlparse(url) return {'url': '{}://{}{}'.format(url.scheme, url.netloc, url.path), - 'user': url.username, - 'pwd': url.password} + 'user': url.username if url.username else '' , + 'pwd': url.password if url.password else ''} - def set_repo_settings(self, url, user, pwd): + def set_repo_conf(self, url, user, pwd): # Update @vm repository configuration url = urllib.parse.urlparse(url) # Create URL with username and password diff --git a/usr/lib/python3.6/vmmgr/wsgiapp.py b/usr/lib/python3.6/vmmgr/wsgiapp.py index 7c90490..26256cd 100644 --- a/usr/lib/python3.6/vmmgr/wsgiapp.py +++ b/usr/lib/python3.6/vmmgr/wsgiapp.py @@ -155,8 +155,9 @@ class WSGIApp: def setup_apps_view(self, request): # Application manager view. repo_error = None + repo_conf = self.vmmgr.get_repo_conf() try: - status = self.appmgr.fetch_online_packages() + status = self.appmgr.fetch_online_packages(repo_conf) except InvalidSignature: repo_error = request.session.lang.invalid_packages_signature() if status in (401, 403): @@ -165,7 +166,7 @@ class WSGIApp: repo_error = request.session.lang.repo_unavailable() table = self.render_setup_apps_table(request) message = self.get_session_message(request) - return self.render_html('setup-apps.html', request, repo_error=repo_error, table=table, message=message) + return self.render_html('setup-apps.html', request, repo_error=repo_error, repo_conf=repo_conf, table=table, message=message) def render_setup_apps_table(self, request): lang = request.session.lang @@ -314,7 +315,7 @@ class WSGIApp: if not validator.is_valid_repo_url(url): request.session['msg'] = 'repo:error:{}'.format(request.session.lang.invalid_url(request.form['repourl'])) else: - self.vmmgr.update_repo_settings(url, request.form['repousername'], request.form['repopassword']) + self.vmmgr.update_repo_conf(url, request.form['repousername'], request.form['repopassword']) request.session['msg'] = 'repo:info:{}'.format(request.session.lang.repo_updated()) return redirect('/setup-apps') diff --git a/usr/share/vmmgr/templates/setup-apps.html b/usr/share/vmmgr/templates/setup-apps.html index 486bd34..8d9e252 100644 --- a/usr/share/vmmgr/templates/setup-apps.html +++ b/usr/share/vmmgr/templates/setup-apps.html @@ -26,11 +26,11 @@ - + - +
URL serveru:
Uživatelské jméno:
Heslo: