Skip to content

Commit 9584382

Browse files
authored
Isolate use of HideableValue in Enso code (#14039)
- Secret's as Private Key should be a `Derived_Secret_Value` (was used by Snowflake). - `HideableValue` only used in Enso_Secret.enso. - Only called by Enso just before going to Java.
1 parent 7aa93d4 commit 9584382

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

distribution/lib/Standard/Base/0.0.0-dev/docs/api/Enso_Cloud/Enso_Secret.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- type Derived_Secret_Value
44
- Base_64_Encode value:Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value
55
- Concat left:Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value right:Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value
6+
- Interpret_As_Private_Key secret:Standard.Base.Enso_Cloud.Enso_Secret.Enso_Secret
67
- Plain_Text text:Standard.Base.Data.Text.Text
78
- Secret_Value secret:Standard.Base.Enso_Cloud.Enso_Secret.Enso_Secret
89
- + self other:Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value -> Standard.Base.Any.Any

distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Enso_Secret.enso

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ polyglot java import org.enso.base.enso_cloud.HideableValue.Base64EncodeValue
2626
polyglot java import org.enso.base.enso_cloud.HideableValue.ConcatValues
2727
polyglot java import org.enso.base.enso_cloud.HideableValue.PlainValue
2828
polyglot java import org.enso.base.enso_cloud.HideableValue.SecretValue
29+
polyglot java import org.enso.base.enso_cloud.InterpretAsPrivateKey
2930

3031
## A reference to a secret stored in the Enso Cloud.
3132
type Enso_Secret
@@ -278,6 +279,12 @@ type Derived_Secret_Value
278279
---
279280
Base_64_Encode (value : Derived_Secret_Value)
280281

282+
## ---
283+
private: true
284+
---
285+
Interprets the value as a Private Key.
286+
Interpret_As_Private_Key (secret : Enso_Secret)
287+
281288
## ---
282289
private: true
283290
---
@@ -338,6 +345,7 @@ as_hideable_value (value : Text | Enso_Secret | Derived_Secret_Value) = case val
338345
Derived_Secret_Value.Secret_Value secret -> as_hideable_value secret
339346
Derived_Secret_Value.Concat left right -> HideableValue.ConcatValues.new (as_hideable_value left) (as_hideable_value right)
340347
Derived_Secret_Value.Base_64_Encode inner -> HideableValue.Base64EncodeValue.new (as_hideable_value inner)
348+
Derived_Secret_Value.Interpret_As_Private_Key secret -> InterpretAsPrivateKey.new (as_hideable_value secret)
341349

342350
## ---
343351
private: true

distribution/lib/Standard/Database/0.0.0-dev/src/Internal/JDBC_Connection.enso

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ polyglot java import java.sql.DatabaseMetaData
2121
polyglot java import java.sql.PreparedStatement
2222
polyglot java import java.sql.SQLException
2323
polyglot java import java.sql.SQLTimeoutException
24-
polyglot java import org.enso.base.enso_cloud.HideableValue
2524
polyglot java import org.enso.database.dryrun.OperationSynchronizer
2625
polyglot java import org.enso.database.JDBCProxy
2726
polyglot java import org.graalvm.collections.Pair as Java_Pair
@@ -303,10 +302,7 @@ create url properties = handle_sql_errors <|
303302
---
304303
properties_as_java_props properties =
305304
properties.map pair->
306-
# Some parameters may be passed by the dialect as a `HideableValue` directly, so they do not need to be converted.
307-
value = pair.second
308-
java_value = if value.is_a HideableValue then value else
309-
as_hideable_value value
305+
java_value = as_hideable_value pair.second
310306
Java_Pair.create pair.first java_value
311307

312308
## ---

distribution/lib/Standard/Generic_JDBC/0.0.0-dev/src/Generic_JDBC_Connection.enso

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ from Standard.Database.Internal.Result_Set import result_set_to_table
2222
polyglot java import java.sql.DatabaseMetaData
2323
polyglot java import java.sql.SQLException
2424
polyglot java import java.sql.SQLTimeoutException
25-
polyglot java import org.enso.base.enso_cloud.HideableValue
2625
polyglot java import org.enso.database.dryrun.OperationSynchronizer
2726
polyglot java import org.enso.database.JDBCProxy
2827
polyglot java import org.enso.database.JDBCUtils
@@ -379,10 +378,7 @@ private create_jdbc_connection url properties = handle_sql_errors <|
379378
---
380379
private properties_as_java_props properties =
381380
properties.map pair->
382-
# Some parameters may be passed by the dialect as a `HideableValue` directly, so they do not need to be converted.
383-
value = pair.second
384-
java_value = if value.is_a HideableValue then value else
385-
as_hideable_value value
381+
java_value = as_hideable_value pair.second
386382
Java_Pair.create pair.first java_value
387383

388384
## ---

distribution/lib/Standard/Snowflake/0.0.0-dev/src/Snowflake_Connection.enso

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from Standard.Base import all
2+
import Standard.Base.Enso_Cloud.Enso_Secret.Derived_Secret_Value
23
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
34
import Standard.Base.Metadata.Display
4-
from Standard.Base.Enso_Cloud.Enso_Secret import as_credential_reference, as_hideable_value
5+
from Standard.Base.Enso_Cloud.Enso_Secret import as_credential_reference
56
from Standard.Base.Metadata.Choice import Option
67
from Standard.Base.Metadata.Widget import Single_Choice, Text_Input
78
from Standard.Base.Visualization.Table_Viz_Data import Table_Viz_Data, Table_Viz_Header
@@ -26,7 +27,6 @@ from Standard.Database.Internal.Upload.Helpers.Default_Arguments import first_co
2627
import project.Connection.Key_Pair_Credentials.Key_Pair_Credentials
2728
import project.Internal.Snowflake_Dialect
2829

29-
polyglot java import org.enso.base.enso_cloud.InterpretAsPrivateKey
3030
polyglot java import org.enso.snowflake.SnowflakeCloudCredentials
3131

3232
type Snowflake_Connection
@@ -436,16 +436,15 @@ private auth_jdbc_properties credentials = case credentials of
436436
secret : Enso_Secret ->
437437
if resolved_passphrase != Nothing then
438438
Error.throw (Illegal_Argument.Error "Passphrase is not applicable when using a secret as a private key.")
439-
secret_as_private_key = InterpretAsPrivateKey.new (as_hideable_value secret)
440-
[Pair.new 'privateKey' secret_as_private_key]
439+
[Pair.new 'privateKey' (Derived_Secret_Value.Interpret_As_Private_Key secret)]
441440
[Pair.new 'user' username] + key_part
442441
_ : Enso_Secret ->
443442
Panic.throw (Illegal_Argument.Error "Cannot extract `auth_jdbc_properties` from a Cloud Credential. This is a bug in Snowflake library.")
444443

445-
private _resolve_passphrase passphrase:Text|Enso_Secret =
446-
case passphrase of
447-
_ : Text -> if passphrase.is_empty then Nothing else passphrase
448-
secret : Enso_Secret -> as_hideable_value secret
444+
private _resolve_passphrase passphrase:Text|Enso_Secret = case passphrase of
445+
_ : Text -> if passphrase.is_empty then Nothing else passphrase
446+
_ : Enso_Secret -> passphrase
447+
449448
## ---
450449
private: true
451450
---

0 commit comments

Comments
 (0)