Deduplicate artifact bytes and deliver files by authenticated hash
This commit is contained in:
@@ -33,7 +33,7 @@ import urllib.parse
|
||||
import urllib.request
|
||||
import uuid
|
||||
|
||||
VERSION = "1.5.3"
|
||||
VERSION = "1.6.0"
|
||||
LABEL = "io.electric-cherry"
|
||||
MAX_FILE = 32 * 1024 * 1024
|
||||
MANIFEST_MAX_ENTRIES = 10000
|
||||
@@ -1356,7 +1356,7 @@ class Agent:
|
||||
if line.startswith("PRETTY_NAME="):
|
||||
os_name = line.split("=", 1)[1].strip('"')
|
||||
update = self.update_inventory()
|
||||
capabilities = ["library.remove", "instance.cancel-create", "instance.safety-override", "operations.read-lane", "operations.health-lane", "rcon.status-batch", "instance.heartbeat-state", "files.manifest"] + (["host.decommission"] if self.can_uninstall() else []) + (["agent.update"] if update["enabled"] else [])
|
||||
capabilities = ["library.remove", "instance.cancel-create", "instance.safety-override", "operations.read-lane", "operations.health-lane", "rcon.status-batch", "instance.heartbeat-state", "files.manifest", "files.blobs"] + (["host.decommission"] if self.can_uninstall() else []) + (["agent.update"] if update["enabled"] else [])
|
||||
return {"hostname": socket.gethostname(), "agentVersion": VERSION, "protocolVersion": 1, "capabilities": capabilities, "agentUpdate": update, "agentLanes": self.lane_inventory(), "os": os_name, "osVersion": platform.release(), "architecture": platform.machine(), "cpu": platform.processor() or platform.machine(), "cpuCount": os.cpu_count() or 0, **resources, **({"cpuUsagePercent": cpu_usage} if cpu_usage is not None else {}), "memoryTotal": memory.get("MemTotal", 0), "memoryAvailable": memory.get("MemAvailable", 0), "storageTotal": usage.total, "storageAvailable": usage.free, "dockerVersion": docker_version, "dockerRunning": docker_running, "directoriesWritable": os.access(self.root, os.W_OK), "runtimeImages": sorted(set(images)), "libraries": libraries, "libraryCaches": caches, "currentOperation": self.current_operation, "portRange": self.config.get("portRange", {"min": 28960, "max": 29060})}
|
||||
|
||||
def safe_to_disrupt(self, instance_id, generation):
|
||||
@@ -1559,6 +1559,18 @@ class Agent:
|
||||
managed_write(root, item["path"], content, int(self.config.get("runtimeUid", 1000)), int(self.config.get("runtimeGid", 1000)))
|
||||
|
||||
def decode_file(self, item):
|
||||
if "contentSha256" in item:
|
||||
sha = item["contentSha256"]
|
||||
if not isinstance(sha, str) or not re.fullmatch(r"[a-f0-9]{64}", sha):
|
||||
raise AgentError("Invalid file content hash")
|
||||
url = self.config["controller"].rstrip("/") + "/api/agent/blobs/" + sha
|
||||
with self.artifact_open("GET", url) as response:
|
||||
content = response.read(MAX_FILE + 1)
|
||||
if len(content) > MAX_FILE:
|
||||
raise AgentError("File exceeds staging size limit")
|
||||
if digest(content) != sha or item.get("sha256", sha) != sha:
|
||||
raise AgentError("Staged file checksum mismatch")
|
||||
return content
|
||||
try:
|
||||
content = base64.b64decode(item["contentBase64"], validate=True)
|
||||
except (ValueError, KeyError, TypeError):
|
||||
@@ -1677,7 +1689,7 @@ class Agent:
|
||||
if item["path"] in paths:
|
||||
raise AgentError("Duplicate staged file path")
|
||||
paths.add(item["path"])
|
||||
deleting = item.get("delete") is True or item.get("contentBase64") is None
|
||||
deleting = item.get("delete") is True or (item.get("contentBase64") is None and "contentSha256" not in item)
|
||||
content = None if deleting else self.decode_file(item)
|
||||
total_size += len(content) if content is not None else 0
|
||||
if total_size > 64 * 1024 * 1024:
|
||||
|
||||
Reference in New Issue
Block a user