Skip to content

Commit

Permalink
Connection.as_curl: add option obfuscate_auth
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed May 17, 2023
1 parent 638c189 commit 3ce362b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions openeo/rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,20 +1383,22 @@ 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).
: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]
Expand Down

0 comments on commit 3ce362b

Please sign in to comment.