Skip to content

Commit 1be2aae

Browse files
committed
add TLS certs to curl debug output
Also use shlex.quote() for proper escaping of arguments for better copy&paste compatibility.
1 parent b535ba9 commit 1be2aae

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- Add TLS certificate options to "curl" debug output
14+
1115
### Fixed
1216

1317
- Correctly pass parameters in error_report_delete

linstor/linstorapi.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
from __future__ import print_function
55

6+
import shlex
67
import socket
78
import sys
89
import time
@@ -343,17 +344,24 @@ def __output_curl_command(self, method, path, body):
343344
url = urlparse(self._ctrl_host)
344345
cmd = ["curl", "-X", method]
345346
if body is not None:
346-
cmd += ['-H "Content-Type: application/json"']
347-
cmd += ["-d '" + json.dumps(body) + "'"]
347+
cmd += ["-H", "Content-Type: application/json"]
348+
cmd += ["-d", json.dumps(body)]
348349

349-
port = url.port if url.port else Linstor.REST_PORT
350-
is_https = True if url.scheme == "linstor+ssl" else False
350+
port = url.port or Linstor.REST_PORT
351+
is_https = url.scheme == "linstor+ssl" or url.scheme == "https"
351352

352353
port = port if not is_https else Linstor.REST_HTTPS_PORT
353354

355+
if self.cafile:
356+
cmd += ["--cacert", self.cafile]
357+
if self.certfile:
358+
cmd += ["--cert", self.certfile]
359+
if self.keyfile:
360+
cmd += ["--key", self.keyfile]
361+
354362
scheme = "https" if is_https else "http"
355363
cmd += [scheme + "://" + url.hostname + ":" + str(port) + path]
356-
print(" ".join(cmd))
364+
print(" ".join([shlex.quote(arg) for arg in cmd]))
357365

358366
@classmethod
359367
def _current_milli_time(cls):

0 commit comments

Comments
 (0)