Properly read repository info

This commit is contained in:
Disassembler 2019-02-15 12:05:12 +01:00
parent 3abe7470e7
commit deb56f0c7b
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
5 changed files with 14 additions and 13 deletions

View File

@ -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"

View File

@ -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)

View File

@ -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

View File

@ -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')

View File

@ -26,11 +26,11 @@
<table>
<tr>
<td>URL serveru:</td>
<td><input type="text" name="repourl" value="{{ conf['repo']['url'] }}"></td>
<td><input type="text" name="repourl" value="{{ repo_conf['url'] }}"></td>
</tr>
<tr>
<td>Uživatelské jméno:</td>
<td><input type="text" name="repousername" value="{{ conf['repo']['user'] }}"></td>
<td><input type="text" name="repousername" value="{{ repo_conf['user'] }}"></td>
</tr>
<tr>
<td>Heslo:</td>