Skip to content

Commit f97f713

Browse files
little-dudeshin-
authored andcommitted
refactor ProxyConfig
Signed-off-by: Corentin Henry <[email protected]>
1 parent 9146dd5 commit f97f713

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

docker/utils/proxy.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
11
from .utils import format_environment
22

33

4-
class ProxyConfig():
4+
class ProxyConfig(dict):
55
'''
66
Hold the client's proxy configuration
77
'''
8+
@property
9+
def http(self):
10+
return self['http']
811

9-
def __init__(self, http=None, https=None, ftp=None, no_proxy=None):
10-
self.http = http
11-
self.https = https
12-
self.ftp = ftp
13-
self.no_proxy = no_proxy
12+
@http.setter
13+
def http(self, value):
14+
self['http'] = value
15+
16+
@property
17+
def https(self):
18+
return self['https']
19+
20+
@https.setter
21+
def https(self, value):
22+
self['https'] = value
23+
24+
@property
25+
def ftp(self):
26+
return self['ftp']
27+
28+
@ftp.setter
29+
def ftp(self, value):
30+
self['ftp'] = value
31+
32+
@property
33+
def no_proxy(self):
34+
return self['no_proxy']
35+
36+
@no_proxy.setter
37+
def no_proxy(self, value):
38+
self['no_proxy'] = value
1439

1540
@staticmethod
1641
def from_dict(config):
@@ -22,10 +47,11 @@ def from_dict(config):
2247
https://docs.docker.com/network/proxy/#configure-the-docker-client
2348
'''
2449
return ProxyConfig(
25-
http=config.get('httpProxy', None),
26-
https=config.get('httpsProxy', None),
27-
ftp=config.get('ftpProxy', None),
28-
no_proxy=config.get('noProxy', None))
50+
http=config.get('httpProxy'),
51+
https=config.get('httpsProxy'),
52+
ftp=config.get('ftpProxy'),
53+
no_proxy=config.get('noProxy'),
54+
)
2955

3056
def get_environment(self):
3157
'''
@@ -58,12 +84,6 @@ def inject_proxy_environment(self, environment):
5884
# variables defined in "environment" to take precedence.
5985
return proxy_env + environment
6086

61-
def __bool__(self):
62-
return bool(self.http or self.https or self.ftp or self.no_proxy)
63-
64-
def __nonzero__(self):
65-
return self.__bool__()
66-
6787
def __str__(self):
6888
return 'ProxyConfig(http={}, https={}, ftp={}, no_proxy={})'.format(
6989
self.http, self.https, self.ftp, self.no_proxy)

0 commit comments

Comments
 (0)