diff --git a/CHANGELOG.md b/CHANGELOG.md index cbfc0cb91197..337d82e40904 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,11 @@ - [Using dual JVM mode for Standard.Microsoft][14476]. - [Standard.Test pending field is lazy][14536]. +- [Using dual JVM mode for Standard.AWS][14568]. [14476]: https://github.com/enso-org/enso/pull/14476 [14536]: https://github.com/enso-org/enso/pull/14536 +[14568]: https://github.com/enso-org/enso/pull/14568 #### Enso Language & Runtime diff --git a/build.sbt b/build.sbt index f5ab5c5f72ac..d5e015280dd6 100644 --- a/build.sbt +++ b/build.sbt @@ -3836,7 +3836,6 @@ lazy val `engine-runner` = project `database-polyglot-root` .listFiles("*.jar") .map(_.getAbsolutePath()) ++ - `std-aws-polyglot-root`.listFiles("*.jar").map(_.getAbsolutePath()) ++ `std-tableau-polyglot-root` .listFiles("*.jar") .map(_.getAbsolutePath()) ++ diff --git a/distribution/lib/Standard/AWS/0.0.0-dev/src/AWS_Credential.enso b/distribution/lib/Standard/AWS/0.0.0-dev/src/AWS_Credential.enso index 889fbf8a0e74..30fc9d6d2440 100644 --- a/distribution/lib/Standard/AWS/0.0.0-dev/src/AWS_Credential.enso +++ b/distribution/lib/Standard/AWS/0.0.0-dev/src/AWS_Credential.enso @@ -9,6 +9,7 @@ import project.AWS_Region.AWS_Region polyglot java import org.enso.aws.AwsCredential polyglot java import org.enso.aws.ClientBuilder polyglot java import org.enso.aws.ProfileReader +polyglot java import org.enso.base.enso_cloud.HideableValue type AWS_Credential ## Access AWS using the default credential method. @@ -63,7 +64,9 @@ type AWS_Credential AWS_Credential.Default -> AwsCredential.Default.new AWS_Credential.Profile profile -> AwsCredential.Profile.new profile AWS_Credential.Key access_key_id secret_access_key -> - AwsCredential.Key.new (as_hideable_value access_key_id) (as_hideable_value secret_access_key) + key = as_hideable_value access_key_id factory=HideableValue + secret = as_hideable_value secret_access_key factory=HideableValue + AwsCredential.Key.new key secret AWS_Credential.With_Configuration base_credential _ -> base_credential.as_java diff --git a/distribution/lib/Standard/AWS/0.0.0-dev/src/Internal/Request_Body.enso b/distribution/lib/Standard/AWS/0.0.0-dev/src/Internal/Request_Body.enso index 7a88aaa5bba0..bcffc711d7b7 100644 --- a/distribution/lib/Standard/AWS/0.0.0-dev/src/Internal/Request_Body.enso +++ b/distribution/lib/Standard/AWS/0.0.0-dev/src/Internal/Request_Body.enso @@ -2,13 +2,50 @@ private from Standard.Base import all import Standard.Base.Errors.File_Error.File_Error -from Standard.Base.System.File import file_as_java +polyglot java import java.io.File as Java_File +polyglot java import java.io.FileNotFoundException +polyglot java import java.io.IOException +polyglot java import java.io.UncheckedIOException +polyglot java import java.nio.file.AccessDeniedException +polyglot java import java.nio.file.DirectoryNotEmptyException +polyglot java import java.nio.file.FileAlreadyExistsException +polyglot java import java.nio.file.FileSystemException +polyglot java import java.nio.file.NoSuchFileException +polyglot java import java.nio.file.NotDirectoryException polyglot java import software.amazon.awssdk.core.sync.RequestBody -## --- - private: true - --- -from_local_file (file : File) = File_Error.handle_java_exceptions file <| - java_file = file_as_java file - RequestBody.fromFile java_file +wrap_io_exception (file : File | Nothing) io_exception = + associated_file = case io_exception of + _ : FileSystemException -> + path_from_exception = io_exception.getFile + if path_from_exception.is_nothing then file else + File.new path_from_exception + _ -> file + + ## If the file is not known, all we can do is throw a generic IO error. + This will only usually matter on stream operations, where there is no relevant file - + and so the exceptions like `NoSuchFileException` should not occur in such context. + But instead of risking a Type_Error, we just throw the more generic IO_Error. + if associated_file.is_nothing then Error.throw (File_Error.IO_Error Nothing "An IO error has occurred: "+io_exception.to_text) else case io_exception of + _ : FileNotFoundException -> Error.throw (File_Error.Not_Found associated_file) + _ : NoSuchFileException -> Error.throw (File_Error.Not_Found associated_file) + _ : FileAlreadyExistsException -> Error.throw (File_Error.Already_Exists associated_file) + _ : AccessDeniedException -> File_Error.access_denied associated_file + _ : DirectoryNotEmptyException -> Error.throw (File_Error.Directory_Not_Empty associated_file) + _ : NotDirectoryException -> Error.throw (File_Error.Not_A_Directory associated_file) + _ -> Error.throw (File_Error.IO_Error associated_file "An IO error has occurred: "+io_exception.to_text) + +handle_java_exceptions (file : File | Nothing) ~action = + handle_io_exception caught_panic = + wrap_io_exception file caught_panic.payload + handle_unchecked_io_exception caught_panic = + wrap_io_exception file caught_panic.payload.getCause + Panic.catch IOException handler=handle_io_exception <| + Panic.catch UncheckedIOException handler=handle_unchecked_io_exception <| + action + +from_local_file (file : File) = + handle_java_exceptions file <| + java_file = Java_File.new file.absolute.normalize.path + RequestBody.fromFile java_file diff --git a/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Enso_Cloud/Enso_Secret.md b/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Enso_Cloud/Enso_Secret.md index 21bf1e173cd9..131ad28217de 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Enso_Cloud/Enso_Secret.md +++ b/distribution/lib/Standard/Base/0.0.0-dev/docs/api/Enso_Cloud/Enso_Secret.md @@ -34,6 +34,6 @@ - Not_Found resolved_path:Standard.Base.Any.Any - to_display_text self -> Standard.Base.Any.Any - as_credential_reference secret:Standard.Base.Enso_Cloud.Enso_Secret.Enso_Secret credential_reference:Standard.Base.Any.Any -> Standard.Base.Any.Any -- as_hideable_value value:(Standard.Base.Data.Text.Text|Standard.Base.Enso_Cloud.Enso_Secret.Enso_Secret|Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value) factory:Standard.Base.Any.Any= -> Standard.Base.Any.Any +- as_hideable_value value:(Standard.Base.Data.Text.Text|Standard.Base.Enso_Cloud.Enso_Secret.Enso_Secret|Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value) factory:Standard.Base.Any.Any -> Standard.Base.Any.Any - secret_resource_uri secret:Standard.Base.Any.Any -> Standard.Base.Any.Any - Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value.from that:Standard.Base.Data.Text.Text -> Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value diff --git a/distribution/lib/Standard/Base/0.0.0-dev/docs/api/System/File.md b/distribution/lib/Standard/Base/0.0.0-dev/docs/api/System/File.md index e38e6e59daae..b7e31c2976cc 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/docs/api/System/File.md +++ b/distribution/lib/Standard/Base/0.0.0-dev/docs/api/System/File.md @@ -48,7 +48,6 @@ - with_output_stream self open_options:Standard.Base.Data.Vector.Vector action:Standard.Base.Any.Any -> Standard.Base.Any.Any - type File_System_SPI - new protocol:Standard.Base.Data.Text.Text typ:Standard.Base.Any.Any -> Standard.Base.Any.Any -- file_as_java file:Standard.Base.System.File.File -> Standard.Base.Any.Any - find_extension_from_name name:Standard.Base.Any.Any -> Standard.Base.Any.Any - get_child_widget file:Standard.Base.Any.Any -> Standard.Base.Any.Any - list_descendants file:Standard.Base.Any.Any -> Standard.Base.Any.Any diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Enso_Secret.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Enso_Secret.enso index 03c73d5d9d6d..7d861c0fe7c4 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Enso_Secret.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Enso_Secret.enso @@ -292,7 +292,7 @@ type Derived_Secret_Value If the value contains secrets, it raises an error. to_plain_text : Text ! Enso_Secret_Error to_plain_text self = - java_repr = as_hideable_value self + java_repr = as_hideable_value self factory=HideableValue if java_repr.containsSecrets then Error.throw Enso_Secret_Error.Access_Denied java_repr.safeResolve @@ -301,7 +301,7 @@ type Derived_Secret_Value private: true --- to_text : Text - to_text self = as_hideable_value self . render + to_text self = as_hideable_value self factory=HideableValue . render ## --- private: true @@ -330,7 +330,7 @@ Derived_Secret_Value.from (that : Enso_Secret) = Derived_Secret_Value.Secret_Val private: true --- as_hideable_value : Text | Enso_Secret | Derived_Secret_Value -> Any -> HideableValue -as_hideable_value (value : Text | Enso_Secret | Derived_Secret_Value) factory=HideableValue = case value of +as_hideable_value (value : Text | Enso_Secret | Derived_Secret_Value) factory = case value of text : Text -> factory.plain text secret : Enso_Secret -> if secret.is_credential then diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Header.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Header.enso index 64cdad7e0472..0248ba77f65b 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Header.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Header.enso @@ -21,6 +21,7 @@ from project.Metadata.Widget import Single_Choice, Vector_Editor from project.Nothing import all polyglot java import org.graalvm.collections.Pair as Java_Pair +polyglot java import org.enso.base.enso_cloud.HideableValue type Header ## --- @@ -290,7 +291,7 @@ type Header --- to_java_pair : Java_Pair to_java_pair self = - Java_Pair.create self.name (as_hideable_value self.value) + Java_Pair.create self.name (as_hideable_value self.value factory=HideableValue) ## --- private: true diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/URI.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/URI.enso index e7db8dac94eb..674d906ce8f9 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/URI.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/URI.enso @@ -23,6 +23,7 @@ from project.Nothing import all polyglot java import java.net.URI as Java_URI polyglot java import java.net.URISyntaxException polyglot java import org.enso.base.enso_cloud.EnsoSecretAccessDenied +polyglot java import org.enso.base.enso_cloud.HideableValue polyglot java import org.enso.base.net.URITransformer polyglot java import org.enso.base.net.URIWithSecrets polyglot java import org.graalvm.collections.Pair as Java_Pair @@ -377,7 +378,7 @@ type URI to_java_representation : URIWithSecrets to_java_representation self = parameters = self.additional_query_parameters.map p-> - Java_Pair.create p.first (as_hideable_value p.second) + Java_Pair.create p.first (as_hideable_value p.second factory=HideableValue) URIWithSecrets.new self.internal_uri parameters ## --- diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso index 30325c3a3e9f..f9a2f62e8786 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso @@ -1182,12 +1182,6 @@ find_extension_from_name name = Convert from a Text to a File. File.from (that:Text) = File.new that -## --- - private: true - --- -file_as_java : File -> Java_File -file_as_java (file : File) = Java_File.new file.absolute.normalize.path - ## --- private: true --- diff --git a/distribution/lib/Standard/Saas/0.0.0-dev/src/Internal/Email_Provider_SMTP_Implementation.enso b/distribution/lib/Standard/Saas/0.0.0-dev/src/Internal/Email_Provider_SMTP_Implementation.enso index 01bbf8ea8740..b99753604fa9 100644 --- a/distribution/lib/Standard/Saas/0.0.0-dev/src/Internal/Email_Provider_SMTP_Implementation.enso +++ b/distribution/lib/Standard/Saas/0.0.0-dev/src/Internal/Email_Provider_SMTP_Implementation.enso @@ -11,6 +11,7 @@ import project.Email_Provider_SMTP.Email_Provider_SMTP polyglot java import org.apache.commons.mail.EmailAttachment polyglot java import org.apache.commons.mail.EmailException polyglot java import org.apache.commons.mail.HtmlEmail +polyglot java import org.enso.base.enso_cloud.HideableValue polyglot java import org.enso.saas.CredentialSetter ## The SMTP implementation of the Email Provider SPI. @@ -21,7 +22,7 @@ type Email_Provider_SMTP_Implementation java_email = HtmlEmail.new java_email.setHostName self.config.server java_email.setSmtpPort self.config.port - CredentialSetter.setAuthenticator java_email self.config.username (as_hideable_value self.config.password) + CredentialSetter.setAuthenticator java_email self.config.username (as_hideable_value self.config.password factory=HideableValue) java_email.setSSLOnConnect self.config.use_tls from_address = email.from_address diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Excel_Writer.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Excel_Writer.enso index e53498c6ef6a..91999a67b6da 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Excel_Writer.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Excel_Writer.enso @@ -4,7 +4,6 @@ import Standard.Base.Errors.Illegal_Argument.Illegal_Argument import Standard.Base.Errors.Illegal_State.Illegal_State import Standard.Base.Runtime.Context import Standard.Base.System.File.Generic.Writable_File.Writable_File -from Standard.Base.System.File import file_as_java import project.Excel.Excel_File_Format.Excel_File_Format import project.Excel.Excel_Range.Excel_Range @@ -70,19 +69,22 @@ write_file (file : Writable_File) (table : Table) (on_existing_file : Existing_F private: true --- write_local_file (file:File) table on_existing_file section match_columns xls_format = - java_file = file_as_java file + to_java f:File = + Java_File.new f.absolute.normalize.path + + java_file = to_java file file_format = xls_format.to_java ExcelWriter.setEnsoToTextCallbackIfUnset (.to_text) is_dry_run = Context.Output.is_enabled.not Panic.recover File_Error <| File_Error.handle_java_exceptions file <| handle_writer <| - possible_backup_file = if on_existing_file == Existing_File_Behavior.Backup then file_as_java (find_bak_file file) else Nothing + possible_backup_file = if on_existing_file == Existing_File_Behavior.Backup then to_java (find_bak_file file) else Nothing possible_dry_run_file = if is_dry_run.not then Nothing else preexisting_dry_run_file = DryRunFileManager.preExistingTemporaryFile file.absolute.normalize.path preexisting_dry_run_file.if_not_nothing <| Java_File.new preexisting_dry_run_file - + ## Make sure all of the files we may touch as part of the write operation are not open for reading in the cache possible_backup_file.if_not_nothing <| ExcelReader.closeFile possible_backup_file file_format possible_dry_run_file.if_not_nothing <| ExcelReader.closeFile possible_dry_run_file file_format @@ -95,8 +97,8 @@ write_local_file (file:File) table on_existing_file section match_columns xls_fo doesn't exist we also ensure that the temp file is not polluted with data from previous (dry-run) writes. Context.Output.with_enabled <| Panic.rethrow <| if file.exists then (file.copy_to temp_file replace_existing=True) else (temp_file.delete_if_exists) - - write_to_workbook (file_as_java temp_file) file_format table section on_existing_file match_columns + + write_to_workbook (to_java temp_file) file_format table section on_existing_file match_columns Context.Output.with_enabled <| result_file = if is_dry_run then temp_file else diff --git a/test/Cloud_Tests/src/Network/Enso_Cloud/Secrets_Spec.enso b/test/Cloud_Tests/src/Network/Enso_Cloud/Secrets_Spec.enso index ad86b893232a..4a853cf0b145 100644 --- a/test/Cloud_Tests/src/Network/Enso_Cloud/Secrets_Spec.enso +++ b/test/Cloud_Tests/src/Network/Enso_Cloud/Secrets_Spec.enso @@ -18,6 +18,7 @@ import project.Network.Enso_Cloud.Cloud_Tests_Setup.Temporary_Directory polyglot java import org.enso.base.enso_cloud.EnsoSecretAccessDenied polyglot java import org.enso.base.enso_cloud.ExternalLibrarySecretHelper +polyglot java import org.enso.base.enso_cloud.HideableValue add_specs suite_builder setup:Cloud_Tests_Setup = suite_builder.group "Enso Cloud Secrets" pending=setup.pending group_builder-> @@ -144,7 +145,7 @@ add_specs suite_builder setup:Cloud_Tests_Setup = secret1 = Enso_Secret.create "my_test_secret-12"+Temporary_Directory.timestamp_text "Something" secret1.should_succeed Panic.with_finalizer secret1.delete <| Test.with_retries <| - java_repr = as_hideable_value secret1 + java_repr = as_hideable_value secret1 factory=HideableValue Test.expect_panic EnsoSecretAccessDenied <| ExternalLibrarySecretHelper.resolveValue java_repr