Skip to content

Commit

Permalink
implement reading data links from Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Feb 29, 2024
1 parent 46b09d4 commit 8db4f8a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import project.System.File_Format_Metadata.File_Format_Metadata
import project.System.Input_Stream.Input_Stream
import project.System.Output_Stream.Output_Stream
from project.Data.Boolean import Boolean, False, True
from project.Enso_Cloud.Data_Link import read_datalink
from project.Enso_Cloud.Public_Utils import get_required_field
from project.Data.Text.Extensions import all
from project.System.File.Generic.File_Write_Strategy import generic_copy
Expand Down Expand Up @@ -66,7 +67,7 @@ type Enso_File
Enso_Asset_Type.Directory -> Utils.directory_api + "/" + self.id
Enso_Asset_Type.File -> Utils.files_api + "/" + self.id
Enso_Asset_Type.Project -> Utils.projects_api + "/" + self.id
Enso_Asset_Type.Data_Link -> Utils.secrets_api + "/" + self.id
Enso_Asset_Type.Data_Link -> Utils.datalinks_api + "/" + self.id
Enso_Asset_Type.Secret -> Error.throw (Illegal_Argument.Error "Secrets cannot be accessed directly.")

## GROUP Metadata
Expand Down Expand Up @@ -184,7 +185,9 @@ type Enso_File
read self format=Auto_Detect (on_problems=Problem_Behavior.Report_Warning) = case self.asset_type of
Enso_Asset_Type.Project -> Error.throw (Illegal_Argument.Error "Projects cannot be read within Enso code. Open using the IDE.")
Enso_Asset_Type.Secret -> Error.throw (Illegal_Argument.Error "Secrets cannot be read directly.")
Enso_Asset_Type.Data_Link -> Unimplemented.throw "Reading from a Data Link is not implemented yet."
Enso_Asset_Type.Data_Link ->
json = Utils.http_request_as_json HTTP_Method.Get self.internal_uri
read_datalink json on_problems
Enso_Asset_Type.Directory -> if format == Auto_Detect then self.list else Error.throw (Illegal_Argument.Error "Directories can only be read using the Auto_Detect format.")
Enso_Asset_Type.File -> case format of
Auto_Detect ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ projects_api = cloud_root_uri + "projects"
Root address for Secrets API
secrets_api = cloud_root_uri + "secrets"

## PRIVATE
Root address for DataLinks API
datalinks_api = cloud_root_uri + "connectors"

## PRIVATE
The current project directory that will be used as the working directory,
if the user is running in the Cloud.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ add_specs suite_builder setup:Cloud_Tests_Setup = setup.with_prepared_environmen
datalink.should_be_a Enso_File
datalink.asset_type.should_equal Enso_Asset_Type.Data_Link

# We assume that the datalink links to some HTML website
datalink.read.should_contain "<head>"
# We assume that the datalink points to https://raw.githubusercontent.com/enso-org/enso/develop/test/Base_Tests/data/sample.txt
r = datalink.read
r.should_be_a Text
r.should_contain "Cupcake"

main filter=Nothing =
setup = Cloud_Tests_Setup.prepare
Expand Down

0 comments on commit 8db4f8a

Please sign in to comment.