Skip to content

Commit

Permalink
Start using pre-signed URLs for Enso Files (#9227)
Browse files Browse the repository at this point in the history
Since the cloud finally gives us the pre-signed URLs, we can start using that.
  • Loading branch information
radeusgd authored Mar 1, 2024
1 parent 54675b1 commit b33802a
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ type Enso_File
with_input_stream : Vector File_Access -> (Input_Stream -> Any ! File_Error) -> Any ! File_Error | Illegal_Argument
with_input_stream self (open_options : Vector) action = if self.asset_type != Enso_Asset_Type.File then Error.throw (Illegal_Argument.Error "Only files can be opened as a stream.") else
if (open_options != [File_Access.Read]) then Error.throw (Illegal_Argument.Error "Files can only be opened for reading.") else
s3_url = get_download_url_for_file self
response = HTTP.fetch s3_url HTTP_Method.Get []
response = HTTP.fetch (get_download_url_for_file self) HTTP_Method.Get []
response.if_not_error <| response.body.with_stream action

## ALIAS load, open
Expand Down Expand Up @@ -341,7 +340,7 @@ Enso_Asset_Type.from (that:Text) = case that of
"file" -> Enso_Asset_Type.File
"directory" -> Enso_Asset_Type.Directory
"secret" -> Enso_Asset_Type.Secret
"connection" -> Enso_Asset_Type.Data_Link
"connector" -> Enso_Asset_Type.Data_Link
_ -> Error.throw (Illegal_Argument.Error "Invalid asset type.")

## PRIVATE
Expand All @@ -357,7 +356,5 @@ get_file_description file:Enso_File -> JS_Object =
stored anywhere.
get_download_url_for_file file:Enso_File -> Text =
file_description = get_file_description file
## TODO migrate to the pre-signed URLs once that is implemented
presigned_url = file_description |> get_required_field "url"
path = file_description |> get_required_field "file" |> get_required_field "path"
path.replace "s3://production-enso-organizations-files/" "https://production-enso-organizations-files.s3.eu-west-1.amazonaws.com/"
presigned_url = file_description |> get_required_field "url"
presigned_url

0 comments on commit b33802a

Please sign in to comment.