db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# Secrets responder test client
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# Copyright (c) 2016 Red Hat, Inc.
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# This is free software; you can redistribute it and/or modify it
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# under the terms of the GNU General Public License as published by
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# the Free Software Foundation; version 2 only
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# This program is distributed in the hope that it will be useful, but
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# WITHOUT ANY WARRANTY; without even the implied warranty of
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# General Public License for more details.
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# You should have received a copy of the GNU General Public License
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek# along with this program. If not, see <http://www.gnu.org/licenses/>.
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozekfrom requests.packages.urllib3.connection import HTTPConnection
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozekfrom requests.packages.urllib3.connectionpool import HTTPConnectionPool
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozekfrom requests.compat import quote, unquote, urlparse
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek def __init__(self, host, timeout=60, **kwargs):
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek super(HTTPUnixConnection, self).__init__('localhost')
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozekclass HTTPUnixConnectionPool(HTTPConnectionPool):
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek # proxies, silently ignored
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek def __init__(self, content_type='application/json', sock_path=None):
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek self.session.mount('http+unix://', HTTPUnixAdapter())
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek self.headers = dict({'Content-Type': content_type})
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek if resource is not None:
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek kwargs['headers'] = self._add_headers(**kwargs)
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek return self._request(self.session.get, path, **kwargs)
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek return self._request(self.session.get, None, **kwargs)
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek return self._request(self.session.put, name, **kwargs)
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek return self._request(self.session.delete, name, **kwargs)
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek return self._request(self.session.post, name, **kwargs)
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek raise TypeError("Invalid key type: %s" % ktype)
db0982c52294ee5ea08ed242d27660783fde29cdJakub Hrozek res = self.put(name, json={"type": "simple", "value": value})