diff --git a/basic/srv/vm/config.json b/basic/srv/vm/config.json index 5f83b0d..aeda6b4 100644 --- a/basic/srv/vm/config.json +++ b/basic/srv/vm/config.json @@ -4,6 +4,7 @@ "email": "admin@example.com", "gmaps-api-key": "" }, + "packages": {}, "host": { "repo": "https://dl.dasm.cz/spotter-repo", "adminpwd": "$2b$12$nLrIefUoWN.pK6j90gsfkO0/tg4EGXDmdjN8HOGB0U.9BcHTFxzWS", diff --git a/basic/srv/vm/mgr/pkgmgr.py b/basic/srv/vm/mgr/pkgmgr.py index cea4f32..897af44 100644 --- a/basic/srv/vm/mgr/pkgmgr.py +++ b/basic/srv/vm/mgr/pkgmgr.py @@ -12,7 +12,7 @@ from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.serialization import load_pem_public_key CONF_FILE = '/srv/vm/config.json' -CERT_FILE = '/srv/vm/packages.pub' +PUB_FILE = '/srv/vm/packages.pub' LXC_ROOT = '/var/lib/lxc' class PackageManager: @@ -32,7 +32,7 @@ class PackageManager: repo_url = self.conf['host']['repo'] packages = requests.get('{}/packages'.format(repo_url)).content packages_sig = requests.get('{}/packages.sig'.format(repo_url)).content - with open(CERT_FILE, 'rb') as f: + with open(PUB_FILE, 'rb') as f: pub_key = load_pem_public_key(f.read(), default_backend()) pub_key.verify(packages_sig, packages, ec.ECDSA(hashes.SHA512())) return json.loads(packages) @@ -40,16 +40,15 @@ class PackageManager: def install_package(self, name): self.online_packages = get_online_packages() for dep in self.get_deps(name): - if dep not in self.conf['apps']: + if dep not in self.conf['packages']: self.download_package(name) - if 'host' in self.online_packages[name]: - self.register_app(name, self.online_packages[name]) + self.register_package(name) self.setup_package() def download_package(self, name): # Downloads, verifies, unpacks and sets up a package local_archive = tempfile.mkstemp('.tar.xz') - r = requests.get('{}/{}.tar.xz'.format(self.repo_url, name), stream=True) + r = requests.get('{}/{}.tar.xz'.format(self.repo_url, name), auth=('test', 'txUqqZLaM.Z;3E2E'), stream=True) # TODO: Remove the testing password with open(local_archive, 'wb') as f: for chunk in r.iter_content(chunk_size=65536): if chunk: @@ -61,15 +60,18 @@ class PackageManager: subprocess.run(['tar', 'xJf', local_archive], cwd=LXC_ROOT) os.unlink(local_archive) - def register_app(self, name, metadata): - self.conf['apps'][name] = { - 'title': metadata['title'], + def register_package(self, name, metadata): + self.conf['packages'][name] = { 'version': metadata['version'], - 'host': metadata['host'], - 'login': 'N/A', - 'password': 'N/A', - 'visible': False } + if 'host' in self.online_packages[name]: + self.conf['apps'][name] = { + 'title': metadata['title'], + 'host': metadata['host'], + 'login': 'N/A', + 'password': 'N/A', + 'visible': False + } self.save_conf() def setup_package(self):