]> git.ipfire.org Git - pakfire.git/commitdiff
http: Automatically configure client
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Dec 2016 18:52:37 +0000 (19:52 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Dec 2016 18:52:37 +0000 (19:52 +0100)
This patch makes the HTTP client read some basic
settings from the configuration file.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
contrib/config/general.conf
src/pakfire/http.py

index 864cfb3dbfe3f7488050b557badbdccde231dc4c..6f2b8625efb902276f856f19300e019526d31bee 100644 (file)
@@ -6,21 +6,13 @@
 #debug = false
 
 [downloader]
-# Pakfire can use a HTTP proxy for all downloads.
-# Authentication can be used like this:
-#   http://foo:bar@192.168.180.1:800
+# Pakfire can use a proxy for HTTP, HTTPS and FTP
 # If no proxy setting is configured, Pakfire will
 # use the environment settings.
-#http_proxy = http://192.168.180.1:800
+#proxy = http://192.168.180.1:800
 
-# You can throttle the download bandwidth with this
-# parameter. Unit: bytes per second.
-#bandwidth_throttle = 10240
-
-# Offline mode.
-# You may disable any kind of download action.
-# Howevery, pakfire won't be fully functionable.
-#offline = False
+# Verify SSL certificates?
+#verify = true
 
 [signatures]
 # Sets the mode of the signature verification.
index 3b51d29b20c081b247769385efb99ecea8d5a617..420ef33b5ecf86fc11d7a648f026a1946ef5aa45 100644 (file)
@@ -29,6 +29,7 @@ import urllib.request
 
 from .ui import progressbar
 
+from .config import config
 from .constants import *
 from . import errors
 
@@ -49,13 +50,24 @@ class Client(object):
                # Create an SSL context to HTTPS connections
                self.ssl_context = ssl.create_default_context()
 
+               # Configure upstream proxies
+               proxy = config.get("downloader", "proxy")
+               if proxy:
+                       for protocol in ("http", "https", "ftp"):
+                               self.set_proxy(protocol, proxy)
+
+               # Should we verify SSL certificates?
+               verify = config.get_bool("downloader", "verify", True)
+               if not verify:
+                       self.disable_certificate_verification()
+
        def set_proxy(self, protocol, host):
                """
                        Sets a proxy that will be used to send this request
                """
                self.proxies[protocol] = host
 
-       def disable_certificate_validation(self):
+       def disable_certificate_verification(self):
                # Disable checking hostname
                self.ssl_context.check_hostname = False