luminarycloud 0.21.0__py3-none-any.whl → 0.21.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -113,9 +113,11 @@ class HttpClient:
113
113
  f"Bearer {self.auth0_client.fetch_access_token()}"
114
114
  )
115
115
 
116
- def _request(self, method: str, path: str, **kwargs) -> requests.Response:
116
+ # This method, which takes a full URL instead of just a path, is made public so the upload
117
+ # helper can use it to make authenticated requests to a gcsproxy endpoint which is hosted by
118
+ # jobmaster, not apiserver
119
+ def raw_request(self, method: str, url: str, **kwargs) -> requests.Response:
117
120
  self._authenticate_session()
118
- url = self._url(path)
119
121
  self._log_request(method, url, kwargs)
120
122
  resp = self.session.request(method, url, timeout=self.timeout, **kwargs)
121
123
  self._log_response(resp)
@@ -128,22 +130,22 @@ class HttpClient:
128
130
 
129
131
  # ---- Raw methods ----
130
132
  def raw_get(self, path: str, **kwargs) -> requests.Response:
131
- return self._request("GET", path, **kwargs)
133
+ return self.raw_request("GET", self._url(path), **kwargs)
132
134
 
133
135
  def raw_post(self, path: str, body: dict | None = None, **kwargs) -> requests.Response:
134
- return self._request("POST", path, json=body, **kwargs)
136
+ return self.raw_request("POST", self._url(path), json=body, **kwargs)
135
137
 
136
138
  def raw_put(self, path: str, body: dict | None = None, **kwargs) -> requests.Response:
137
- return self._request("PUT", path, json=body, **kwargs)
139
+ return self.raw_request("PUT", self._url(path), json=body, **kwargs)
138
140
 
139
141
  def raw_patch(self, path: str, body: dict | None = None, **kwargs) -> requests.Response:
140
- return self._request("PATCH", path, json=body, **kwargs)
142
+ return self.raw_request("PATCH", self._url(path), json=body, **kwargs)
141
143
 
142
144
  def raw_delete(self, path: str, **kwargs) -> requests.Response:
143
- return self._request("DELETE", path, **kwargs)
145
+ return self.raw_request("DELETE", self._url(path), **kwargs)
144
146
 
145
147
  def raw_head(self, path: str, **kwargs) -> requests.Response:
146
- return self._request("HEAD", path, **kwargs)
148
+ return self.raw_request("HEAD", self._url(path), **kwargs)
147
149
 
148
150
  # ---- JSON convenience methods ----
149
151
  def get(self, path: str, **kwargs) -> dict:
