Created
May 29, 2019 17:38
-
-
Save caiaffa/be3cdca253b1ec7a94e00b958b34fcbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import gnupg | |
def initialize_gpg(key_paths): | |
gpg = gnupg.GPG() | |
for path in key_paths: | |
key_data = open(path).read() | |
gpg.import_keys(key_data) | |
# return | |
return gpg | |
def remove_gpg_from_path(path): | |
""" | |
We expect the given path as argument to have the form: file-name.ext.gpg | |
So we want to return: file-name.ext | |
For example: | |
input: bottles.csv.gpg | |
output: bottles.csv | |
""" | |
return os.path.splitext(path)[0] | |
def decrypt_file(gpg, encrypted_path): | |
with open(encrypted_path, 'rb') as a_file: | |
decrypted_path = remove_gpg_from_path(encrypted_path) | |
gpg.decrypt_file(a_file, output=decrypted_path) | |
return decrypted_path | |
FROM python:3.3-wheezy | |
# Install gpg | |
RUN apt-get update && apt-get install gnupg | |
RUN apt-get install -y ca-certificates wget | |
# Copy source code | |
RUN mkdir -p /root/app | |
COPY . /root/app | |
WORKDIR /root/app | |
# Add keys to gpg | |
RUN gpg --import <path-to-private-key> | |
RUN gpg --import <path-to-public-key> | |
# Install dependencies and open port | |
RUN pip3 install -r requirements.txt | |
EXPOSE 5001 | |
import os | |
import gnupg | |
def initialize_gpg(key_paths): | |
gpg = gnupg.GPG(homedir="~/.gnupg") | |
for path in key_paths: | |
key_data = open(path).read() | |
gpg.import_keys(key_data) | |
# return | |
return gpg | |
def remove_gpg_from_path(path): | |
""" | |
We expect the given path as argument to have the form: file-name.ext.gpg | |
So we want to return: file-name.ext | |
For example: | |
input: bottles.csv.gpg | |
output: bottles.csv | |
""" | |
return os.path.splitext(path)[0] | |
def decrypt_file(gpg, encrypted_path): | |
with open(encrypted_path, 'rb') as a_file: | |
decrypted_path = remove_gpg_from_path(encrypted_path) | |
gpg.decrypt_file(a_file, output=decrypted_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment