From patchwork Tue Dec 13 10:37:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 705349 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tdGQW6HFZz9t1T for ; Tue, 13 Dec 2016 21:38:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=6wind-com.20150623.gappssmtp.com header.i=@6wind-com.20150623.gappssmtp.com header.b="UEYdQycv"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3tdGQW59dqzDw3R for ; Tue, 13 Dec 2016 21:38:43 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=6wind-com.20150623.gappssmtp.com header.i=@6wind-com.20150623.gappssmtp.com header.b="UEYdQycv"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mail-wm0-x229.google.com (mail-wm0-x229.google.com [IPv6:2a00:1450:400c:c09::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3tdGPj0W6MzDvhD for ; Tue, 13 Dec 2016 21:38:01 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=6wind-com.20150623.gappssmtp.com header.i=@6wind-com.20150623.gappssmtp.com header.b="UEYdQycv"; dkim-atps=neutral Received: by mail-wm0-x229.google.com with SMTP id t79so113069171wmt.0 for ; Tue, 13 Dec 2016 02:38:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=pi5uRyiEkY6TaYEEFLSElL9TiNxt8o1knsLHavKpRvM=; b=UEYdQycvgweCd0IZ+4kJaZaroK3kYAUmjlVOATLD+uD5Xyc8lkISDnVbhq0y4kPqSk YdqIZtrFJOu2UU7DUzNcxeJNAEC+ryv6M3GkqULNrHeaSooNS+AX1TjwEo1B09+608SW v2JQOShF8R6YEuaVUW2GpLxhh6sflnhnLlnso9z99v7sySlf8Z6PtTvo1xyHwmbtnx2m 5nnegbsaqje9EJ2K2Dx5O7n7sE2owjOscgkGvPl+dJVxwKAJEYI5qwmnh2XvJz5BmYxM A/WMJ6Ot4a41s4JtbEsA9d7DEd7fKvTNvSlRYw26dREcNY6MfVBF4ae44sA9NqtW55FX EY1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=pi5uRyiEkY6TaYEEFLSElL9TiNxt8o1knsLHavKpRvM=; b=jszSHnKZYELzOcz1SKnDgoDSH/HrG5L5COirtqL1s5unIaVfkG1/Y4hw3Z8rz9mgFx ksm0bA2NH+HJ9neyT+lt572EePO9Jlxpjb+RdICKYKJNsilZ5xVrqvp964z1zGOSEPTT x2+7O0FV1QR3BgKjMyiCNtTFF9eGCXuz5UfBqdTTMQpGsNCQAiwu1JVWyP+nOCZkAgLZ HT1CxCXAAjBd/zeQmJhRatJx9ek+SR19TijbfkcuU32C/tjCZtI/S/njs1JiJuMAS8Ss /XqnRw9X6hNFsxAGHVVmj+gaWofazwtVFFUexJHyPeS9XaDBxgw3xen19cW/4glXXuUG uZ5g== X-Gm-Message-State: AKaTC01GHmp2YM9ZPzc/AcOduh7bDI8put/YF+FfqXxbBOO9hdNdmixV6juFHFCu/30/IbGG X-Received: by 10.28.62.77 with SMTP id l74mr1931590wma.37.1481625476932; Tue, 13 Dec 2016 02:37:56 -0800 (PST) Received: from XPS13.localdomain (184.203.134.77.rev.sfr.net. [77.134.203.184]) by smtp.gmail.com with ESMTPSA id xu5sm61416242wjc.49.2016.12.13.02.37.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Dec 2016 02:37:56 -0800 (PST) From: Thomas Monjalon To: patchwork@lists.ozlabs.org Subject: [PATCH v2 2/3] pwclient: Support proxy configuration Date: Tue, 13 Dec 2016 11:37:46 +0100 Message-Id: <1481625467-18217-3-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1481625467-18217-1-git-send-email-thomas.monjalon@6wind.com> References: <1481333552-2294-1-git-send-email-thomas.monjalon@6wind.com> <1481625467-18217-1-git-send-email-thomas.monjalon@6wind.com> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" The environment variables http_proxy and https_proxy can be used to configure the HTTP transport. The TCP connection is made with the proxy host, whereas the original host is maintained in the HTTP POST URI via "handler" in "send_request". The send_request() method of xmlrpclib has a different signature and behaviour in Python 2 and 3. Fixes #47 Signed-off-by: Thomas Monjalon Reviewed-by: Stephen Finucane --- patchwork/bin/pwclient | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient index 633ffc2..660ed76 100755 --- a/patchwork/bin/pwclient +++ b/patchwork/bin/pwclient @@ -107,12 +107,24 @@ class Transport(xmlrpclib.SafeTransport): def __init__(self, url): xmlrpclib.SafeTransport.__init__(self) self.credentials = None + self.host = None + self.proxy = None + self.scheme = url.split('://', 1)[0] self.https = url.startswith('https') + if self.https: + self.proxy = os.environ.get('https_proxy') + else: + self.proxy = os.environ.get('http_proxy') + if self.proxy: + self.https = self.proxy.startswith('https') def set_credentials(self, username=None, password=None): self.credentials = '%s:%s' % (username, password) def make_connection(self, host): + self.host = host + if self.proxy: + host = self.proxy.split('://', 1)[-1] if self.credentials: host = '@'.join([self.credentials, host]) if self.https: @@ -120,6 +132,18 @@ class Transport(xmlrpclib.SafeTransport): else: return xmlrpclib.Transport.make_connection(self, host) + if sys.version_info[0] == 2: + + def send_request(self, connection, handler, request_body): + handler = '%s://%s%s' % (self.scheme, self.host, handler) + xmlrpclib.Transport.send_request(self, connection, handler, request_body) + + else: # Python 3 + + def send_request(self, host, handler, request_body, debug): + handler = '%s://%s%s' % (self.scheme, host, handler) + return xmlrpclib.Transport.send_request(self, host, handler, request_body, debug) + def project_id_by_name(rpc, linkname): """Given a project short name, look up the Project ID."""