@@ -137,6 +137,7 @@ def _upload_mesh_from_path(
137
137
  logger.debug(f"started upload")
138
138
 
139
139
  gcs_resumable_upload(
140
+ client=client,
140
141
  filepath=pathlib.Path(filepath),
141
142
  signed_url=start_res.upload.gcs_resumable.signed_url,
142
143
  http_headers=start_res.upload.gcs_resumable.http_headers,
@@ -3,6 +3,7 @@ from os import PathLike
3
3
  import os
4
4
  import pathlib
5
5
  from typing import Mapping
6
+ from urllib.parse import urlparse
6
7
  import requests
7
8
  import logging
8
9
  import grpc
@@ -15,7 +16,7 @@ logger = logging.getLogger(__name__)
15
16
 
16
17
 
17
18
  def gcs_resumable_upload(
18
- filepath: PathLike | str, signed_url: str, http_headers: Mapping[str, str]
19
+ client: Client, filepath: PathLike | str, signed_url: str, http_headers: Mapping[str, str]
19
20
  ) -> None:
20
21
  """
21
22
  Performs a resumable upload to a GCS signed url.
@@ -24,12 +25,17 @@ def gcs_resumable_upload(
24
25
  """
25
26
 
26
27
  # initiate the upload
28
+ parsed_url = urlparse(signed_url)
27
29
  try:
28
- post_res = requests.post(
29
- url=signed_url,
30
- headers=http_headers,
31
- json={}, # intentionally empty, we're not uploading the file data yet
32
- )
30
+ if parsed_url.hostname and parsed_url.hostname.endswith(".luminarycloud.com"):
31
+ # we must be using the gcsproxy, so we'll use the `client.http` client to authenticate
32
+ # with our backend
33
+ logger.debug("signed url points to LC backend, will use authenticated client")
34
+ post_res = client.http.raw_request("POST", signed_url, headers=http_headers)
35
+ else:
36
+ # we're using the GCS signed url directly, no additional authentication is needed
37
+ logger.debug("signed url points to GCS, will use unauthenticated client")
38
+ post_res = requests.post(url=signed_url, headers=http_headers)
33
39
  logger.debug(
34
40
  f"sucessfully initialized signed URL upload for {filepath}, POST status code: {post_res.status_code}"
35
41
  )
@@ -49,6 +55,8 @@ def gcs_resumable_upload(
49
55
  session_uri = post_res.headers["Location"]
50
56
  size = os.path.getsize(filepath)
51
57
  with open(filepath, "rb") as fp:
58
+ # even if a signed url upload is initiated via the gcsproxy, the subsequent PUT request
59
+ # goes straight to GCS, so we don't want to use the authenticated client here
52
60
  put_res = requests.put(
53
61
  url=session_uri,
54
62
  headers={
@@ -89,6 +97,7 @@ def upload_file(
89
97
  logger.debug("started gcs upload")
90
98
 
91
99
  gcs_resumable_upload(
100
+ client=client,
92
101
  filepath=pathlib.Path(file_path),
93
102
  signed_url=start_res.upload.gcs_resumable.signed_url,
94
103
  http_headers=start_res.upload.gcs_resumable.http_headers,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: luminarycloud
3
- Version: 0.21.0
3
+ Version: 0.21.1
4
4
  Summary: Luminary Cloud SDK
5
5
  Project-URL: Homepage, https://www.luminarycloud.com/
6
6
  Project-URL: Documentation, https://app.luminarycloud.com/docs/api/
@@ -29,7 +29,7 @@ luminarycloud/_client/__init__.py,sha256=q-q1lnJE9EirX5p_O15FnanUoSYdEOD5zP1XrUe
29
29
  luminarycloud/_client/authentication_plugin.py,sha256=eJXs0b8pYih12fBU1vgJ8gGpAdtjfbqCuxSprjR-p9E,1351
30
30
  luminarycloud/_client/client.py,sha256=KiugyhRBcWIQY61bS22HjTz0-beRdBms3NGkgC36388,11307
31
31
  luminarycloud/_client/config.py,sha256=o_HJsmPOLaeorYToR9_wzNhJYRoFnmeqcxCRAoUAqZk,236
32
- luminarycloud/_client/http_client.py,sha256=yWx6BJ5C40PRI6Y5qo7b4abUecME_QGcWu1IQVwMHDU,6423
32
+ luminarycloud/_client/http_client.py,sha256=d_Yqxa6BMoq44ikF5uWVERucIhCQ9ISH7WmsqMSNFbM,6702
33
33
  luminarycloud/_client/logging_interceptor.py,sha256=I7xJzTQoV5O_Ioi7OjWXI2mQWxdpbagu7QnzbJSFcHg,2593
34
34
  luminarycloud/_client/retry_interceptor.py,sha256=EnswA3e7v8je2AqNCIcOoBVd1yKg6gLn_3nuUtwW8Mo,2908
35
35
  luminarycloud/_client/rpc_error.py,sha256=SgOYyLs5YYAuODFfyHMgJeJ3j2R7SJ8lUiqywvNRTfg,1250
@@ -42,7 +42,7 @@ luminarycloud/_helpers/_entity_identifier.py,sha256=Elb9gD5NFVxUxngiikGuNvNZ5YfS
42
42
  luminarycloud/_helpers/_get_project_id.py,sha256=OC0JI0gEXd_j8frss5AsjdzMX9C0mV3lAJdmB_cRmgw,885
43
43
  luminarycloud/_helpers/_simulation_params_from_json.py,sha256=Iq7S8XUqh3Y-6cZ2rvekJJxM3C-o8eFqTkBJpwdlHvU,726
44
44
  luminarycloud/_helpers/_timestamp_to_datetime.py,sha256=Vh2-e7MRrxG8z7CMA-DRIIAhqGSUGYuIhW9csoh9pBw,299
45
- luminarycloud/_helpers/_upload_mesh.py,sha256=eiWBSheNNdejfH3gkE7UohPXLRT3COOPPTN-yn2OU24,11955
45
+ luminarycloud/_helpers/_upload_mesh.py,sha256=b-QFxr0z-z02XUOXyPad8QEutcYM-PZyxhdvIaJKwcg,11978
46
46
  luminarycloud/_helpers/_upload_table.py,sha256=B7Svu97Dr6UYt8pubD99kGvXkR0oKUtKSi3Ppj_qUMI,2211
47
47
  luminarycloud/_helpers/_wait_for_mesh.py,sha256=p7Zp6ulifpZDAfRcN0kOPVjOU2e9oWutSrPIbMcsreg,1871
48
48
  luminarycloud/_helpers/_wait_for_simulation.py,sha256=DusHJLmLi7NvLu3K7cfrb2ZSbPBrySK8t7TLS22oTms,3520
@@ -53,7 +53,7 @@ luminarycloud/_helpers/file_chunk_stream.py,sha256=Z5dfuGWZMZ3JDhZH9jgxSqgkFu_e8
53
53
  luminarycloud/_helpers/named_variables.py,sha256=GLjBEQxf0SwfzLemY6_hnNbReD2gTcX0N9Hfvrk3-xc,481
54
54
  luminarycloud/_helpers/pagination.py,sha256=MYBuFvxYWe4U2QQ9UyZt-TvTTo69Qv2bXREiD6f5i5E,2076
55
55
  luminarycloud/_helpers/proto_decorator.py,sha256=Jrls0V2epTjH1P1ezwAsn24_I2e3Lyys87ftivTdqGg,1429
56
- luminarycloud/_helpers/upload.py,sha256=22Qqu4TN6iWDKLBLuXWT8Cw6IT0ujJt7ViUBIXxx8BU,4110
56
+ luminarycloud/_helpers/upload.py,sha256=aZ_aqCyiBEdcwtP7nOLLjLLo6XtGDfGcI4te2tx1tx8,4892
57
57
  luminarycloud/_helpers/util.py,sha256=GeBb9h10c-hWYkeBIxmK0UNgfbLryiRTE3EXNWhZLxI,3179
58
58
  luminarycloud/_helpers/warnings/__init__.py,sha256=I0nW7YIKZnapCdITVFopE60wQ6MfLy38tB4m8kuOVRQ,35
59
59
  luminarycloud/_helpers/warnings/deprecated.py,sha256=1SnhBAUqntgxHRMFG4Gzy_yqOMnBcAPN9b9Xxk0eieM,1259
@@ -521,6 +521,6 @@ luminarycloud/vis/primitives.py,sha256=_EDSEAddSAFTRUU9at1Gxt-5chLO723f9c8V5atTe
521
521
  luminarycloud/vis/report.py,sha256=wlRT-zj8MoVYfa9E5vUyZLYi_STBsShExN-TZtN0LlU,10552
522
522
  luminarycloud/vis/vis_util.py,sha256=AWGmHcfYXGmfe5t5Jbb1Fqe2nxVdEQbBitCaWSeT89M,1821
523
523
  luminarycloud/vis/visualization.py,sha256=pZSscRSCcwe8a0Z4-nRkL5kJ2btqLtkaUyQ76o1_AbA,61003
524
- luminarycloud-0.21.0.dist-info/METADATA,sha256=-89y2gZ9MhnLyfbh8gG-ixcNPAsnnI64-ZrleO7vBOw,2574
525
- luminarycloud-0.21.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
526
- luminarycloud-0.21.0.dist-info/RECORD,,
524
+ luminarycloud-0.21.1.dist-info/METADATA,sha256=QMDYlQvnNX7nNoBg12jLLMS5qV89eiUB1hpjGt7BBNM,2574
525
+ luminarycloud-0.21.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
526
+ luminarycloud-0.21.1.dist-info/RECORD,,