diff --git a/README.md b/README.md index 8d52a66..6418d8e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Package](https://img.shields.io/bintray/v/lucidsoftware/apt/apt-boto-s3.svg)](https://bintray.com/lucidsoftware/apt/apt-boto-s3/_latestVersion) 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? @@ -69,6 +70,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. diff --git a/s3.py b/s3.py index 5f557a1..a7b30be 100755 --- a/s3.py +++ b/s3.py @@ -12,6 +12,8 @@ import threading import urllib import urlparse +import os +from botocore.config import Config class Settings(object): def __init__(self): @@ -304,8 +306,12 @@ def _handle_message(self, message): region_name=region or 'us-east-1', botocore_session=botocore_session, ) + 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=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) @@ -365,10 +371,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.startswith('Acquire::http::Proxy'): + (key, value) = line.split(' ') + ProxyForS3.proxies['http'] = re.sub('[;"]', '', value).rstrip() + if line.startswith('Acquire::https::Proxy'): + (key, value) = line.split(' ') + ProxyForS3.proxies['https'] = re.sub('[;"]', '', value).rstrip() + if line.startswith('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