From 3ce362b5eb2c1b1ed407bdd1a5663dce46bb7621 Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Wed, 17 May 2023 15:25:58 +0200 Subject: [PATCH] Connection.as_curl: add option obfuscate_auth --- openeo/rest/connection.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openeo/rest/connection.py b/openeo/rest/connection.py index 8d5cc32d4..f8db8e750 100644 --- a/openeo/rest/connection.py +++ b/openeo/rest/connection.py @@ -1383,7 +1383,7 @@ def load_disk_collection( self, format, glob_pattern, **(options or {}) ) - def as_curl(self, data: Union[dict, DataCube], path="/result", method="POST") -> str: + def as_curl(self, data: Union[dict, DataCube], path="/result", method="POST", obfuscate_auth: bool = False) -> str: """ Build curl command to evaluate given process graph or data cube (including authorization and content-type headers). @@ -1391,12 +1391,14 @@ def as_curl(self, data: Union[dict, DataCube], path="/result", method="POST") -> :param data: process graph dictionary or :py:class:`~openeo.rest.datacube.DataCube` object :param path: endpoint to send request to :param method: HTTP method to use + :param obfuscate_auth: don't show actual bearer token + :return: curl command as a string """ cmd = ["curl", "-i", "-X", method] cmd += ["-H", "Content-Type: application/json"] if isinstance(self.auth, BearerAuth): - cmd += ["-H", f"Authorization: Bearer {self.auth.bearer}"] + cmd += ["-H", f"Authorization: Bearer {'...' if obfuscate_auth else self.auth.bearer}"] post_data = self._build_request_with_process_graph(data) post_json = json.dumps(post_data, separators=(',', ':')) cmd += ["--data", post_json]