Skip to content
This repository was archived by the owner on Jun 7, 2022. It is now read-only.

Add support for Proxy into APT #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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.
Expand Down
27 changes: 25 additions & 2 deletions s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import threading
import urllib
import urlparse
import os
from botocore.config import Config

class Settings(object):
def __init__(self):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()