Adds TLS support in pythonk8sclient.
Change-Id: Iba53edeccf88047f08d5ff54515f35e975eb850b Implements: bp tls-pythonk8sclient
This commit is contained in:
parent
efedf2c618
commit
7f15c9c8d2
@ -2364,7 +2364,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['namespaces', 'body']
|
||||
allParams = ['namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -2407,8 +2407,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
@ -2435,7 +2439,7 @@ class ApivbetaApi(object):
|
||||
Returns: V1beta3_Pod
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces']
|
||||
allParams = ['name', 'namespaces', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -2481,8 +2485,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
|
||||
if not response:
|
||||
@ -2512,7 +2520,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces', 'body']
|
||||
allParams = ['name', 'namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -2561,8 +2569,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
@ -2592,7 +2604,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces', 'body']
|
||||
allParams = ['name', 'namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -2641,8 +2653,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
@ -2671,7 +2687,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces', 'body']
|
||||
allParams = ['name', 'namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -2720,8 +2736,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
|
||||
|
||||
@ -2981,7 +3001,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['namespaces', 'body']
|
||||
allParams = ['namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -3024,8 +3044,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
@ -3052,7 +3076,7 @@ class ApivbetaApi(object):
|
||||
Returns: V1beta3_ReplicationController
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces']
|
||||
allParams = ['name', 'namespaces', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -3098,8 +3122,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
|
||||
if not response:
|
||||
@ -3129,7 +3157,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces', 'body']
|
||||
allParams = ['name', 'namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -3178,8 +3206,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
@ -3209,7 +3241,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces', 'body']
|
||||
allParams = ['name', 'namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -3258,8 +3290,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
@ -3288,7 +3324,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces', 'body']
|
||||
allParams = ['name', 'namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -3337,8 +3373,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
|
||||
|
||||
@ -4416,7 +4456,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['namespaces', 'body']
|
||||
allParams = ['namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -4459,8 +4499,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
@ -4487,7 +4531,7 @@ class ApivbetaApi(object):
|
||||
Returns: V1beta3_Service
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces']
|
||||
allParams = ['name', 'namespaces', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -4533,8 +4577,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
|
||||
if not response:
|
||||
@ -4564,7 +4612,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces', 'body']
|
||||
allParams = ['name', 'namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -4613,8 +4661,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
@ -4641,7 +4693,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces']
|
||||
allParams = ['name', 'namespaces', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -4687,8 +4739,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
if not response:
|
||||
return None
|
||||
@ -4717,7 +4773,7 @@ class ApivbetaApi(object):
|
||||
Returns:
|
||||
"""
|
||||
|
||||
allParams = ['name', 'namespaces', 'body']
|
||||
allParams = ['name', 'namespaces', 'body', 'ca', 'cert', 'key']
|
||||
|
||||
params = locals()
|
||||
for (key, val) in params['kwargs'].iteritems():
|
||||
@ -4766,8 +4822,12 @@ class ApivbetaApi(object):
|
||||
|
||||
postData = (formParams if formParams else bodyParam)
|
||||
|
||||
ca = params.get('ca')
|
||||
cert = params.get('cert')
|
||||
key = params.get('key')
|
||||
|
||||
response = self.apiClient.callAPI(resourcePath, method, queryParams,
|
||||
postData, headerParams, files=files)
|
||||
postData, ca, cert, key, headerParams, files=files)
|
||||
|
||||
|
||||
|
||||
|
@ -24,6 +24,7 @@ import __builtin__
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
import urllib
|
||||
import urllib2
|
||||
import httplib
|
||||
@ -68,7 +69,7 @@ class ApiClient(object):
|
||||
self.defaultHeaders[headerName] = headerValue
|
||||
|
||||
def callAPI(self, resourcePath, method, queryParams, postData,
|
||||
headerParams=None, files=None):
|
||||
ca=None, cert=None, key=None, headerParams=None, files=None):
|
||||
|
||||
url = self.host + resourcePath
|
||||
|
||||
@ -114,17 +115,12 @@ class ApiClient(object):
|
||||
|
||||
utils.raise_exception_invalid_scheme(url)
|
||||
|
||||
request = MethodRequest(method=method, url=url, headers=headers,
|
||||
data=data)
|
||||
|
||||
# Make the request
|
||||
response = urllib2.urlopen(request) #nosec
|
||||
response = requests.request(method, url=url, headers=headers, data=data,
|
||||
cert=(cert, key), verify=ca)
|
||||
if 'Set-Cookie' in response.headers:
|
||||
self.cookie = response.headers['Set-Cookie']
|
||||
string = response.read()
|
||||
|
||||
try:
|
||||
data = json.loads(string)
|
||||
data = json.loads(response.content)
|
||||
except ValueError: # PUT requests don't return anything
|
||||
data = None
|
||||
|
||||
@ -269,7 +265,6 @@ class ApiClient(object):
|
||||
setattr(instance, attr, subValues)
|
||||
else:
|
||||
setattr(instance, attr, self.deserialize(value, attrType))
|
||||
|
||||
return instance
|
||||
|
||||
def __parse_string_to_datetime(self, string):
|
||||
@ -283,17 +278,3 @@ class ApiClient(object):
|
||||
return parse(string)
|
||||
except ImportError:
|
||||
return string
|
||||
|
||||
class MethodRequest(urllib2.Request):
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Construct a MethodRequest. Usage is the same as for
|
||||
`urllib2.Request` except it also takes an optional `method`
|
||||
keyword argument. If supplied, `method` will be used instead of
|
||||
the default."""
|
||||
|
||||
if 'method' in kwargs:
|
||||
self.method = kwargs.pop('method')
|
||||
return urllib2.Request.__init__(self, *args, **kwargs)
|
||||
|
||||
def get_method(self):
|
||||
return getattr(self, 'method', urllib2.Request.get_method(self))
|
||||
|
Loading…
x
Reference in New Issue
Block a user