From a32066172795291647eda224211e891792a420ea Mon Sep 17 00:00:00 2001 From: Disassembler Date: Fri, 14 Feb 2020 23:17:03 +0100 Subject: [PATCH] Download image including parent layers --- etc/spoc/spoc.conf | 2 -- usr/bin/spoc-image | 6 +++++- usr/lib/python3.8/spoc/config.py | 11 ++--------- usr/lib/python3.8/spoc/repo_online.py | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/etc/spoc/spoc.conf b/etc/spoc/spoc.conf index 33d0249..b9c1b33 100644 --- a/etc/spoc/spoc.conf +++ b/etc/spoc/spoc.conf @@ -9,6 +9,4 @@ signing-key = /etc/spoc/publish.key [repo] url = https://repo.spotter.cz/spoc/ -username = -password = public-key = MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEWJXH4Qm0kt2L86sntQH+C1zOJNQ0qMRt0vx4krTxRs9HQTQYAy//JC92ea2aKleA8OL0JF90b1NYXcQCWdAS+vE/ng9IEAii8C2+5nfuFeZ5YUjbQhfFblwHSM0c7hEG diff --git a/usr/bin/spoc-image b/usr/bin/spoc-image index 7a32c54..428796d 100644 --- a/usr/bin/spoc-image +++ b/usr/bin/spoc-image @@ -36,7 +36,11 @@ def listing(repo_type): print(image) def download(image_name): - Image(image_name, False).download() + local_images = repo_local.get_images() + for layer in repo_online.get_image(image_name)['layers']: + if layer not in local_images: + print(f'Downloading {layer}...') + Image(layer, False).download() def delete(image_name): Image(image_name, False).delete() diff --git a/usr/lib/python3.8/spoc/config.py b/usr/lib/python3.8/spoc/config.py index 9efa37b..e749a28 100644 --- a/usr/lib/python3.8/spoc/config.py +++ b/usr/lib/python3.8/spoc/config.py @@ -7,13 +7,6 @@ import urllib.parse config = configparser.ConfigParser() config.read('/etc/spoc/spoc.conf') -def get_repo_auth(config): - username = config.get('repo', 'username', fallback='') - password = config.get('repo', 'password', fallback='') - if not username and not password: - return None - return (username, password) - NETWORK_INTERFACE = config.get('general', 'network-interface', fallback='spocbr0') DATA_DIR = config.get('general', 'data-dir', fallback='/var/lib/spoc/') @@ -34,11 +27,11 @@ PUB_SIG_FILE = os.path.join(PUB_DIR, 'repository.sig') PUB_PRIVKEY_FILE = config.get('publish', 'signing-key', fallback='/etc/spoc/publish.key') PUB_LOCK_FILE = '/run/lock/spoc-publish.lock' -ONLINE_BASE_URL = config.get('repo', 'url', fallback='https://localhost/') +# URLs which are an actual directories need to end with trailing slash +ONLINE_BASE_URL = '{}/'.format(config.get('repo', 'url', fallback='https://localhost').rstrip('/')) ONLINE_LAYERS_URL = urllib.parse.urljoin(ONLINE_BASE_URL, 'layers/') ONLINE_APPS_URL = urllib.parse.urljoin(ONLINE_BASE_URL, 'apps/') ONLINE_REPO_URL = urllib.parse.urljoin(ONLINE_BASE_URL, 'repository.json') ONLINE_SIG_URL = urllib.parse.urljoin(ONLINE_BASE_URL, 'repository.sig') ONLINE_REPO_FILE = os.path.join(DATA_DIR, 'online.json') -ONLINE_AUTH = get_repo_auth(config) # TODO: Username + password as part of url? ONLINE_PUBKEY = config.get('repo', 'public-key', fallback='') diff --git a/usr/lib/python3.8/spoc/repo_online.py b/usr/lib/python3.8/spoc/repo_online.py index d368ed1..49e42cf 100644 --- a/usr/lib/python3.8/spoc/repo_online.py +++ b/usr/lib/python3.8/spoc/repo_online.py @@ -14,7 +14,7 @@ from cryptography.hazmat.primitives.asymmetric import ec, utils from cryptography.hazmat.primitives.serialization import load_pem_public_key from .exceptions import AppNotFoundError, ImageNotFoundError -from .config import ONLINE_REPO_FILE, ONLINE_AUTH, ONLINE_PUBKEY, ONLINE_REPO_URL, ONLINE_SIG_URL +from .config import ONLINE_REPO_FILE, ONLINE_PUBKEY, ONLINE_REPO_URL, ONLINE_SIG_URL TYPE_APP = 'apps' TYPE_IMAGE = 'images'