Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 1.2.0 (2026-09-10)

- Added `GetCertificate` and `UploadCertificate` for the webstack certificate API. `GetCertificate`
returns the stored PEM chain and raises `APIServerError` when nothing is stored under that id; the
private key is write only and never comes back. `UploadCertificate` creates or replaces a
certificate from a PEM bundle of the chain and, optionally, its matching private key.
- `APICall` accepts `parseJsonResponse`, which returns the response body as `bytes` instead of
decoding it as JSON. Endpoints that serve another content type on success, such as the certificate
download, can now go through `APICall` and get its error handling; error responses are still
decoded as JSON either way.

## 1.1.2 (2026-09-01)

- `LazyGraphQuery` no longer requests `meta.totalCount` on every graph list query. The count is
Expand Down
10 changes: 8 additions & 2 deletions python/mujinwebstackclient/controllerwebclientraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def APICall(
files: Optional[Dict[str, Any]] = None,
timeout: float = 5,
apiVersion: str = 'v1',
parseJsonResponse: bool = True,
) -> Any:
path = '/api/%s/%s' % (apiVersion, path.lstrip('/'))
if apiVersion == 'v1' and not path.endswith('/'):
Expand Down Expand Up @@ -470,10 +471,11 @@ def APICall(

response = self.Request(method, path, params=params, data=data, files=files, headers=headers, timeout=timeout)

# Try to parse response
# Errors always come back as JSON, even from endpoints that serve another content type on
# success, so decode the body whenever it could be carrying one
raw = response.content.decode('utf-8', 'replace').strip()
content: Optional[Dict[str, Any]] = None
if len(raw) > 0:
if len(raw) > 0 and (parseJsonResponse or response.status_code >= 400):
content = self.DecodeJSON(raw)

# First check error
Expand Down Expand Up @@ -502,6 +504,10 @@ def APICall(
log.error('response status code is %d, expecting %d for %s %s: %s', response.status_code, expectedStatusCode, method, path, raw)
raise APIServerError(_('Unexpected server response %d: %s') % (response.status_code, raw))

# Hand back the body untouched for endpoints whose successful response is not JSON
if not parseJsonResponse:
return response.content

return content

def CallGraphAPI(
Expand Down
2 changes: 1 addition & 1 deletion python/mujinwebstackclient/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '1.1.2'
__version__ = '1.2.0'

# Do not forget to update CHANGELOG.md
35 changes: 35 additions & 0 deletions python/mujinwebstackclient/webstackclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

log = logging.getLogger(__name__)

# Content type the certificate API speaks in both directions
CERTIFICATE_CONTENT_TYPE = 'application/x-pem-file'


def GetFilenameFromURI(uri, mujinpath):
"""Returns the filesystem path that the URI points to.
Expand Down Expand Up @@ -874,6 +877,38 @@ def DownloadBlob(self, blobId, timeout=5):
raise WebstackClientError(response.content.decode('utf-8'), response=response.content)
return response

#
# Certificate related
#

def GetCertificate(self, certificateId, timeout=5):
# type: (str, float) -> bytes
"""Downloads a stored TLS certificate as PEM.

The private key is write only, so what comes back is the leaf certificate followed by any
intermediates, never the key it may have been uploaded with.

:param certificateId: id the certificate is stored under
:param timeout: number of seconds to wait for the response
:return: the PEM encoded certificate chain
"""
return self._webclient.APICall('GET', 'certificate/%s' % certificateId, headers={'Accept': CERTIFICATE_CONTENT_TYPE}, timeout=timeout, apiVersion='v2', parseJsonResponse=False)

def UploadCertificate(self, certificateId, pemData, timeout=5):
# type: (str, bytes, float) -> Any
"""Creates or replaces a TLS certificate from a PEM bundle.

The bundle holds the leaf certificate followed by any intermediates, and optionally the
matching private key, which is stored but never served back. A key that does not match the
leaf is rejected. Any name and description already set on the certificate are preserved.

:param certificateId: id to store the certificate under
:param pemData: PEM bundle of the certificate chain, optionally with its private key
:param timeout: number of seconds to wait for the response
:return: the stored certificate and its derived metadata, without any key material
"""
return self._webclient.APICall('PUT', 'certificate/%s' % certificateId, data=pemData, headers={'Content-Type': CERTIFICATE_CONTENT_TYPE}, expectedStatusCode=200, timeout=timeout, apiVersion='v2')

#
# Log related
#
Expand Down
Loading