Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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()) ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proper Fix

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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
## ---
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

## ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/Cloud_Tests/src/Network/Enso_Cloud/Secrets_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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->
Expand Down Expand Up @@ -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

Expand Down
Loading