From 161d59c9aa4de37e5de347c96c6c2a9af84855b9 Mon Sep 17 00:00:00 2001 From: metacoma <5146707+metacoma@users.noreply.github.com> Date: Fri, 13 Jan 2023 10:48:55 +0100 Subject: [PATCH] more accurate handle for .zip kapitan-dependency (#912) * more accurate handle for .zip kapitan-dependency * fix typo * python-magic used to properly handle file content * fix indent * fix lint regarding failed job https://github.com/kapicorp/kapitan/actions/runs/3660886643/jobs/6373194593 --- Dockerfile | 1 + kapitan/utils.py | 6 ++++++ requirements.txt | 2 ++ 3 files changed, 9 insertions(+) diff --git a/Dockerfile b/Dockerfile index c941fc478..8b17936a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,6 +48,7 @@ RUN apt-get update \ && apt-get install --no-install-recommends -y \ git \ ssh-client \ + libmagic1 \ gnupg \ ca-certificates \ && apt-get clean \ diff --git a/kapitan/utils.py b/kapitan/utils.py index a0745d1ce..14067cdba 100644 --- a/kapitan/utils.py +++ b/kapitan/utils.py @@ -9,6 +9,7 @@ import collections import json import logging +import magic import math import os import re @@ -530,6 +531,11 @@ def make_request(source): def unpack_downloaded_file(file_path, output_path, content_type): """unpacks files of various MIME type and stores it to the output_path""" + + if (content_type == None or content_type == "application/octet-stream"): + if re.search(r"^Zip archive data.*", magic.from_file(file_path)): + content_type = 'application/zip' + if content_type == "application/x-tar": tar = tarfile.open(file_path) tar.extractall(path=output_path) diff --git a/requirements.txt b/requirements.txt index a7a3a5e62..3a11561cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -188,6 +188,8 @@ python-dateutil==2.8.2 # botocore python-gnupg==0.4.7 # via -r requirements.txt +python-magic==0.4.27 + # via -r requirements.txt pytz==2021.1 # via # -r requirements.txt