Skip to content

Commit

Permalink
more accurate handle for .zip kapitan-dependency (#912)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
metacoma authored Jan 13, 2023
1 parent 45d1858 commit 161d59c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 6 additions & 0 deletions kapitan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import collections
import json
import logging
import magic
import math
import os
import re
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 161d59c

Please sign in to comment.