From 0485ac1c97908d086eab9f5766f82f30dc96d5f7 Mon Sep 17 00:00:00 2001 From: Nicolae Date: Thu, 8 Feb 2018 16:08:30 +0200 Subject: [PATCH 1/3] Adding support for Proxies --- s3.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/s3.py b/s3.py index 870f356..0fcc1b3 100755 --- a/s3.py +++ b/s3.py @@ -10,6 +10,8 @@ import threading import urllib import urlparse +import os +from botocore.config import Config class Interrupt(): def __init__(self): @@ -246,8 +248,9 @@ def _handle_message(self, message): aws_secret_access_key=access_secret, region_name=region or 'us-east-1', ) + config_lrn = Config(signature_version=s3_uri.signature_version(), proxies=ProxyForS3.proxies) s3 = session.resource('s3', - config=botocore.client.Config(signature_version=s3_uri.signature_version()), + config=config_lrn, endpoint_url=s3_uri.endpoint_url(), ) s3_object = s3.Bucket(bucket).Object(key) @@ -307,10 +310,27 @@ def _handle_message(self, message): ('URI', uri), ))) + +class ProxyForS3(): + proxies = {} + if __name__ == '__main__': + if os.path.isfile('/etc/apt/apt.conf'): + with open('/etc/apt/apt.conf') as file: + for line in file.readlines(): + if line.find('Acquire::http::Proxy'): + (key, value) = line.split(' ') + ProxyForS3.proxies['http'] = re.sub('[;"]', '', value).rstrip() + if line.find('Acquire::https::Proxy'): + (key, value) = line.split(' ') + ProxyForS3.proxies['https'] = re.sub('[;"]', '', value).rstrip() + if line.find('Acquire::ftp::Proxy'): + (key, value) = line.split(' ') + ProxyForS3.proxies['ftp'] = re.sub('[;"]', '', value).rstrip() + # interrupt signals are sometimes sent def signal_handler(signal, frame): pass signal.signal(signal.SIGINT, signal_handler) - PipelinedAptMethod(S3AptMethodType(), Pipes(sys.stdin, sys.stdout)).run() + PipelinedAptMethod(S3AptMethodType(), Pipes(sys.stdin, sys.stdout)).run() \ No newline at end of file From 563166cb46e6b22d3d0cbbbd358ded1500404075 Mon Sep 17 00:00:00 2001 From: Nicolae Date: Thu, 8 Feb 2018 16:55:27 +0200 Subject: [PATCH 2/3] Small fix for proxies --- s3.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/s3.py b/s3.py index 0fcc1b3..feb124d 100755 --- a/s3.py +++ b/s3.py @@ -248,7 +248,10 @@ def _handle_message(self, message): aws_secret_access_key=access_secret, region_name=region or 'us-east-1', ) - config_lrn = Config(signature_version=s3_uri.signature_version(), proxies=ProxyForS3.proxies) + if len(ProxyForS3.proxies)>0: + config_lrn = Config(signature_version=s3_uri.signature_version(), proxies=ProxyForS3.proxies) + else: + config_lrn = Config(signature_version=s3_uri.signature_version()) s3 = session.resource('s3', config=config_lrn, endpoint_url=s3_uri.endpoint_url(), @@ -318,13 +321,13 @@ class ProxyForS3(): if os.path.isfile('/etc/apt/apt.conf'): with open('/etc/apt/apt.conf') as file: for line in file.readlines(): - if line.find('Acquire::http::Proxy'): + if line.startswith('Acquire::http::Proxy'): (key, value) = line.split(' ') ProxyForS3.proxies['http'] = re.sub('[;"]', '', value).rstrip() - if line.find('Acquire::https::Proxy'): + if line.startswith('Acquire::https::Proxy'): (key, value) = line.split(' ') ProxyForS3.proxies['https'] = re.sub('[;"]', '', value).rstrip() - if line.find('Acquire::ftp::Proxy'): + if line.startswith('Acquire::ftp::Proxy'): (key, value) = line.split(' ') ProxyForS3.proxies['ftp'] = re.sub('[;"]', '', value).rstrip() From 866f771a1b79d2fec26dba0b70d1444eb844f7b8 Mon Sep 17 00:00:00 2001 From: Nicolae Date: Fri, 9 Feb 2018 10:34:49 +0200 Subject: [PATCH 3/3] Add documentation about setup proxy --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 331275f..4ed1d16 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # apt-boto-s3 The *fast* and *simple* S3 transport for apt. Access S3-hosted apt repositories via the AWS APIs. +In this fork was added support for proxy servers. ## Why apt-boto-s3? @@ -66,6 +67,16 @@ deb s3://AKIAIOSFODNN7EXAMPLE:wJalrXUtnFEMI%2FK7MDENG%2FbPxRfiCYEXAMPLEKEY@my-bu URL credentials take precendent when present. +## Proxy +If access to S3 requires a proxy, the proxy can be set in `/etc/apt/apt.conf`. + +Example: +```sh +Acquire::http::Proxy "http://proxy-01.server:PORT"; +Acquire::https::Proxy "http://proxy-02.server:PORT"; +Acquire::ftp::Proxy "http://proxy-03.server:PORT"; +``` + #### Signature version Hopefully, this should "just work" and you can ignore this. @@ -81,9 +92,6 @@ S3::Signature::Version "2"; ``` ## Build - -[![Build Status](https://travis-ci.org/lucidsoftware/apt-boto-s3.svg?branch=master)](https://travis-ci.org/lucidsoftware/apt-boto-s3) - To build and install from source, ```sh