Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 489BC200CE0 for ; Fri, 11 Aug 2017 06:53:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4747616C752; Fri, 11 Aug 2017 04:53:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3A89716C73F for ; Fri, 11 Aug 2017 06:53:21 +0200 (CEST) Received: (qmail 79915 invoked by uid 500); 11 Aug 2017 04:53:20 -0000 Mailing-List: contact notifications-help@libcloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@libcloud.apache.org Delivered-To: mailing list notifications@libcloud.apache.org Received: (qmail 79810 invoked by uid 500); 11 Aug 2017 04:53:20 -0000 Delivered-To: apmail-libcloud-commits@libcloud.apache.org Received: (qmail 79803 invoked by uid 99); 11 Aug 2017 04:53:20 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Aug 2017 04:53:20 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B90ECF32DC; Fri, 11 Aug 2017 04:53:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anthonyshaw@apache.org To: commits@libcloud.apache.org Date: Fri, 11 Aug 2017 04:53:22 -0000 Message-Id: <5defc719060444b48c9f97d2dcf745c7@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [6/9] libcloud git commit: add DockertlsConnection, a subclass of KeyCertificateConnection fix DockerContainerDriver connect either with http or tls pass key_file, cert_file through function _ex_connection_class_kwargs archived-at: Fri, 11 Aug 2017 04:53:22 -0000 add DockertlsConnection, a subclass of KeyCertificateConnection fix DockerContainerDriver connect either with http or tls pass key_file, cert_file through function _ex_connection_class_kwargs Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/2272c93a Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/2272c93a Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/2272c93a Branch: refs/heads/trunk Commit: 2272c93ad0b6947554daa6ac36ae9b237ff7a77b Parents: 48d8063 Author: johnnyWalnut Authored: Fri Jun 2 13:54:10 2017 +0200 Committer: Anthony Shaw Committed: Fri Aug 11 14:43:39 2017 +1000 ---------------------------------------------------------------------- libcloud/container/drivers/docker.py | 68 ++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/2272c93a/libcloud/container/drivers/docker.py ---------------------------------------------------------------------- diff --git a/libcloud/container/drivers/docker.py b/libcloud/container/drivers/docker.py index 8fce78f..7b9d28b 100644 --- a/libcloud/container/drivers/docker.py +++ b/libcloud/container/drivers/docker.py @@ -17,6 +17,7 @@ import base64 import datetime import shlex import re +import os try: import simplejson as json @@ -27,6 +28,7 @@ from libcloud.utils.py3 import httplib from libcloud.utils.py3 import b from libcloud.common.base import JsonResponse, ConnectionUserAndKey +from libcloud.common.base import KeyCertificateConnection from libcloud.common.types import InvalidCredsError from libcloud.container.base import (Container, ContainerDriver, @@ -113,6 +115,46 @@ class DockerConnection(ConnectionUserAndKey): return headers +class DockertlsConnection(KeyCertificateConnection): + + responseCls = DockerResponse + + def __init__(self, key, secret, secure=True, + host='localhost', + port=4243, ca_cert='', key_file='', cert_file='', **kwargs): + + super(DockertlsConnection, self).__init__(key_file=key_file, + cert_file=cert_file, + secure=secure, host=host, + port=port, url=None, + proxy_url=None, + timeout=None, backoff=None, + retry_delay=None) + if key_file: + keypath = os.path.expanduser(key_file) + is_file_path = os.path.exists(keypath) and os.path.isfile(keypath) + if not is_file_path: + raise InvalidCredsError( + 'You need an key PEM file to authenticate with ' + 'Docker tls. This can be found in the server.' + ) + self.key_file = key_file + + certpath = os.path.expanduser(cert_file) + is_file_path = os.path.exists(certpath) and os.path.isfile(certpath) + if not is_file_path: + raise InvalidCredsError( + 'You need an certificate PEM file to authenticate with ' + 'Docker tls. This can be found in the server.' + ) + self.cert_file = cert_file + + def add_default_headers(self, headers): + + headers['Content-Type'] = 'application/json' + return headers + + class DockerContainerDriver(ContainerDriver): """ Docker container driver class. @@ -164,11 +206,12 @@ class DockerContainerDriver(ContainerDriver): :return: ``None`` """ - super(DockerContainerDriver, self).__init__(key=key, secret=secret, - secure=secure, host=host, - port=port, - key_file=key_file, - cert_file=cert_file) + if key_file: + self.connectionCls = DockertlsConnection + self.key_file = key_file + self.cert_file = cert_file + secure = True + if host.startswith('https://'): secure = True @@ -178,6 +221,12 @@ class DockerContainerDriver(ContainerDriver): if host.startswith(prefix): host = host.strip(prefix) + super(DockerContainerDriver, self).__init__(key=key, secret=secret, + secure=secure, host=host, + port=port, + key_file=key_file, + cert_file=cert_file) + if key_file or cert_file: # docker tls authentication- # https://docs.docker.com/articles/https/ @@ -194,9 +243,18 @@ class DockerContainerDriver(ContainerDriver): else: self.connection.secure = secure + self.connection.secure = secure self.connection.host = host self.connection.port = port + def _ex_connection_class_kwargs(self): + kwargs = {} + if hasattr(self, 'key_file'): + kwargs['key_file'] = self.key_file + if hasattr(self, 'cert_file'): + kwargs['cert_file'] = self.cert_file + return kwargs + def install_image(self, path): """ Install a container image from a remote path.