Skip to content

Commit 069f7bb

Browse files
committedJul 30, 2024
Set SSL verification settings to licensing and logging clients
1 parent 9ff7d7a commit 069f7bb

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed
 

‎coriolisclient/cli/shell.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def build_kwargs_based_on_version(self, args, api_version=None):
124124
return dict((k, v) for (k, v) in six.iteritems(kwargs) if v)
125125

126126
def create_keystone_session(
127-
self, args, api_version, kwargs_dict, auth_type
127+
self, args, api_version, kwargs_dict, auth_type, verify=True,
128128
):
129129
# Make sure we have the correct arguments to function
130130
self.check_auth_arguments(args, api_version, raise_exc=True)
@@ -148,15 +148,14 @@ def create_keystone_session(
148148

149149
auth = method(**kwargs)
150150

151-
verify = args.os_cacert or not args.insecure
152-
153151
return session.Session(auth=auth, verify=verify)
154152

155153
def create_client(self, args):
156154
created_client = None
157155
endpoint_filter_kwargs = self._get_endpoint_filter_kwargs(args)
158156

159157
api_version = args.os_identity_api_version
158+
verify = args.os_cacert or not args.insecure
160159
if args.no_auth and args.os_auth_url:
161160
raise Exception(
162161
'ERROR: argument --os-auth-url/-A: not allowed '
@@ -172,7 +171,7 @@ def create_client(self, args):
172171
created_client = client.Client(
173172
endpoint=args.endpoint,
174173
project_id=args.os_tenant_id or args.os_project_id,
175-
verify=not args.insecure,
174+
verify=verify,
176175
**endpoint_filter_kwargs
177176
)
178177
# Token-based authentication
@@ -184,11 +183,12 @@ def create_client(self, args):
184183
'token': args.os_auth_token
185184
}
186185
session = self.create_keystone_session(
187-
args, api_version, token_kwargs, auth_type='token'
188-
)
186+
args, api_version, token_kwargs, auth_type='token',
187+
verify=verify)
189188
created_client = client.Client(
190189
session=session,
191190
endpoint=args.endpoint,
191+
verify=verify,
192192
**endpoint_filter_kwargs
193193
)
194194

@@ -201,11 +201,12 @@ def create_client(self, args):
201201
'username': args.os_username,
202202
}
203203
session = self.create_keystone_session(
204-
args, api_version, password_kwargs, auth_type='password'
205-
)
204+
args, api_version, password_kwargs, auth_type='password',
205+
verify=verify)
206206
created_client = client.Client(
207207
session=session,
208208
endpoint=args.endpoint,
209+
verify=verify,
209210
**endpoint_filter_kwargs
210211
)
211212
else:

‎coriolisclient/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@
4949

5050

5151
class _HTTPClient(adapter.Adapter):
52-
def __init__(self, session, project_id=None, **kwargs):
52+
def __init__(self, session, project_id=None, verify=True, **kwargs):
5353
kwargs.setdefault('interface', _DEFAULT_SERVICE_INTERFACE)
5454
kwargs.setdefault('service_type', _DEFAULT_SERVICE_TYPE)
5555
kwargs.setdefault('version', _DEFAULT_API_VERSION)
5656
endpoint = kwargs.pop('endpoint', None)
57+
self.verify = verify
5758

5859
super(_HTTPClient, self).__init__(session, **kwargs)
5960

‎coriolisclient/v1/licensing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _do_req(self, method_name, resource, body=None, response_key=None,
5656
endpoint_url = self._get_licensing_endpoint_url()
5757
url = '%s/%s' % (endpoint_url.rstrip('/'), resource.lstrip('/'))
5858

59-
kwargs = dict()
59+
kwargs = {"verify": self._cli.verify}
6060
if body:
6161
if not isinstance(body, (str, bytes)):
6262
body = json.dumps(body)

‎coriolisclient/v1/logging.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import datetime
1818
import json
1919
import logging
20+
import ssl
2021
import traceback
2122

2223
import requests
@@ -100,9 +101,18 @@ def stream_logs(self, app_name=None, severity=None):
100101
"severity": severity,
101102
}
102103
url = self._construct_url("ws", args, is_websocket=True)
104+
if self._cli.verify:
105+
cafile = None
106+
if isinstance(self._cli.verify, str):
107+
cafile = self._cli.verify
108+
ssl_context = ssl.create_default_context(cafile=cafile)
109+
else:
110+
ssl_context = ssl.SSLContext()
111+
ssl_context.verify_mode = ssl.CERT_NONE
103112

104113
async def nested():
105-
async with websockets.connect(url, extra_headers=headers) as ws:
114+
async with websockets.connect(
115+
url, extra_headers=headers, ssl=ssl_context) as ws:
106116
while True:
107117
msg = await ws.recv()
108118
as_dict = json.loads(msg)
@@ -162,7 +172,9 @@ def download_logs(self, app, to, start_time=None, end_time=None):
162172
}
163173
resource = "logs/%s/" % app
164174
url = self._construct_url(resource, args)
165-
with requests.get(url, headers=headers, stream=True) as r:
175+
verify = self._cli.verify
176+
with requests.get(
177+
url, headers=headers, stream=True, verify=verify) as r:
166178
r.raise_for_status()
167179
with open(to, 'wb') as fd:
168180
for chunk in r.iter_content(chunk_size=8192):
@@ -172,7 +184,7 @@ def download_logs(self, app, to, start_time=None, end_time=None):
172184
def list_logs(self):
173185
headers = self._auth_headers
174186
url = self._construct_url("logs/")
175-
req = requests.get(url, headers=headers)
187+
req = requests.get(url, headers=headers, verify=self._cli.verify)
176188
req.raise_for_status()
177189
ret = req.json()
178190
return ret.get("logs", [])

0 commit comments

Comments
 (0)
Failed to load comments.