Distinguish registered apps and packages
This commit is contained in:
parent
1c967a0431
commit
14984b3199
@ -4,6 +4,7 @@
|
|||||||
"email": "admin@example.com",
|
"email": "admin@example.com",
|
||||||
"gmaps-api-key": ""
|
"gmaps-api-key": ""
|
||||||
},
|
},
|
||||||
|
"packages": {},
|
||||||
"host": {
|
"host": {
|
||||||
"repo": "https://dl.dasm.cz/spotter-repo",
|
"repo": "https://dl.dasm.cz/spotter-repo",
|
||||||
"adminpwd": "$2b$12$nLrIefUoWN.pK6j90gsfkO0/tg4EGXDmdjN8HOGB0U.9BcHTFxzWS",
|
"adminpwd": "$2b$12$nLrIefUoWN.pK6j90gsfkO0/tg4EGXDmdjN8HOGB0U.9BcHTFxzWS",
|
||||||
|
@ -12,7 +12,7 @@ from cryptography.hazmat.primitives.asymmetric import ec
|
|||||||
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
||||||
|
|
||||||
CONF_FILE = '/srv/vm/config.json'
|
CONF_FILE = '/srv/vm/config.json'
|
||||||
CERT_FILE = '/srv/vm/packages.pub'
|
PUB_FILE = '/srv/vm/packages.pub'
|
||||||
LXC_ROOT = '/var/lib/lxc'
|
LXC_ROOT = '/var/lib/lxc'
|
||||||
|
|
||||||
class PackageManager:
|
class PackageManager:
|
||||||
@ -32,7 +32,7 @@ class PackageManager:
|
|||||||
repo_url = self.conf['host']['repo']
|
repo_url = self.conf['host']['repo']
|
||||||
packages = requests.get('{}/packages'.format(repo_url)).content
|
packages = requests.get('{}/packages'.format(repo_url)).content
|
||||||
packages_sig = requests.get('{}/packages.sig'.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 = load_pem_public_key(f.read(), default_backend())
|
||||||
pub_key.verify(packages_sig, packages, ec.ECDSA(hashes.SHA512()))
|
pub_key.verify(packages_sig, packages, ec.ECDSA(hashes.SHA512()))
|
||||||
return json.loads(packages)
|
return json.loads(packages)
|
||||||
@ -40,16 +40,15 @@ class PackageManager:
|
|||||||
def install_package(self, name):
|
def install_package(self, name):
|
||||||
self.online_packages = get_online_packages()
|
self.online_packages = get_online_packages()
|
||||||
for dep in self.get_deps(name):
|
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)
|
self.download_package(name)
|
||||||
if 'host' in self.online_packages[name]:
|
self.register_package(name)
|
||||||
self.register_app(name, self.online_packages[name])
|
|
||||||
self.setup_package()
|
self.setup_package()
|
||||||
|
|
||||||
def download_package(self, name):
|
def download_package(self, name):
|
||||||
# Downloads, verifies, unpacks and sets up a package
|
# Downloads, verifies, unpacks and sets up a package
|
||||||
local_archive = tempfile.mkstemp('.tar.xz')
|
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:
|
with open(local_archive, 'wb') as f:
|
||||||
for chunk in r.iter_content(chunk_size=65536):
|
for chunk in r.iter_content(chunk_size=65536):
|
||||||
if chunk:
|
if chunk:
|
||||||
@ -61,15 +60,18 @@ class PackageManager:
|
|||||||
subprocess.run(['tar', 'xJf', local_archive], cwd=LXC_ROOT)
|
subprocess.run(['tar', 'xJf', local_archive], cwd=LXC_ROOT)
|
||||||
os.unlink(local_archive)
|
os.unlink(local_archive)
|
||||||
|
|
||||||
def register_app(self, name, metadata):
|
def register_package(self, name, metadata):
|
||||||
self.conf['apps'][name] = {
|
self.conf['packages'][name] = {
|
||||||
'title': metadata['title'],
|
|
||||||
'version': metadata['version'],
|
'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()
|
self.save_conf()
|
||||||
|
|
||||||
def setup_package(self):
|
def setup_package(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user