Skip to content

Commit 54ec6d1

Browse files
e-r-i-k-arobghchen
andauthored
fix(deployments): pass clusterid to getPresignedDeploymentUrl ps-14880 (#318)
* pass clusterid to getPresignedDeploymentUrl * fix(deployments): able to upload file/directory to s3 when creating a deployment PS-14880 * fix(deployments): upload with the same 'contentType' that psapi is using * Revert "fix(deployments): upload with the same 'contentType' that psapi is using" This reverts commit c3980f9. * fix(models): unbreak upload to model * fix(deployments): typo for data.content_type * refactor(deployments): pass 'file_path' into upload() instead of pulling it out from 'data.encoder.fields' * test(s3): change assert 'post' to 'put' request * test(uploaders): asset 'put' instead of 'post' request * test(experiments): assert 'put' instead of 'post' request * test(experiments): param position * test(experiments): param position * fix(uploads): model/deployment/experiment upload all works * test(experiments): revert the changes to test_experiments.py * test(upload): revert test_uploaders.py and test_archiver_class.py Co-authored-by: Robert Chen <[email protected]>
1 parent b89c64f commit 54ec6d1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

gradient/api_sdk/s3_uploader.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class DeploymentWorkspaceDirectoryUploader(object):
305305
def __init__(self, api_key, uploader=None, logger=None, ps_client_name=None):
306306
"""
307307
:param str api_key:
308-
:param S3FileUploader uploader:
308+
:param S3PutFileUploader uploader:
309309
:param Logger logger:
310310
"""
311311
self.logger = logger or MuteLogger()
@@ -315,13 +315,14 @@ def __init__(self, api_key, uploader=None, logger=None, ps_client_name=None):
315315
logger=self.logger,
316316
ps_client_name=ps_client_name,
317317
)
318-
self.uploader = uploader or S3PutFileUploader(logger=self.logger, ps_client_name=ps_client_name)
318+
self.uploader = S3PutFileUploader(logger=self.logger, ps_client_name=ps_client_name)
319319

320-
def _get_upload_data(self, file_path, project_id):
320+
def _get_upload_data(self, file_path, project_id, cluster_id=None):
321321
"""Ask API for data required to upload deployment workspace a file to S3
322322
323323
:param str file_path:
324324
:param str project_id:
325+
:param str cluster_id:
325326
326327
:rtype: str
327328
:return: URL to which send the file, name of the bucket and a dictionary required by S3 service
@@ -333,6 +334,8 @@ def _get_upload_data(self, file_path, project_id):
333334
}
334335
if project_id:
335336
params['projectId'] = project_id
337+
if cluster_id:
338+
params['clusterHandle'] = cluster_id
336339
response = self.ps_api_client.get("/deployments/getPresignedDeploymentUrl", params=params)
337340
if not response.ok:
338341
raise sdk_exceptions.PresignedUrlConnectionError(response.reason)
@@ -347,15 +350,16 @@ def _get_upload_data(self, file_path, project_id):
347350

348351
return presigned_url, bucket_name, workspace_url
349352

350-
def upload(self, file_path, project_id=None, **kwargs):
353+
def upload(self, file_path, project_id=None, cluster_id=None, **kwargs):
351354
"""Upload file to S3 bucket for a project
352355
353356
:param str file_path:
354357
:param str project_id:
358+
:param str cluster_id:
355359
356360
:rtype: str
357361
:return: S3 bucket's URL
358362
"""
359-
url, bucket_name, workspace_url = self._get_upload_data(file_path, project_id)
363+
url, bucket_name, workspace_url = self._get_upload_data(file_path, project_id, cluster_id)
360364
self.uploader.upload(file_path, url)
361365
return workspace_url

0 commit comments

Comments
 (0)