Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cf_remote/aramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,18 @@ def _wait_for_tasks(hosts, tasks, ignore_failed, echo, echo_action, out_flag="")

if task.proc.args[0] == "scp":
log.debug(
f"Copying '{task.action}' to {task.host.user}@{task.host.host_name} over scp"
"Copying '{}' to {}@{} over scp".format(
task.action, task.host.user, task.host.host_name
)
)
else:
log.debug(
f"Running '{task.action}' on {task.host.user}@{task.host.host_name} over {task.proc.args[0]}"
"Running '{}' on {}@{} over {}".format(
task.action,
task.host.user,
task.host.host_name,
task.proc.args[0],
)
)

try:
Expand Down
29 changes: 23 additions & 6 deletions cf_remote/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
get_package_name,
user_error,
)
from cf_remote.utils import user_error, is_package_url, print_progress_dot
from cf_remote.utils import (
user_error,
is_package_url,
print_progress_dot,
ChecksumError,
)
from cf_remote.spawn import VM, VMRequest, Providers, AWSCredentials, GCPCredentials
from cf_remote.spawn import spawn_vms, destroy_vms, dump_vms_info, get_cloud_driver
from cf_remote import log
Expand Down Expand Up @@ -180,7 +185,11 @@ def install(
if remote_download:
package, hub_package, client_package = _verify_package_urls(packages)
else:
package, hub_package, client_package = _download_urls(packages)
try:
package, hub_package, client_package = _download_urls(packages)
except ChecksumError as ce:
log.error(ce)
return 1

# If any of these are folders, transform them to lists of the files inside those folders:
package = _maybe_packages_in_folder(package)
Expand Down Expand Up @@ -308,9 +317,13 @@ def _iterate_over_packages(
else:
for artifact in artifacts:
if download:
package_path = download_package(
artifact.url, checksum=artifact.checksum
)
try:
package_path = download_package(
artifact.url, checksum=artifact.checksum
)
except ChecksumError as ce:
log.error(ce)
return 1
if output_dir:
output_dir = os.path.abspath(os.path.expanduser(output_dir))
parent = os.path.dirname(output_dir)
Expand Down Expand Up @@ -854,7 +867,11 @@ def deploy(hubs, masterfiles):
print("Found cfbs policy set: '{}'".format(masterfiles))
elif masterfiles and masterfiles.startswith(("http://", "https://")):
urls = [masterfiles]
paths = _download_urls(urls)
try:
paths = _download_urls(urls)
except ChecksumError as ce:
log.error(ce)
return 1
assert len(paths) == 1
masterfiles = paths[0]
log.debug("Deploying downloaded: %s" % masterfiles)
Expand Down
25 changes: 15 additions & 10 deletions cf_remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
user_error,
parse_systeminfo,
parse_version,
ChecksumError,
)
from cf_remote.ssh import ssh_sudo, ssh_cmd, scp, auto_connect
from cf_remote import log
Expand Down Expand Up @@ -515,16 +516,20 @@ def install_host(
package = packages[0]

if not package:
package = get_package_from_host_info(
data.get("package_tags"),
data.get("bin"),
data.get("arch"),
version,
hub,
edition,
packages,
remote_download,
)
try:
package = get_package_from_host_info(
data.get("package_tags"),
data.get("bin"),
data.get("arch"),
version,
hub,
edition,
packages,
remote_download,
)
except ChecksumError as ce:
log.error(ce)
return 1

if not package:
log.error("Installation failed - no package found!")
Expand Down
4 changes: 4 additions & 0 deletions cf_remote/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,7 @@ def has_unescaped_character(string, char):

def programmer_error(msg):
sys.exit("Programmer error: " + msg)


class ChecksumError(Exception):
pass
8 changes: 4 additions & 4 deletions cf_remote/web.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import hashlib
import os
import fcntl
import re
Expand All @@ -14,6 +13,7 @@
)
from cf_remote import log
from cf_remote.paths import cf_remote_dir, cf_remote_packages_dir
from cf_remote.utils import ChecksumError

SHA256_RE = re.compile(r"^[0-9a-f]{64}$")

Expand All @@ -35,7 +35,7 @@ def get_json(url):
def download_package(url, path=None, checksum=None):

if checksum and not SHA256_RE.match(checksum):
user_error(
raise ChecksumError(
"Invalid checksum or unsupported checksum algorithm: '%s'" % checksum
)

Expand All @@ -58,7 +58,7 @@ def download_package(url, path=None, checksum=None):
f.seek(0)
content = f.read()
if checksum and is_different_checksum(checksum, content):
user_error(
raise ChecksumError(
"Downloaded file '{}' does not match expected checksum '{}'. Please delete the file.".format(
filename, checksum
)
Expand All @@ -69,7 +69,7 @@ def download_package(url, path=None, checksum=None):

answer = urllib.request.urlopen(url).read()
if checksum and is_different_checksum(checksum, answer):
user_error(
raise ChecksumError(
"Downloaded file '{}' does not match expected checksum '{}'. Please delete the file.".format(
filename, checksum
)
Expand Down