Change repo configuration structure

This commit is contained in:
Disassembler 2018-10-26 15:38:35 +02:00
parent 8be2bb2083
commit 920f01cf45
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
2 changed files with 15 additions and 8 deletions

View File

@ -4,12 +4,17 @@
"email": "admin@example.com",
"gmaps-api-key": ""
},
"packages": {},
"host": {
"repo": "https://dl.dasm.cz/spotter-repo",
"adminpwd": "$2b$12$nLrIefUoWN.pK6j90gsfkO0/tg4EGXDmdjN8HOGB0U.9BcHTFxzWS",
"domain": "spotter.vm",
"firstrun": true,
"port": "443"
},
"packages": {},
"pending-packages": {},
"repo": {
"pwd": "",
"url": "https://dl.dasm.cz/spotter-repo",
"user": ""
}
}

View File

@ -23,26 +23,28 @@ class PackageManager:
def __init__(self):
# Load JSON configuration
self.conf = Config()
self.repo_url = self.conf['host']['repo']
self.online_packages = {}
def get_repo_resource(self, url, stream=False):
return requests.get('{}/{}'.format(self.conf['repo']['url'], url), auth=(self.conf['repo']['user'], self.conf['repo']['pwd']), stream=stream)
def fetch_online_packages(self):
# Fetches and verifies online packages. Can raise InvalidSignature
packages = requests.get('{}/packages'.format(self.repo_url)).content
packages_sig = requests.get('{}/packages.sig'.format(self.repo_url)).content
packages = self.get_repo_resource('packages').content
packages_sig = self.get_repo_resource('packages.sig').content
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()))
self.online_packages = json.loads(packages)
def install_package(self, name):
# Main installation function. Wrapper for download, install script and registration
# Main installation function. Wrapper for download, registration and install script
self.fetch_online_packages()
for dep in self.get_deps(name):
if dep not in self.conf['packages']:
self.download_package(dep)
self.run_install_script(dep)
self.register_package(dep)
self.run_install_script(dep)
def uninstall_package(self, name):
# Main uninstallation function. Wrapper for uninstall script, filesystem purge and unregistration
@ -54,7 +56,7 @@ class PackageManager:
def download_package(self, name):
# Downloads, verifies, unpacks and sets up a package
tmp_archive = tempfile.mkstemp('.tar.xz')[1]
r = requests.get('{}/{}.tar.xz'.format(self.repo_url, name), auth=('test', 'txUqqZLaM.Z;3E2E'), stream=True) # TODO: Remove the testing password
r = self.get_repo_resource('{}.tar.xz'.format(name), True)
with open(tmp_archive, 'wb') as f:
for chunk in r.iter_content(chunk_size=65536):
if chunk: