diff --git a/build.sbt b/build.sbt index 4bb1ec5ed..1fd3d28af 100644 --- a/build.sbt +++ b/build.sbt @@ -1,16 +1,9 @@ -import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._ import sbt.Keys._ import sbt._ -import java.time.Year - import raw.build.Dependencies._ import raw.build.BuildSettings._ -import java.io.IOException -import java.nio.file.{Files, Paths} -import java.nio.charset.StandardCharsets - import scala.sys.process._ import com.jsuereth.sbtpgp.PgpKeys.{publishSigned} @@ -43,6 +36,7 @@ writeVersionToFile := { lazy val root = (project in file(".")) .aggregate( + protocol, utils, sources, client, @@ -108,9 +102,22 @@ lazy val sources = (project in file("sources")) ) ) +lazy val protocol = (project in file("protocol")) + .enablePlugins(ProtobufPlugin) + .settings( + commonSettings, + commonCompileSettings, + testSettings, + ProtobufConfig / version := "3.18.0", + libraryDependencies += "com.google.protobuf" % "protobuf-java" % (ProtobufConfig / version).value, + // Include the protobuf files in the JAR + Compile / unmanagedResourceDirectories += (ProtobufConfig / sourceDirectory).value + ) + lazy val client = (project in file("client")) .dependsOn( - utils % "compile->compile;test->test" + utils % "compile->compile;test->test", + protocol % "compile->compile;test->test" ) .settings( commonSettings, diff --git a/client/src/main/java/module-info.java b/client/src/main/java/module-info.java index bb8912bd5..f7f00664a 100644 --- a/client/src/main/java/module-info.java +++ b/client/src/main/java/module-info.java @@ -21,6 +21,7 @@ requires com.fasterxml.jackson.datatype.jsr310; requires com.fasterxml.jackson.datatype.jdk8; requires raw.utils; + requires raw.protocol; exports raw.client.api; exports raw.client.writers; diff --git a/client/src/main/scala/raw/client/api/ProgramEnvironment.scala b/client/src/main/scala/raw/client/api/ProgramEnvironment.scala index 4b9bd9ff2..23384ec61 100644 --- a/client/src/main/scala/raw/client/api/ProgramEnvironment.scala +++ b/client/src/main/scala/raw/client/api/ProgramEnvironment.scala @@ -12,99 +12,45 @@ package raw.client.api -import com.fasterxml.jackson.annotation.JsonSubTypes.{Type => JsonType} -import com.fasterxml.jackson.annotation.{JsonSubTypes, JsonTypeInfo} -import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.core.{JsonGenerator, JsonParser} +import com.fasterxml.jackson.databind.module.SimpleModule +import com.fasterxml.jackson.databind.{ + DeserializationContext, + JsonDeserializer, + JsonSerializer, + ObjectMapper, + SerializerProvider +} import com.fasterxml.jackson.datatype.jdk8.Jdk8Module import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule} + import raw.utils.RawUid +import raw.protocol.LocationConfig final case class ProgramEnvironment( uid: RawUid, maybeArguments: Option[Array[(String, RawValue)]], scopes: Set[String], secrets: Map[String, String], - jdbcServers: Map[String, JdbcLocation], - httpHeaders: Map[String, Map[String, String]], - s3Credentials: Map[String, S3Credential], + locationConfigs: Map[String, LocationConfig], options: Map[String, String], jdbcUrl: Option[String] = None, maybeTraceId: Option[String] = None ) -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") -@JsonSubTypes( - Array( - new JsonType(value = classOf[MySqlJdbcLocation], name = "mysql"), - new JsonType(value = classOf[OracleJdbcLocation], name = "oracle"), - new JsonType(value = classOf[PostgresJdbcLocation], name = "postgres"), - new JsonType(value = classOf[SqlServerJdbcLocation], name = "sqlserver"), - new JsonType(value = classOf[SnowflakeJdbcLocation], name = "snowflake"), - new JsonType(value = classOf[SqliteJdbcLocation], name = "sqlite"), - new JsonType(value = classOf[TeradataJdbcLocation], name = "teradata") - ) -) -trait JdbcLocation -final case class MySqlJdbcLocation( - host: String, - port: Int, - database: String, - username: String, - password: String -) extends JdbcLocation -final case class OracleJdbcLocation( - host: String, - port: Int, - database: String, - username: String, - password: String -) extends JdbcLocation -final case class PostgresJdbcLocation( - host: String, - port: Int, - database: String, - username: String, - password: String -) extends JdbcLocation -final case class SqlServerJdbcLocation( - host: String, - port: Int, - database: String, - username: String, - password: String -) extends JdbcLocation -final case class SnowflakeJdbcLocation( - database: String, - username: String, - password: String, - accountIdentifier: String, - parameters: Map[String, String] -) extends JdbcLocation -final case class SqliteJdbcLocation( - path: String -) extends JdbcLocation -final case class TeradataJdbcLocation( - host: String, - port: Int, - database: String, - username: String, - password: String, - parameters: Map[String, String] -) extends JdbcLocation - -final case class S3Credential( - accessKey: Option[String], - secretKey: Option[String], - region: Option[String] -) - object ProgramEnvironment { private val jsonMapper = new ObjectMapper with ClassTagExtensions { registerModule(DefaultScalaModule) registerModule(new JavaTimeModule()) registerModule(new Jdk8Module()) + + // Register custom serializer and deserializer for LocationConfig + val customModule = new SimpleModule() + customModule.addSerializer(classOf[LocationConfig], new LocationConfigSerializer) + customModule.addDeserializer(classOf[LocationConfig], new LocationConfigDeserializer) + registerModule(customModule) } private val reader = jsonMapper.readerFor[ProgramEnvironment] @@ -119,3 +65,15 @@ object ProgramEnvironment { } } + +class LocationConfigSerializer extends JsonSerializer[LocationConfig] { + override def serialize(value: LocationConfig, gen: JsonGenerator, serializers: SerializerProvider): Unit = { + gen.writeBinary(value.toByteArray) + } +} + +class LocationConfigDeserializer extends JsonDeserializer[LocationConfig] { + override def deserialize(p: JsonParser, ctxt: DeserializationContext): LocationConfig = { + LocationConfig.parseFrom(p.getBinaryValue) + } +} diff --git a/project/plugins.sbt b/project/plugins.sbt index c01177045..914520556 100755 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -19,3 +19,5 @@ addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1") libraryDependencies += "commons-io" % "commons-io" % "2.11.0" addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.8.0") + +addSbtPlugin("com.github.sbt" % "sbt-protobuf" % "0.8.0") diff --git a/protocol/src/main/java/module-info.java b/protocol/src/main/java/module-info.java new file mode 100644 index 000000000..912b1664f --- /dev/null +++ b/protocol/src/main/java/module-info.java @@ -0,0 +1,17 @@ +/* + * Copyright 2024 RAW Labs S.A. + * + * Use of this software is governed by the Business Source License + * included in the file licenses/BSL.txt. + * + * As of the Change Date specified in that file, in accordance with + * the Business Source License, use of this software will be governed + * by the Apache License, Version 2.0, included in the file + * licenses/APL.txt. + */ + +module raw.protocol { + requires com.google.protobuf; + + exports raw.protocol; +} diff --git a/protocol/src/main/java/raw/protocol/Placeholder.java b/protocol/src/main/java/raw/protocol/Placeholder.java new file mode 100644 index 000000000..c91fe2176 --- /dev/null +++ b/protocol/src/main/java/raw/protocol/Placeholder.java @@ -0,0 +1,17 @@ +/* + * Copyright 2024 RAW Labs S.A. + * + * Use of this software is governed by the Business Source License + * included in the file licenses/BSL.txt. + * + * As of the Change Date specified in that file, in accordance with + * the Business Source License, use of this software will be governed + * by the Apache License, Version 2.0, included in the file + * licenses/APL.txt. + */ + +package raw.protocol; + +class Placeholder { + // Placeholder class to allow the module-info.java file to be compiled +} diff --git a/protocol/src/main/protobuf/raw/protocol/protocol.proto b/protocol/src/main/protobuf/raw/protocol/protocol.proto new file mode 100644 index 000000000..dfe089835 --- /dev/null +++ b/protocol/src/main/protobuf/raw/protocol/protocol.proto @@ -0,0 +1,148 @@ +syntax = "proto3"; + +option java_package = "raw.protocol"; +option java_multiple_files = true; + +package raw.protocol; + +message LocationConfig { + oneof config { + S3Config s3 = 1; + MySqlConfig mysql = 2; + OracleConfig oracle = 3; + PostgreSQLConfig postgresql = 4; + SQLServerConfig sqlserver = 5; + SnowflakeConfig snowflake = 6; + SqliteConfig sqlite = 7; + TeradataConfig teradata = 8; + GitHubConfig github = 9; + JiraConfig jira = 10; + ConfluenceConfig confluence = 11; + SalesforceConfig salesforce = 12; + DropboxAccessTokenConfig dropboxAccessToken = 13; + DropboxUsernamePasswordConfig dropboxUsernamePassword = 14; + HttpHeadersConfig httpHeaders = 15; + SecretConfig secret = 99; + } +} + +message S3Config { + optional S3AccessSecretKey accessSecretKey = 1; + optional string region = 2; +} + +message S3AccessSecretKey { + string accessKey = 1; + string secretKey = 2; +} + +message MySqlConfig { + string host = 1; + int32 port = 2; + string database = 3; + string user = 4; + string password = 5; +} + +message OracleConfig { + string host = 1; + int32 port = 2; + string database = 3; + string user = 4; + string password = 5; + optional string schema = 6; +} + +message PostgreSQLConfig { + string host = 1; + int32 port = 2; + string database = 3; + string user = 4; + string password = 5; + optional string schema = 6; +} + +message SQLServerConfig { + string host = 1; + int32 port = 2; + string database = 3; + string user = 4; + string password = 5; + optional string schema = 6; +} + +message SnowflakeConfig { + string database = 1; + string user = 2; + string password = 3; + string accountIdentifier = 4; + map parameters = 5; + optional string schema = 6; +} + +message SqliteConfig { + string path = 1; + optional string schema = 2; +} + +message TeradataConfig { + string host = 1; + int32 port = 2; + string database = 3; + string user = 4; + string password = 5; + map parameters = 6; + optional string schema = 7; +} + +message GitHubConfig { + string token = 1; + optional string baseUrl = 2; +} + +message JiraConfig { + string baseUrl = 1; + string username = 2; + string token = 3; + JiraTokenType tokenType = 4; +} + +enum JiraTokenType { + STANDARD_ACCESS_TOKEN = 0; + PERSONAL_ACCESS_TOKEN = 1; +} + +message ConfluenceConfig { + string baseUrl = 1; + string username = 2; + string token = 3; +} + +message SalesforceConfig { + string url = 1; + string username = 2; + string password = 3; + string securityToken = 4; + string clientId = 5; + string apiVersion = 6; + repeated string customObjects = 7; +} + +message DropboxAccessTokenConfig { + string accessToken = 1; +} + +message DropboxUsernamePasswordConfig { + string username = 1; + string password = 2; +} + +message HttpHeadersConfig { + map headers = 1; +} + +// This is not used in practice but is kept for compatibility with FDW interface. +message SecretConfig { + string name = 1; + string value = 2; +} \ No newline at end of file diff --git a/python-client/src/test/scala/raw/client/python/TestPythonCompilerService.scala b/python-client/src/test/scala/raw/client/python/TestPythonCompilerService.scala index 95e6a3a93..03f8328ce 100644 --- a/python-client/src/test/scala/raw/client/python/TestPythonCompilerService.scala +++ b/python-client/src/test/scala/raw/client/python/TestPythonCompilerService.scala @@ -13,7 +13,7 @@ package raw.client.python import raw.client.api.{CompilerService, ExecutionSuccess, ProgramEnvironment, RawInt} -import raw.utils.{RawTestSuite, SettingsTestContext, TrainingWheelsContext, RawUid} +import raw.utils.{RawTestSuite, RawUid, SettingsTestContext, TrainingWheelsContext} import java.io.ByteArrayOutputStream @@ -44,8 +44,6 @@ class TestPythonCompilerService extends RawTestSuite with SettingsTestContext wi Set.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "json") ) val baos = new ByteArrayOutputStream() @@ -60,8 +58,6 @@ class TestPythonCompilerService extends RawTestSuite with SettingsTestContext wi Set.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "json") ) val baos = new ByteArrayOutputStream() @@ -76,8 +72,6 @@ class TestPythonCompilerService extends RawTestSuite with SettingsTestContext wi Set.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "json") ) val baos = new ByteArrayOutputStream() diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/Rql2CompilerTestContext.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/Rql2CompilerTestContext.scala index 15c33dfb6..375a9a3ce 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/Rql2CompilerTestContext.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/Rql2CompilerTestContext.scala @@ -21,12 +21,25 @@ import raw.client.rql2.api._ import raw.compiler.base.source.{BaseProgram, Type} import raw.compiler.rql2.api.{Rql2CompilerServiceTestContext, Rql2OutputTestContext} import raw.inferrer.local.LocalInferrerTestContext +import raw.protocol.{ + DropboxAccessTokenConfig, + HttpHeadersConfig, + LocationConfig, + MySqlConfig, + OracleConfig, + PostgreSQLConfig, + S3AccessSecretKey, + S3Config, + SQLServerConfig, + SnowflakeConfig +} import raw.utils._ import java.io.{ByteArrayOutputStream, FileWriter} import java.nio.charset.{Charset, StandardCharsets} import java.nio.file.{Files, Path, StandardOpenOption} import scala.collection.mutable +import scala.collection.JavaConverters._ import scala.io.Source object TestCredentials { @@ -50,23 +63,43 @@ object TestCredentials { // Bucket with public access val UnitTestPublicBucket = "rawlabs-public-test-data" - val UnitTestPublicBucketCred = S3Credential(None, None, Some("eu-west-1")) + val UnitTestPublicBucketCred = S3Config.newBuilder().setRegion("eu-west-1").build() // IAM user 'unit-test-private-bucket', which only has permissions only to access bucket 'rawlabs-private-test-data' val UnitTestPrivateBucket = "rawlabs-private-test-data" - val UnitTestPrivateBucketCred = S3Credential(Some(accessKeyId), Some(secretKeyId), Some("eu-west-1")) + val UnitTestPrivateBucketCred = S3Config + .newBuilder() + .setAccessSecretKey(S3AccessSecretKey.newBuilder().setAccessKey(accessKeyId).setSecretKey(secretKeyId)) + .setRegion("eu-west-1") + .build() val UnitTestPrivateBucket2 = "rawlabs-unit-tests" - val UnitTestPrivateBucket2Cred = S3Credential(Some(accessKeyId), Some(secretKeyId), Some("eu-west-1")) + val UnitTestPrivateBucket2Cred = S3Config + .newBuilder() + .setAccessSecretKey(S3AccessSecretKey.newBuilder().setAccessKey(accessKeyId).setSecretKey(secretKeyId)) + .setRegion("eu-west-1") + .build() val UnitTestEmptyBucketPrivateBucket = "rawlabs-unit-test-empty-bucket" - val UnitTestEmptyBucketPrivateBucketCred = S3Credential(Some(accessKeyId), Some(secretKeyId), Some("eu-west-1")) + val UnitTestEmptyBucketPrivateBucketCred = S3Config + .newBuilder() + .setAccessSecretKey(S3AccessSecretKey.newBuilder().setAccessKey(accessKeyId).setSecretKey(secretKeyId)) + .setRegion("eu-west-1") + .build() val UnitTestListRootPrivateBucket = "rawlabs-unit-test-list-root" - val UnitTestListRootPrivateBucketCred = S3Credential(Some(accessKeyId), Some(secretKeyId), Some("eu-west-1")) + val UnitTestListRootPrivateBucketCred = S3Config + .newBuilder() + .setAccessSecretKey(S3AccessSecretKey.newBuilder().setAccessKey(accessKeyId).setSecretKey(secretKeyId)) + .setRegion("eu-west-1") + .build() val unitTestPrivateBucketUsEast1 = "rawlabs-unit-tests-us-east-1" - val unitTestPrivateBucketUsEast1Cred = S3Credential(Some(accessKeyId), Some(secretKeyId), Some("us-east-1")) + val unitTestPrivateBucketUsEast1Cred = S3Config + .newBuilder() + .setAccessSecretKey(S3AccessSecretKey.newBuilder().setAccessKey(accessKeyId).setSecretKey(secretKeyId)) + .setRegion("eu-west-1") + .build() /////////////////////////////////////////////////////////////////////////// // Jdbc Credentials @@ -76,40 +109,70 @@ object TestCredentials { val mysqlTestDB = getEnv("RAW_MYSQL_TEST_DB") val mysqlTestUser = getEnv("RAW_MYSQL_TEST_USER") val mysqlTestPassword = getEnv("RAW_MYSQL_TEST_PASSWORD") - val mysqlCreds = MySqlJdbcLocation(mysqlTestHost, 3306, mysqlTestDB, mysqlTestUser, mysqlTestPassword) + val mysqlCreds = MySqlConfig + .newBuilder() + .setHost(mysqlTestHost) + .setPort(3306) + .setDatabase(mysqlTestDB) + .setUser(mysqlTestUser) + .setPassword(mysqlTestPassword) + .build() val pgsqlTestHost = getEnv("RAW_PGSQL_TEST_HOST") val pgsqlTestDB = getEnv("RAW_PGSQL_TEST_DB") val pgsqlTestUser = getEnv("RAW_PGSQL_TEST_USER") val pgsqlTestPassword = getEnv("RAW_PGSQL_TEST_PASSWORD") - val pgsqlCreds = PostgresJdbcLocation(pgsqlTestHost, 5432, pgsqlTestDB, pgsqlTestUser, pgsqlTestPassword) + val pgsqlCreds = PostgreSQLConfig + .newBuilder() + .setHost(pgsqlTestHost) + .setPort(5432) + .setDatabase(pgsqlTestDB) + .setUser(pgsqlTestUser) + .setPassword(pgsqlTestPassword) + .build() val oracleTestHost = getEnv("RAW_ORACLE_TEST_HOST") val oracleTestDB = getEnv("RAW_ORACLE_TEST_DB") val oracleTestUser = getEnv("RAW_ORACLE_TEST_USER") val oracleTestPassword = getEnv("RAW_ORACLE_TEST_PASSWORD") - val oracleCreds = OracleJdbcLocation(oracleTestHost, 1521, oracleTestDB, oracleTestUser, oracleTestPassword) + val oracleCreds = OracleConfig + .newBuilder() + .setHost(oracleTestHost) + .setPort(1521) + .setDatabase(oracleTestDB) + .setUser(oracleTestUser) + .setPassword(oracleTestPassword) + .build() val sqlServerTestHost = getEnv("RAW_SQLSERVER_TEST_HOST") val sqlserverTestDB = getEnv("RAW_SQLSERVER_TEST_DB") val sqlServerTestUser = getEnv("RAW_SQLSERVER_TEST_USER") val sqlServerTestPassword = getEnv("RAW_SQLSERVER_TEST_PASSWORD") - val sqlServerCreds = SqlServerJdbcLocation( - sqlServerTestHost, - 1433, - sqlserverTestDB, - sqlServerTestUser, - sqlServerTestPassword - ) + val sqlServerCreds = SQLServerConfig + .newBuilder() + .setHost(sqlServerTestHost) + .setPort(1433) + .setDatabase(sqlserverTestDB) + .setUser(sqlServerTestUser) + .setPassword(sqlServerTestPassword) + .build() val snowflakeTestHost = getEnv("RAW_SNOWFLAKE_TEST_HOST") val snowflakeTestDB = getEnv("RAW_SNOWFLAKE_TEST_DB") val snowflakeTestUser = getEnv("RAW_SNOWFLAKE_TEST_USER") val snowflakeTestPassword = getEnv("RAW_SNOWFLAKE_TEST_PASSWORD") - val snowflakeCreds = SnowflakeJdbcLocation( - snowflakeTestDB, - snowflakeTestUser, - snowflakeTestPassword, - snowflakeTestHost, - Map("timezone" -> "UTC") - ) - val badMysqlCreds = MySqlJdbcLocation("does-not-exist.raw-labs.com", 3306, "rdbmstest", "t0or", "$up3r$3cr3tValu3") + val snowflakeCreds = SnowflakeConfig + .newBuilder() + .setDatabase(snowflakeTestDB) + .setUser(snowflakeTestUser) + .setPassword(snowflakeTestPassword) + .setAccountIdentifier(snowflakeTestHost) + .putParameters("timezone", "UTC") + .build() + val badMysqlCreds = MySqlConfig + .newBuilder() + .setHost("does-not-exist.raw-labs.com") + .setPort(3306) + .setDatabase("rdbmstest") + .setUser("t0or") + .setPassword("$up3r$3cr3tValu3") + .build() } @@ -126,11 +189,7 @@ trait Rql2CompilerTestContext private val secrets = new mutable.HashMap[String, String]() - private val s3Credentials = new mutable.HashMap[String, S3Credential]() - - private val rdbmsServers = new mutable.HashMap[String, JdbcLocation]() - - private val credHttpHeaders = new mutable.HashMap[String, Map[String, String]]() + private val locationConfigs = new mutable.HashMap[String, LocationConfig]() protected val programOptions = new mutable.HashMap[String, String]() @@ -146,16 +205,42 @@ trait Rql2CompilerTestContext secrets.put(name, value) } - def s3Bucket(name: String, bucket: S3Credential): Unit = { - s3Credentials.put(name, bucket) + def locationConfig(name: String, locationConfig: LocationConfig): Unit = { + locationConfigs.put(name, locationConfig) + } + + def s3Bucket(name: String, bucket: S3Config): Unit = { + locationConfig(name, LocationConfig.newBuilder().setS3(bucket).build()) + } + + def rdbms(name: String, db: MySqlConfig): Unit = { + locationConfig(name, LocationConfig.newBuilder().setMysql(db).build()) } - def rdbms(name: String, db: JdbcLocation): Unit = { - rdbmsServers.put(name, db) + def rdbms(name: String, db: OracleConfig): Unit = { + locationConfig(name, LocationConfig.newBuilder().setOracle(db).build()) + } + + def rdbms(name: String, db: PostgreSQLConfig): Unit = { + locationConfig(name, LocationConfig.newBuilder().setPostgresql(db).build()) + } + + def rdbms(name: String, db: SQLServerConfig): Unit = { + locationConfig(name, LocationConfig.newBuilder().setSqlserver(db).build()) + } + + def rdbms(name: String, db: SnowflakeConfig): Unit = { + locationConfig(name, LocationConfig.newBuilder().setSnowflake(db).build()) } def httpHeaders(name: String, headers: Map[String, String]): Unit = { - credHttpHeaders.put(name, headers) + val httpConfig = HttpHeadersConfig.newBuilder().putAllHeaders(headers.asJava).build() + locationConfig(name, LocationConfig.newBuilder().setHttpHeaders(httpConfig).build()) + } + + def dropbox(name: String, cred: DropboxAccessTokenConfig): Unit = { + val dropboxConfig = LocationConfig.newBuilder().setDropboxAccessToken(cred).build() + locationConfig(name, dropboxConfig) } def option(key: String, value: String): Unit = { @@ -583,9 +668,7 @@ trait Rql2CompilerTestContext maybeArguments, this.runnerScopes ++ scopes, secrets.toMap, - rdbmsServers.toMap, - credHttpHeaders.toMap, - s3Credentials.toMap, + locationConfigs.toMap, this.options ++ options ++ programOptions, None, // jdbcUrl maybeTraceId diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/LocationPackageTest.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/LocationPackageTest.scala index fbeba57bd..ec2554ada 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/LocationPackageTest.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/LocationPackageTest.scala @@ -86,9 +86,9 @@ import raw.testing.tags.TruffleTests | data = Csv.InferAndRead( | S3.Build( | "s3://$UnitTestPrivateBucket/students.csv", - | region = "${UnitTestPrivateBucketCred.region.get}", - | accessKey = "${UnitTestPrivateBucketCred.accessKey.get}", - | secretKey = "${UnitTestPrivateBucketCred.secretKey.get}" + | region = "${UnitTestPrivateBucketCred.getRegion}", + | accessKey = "${UnitTestPrivateBucketCred.getAccessSecretKey.getAccessKey}", + | secretKey = "${UnitTestPrivateBucketCred.getAccessSecretKey.getSecretKey}" | ) | ) |in diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/MySQLPackageTest.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/MySQLPackageTest.scala index 05e5a5d65..f7f48bca0 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/MySQLPackageTest.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/MySQLPackageTest.scala @@ -113,8 +113,8 @@ import raw.testing.tags.TruffleTests } test( - s"""MySQL.InferAndRead("${mysqlCreds.database}", "$mysqlTable", - | host = "${mysqlCreds.host}", username = "${mysqlCreds.username}", password = "${mysqlCreds.password}")""".stripMargin + s"""MySQL.InferAndRead("${mysqlCreds.getDatabase}", "$mysqlTable", + | host = "${mysqlCreds.getHost}", username = "${mysqlCreds.getUser}", password = "${mysqlCreds.getPassword}")""".stripMargin ) { it => it should evaluateTo( """[ @@ -126,9 +126,9 @@ import raw.testing.tags.TruffleTests } test( - s"""MySQL.Read("${mysqlCreds.database}", "$mysqlTable", + s"""MySQL.Read("${mysqlCreds.getDatabase}", "$mysqlTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${mysqlCreds.host}", username = "${mysqlCreds.username}", password = "${mysqlCreds.password}")""".stripMargin + | host = "${mysqlCreds.getHost}", username = "${mysqlCreds.getUser}", password = "${mysqlCreds.getPassword}")""".stripMargin ) { it => it should orderEvaluateTo( """[ @@ -142,10 +142,10 @@ import raw.testing.tags.TruffleTests ignore(s""" |let | d = Location.Describe(MySQL.Build( - | "mysql://${mysqlCreds.database}/$mysqlTable", - | host = "${mysqlCreds.host}", - | username = "${mysqlCreds.username}", - | password = "${mysqlCreds.password}" + | "mysql://${mysqlCreds.getDatabase}/$mysqlTable", + | host = "${mysqlCreds.getHost}", + | username = "${mysqlCreds.getUser}", + | password = "${mysqlCreds.getPassword}" | )) |in | d.columns @@ -160,53 +160,53 @@ import raw.testing.tags.TruffleTests // no credentials test( - s"""MySQL.InferAndRead("${mysqlCreds.database}", "$mysqlTable" )""".stripMargin - )(it => it should runErrorAs(s"""unknown database credential: ${mysqlCreds.database}""".stripMargin)) + s"""MySQL.InferAndRead("${mysqlCreds.getDatabase}", "$mysqlTable" )""".stripMargin + )(it => it should runErrorAs(s"""unknown credential: ${mysqlCreds.getDatabase}""".stripMargin)) test( - s"""MySQL.Read("${mysqlCreds.database}", "$mysqlTable", + s"""MySQL.Read("${mysqlCreds.getDatabase}", "$mysqlTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)) |)""".stripMargin - )(it => it should runErrorAs(s"""unknown database credential: ${mysqlCreds.database}""".stripMargin)) + )(it => it should runErrorAs(s"""unknown credential: ${mysqlCreds.getDatabase}""".stripMargin)) // server does not exist test( s"""MySQL.Read( - | "${badMysqlCreds.database}", "$mysqlTable", + | "${badMysqlCreds.getDatabase}", "$mysqlTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${badMysqlCreds.host}", username = "${mysqlCreds.username}", password = "${mysqlCreds.password}" + | host = "${badMysqlCreds.getHost}", username = "${mysqlCreds.getUser}", password = "${mysqlCreds.getPassword}" |)""".stripMargin - )(it => it should runErrorAs(s"""unknown host: ${badMysqlCreds.host}""".stripMargin)) + )(it => it should runErrorAs(s"""unknown host: ${badMysqlCreds.getHost}""".stripMargin)) // wrong port // Note that when there is a wrong port supplied, the test takes a long time to run and we get a connect time out error. ignore( s"""MySQL.Read( - | "${mysqlCreds.database}", "$mysqlTable", + | "${mysqlCreds.getDatabase}", "$mysqlTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${mysqlCreds.host}", username = "${mysqlCreds.username}", password = "${mysqlCreds.password}", port = 1234 + | host = "${mysqlCreds.getHost}", username = "${mysqlCreds.getUser}", password = "${mysqlCreds.getPassword}", port = 1234 |)""".stripMargin - )(it => it should runErrorAs(s"""connect timed out: ${mysqlCreds.database}""".stripMargin)) + )(it => it should runErrorAs(s"""connect timed out: ${mysqlCreds.getDatabase}""".stripMargin)) // No password test( s"""MySQL.Read( - | "${mysqlCreds.database}", "$mysqlTable", + | "${mysqlCreds.getDatabase}", "$mysqlTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${mysqlCreds.host}" + | host = "${mysqlCreds.getHost}" |)""".stripMargin )(it => it should runErrorAs("""username is required""".stripMargin)) // wrong password test( s"""MySQL.Read( - | "${mysqlCreds.database}", "$mysqlTable", + | "${mysqlCreds.getDatabase}", "$mysqlTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${mysqlCreds.host}", username = "${mysqlCreds.username}", password = "wrong!" + | host = "${mysqlCreds.getHost}", username = "${mysqlCreds.getUser}", password = "wrong!" |)""".stripMargin )(it => it should runErrorAs("""authentication failed""".stripMargin)) - test(s"""MySQL.InferAndQuery("$mysqlRegDb", "SELECT * FROM ${mysqlCreds.database}.$mysqlTable")""") { it => + test(s"""MySQL.InferAndQuery("$mysqlRegDb", "SELECT * FROM ${mysqlCreds.getDatabase}.$mysqlTable")""") { it => it should evaluateTo( """[ | {a: 1, b: 1, c: 1.5, d: 1.5, x: "x1", y: "y1"}, @@ -217,8 +217,8 @@ import raw.testing.tags.TruffleTests } test( - s"""MySQL.InferAndQuery("${mysqlCreds.database}", "SELECT * FROM $mysqlTable", - | host = "${mysqlCreds.host}", username = "${mysqlCreds.username}", password = "${mysqlCreds.password}" )""".stripMargin + s"""MySQL.InferAndQuery("${mysqlCreds.getDatabase}", "SELECT * FROM $mysqlTable", + | host = "${mysqlCreds.getHost}", username = "${mysqlCreds.getUser}", password = "${mysqlCreds.getPassword}" )""".stripMargin ) { it => it should evaluateTo( """[ @@ -242,9 +242,9 @@ import raw.testing.tags.TruffleTests } test( - s"""MySQL.Query("${mysqlCreds.database}", "SELECT * FROM $mysqlTable", + s"""MySQL.Query("${mysqlCreds.getDatabase}", "SELECT * FROM $mysqlTable", | type collection(record(a: int, b: int, c: double, d: double, x: string, y: string)), - | host = "${mysqlCreds.host}", username = "${mysqlCreds.username}", password = "${mysqlCreds.password}" )""".stripMargin + | host = "${mysqlCreds.getHost}", username = "${mysqlCreds.getUser}", password = "${mysqlCreds.getPassword}" )""".stripMargin ) { it => it should evaluateTo( """[ @@ -295,14 +295,14 @@ import raw.testing.tags.TruffleTests s"""List.Transform(["$mysqlTable", "dont_exist"], | table -> | Collection.Count( - | MySQL.Query("${mysqlCreds.database}", "SELECT * FROM " + table, + | MySQL.Query("${mysqlCreds.getDatabase}", "SELECT * FROM " + table, | type collection(record(a: int, b: int, c: double, d: double, x: string, y: string)), - | host = "${mysqlCreds.host}", username = "${mysqlCreds.username}", - | password = "${mysqlCreds.password}") + | host = "${mysqlCreds.getHost}", username = "${mysqlCreds.getUser}", + | password = "${mysqlCreds.getPassword}") | ))""".stripMargin ) { it => val error = - s"""failed to read from database mysql:${mysqlCreds.database}: Table '${mysqlCreds.database}.dont_exist' doesn't exist""" + s"""failed to read from database mysql:${mysqlCreds.getDatabase}: Table '${mysqlCreds.getDatabase}.dont_exist' doesn't exist""" it should evaluateTo(s"""[3L, Error.Build("$error")]""") } diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/OraclePackageTest.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/OraclePackageTest.scala index 944e20e03..bddc5a8a7 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/OraclePackageTest.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/OraclePackageTest.scala @@ -68,7 +68,7 @@ import raw.testing.tags.TruffleTests test( s"""Oracle.InferAndRead("$oracleDb", "$oracleSchema", "$oracleTable", - | host = "${oracleCreds.host}", username = "${oracleCreds.username}", password = "${oracleCreds.password}")""".stripMargin + | host = "${oracleCreds.getHost}", username = "${oracleCreds.getUser}", password = "${oracleCreds.getPassword}")""".stripMargin ) { it => assume(!compilerService.language.contains("rql2-truffle")) it should evaluateTo( @@ -83,7 +83,7 @@ import raw.testing.tags.TruffleTests test( s"""Oracle.Read("$oracleDb", "$oracleSchema", "$oracleTable", | type collection(record(A: int, B: int, C: double, D: double, X: int, Y: string)), - | host = "${oracleCreds.host}", username = "${oracleCreds.username}", password = "${oracleCreds.password}" )""".stripMargin + | host = "${oracleCreds.getHost}", username = "${oracleCreds.getUser}", password = "${oracleCreds.getPassword}" )""".stripMargin ) { it => assume(!compilerService.language.contains("rql2-truffle")) it should orderEvaluateTo( @@ -99,9 +99,9 @@ import raw.testing.tags.TruffleTests |let | d = Location.Describe(Oracle.Build( | "oracle://$oracleDb/$oracleSchema/$oracleTable", - | host = "${oracleCreds.host}", - | username = "${oracleCreds.username}", - | password = "${oracleCreds.password}" + | host = "${oracleCreds.getHost}", + | username = "${oracleCreds.getUser}", + | password = "${oracleCreds.getPassword}" | )) |in | d.columns @@ -117,7 +117,7 @@ import raw.testing.tags.TruffleTests // no credentials test( s"""Oracle.InferAndRead("$oracleDb", "$oracleSchema", "$oracleTable" )""".stripMargin - )(it => it should runErrorAs(s"""unknown database credential: $oracleDb""".stripMargin)) + )(it => it should runErrorAs(s"""unknown credential: $oracleDb""".stripMargin)) test( s"""Oracle.Read("$oracleSchema", "rdbmstest", "$oracleTable", @@ -133,7 +133,7 @@ import raw.testing.tags.TruffleTests s"""Oracle.Read( | "$oracleDb", "$oracleSchema", "$oracleTable", | type collection(record(A: int, B: int, C: double, D: double, X: int, Y: string)), - | host = "oracle.localdomain", username = "${oracleCreds.username}", password = "${oracleCreds.password}" + | host = "oracle.localdomain", username = "${oracleCreds.getUser}", password = "${oracleCreds.getPassword}" |)""".stripMargin ) { it => assume(!compilerService.language.contains("rql2-truffle")) @@ -145,7 +145,7 @@ import raw.testing.tags.TruffleTests s"""Oracle.Read( | "$oracleDb", "$oracleSchema", "$oracleTable", | type collection(record(A: int, B: int, C: double, D: double, X: int, Y: string)), - | host = "localhost", username = "${oracleCreds.username}", password = "${oracleCreds.password}" + | host = "localhost", username = "${oracleCreds.getUser}", password = "${oracleCreds.getPassword}" |)""".stripMargin ) { it => assume(!compilerService.language.contains("rql2-truffle")) @@ -158,7 +158,7 @@ import raw.testing.tags.TruffleTests s"""Oracle.Read( | "$oracleDb", "$oracleSchema", "$oracleTable", | type collection(record(A: int, B: int, C: double, D: double, X: int, Y: string)), - | host = "test-oracle.raw-labs.com", username = "${oracleCreds.username}", password = "${oracleCreds.password}", port = 1234 + | host = "test-oracle.raw-labs.com", username = "${oracleCreds.getUser}", password = "${oracleCreds.getPassword}", port = 1234 |)""".stripMargin ) { it => assume(!compilerService.language.contains("rql2-truffle")) @@ -182,7 +182,7 @@ import raw.testing.tags.TruffleTests s"""Oracle.Read( | "$oracleDb", "$oracleSchema", "$oracleTable", | type collection(record(A: int, B: int, C: double, D: double, X: int, Y: string)), - | host = "test-oracle.raw-labs.com", username = "${oracleCreds.username}", password = "wrong!" + | host = "test-oracle.raw-labs.com", username = "${oracleCreds.getUser}", password = "wrong!" |)""".stripMargin ) { it => assume(!compilerService.language.contains("rql2-truffle")) @@ -201,7 +201,7 @@ import raw.testing.tags.TruffleTests test( s"""Oracle.InferAndQuery("$oracleDb", "SELECT * FROM $oracleSchema.$oracleTable", - | host = "test-oracle.raw-labs.com", username = "${oracleCreds.username}", password = "${oracleCreds.password}" )""".stripMargin + | host = "test-oracle.raw-labs.com", username = "${oracleCreds.getUser}", password = "${oracleCreds.getPassword}" )""".stripMargin ) { it => it should evaluateTo( """[ @@ -227,7 +227,7 @@ import raw.testing.tags.TruffleTests test( s"""Oracle.Query("$oracleDb", "SELECT * FROM $oracleSchema.$oracleTable", | type collection(record(A: int, B: int, C: double, D: double, X: string, Y: string)), - | host = "${oracleCreds.host}", username = "${oracleCreds.username}", password = "${oracleCreds.password}" )""".stripMargin + | host = "${oracleCreds.getHost}", username = "${oracleCreds.getUser}", password = "${oracleCreds.getPassword}" )""".stripMargin ) { it => it should evaluateTo( """[ diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/PostgreSQLPackageTest.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/PostgreSQLPackageTest.scala index a965f96b1..62bc05784 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/PostgreSQLPackageTest.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/PostgreSQLPackageTest.scala @@ -113,8 +113,8 @@ import raw.testing.tags.TruffleTests } test( - s"""PostgreSQL.InferAndRead("${pgsqlCreds.database}", "$pgSchema", "$pgTable", - | host = "${pgsqlCreds.host}", username = "${pgsqlCreds.username}", password = "${pgsqlCreds.password}")""".stripMargin + s"""PostgreSQL.InferAndRead("${pgsqlCreds.getDatabase}", "$pgSchema", "$pgTable", + | host = "${pgsqlCreds.getHost}", username = "${pgsqlCreds.getUser}", password = "${pgsqlCreds.getPassword}")""".stripMargin ) { it => it should evaluateTo( """[ @@ -126,9 +126,9 @@ import raw.testing.tags.TruffleTests } test( - s"""PostgreSQL.Read("${pgsqlCreds.database}", "$pgSchema", "$pgTable", + s"""PostgreSQL.Read("${pgsqlCreds.getDatabase}", "$pgSchema", "$pgTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${pgsqlCreds.host}", username = "${pgsqlCreds.username}", password = "${pgsqlCreds.password}" )""".stripMargin + | host = "${pgsqlCreds.getHost}", username = "${pgsqlCreds.getUser}", password = "${pgsqlCreds.getPassword}" )""".stripMargin ) { it => it should orderEvaluateTo( """[ @@ -142,10 +142,10 @@ import raw.testing.tags.TruffleTests ignore(s""" |let | d = Location.Describe(PostgreSQL.Build( - | "pgsql://${pgsqlCreds.database}/$pgSchema/$pgTable", - | host = "${pgsqlCreds.host}", - | username = "${pgsqlCreds.username}", - | password = "${pgsqlCreds.password}" + | "pgsql://${pgsqlCreds.getDatabase}/$pgSchema/$pgTable", + | host = "${pgsqlCreds.getHost}", + | username = "${pgsqlCreds.getUser}", + | password = "${pgsqlCreds.getPassword}" | )) |in | d.columns @@ -160,49 +160,49 @@ import raw.testing.tags.TruffleTests // no credentials test( - s"""PostgreSQL.InferAndRead("${pgsqlCreds.database}", "$pgSchema", "$pgTable" )""".stripMargin - )(it => it should runErrorAs(s"""unknown database credential: ${pgsqlCreds.database}""".stripMargin)) + s"""PostgreSQL.InferAndRead("${pgsqlCreds.getDatabase}", "$pgSchema", "$pgTable" )""".stripMargin + )(it => it should runErrorAs(s"""unknown credential: ${pgsqlCreds.getDatabase}""".stripMargin)) test( - s"""PostgreSQL.Read("${pgsqlCreds.database}", "$pgSchema", "$pgTable", + s"""PostgreSQL.Read("${pgsqlCreds.getDatabase}", "$pgSchema", "$pgTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)) |)""".stripMargin - )(it => it should runErrorAs(s"""unknown database credential: ${pgsqlCreds.database}""".stripMargin)) + )(it => it should runErrorAs(s"""unknown credential: ${pgsqlCreds.getDatabase}""".stripMargin)) // server does not exist test( s"""PostgreSQL.Read( - | "${pgsqlCreds.database}", "$pgSchema", "$pgTable", + | "${pgsqlCreds.getDatabase}", "$pgSchema", "$pgTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${badMysqlCreds.host}", username = "${pgsqlCreds.username}", password = "${pgsqlCreds.password}" + | host = "${badMysqlCreds.getHost}", username = "${pgsqlCreds.getUser}", password = "${pgsqlCreds.getPassword}" |)""".stripMargin - )(it => it should runErrorAs(s"""unknown host: ${badMysqlCreds.host}""".stripMargin)) + )(it => it should runErrorAs(s"""unknown host: ${badMysqlCreds.getHost}""".stripMargin)) // wrong port // When there is a wrong port supplied the test takes a long time to run and we get an connect time out error. ignore( s"""PostgreSQL.Read( - | "${pgsqlCreds.database}", "$pgSchema", "$pgTable", + | "${pgsqlCreds.getDatabase}", "$pgSchema", "$pgTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${pgsqlCreds.host}", username = "${pgsqlCreds.username}", password = "${pgsqlCreds.password}", port = 1234 + | host = "${pgsqlCreds.getHost}", username = "${pgsqlCreds.getUser}", password = "${pgsqlCreds.getPassword}", port = 1234 |)""".stripMargin - )(it => it should runErrorAs(s"""connect timed out: ${pgsqlCreds.host}""".stripMargin)) + )(it => it should runErrorAs(s"""connect timed out: ${pgsqlCreds.getHost}""".stripMargin)) // No password test( s"""PostgreSQL.Read( - | "${pgsqlCreds.database}", "$pgSchema", "$pgTable", + | "${pgsqlCreds.getDatabase}", "$pgSchema", "$pgTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${pgsqlCreds.host}" + | host = "${pgsqlCreds.getHost}" |)""".stripMargin )(it => it should runErrorAs("username is required")) // wrong password test( s"""PostgreSQL.Read( - | "${pgsqlCreds.database}", "$pgSchema", "$pgTable", + | "${pgsqlCreds.getDatabase}", "$pgSchema", "$pgTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${pgsqlCreds.host}", username = "${pgsqlCreds.username}", password = "wrong!" + | host = "${pgsqlCreds.getHost}", username = "${pgsqlCreds.getUser}", password = "wrong!" |)""".stripMargin )(it => it should runErrorAs("authentication failed")) @@ -217,8 +217,8 @@ import raw.testing.tags.TruffleTests } test( - s"""PostgreSQL.InferAndQuery("${pgsqlCreds.database}", "SELECT * FROM $pgSchema.$pgTable", - | host = "${pgsqlCreds.host}", username = "${pgsqlCreds.username}", password = "${pgsqlCreds.password}" )""".stripMargin + s"""PostgreSQL.InferAndQuery("${pgsqlCreds.getDatabase}", "SELECT * FROM $pgSchema.$pgTable", + | host = "${pgsqlCreds.getHost}", username = "${pgsqlCreds.getUser}", password = "${pgsqlCreds.getPassword}" )""".stripMargin ) { it => it should evaluateTo( """[ @@ -242,9 +242,9 @@ import raw.testing.tags.TruffleTests } test( - s"""PostgreSQL.Query("${pgsqlCreds.database}", "SELECT * FROM $pgSchema.$pgTable", + s"""PostgreSQL.Query("${pgsqlCreds.getDatabase}", "SELECT * FROM $pgSchema.$pgTable", | type collection(record(a: int, b: int, c: double, d: double, x: string, y: string)), - | host = "${pgsqlCreds.host}", username = "${pgsqlCreds.username}", password = "${pgsqlCreds.password}" )""".stripMargin + | host = "${pgsqlCreds.getHost}", username = "${pgsqlCreds.getUser}", password = "${pgsqlCreds.getPassword}" )""".stripMargin ) { it => it should evaluateTo( """[ @@ -259,14 +259,14 @@ import raw.testing.tags.TruffleTests s"""List.Transform(["$pgTable", "dont_exist"], | table -> | Collection.Count( - | PostgreSQL.Query("${pgsqlCreds.database}", "SELECT * FROM $pgSchema." + table, + | PostgreSQL.Query("${pgsqlCreds.getDatabase}", "SELECT * FROM $pgSchema." + table, | type collection(record(a: int, b: int, c: double, d: double, x: string, y: string)), - | host = "${pgsqlCreds.host}", username = "${pgsqlCreds.username}", - | password = "${pgsqlCreds.password}") + | host = "${pgsqlCreds.getHost}", username = "${pgsqlCreds.getUser}", + | password = "${pgsqlCreds.getPassword}") | ))""".stripMargin ) { it => val error = - s"""failed to read from database pgsql:${pgsqlCreds.database}: ERROR: relation \\"$pgSchema.dont_exist\\" does not exist\\n Position: 15""" + s"""failed to read from database pgsql:${pgsqlCreds.getDatabase}: ERROR: relation \\"$pgSchema.dont_exist\\" does not exist\\n Position: 15""" it should evaluateTo(s"""[3L, Error.Build("$error")]""") } diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/S3PackageTest.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/S3PackageTest.scala index 0af280d78..44eccfcf0 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/S3PackageTest.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/S3PackageTest.scala @@ -27,9 +27,9 @@ import raw.testing.tags.TruffleTests | data = Csv.InferAndRead( | S3.Build( | "s3://rawlabs-private-test-data/students.csv", - | region = "${UnitTestPrivateBucketCred.region.get}", - | accessKey = "${UnitTestPrivateBucketCred.accessKey.get}", - | secretKey = "${UnitTestPrivateBucketCred.secretKey.get}" + | region = "${UnitTestPrivateBucketCred.getRegion}", + | accessKey = "${UnitTestPrivateBucketCred.getAccessSecretKey.getAccessKey}", + | secretKey = "${UnitTestPrivateBucketCred.getAccessSecretKey.getSecretKey}" | ) | ) |in @@ -45,9 +45,9 @@ import raw.testing.tags.TruffleTests | data = Location.Ls( | S3.Build( | "s3://$unitTestPrivateBucketUsEast1/csvs/01", - | region = "${unitTestPrivateBucketUsEast1Cred.region.get}", - | accessKey = "${unitTestPrivateBucketUsEast1Cred.accessKey.get}", - | secretKey = "${unitTestPrivateBucketUsEast1Cred.secretKey.get}" + | region = "${unitTestPrivateBucketUsEast1Cred.getRegion}", + | accessKey = "${unitTestPrivateBucketUsEast1Cred.getAccessSecretKey.getAccessKey}", + | secretKey = "${unitTestPrivateBucketUsEast1Cred.getAccessSecretKey.getSecretKey}" | ) | ) |in @@ -62,8 +62,8 @@ import raw.testing.tags.TruffleTests | data = Location.Ls( | S3.Build( | "s3://$unitTestPrivateBucketUsEast1/csvs/01", - | accessKey = "${unitTestPrivateBucketUsEast1Cred.accessKey.get}", - | secretKey = "${unitTestPrivateBucketUsEast1Cred.secretKey.get}" + | accessKey = "${unitTestPrivateBucketUsEast1Cred.getAccessSecretKey.getAccessKey}", + | secretKey = "${unitTestPrivateBucketUsEast1Cred.getAccessSecretKey.getSecretKey}" | ) | ) |in diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/SQLServerPackageTest.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/SQLServerPackageTest.scala index c6ccff467..1d50a22af 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/SQLServerPackageTest.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/SQLServerPackageTest.scala @@ -112,7 +112,7 @@ import raw.testing.tags.TruffleTests test( s"""SQLServer.InferAndRead("$sqlServDb", "$sqlServSchema", "$sqlServTable", - | host = "${sqlServerCreds.host}", username = "${sqlServerCreds.username}", password = "${sqlServerCreds.password}")""".stripMargin + | host = "${sqlServerCreds.getHost}", username = "${sqlServerCreds.getUser}", password = "${sqlServerCreds.getPassword}")""".stripMargin ) { it => it should evaluateTo( """[ @@ -126,7 +126,7 @@ import raw.testing.tags.TruffleTests test( s"""SQLServer.Read("$sqlServDb", "$sqlServSchema", "$sqlServTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${sqlServerCreds.host}", username = "${sqlServerCreds.username}", password = "${sqlServerCreds.password}" )""".stripMargin + | host = "${sqlServerCreds.getHost}", username = "${sqlServerCreds.getUser}", password = "${sqlServerCreds.getPassword}" )""".stripMargin ) { it => it should orderEvaluateTo( """[ @@ -141,9 +141,9 @@ import raw.testing.tags.TruffleTests |let | d = Location.Describe(SQLServer.Build( | "sqlserver://$sqlServDb/$sqlServSchema/$sqlServTable", - | host = "${sqlServerCreds.host}", - | username = "${sqlServerCreds.username}", - | password = "${sqlServerCreds.password}" + | host = "${sqlServerCreds.getHost}", + | username = "${sqlServerCreds.getUser}", + | password = "${sqlServerCreds.getPassword}" | )) |in | d.columns @@ -159,20 +159,20 @@ import raw.testing.tags.TruffleTests // no credentials test( s"""SQLServer.InferAndRead("$sqlServDb", "$sqlServSchema", "$sqlServTable" )""".stripMargin - )(it => it should runErrorAs(s"""unknown database credential: rawtest""".stripMargin)) + )(it => it should runErrorAs(s"""unknown credential: rawtest""".stripMargin)) test( s"""SQLServer.Read("$sqlServDb", "$sqlServSchema", "$sqlServTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)) |)""".stripMargin - )(it => it should runErrorAs(s"""unknown database credential: $sqlServDb""".stripMargin)) + )(it => it should runErrorAs(s"""unknown credential: $sqlServDb""".stripMargin)) // server does not exist test( s"""SQLServer.Read( | "$sqlServDb", "$sqlServSchema", "$sqlServTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "does-not-exist", username = "${sqlServerCreds.username}", password = "${sqlServerCreds.password}" + | host = "does-not-exist", username = "${sqlServerCreds.getUser}", password = "${sqlServerCreds.getPassword}" |)""".stripMargin )(it => it should runErrorAs("""error connecting to database: does-not-exist""".stripMargin)) @@ -182,16 +182,16 @@ import raw.testing.tags.TruffleTests s"""SQLServer.Read( | "$sqlServDb", "$sqlServSchema", "$sqlServTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${sqlServerCreds.host}", username = "${sqlServerCreds.username}", password = "${sqlServerCreds.password}", port = 1234 + | host = "${sqlServerCreds.getHost}", username = "${sqlServerCreds.getUser}", password = "${sqlServerCreds.getPassword}", port = 1234 |)""".stripMargin - )(it => it should runErrorAs(s"""connect timed out: ${sqlServerCreds.host}""".stripMargin)) + )(it => it should runErrorAs(s"""connect timed out: ${sqlServerCreds.getHost}""".stripMargin)) // No password test( s"""SQLServer.Read( | "$sqlServDb", "$sqlServSchema", "$sqlServTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${sqlServerCreds.host}" + | host = "${sqlServerCreds.getHost}" |)""".stripMargin )(it => it should runErrorAs("username is required")) @@ -200,9 +200,9 @@ import raw.testing.tags.TruffleTests s"""SQLServer.Read( | "$sqlServDb", "$sqlServSchema", "$sqlServTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | host = "${sqlServerCreds.host}", username = "${sqlServerCreds.username}", password = "wrong!" + | host = "${sqlServerCreds.getHost}", username = "${sqlServerCreds.getUser}", password = "wrong!" |)""".stripMargin - )(it => it should runErrorAs(s"""Login failed for user '${sqlServerCreds.username}'""".stripMargin)) + )(it => it should runErrorAs(s"""Login failed for user '${sqlServerCreds.getUser}'""".stripMargin)) test(s"""SQLServer.InferAndQuery("$sqlServRegDb", "SELECT * FROM $sqlServSchema.$sqlServTable")""") { it => it should evaluateTo( @@ -216,7 +216,7 @@ import raw.testing.tags.TruffleTests test( s"""SQLServer.InferAndQuery("$sqlServDb", "SELECT * FROM $sqlServSchema.$sqlServTable", - | host = "${sqlServerCreds.host}", username = "${sqlServerCreds.username}", password = "${sqlServerCreds.password}" )""".stripMargin + | host = "${sqlServerCreds.getHost}", username = "${sqlServerCreds.getUser}", password = "${sqlServerCreds.getPassword}" )""".stripMargin ) { it => it should evaluateTo( """[ @@ -242,7 +242,7 @@ import raw.testing.tags.TruffleTests test( s"""SQLServer.Query("$sqlServDb", "SELECT * FROM $sqlServSchema.$sqlServTable", | type collection(record(a: int, b: int, c: double, d: double, x: string, y: string)), - | host = "${sqlServerCreds.host}", username = "${sqlServerCreds.username}", password = "${sqlServerCreds.password}" )""".stripMargin + | host = "${sqlServerCreds.getHost}", username = "${sqlServerCreds.getUser}", password = "${sqlServerCreds.getPassword}" )""".stripMargin ) { it => it should evaluateTo( """[ @@ -259,8 +259,8 @@ import raw.testing.tags.TruffleTests | Collection.Count( | SQLServer.Query("$sqlServDb", "SELECT * FROM $sqlServSchema." + table, | type collection(record(a: int, b: int, c: double, d: double, x: string, y: string)), - | host = "${sqlServerCreds.host}", username = "${sqlServerCreds.username}", - | password = "${sqlServerCreds.password}") + | host = "${sqlServerCreds.getHost}", username = "${sqlServerCreds.getUser}", + | password = "${sqlServerCreds.getPassword}") | ))""".stripMargin ) { it => val error = diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/SnowflakePackageTest.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/SnowflakePackageTest.scala index b3bb66a96..21b49f418 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/SnowflakePackageTest.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/builtin/credentials/SnowflakePackageTest.scala @@ -216,8 +216,8 @@ import raw.testing.tags.TruffleTests } test( - s"""Snowflake.InferAndRead("${snowflakeCreds.database}", "$snowflakeSchema", "$snowflakeMainTable", - | accountID = "${snowflakeCreds.accountIdentifier}", username = "${snowflakeCreds.username}", password = "${snowflakeCreds.password}")""".stripMargin + s"""Snowflake.InferAndRead("${snowflakeCreds.getDatabase}", "$snowflakeSchema", "$snowflakeMainTable", + | accountID = "${snowflakeCreds.getAccountIdentifier}", username = "${snowflakeCreds.getUser}", password = "${snowflakeCreds.getPassword}")""".stripMargin ) { it => it should evaluateTo( """[ @@ -229,9 +229,9 @@ import raw.testing.tags.TruffleTests } test( - s"""Snowflake.Read("${snowflakeCreds.database}", "$snowflakeSchema", "$snowflakeMainTable", + s"""Snowflake.Read("${snowflakeCreds.getDatabase}", "$snowflakeSchema", "$snowflakeMainTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | accountID = "${snowflakeCreds.accountIdentifier}", username = "${snowflakeCreds.username}", password = "${snowflakeCreds.password}" )""".stripMargin + | accountID = "${snowflakeCreds.getAccountIdentifier}", username = "${snowflakeCreds.getUser}", password = "${snowflakeCreds.getPassword}" )""".stripMargin ) { it => it should orderEvaluateTo( """[ @@ -245,10 +245,10 @@ import raw.testing.tags.TruffleTests ignore(s""" |let | d = Location.Describe(Snowflake.Build( - | "snowflake://${snowflakeCreds.database}/$snowflakeSchema/$snowflakeMainTable", - | accountID = "${snowflakeCreds.accountIdentifier}", - | username = "${snowflakeCreds.username}", - | password = "${snowflakeCreds.password}" + | "snowflake://${snowflakeCreds.getDatabase}/$snowflakeSchema/$snowflakeMainTable", + | accountID = "${snowflakeCreds.getAccountIdentifier}", + | username = "${snowflakeCreds.getUser}", + | password = "${snowflakeCreds.getPassword}" | )) |in | d.columns @@ -263,25 +263,25 @@ import raw.testing.tags.TruffleTests // no credentials test( - s"""Snowflake.InferAndRead("${snowflakeCreds.database}", "$snowflakeSchema", "$snowflakeMainTable" )""".stripMargin + s"""Snowflake.InferAndRead("${snowflakeCreds.getDatabase}", "$snowflakeSchema", "$snowflakeMainTable" )""".stripMargin )(it => it should runErrorAs( - s"""unknown database credential: ${snowflakeCreds.database}""".stripMargin + s"""unknown credential: ${snowflakeCreds.getDatabase}""".stripMargin ) ) test( - s"""Snowflake.Read("${snowflakeCreds.database}", "$snowflakeSchema", "$snowflakeMainTable", + s"""Snowflake.Read("${snowflakeCreds.getDatabase}", "$snowflakeSchema", "$snowflakeMainTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)) |)""".stripMargin - )(it => it should runErrorAs(s"""unknown database credential: ${snowflakeCreds.database}""".stripMargin)) + )(it => it should runErrorAs(s"""unknown credential: ${snowflakeCreds.getDatabase}""".stripMargin)) // server does not exist test( s"""Snowflake.Read( - | "${snowflakeCreds.database}", "$snowflakeSchema", "$snowflakeMainTable", + | "${snowflakeCreds.getDatabase}", "$snowflakeSchema", "$snowflakeMainTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | accountID = "does-not-exist", username = "${snowflakeCreds.username}", password = "${snowflakeCreds.password}" + | accountID = "does-not-exist", username = "${snowflakeCreds.getUser}", password = "${snowflakeCreds.getPassword}" |)""".stripMargin ) { it => it should runErrorAs( @@ -292,22 +292,22 @@ import raw.testing.tags.TruffleTests // No username, no password test( s"""Snowflake.Read( - | "${snowflakeCreds.database}", "$snowflakeSchema", "$snowflakeMainTable", + | "${snowflakeCreds.getDatabase}", "$snowflakeSchema", "$snowflakeMainTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | accountID = "${snowflakeCreds.accountIdentifier}" + | accountID = "${snowflakeCreds.getAccountIdentifier}" |)""".stripMargin )(it => it should runErrorAs(s"""username is required""".stripMargin)) // wrong password test( s"""Snowflake.Read( - | "${snowflakeCreds.database}", "$snowflakeSchema", "$snowflakeMainTable", + | "${snowflakeCreds.getDatabase}", "$snowflakeSchema", "$snowflakeMainTable", | type collection(record(a: int, b: int, c: double, d: double, x: int, y: string)), - | accountID = "${snowflakeCreds.accountIdentifier}", username = "${snowflakeCreds.username}", password = "wrong!" + | accountID = "${snowflakeCreds.getAccountIdentifier}", username = "${snowflakeCreds.getUser}", password = "wrong!" |)""".stripMargin ) { it => it should runErrorAs( - s"""unable to establish connection to ${snowflakeCreds.accountIdentifier}: Incorrect username or password was specified.""".stripMargin + s"""unable to establish connection to ${snowflakeCreds.getAccountIdentifier}: Incorrect username or password was specified.""".stripMargin ) } @@ -322,8 +322,8 @@ import raw.testing.tags.TruffleTests } test( - s"""Snowflake.InferAndQuery("${snowflakeCreds.database}", "SELECT * FROM public.$snowflakeMainTable", - | accountID = "${snowflakeCreds.accountIdentifier}", username = "${snowflakeCreds.username}", password = "${snowflakeCreds.password}" )""".stripMargin + s"""Snowflake.InferAndQuery("${snowflakeCreds.getDatabase}", "SELECT * FROM public.$snowflakeMainTable", + | accountID = "${snowflakeCreds.getAccountIdentifier}", username = "${snowflakeCreds.getUser}", password = "${snowflakeCreds.getPassword}" )""".stripMargin ) { it => it should evaluateTo( """[ @@ -347,9 +347,9 @@ import raw.testing.tags.TruffleTests } test( - s"""Snowflake.Query("${snowflakeCreds.database}", "SELECT * FROM public.$snowflakeMainTable", + s"""Snowflake.Query("${snowflakeCreds.getDatabase}", "SELECT * FROM public.$snowflakeMainTable", | type collection(record(a: int, b: int, c: double, d: double, x: string, y: string)), - | accountID = "${snowflakeCreds.accountIdentifier}", username = "${snowflakeCreds.username}", password = "${snowflakeCreds.password}" )""".stripMargin + | accountID = "${snowflakeCreds.getAccountIdentifier}", username = "${snowflakeCreds.getUser}", password = "${snowflakeCreds.getPassword}" )""".stripMargin ) { it => it should evaluateTo( """[ @@ -361,10 +361,10 @@ import raw.testing.tags.TruffleTests } test( - s"""Snowflake.InferAndRead("${snowflakeCreds.database}", "$snowflakeSchema", "$snowflakeSideTable", - | accountID = "${snowflakeCreds.accountIdentifier}", - | username = "${snowflakeCreds.username}", - | password = "${snowflakeCreds.password}", + s"""Snowflake.InferAndRead("${snowflakeCreds.getDatabase}", "$snowflakeSchema", "$snowflakeSideTable", + | accountID = "${snowflakeCreds.getAccountIdentifier}", + | username = "${snowflakeCreds.getUser}", + | password = "${snowflakeCreds.getPassword}", | options = [{"timezone", "America/Los_Angeles"}] |)""".stripMargin ) { it => @@ -405,10 +405,10 @@ import raw.testing.tags.TruffleTests } test( - s"""Snowflake.InferAndQuery("${snowflakeCreds.database}", "SELECT * FROM $snowflakeSchema.$snowflakeSideTable", - | accountID = "${snowflakeCreds.accountIdentifier}", - | username = "${snowflakeCreds.username}", - | password = "${snowflakeCreds.password}", + s"""Snowflake.InferAndQuery("${snowflakeCreds.getDatabase}", "SELECT * FROM $snowflakeSchema.$snowflakeSideTable", + | accountID = "${snowflakeCreds.getAccountIdentifier}", + | username = "${snowflakeCreds.getUser}", + | password = "${snowflakeCreds.getPassword}", | options = [{"timezone", "UTC"}] |)""".stripMargin ) { it => @@ -452,13 +452,13 @@ import raw.testing.tags.TruffleTests s"""List.Transform(["$snowflakeMainTable", "dont_exist"], | table -> | Collection.Count( - | Snowflake.Query("${snowflakeCreds.database}", "SELECT * FROM public." + table, + | Snowflake.Query("${snowflakeCreds.getDatabase}", "SELECT * FROM public." + table, | type collection(record(a: int, b: int, c: double, d: double, x: string, y: string)), - | accountID = "${snowflakeCreds.accountIdentifier}", username = "${snowflakeCreds.username}", - | password = "${snowflakeCreds.password}")))""".stripMargin + | accountID = "${snowflakeCreds.getAccountIdentifier}", username = "${snowflakeCreds.getUser}", + | password = "${snowflakeCreds.getPassword}")))""".stripMargin ) { it => val error = - s"""failed to read from database snowflake:${snowflakeCreds.database}: SQL compilation error:\\nObject '${snowflakeCreds.database.toUpperCase}.PUBLIC.DONT_EXIST' does not exist or not authorized.""".stripMargin + s"""failed to read from database snowflake:${snowflakeCreds.getDatabase}: SQL compilation error:\\nObject '${snowflakeCreds.getDatabase.toUpperCase}.PUBLIC.DONT_EXIST' does not exist or not authorized.""".stripMargin it should evaluateTo(s"""[3L, Error.Build("$error")]""") } diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/regressions/RD10767Test.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/regressions/RD10767Test.scala index ebe95e7c7..61060e389 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/regressions/RD10767Test.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/regressions/RD10767Test.scala @@ -35,8 +35,6 @@ class RD10767Test extends Rql2TruffleCompilerTestContext { Map.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, None, None ) @@ -60,8 +58,6 @@ class RD10767Test extends Rql2TruffleCompilerTestContext { Map.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, None, None ) diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/regressions/credentials/RD4445Test.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/regressions/credentials/RD4445Test.scala index e718c2cd9..7c0cab651 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/regressions/credentials/RD4445Test.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/regressions/credentials/RD4445Test.scala @@ -13,6 +13,7 @@ package raw.compiler.rql2.tests.regressions.credentials import raw.compiler.rql2.truffle.Rql2TruffleCompilerTestContext +import raw.protocol.DropboxAccessTokenConfig import raw.testing.tags.TruffleTests @TruffleTests class RD4445Test extends Rql2TruffleCompilerTestContext { @@ -21,7 +22,7 @@ import raw.testing.tags.TruffleTests property("raw.sources.dropbox.clientId", dropboxClientId) - httpHeaders("rawlabs-dropbox", Map("Authorization" -> ("Bearer " + dropboxLongLivedAccessToken))) + dropbox("rawlabs-dropbox", DropboxAccessTokenConfig.newBuilder().setAccessToken(dropboxLongLivedAccessToken).build()) test("""String.ReadLines("dropbox://rawlabs-dropbox/New folder/New Document")""")( _ should evaluateTo("""["Hello", "World", "Again!"]""") diff --git a/snapi-frontend/src/main/java/module-info.java b/snapi-frontend/src/main/java/module-info.java index 71adeb22e..478ad7569 100644 --- a/snapi-frontend/src/main/java/module-info.java +++ b/snapi-frontend/src/main/java/module-info.java @@ -38,6 +38,7 @@ requires jul.to.slf4j; requires org.graalvm.polyglot; requires raw.utils; + requires raw.protocol; requires raw.client; requires raw.sources; requires raw.snapi.parser; diff --git a/snapi-frontend/src/main/scala/raw/compiler/rql2/api/LocationDescription.scala b/snapi-frontend/src/main/scala/raw/compiler/rql2/api/LocationDescription.scala index 78532812a..711ec8aff 100644 --- a/snapi-frontend/src/main/scala/raw/compiler/rql2/api/LocationDescription.scala +++ b/snapi-frontend/src/main/scala/raw/compiler/rql2/api/LocationDescription.scala @@ -38,20 +38,13 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.scala.{ClassTagExtensions, DefaultScalaModule} import com.typesafe.scalalogging.StrictLogging -import raw.client.api.{ - JdbcLocation, - MySqlJdbcLocation, - OracleJdbcLocation, - PostgresJdbcLocation, - ProgramEnvironment, - SnowflakeJdbcLocation, - SqlServerJdbcLocation, - SqliteJdbcLocation, - TeradataJdbcLocation -} +import raw.protocol.LocationConfig +import raw.client.api.ProgramEnvironment import java.net.{HttpURLConnection, URI, URISyntaxException} +import scala.collection.JavaConverters._ + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes( Array( @@ -280,21 +273,42 @@ object LocationDescription extends StrictLogging { private val reader = jsonMapper.readerFor[LocationDescription] private val writer = jsonMapper.writerFor[LocationDescription] - def toLocationDescription(l: JdbcLocation): LocationDescription = { - l match { - case MySqlJdbcLocation(host, port, database, username, password) => - MySqlServerLocationDescription(host, port, database, username, password) - case OracleJdbcLocation(host, port, database, username, password) => - OracleServerLocationDescription(host, port, database, username, password) - case PostgresJdbcLocation(host, port, database, username, password) => - PostgresqlServerLocationDescription(host, port, database, username, password) - case SnowflakeJdbcLocation(database, username, password, accountIdentifier, parameters) => - SnowflakeServerLocationDescription(database, username, password, accountIdentifier, parameters) - case SqliteJdbcLocation(path) => SqliteServerLocationDescription(path) - case SqlServerJdbcLocation(host, port, database, username, password) => - SqlServerServerLocationDescription(host, port, database, username, password) - case TeradataJdbcLocation(host, port, database, username, password, parameters) => - TeradataServerLocationDescription(host, port, database, username, password, parameters) + def toLocationDescription(l: LocationConfig): LocationDescription = { + l.getConfigCase match { + case LocationConfig.ConfigCase.MYSQL => + val l1 = l.getMysql + MySqlServerLocationDescription(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword) + case LocationConfig.ConfigCase.ORACLE => + val l1 = l.getOracle + OracleServerLocationDescription(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword) + case LocationConfig.ConfigCase.POSTGRESQL => + val l1 = l.getPostgresql + PostgresqlServerLocationDescription(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword) + case LocationConfig.ConfigCase.SNOWFLAKE => + val l1 = l.getSnowflake + SnowflakeServerLocationDescription( + l1.getDatabase, + l1.getUser, + l1.getPassword, + l1.getAccountIdentifier, + l1.getParametersMap.asScala.toMap + ) + case LocationConfig.ConfigCase.SQLITE => + val l1 = l.getSqlite + SqliteServerLocationDescription(l1.getPath) + case LocationConfig.ConfigCase.SQLSERVER => + val l1 = l.getSqlserver + SqlServerServerLocationDescription(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword) + case LocationConfig.ConfigCase.TERADATA => + val l1 = l.getTeradata + TeradataServerLocationDescription( + l1.getHost, + l1.getPort, + l1.getDatabase, + l1.getUser, + l1.getPassword, + l1.getParametersMap.asScala.toMap + ) } } @@ -369,7 +383,7 @@ object LocationDescription extends StrictLogging { } } - def toLocation(l: JdbcLocation)(implicit settings: RawSettings): Location = { + def toLocation(l: LocationConfig)(implicit settings: RawSettings): Location = { toLocation(toLocationDescription(l)) } @@ -579,13 +593,15 @@ object LocationDescription extends StrictLogging { if (maybeAccessKey.isEmpty) { // If the access key/secret key are not defined, check if credential exists. - programEnvironment.s3Credentials.get(bucketName) match { - case Some(s3Credential) => Right( + programEnvironment.locationConfigs.get(bucketName) match { + case Some(l) if l.hasS3 => + val s3Credential = l.getS3 + Right( S3PathLocationDescription( bucketName, - s3Credential.region, - s3Credential.accessKey, - s3Credential.secretKey, + if (s3Credential.hasRegion) Some(s3Credential.getRegion) else None, + if (s3Credential.hasAccessSecretKey) Some(s3Credential.getAccessSecretKey.getAccessKey) else None, + if (s3Credential.hasAccessSecretKey) Some(s3Credential.getAccessSecretKey.getSecretKey) else None, objectKey ) ) @@ -603,10 +619,16 @@ object LocationDescription extends StrictLogging { if (name == null) { return Left("missing Dropbox credential") } - programEnvironment.httpHeaders.get(name) match { - case Some(httpHeaders) => Right( - DropboxAccessTokenLocationDescription( - httpHeaders("Authorization").split("Bearer ")(1), + programEnvironment.locationConfigs.get(name) match { + case Some(l) if l.hasDropboxAccessToken => + val dropboxAccessToken = l.getDropboxAccessToken + Right(DropboxAccessTokenLocationDescription(dropboxAccessToken.getAccessToken, path)) + case Some(l) if l.hasDropboxUsernamePassword => + val dropboxUsernamePassword = l.getDropboxUsernamePassword + Right( + DropboxUsernamePasswordLocationDescription( + dropboxUsernamePassword.getUsername, + dropboxUsernamePassword.getPassword, path ) ) diff --git a/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/MySQLPackage.scala b/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/MySQLPackage.scala index 1b2198940..198a02b9b 100644 --- a/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/MySQLPackage.scala +++ b/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/MySQLPackage.scala @@ -144,11 +144,14 @@ class MySQLInferAndReadEntry extends SugarEntryExtension { getStringValue(optionalArgs.find(_._1 == "password").getOrElse(return Left("password is required"))._2) new MySqlTableLocation(host, port, db, username, password, table)(programContext.settings) } else { - programContext.programEnvironment.jdbcServers.get(db) match { - case Some(l: MySqlJdbcLocation) => - new MySqlTableLocation(l.host, l.port, l.database, l.username, l.password, table)(programContext.settings) + programContext.programEnvironment.locationConfigs.get(db) match { + case Some(l) if l.hasMysql => + val l1 = l.getMysql + new MySqlTableLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword, table)( + programContext.settings + ) case Some(_) => return Left("not a MySQL server") - case None => return Left(s"unknown database credential: $db") + case None => return Left(s"unknown credential: $db") } } Right(SqlTableInferrerProperties(location, None)) @@ -385,11 +388,14 @@ class MySQLInferAndQueryEntry extends SugarEntryExtension { getStringValue(optionalArgs.find(_._1 == "password").getOrElse(return Left("password is required"))._2) new MySqlServerLocation(host, port, db, username, password)(programContext.settings) } else { - programContext.programEnvironment.jdbcServers.get(db) match { - case Some(l: MySqlJdbcLocation) => - new MySqlServerLocation(l.host, l.port, l.database, l.username, l.password)(programContext.settings) + programContext.programEnvironment.locationConfigs.get(db) match { + case Some(l) if l.hasMysql => + val l1 = l.getMysql + new MySqlServerLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword)( + programContext.settings + ) case Some(_) => return Left("not a MySQL server") - case None => return Left(s"unknown database credential: $db") + case None => return Left(s"unknown credential: $db") } } Right(SqlQueryInferrerProperties(location, query, None)) diff --git a/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/OraclePackage.scala b/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/OraclePackage.scala index 9722496bc..5475fc3cd 100644 --- a/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/OraclePackage.scala +++ b/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/OraclePackage.scala @@ -164,13 +164,14 @@ class OracleInferAndReadEntry extends SugarEntryExtension { getStringValue(optionalArgs.find(_._1 == "password").getOrElse(return Left("password is required"))._2) new OracleTableLocation(host, port, db, username, password, schema, table)(programContext.settings) } else { - programContext.programEnvironment.jdbcServers.get(db) match { - case Some(l: OracleJdbcLocation) => - new OracleTableLocation(l.host, l.port, l.database, l.username, l.password, schema, table)( + programContext.programEnvironment.locationConfigs.get(db) match { + case Some(l) if l.hasOracle => + val l1 = l.getOracle + new OracleTableLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword, schema, table)( programContext.settings ) case Some(_) => return Left("not an Oracle server") - case None => return Left(s"unknown database credential: $db") + case None => return Left(s"unknown credential: $db") } } Right(SqlTableInferrerProperties(location, None)) @@ -416,11 +417,14 @@ class OracleInferAndQueryEntry extends SugarEntryExtension { getStringValue(optionalArgs.find(_._1 == "password").getOrElse(return Left("password is required"))._2) new OracleServerLocation(host, port, db, username, password)(programContext.settings) } else { - programContext.programEnvironment.jdbcServers.get(db) match { - case Some(l: OracleJdbcLocation) => - new OracleServerLocation(l.host, l.port, l.database, l.username, l.password)(programContext.settings) + programContext.programEnvironment.locationConfigs.get(db) match { + case Some(l) if l.hasOracle => + val l1 = l.getOracle + new OracleServerLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword)( + programContext.settings + ) case Some(_) => return Left("not an Oracle server") - case None => return Left(s"unknown database credential: $db") + case None => return Left(s"unknown credential: $db") } } Right(SqlQueryInferrerProperties(location, query, None)) diff --git a/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/PostgreSQLPackage.scala b/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/PostgreSQLPackage.scala index b986a3f4b..3770f92ef 100644 --- a/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/PostgreSQLPackage.scala +++ b/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/PostgreSQLPackage.scala @@ -164,13 +164,22 @@ class PostgreSQLInferAndReadEntry extends SugarEntryExtension { getStringValue(optionalArgs.find(_._1 == "password").getOrElse(return Left("password is required"))._2) new PostgresqlTableLocation(host, port, db, username, password, schema, table)(programContext.settings) } else { - programContext.programEnvironment.jdbcServers.get(db) match { - case Some(l: PostgresJdbcLocation) => - new PostgresqlTableLocation(l.host, l.port, l.database, l.username, l.password, schema, table)( + programContext.programEnvironment.locationConfigs.get(db) match { + case Some(l) if l.hasPostgresql => + val l1 = l.getPostgresql + new PostgresqlTableLocation( + l1.getHost, + l1.getPort, + l1.getDatabase, + l1.getUser, + l1.getPassword, + schema, + table + )( programContext.settings ) case Some(_) => return Left("not a PostgreSQL server") - case None => return Left(s"unknown database credential: $db") + case None => return Left(s"unknown credential: $db") } } Right(SqlTableInferrerProperties(location, None)) @@ -418,11 +427,14 @@ class PostgreSQLInferAndQueryEntry extends SugarEntryExtension { getStringValue(optionalArgs.find(_._1 == "password").getOrElse(return Left("password is required"))._2) new PostgresqlServerLocation(host, port, db, username, password)(programContext.settings) } else { - programContext.programEnvironment.jdbcServers.get(db) match { - case Some(l: PostgresJdbcLocation) => - new PostgresqlServerLocation(l.host, l.port, l.database, l.username, l.password)(programContext.settings) + programContext.programEnvironment.locationConfigs.get(db) match { + case Some(l) if l.hasPostgresql => + val l1 = l.getPostgresql + new PostgresqlServerLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword)( + programContext.settings + ) case Some(_) => return Left("not an Oracle server") - case None => return Left(s"unknown database credential: $db") + case None => return Left(s"unknown credential: $db") } } Right(SqlQueryInferrerProperties(location, query, None)) diff --git a/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/SQLServerPackage.scala b/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/SQLServerPackage.scala index c0581d988..1f57e1aab 100644 --- a/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/SQLServerPackage.scala +++ b/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/SQLServerPackage.scala @@ -165,13 +165,22 @@ class SQLServerInferAndReadEntry extends SugarEntryExtension { getStringValue(optionalArgs.find(_._1 == "password").getOrElse(return Left("password is required"))._2) new SqlServerTableLocation(host, port, db, username, password, schema, table)(programContext.settings) } else { - programContext.programEnvironment.jdbcServers.get(db) match { - case Some(l: SqlServerJdbcLocation) => - new SqlServerTableLocation(l.host, l.port, l.database, l.username, l.password, schema, table)( + programContext.programEnvironment.locationConfigs.get(db) match { + case Some(l) if l.hasSqlserver => + val l1 = l.getSqlserver + new SqlServerTableLocation( + l1.getHost, + l1.getPort, + l1.getDatabase, + l1.getUser, + l1.getPassword, + schema, + table + )( programContext.settings ) case Some(_) => return Left("not an Oracle server") - case None => return Left(s"unknown database credential: $db") + case None => return Left(s"unknown credential: $db") } } Right(SqlTableInferrerProperties(location, None)) @@ -420,11 +429,14 @@ class SQLServerInferAndQueryEntry extends SugarEntryExtension { getStringValue(optionalArgs.find(_._1 == "password").getOrElse(return Left("password is required"))._2) new SqlServerServerLocation(host, port, db, username, password)(programContext.settings) } else { - programContext.programEnvironment.jdbcServers.get(db) match { - case Some(l: SqlServerJdbcLocation) => - new SqlServerServerLocation(l.host, l.port, l.database, l.username, l.password)(programContext.settings) + programContext.programEnvironment.locationConfigs.get(db) match { + case Some(l) if l.hasSqlserver => + val l1 = l.getSqlserver + new SqlServerServerLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword)( + programContext.settings + ) case Some(_) => return Left("not an Oracle server") - case None => return Left(s"unknown database credential: $db") + case None => return Left(s"unknown credential: $db") } } Right(SqlQueryInferrerProperties(location, query, None)) diff --git a/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/SnowflakePackage.scala b/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/SnowflakePackage.scala index f0a276073..fcbe1be09 100644 --- a/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/SnowflakePackage.scala +++ b/snapi-frontend/src/main/scala/raw/compiler/rql2/builtin/SnowflakePackage.scala @@ -197,20 +197,22 @@ class SnowflakeInferAndReadEntry extends SugarEntryExtension { programContext.settings ) } else { - programContext.programEnvironment.jdbcServers.get(db) match { - case Some(l: SnowflakeJdbcLocation) => new SnowflakeTableLocation( - l.database, - l.username, - l.password, - l.accountIdentifier, - l.parameters, + programContext.programEnvironment.locationConfigs.get(db) match { + case Some(l) if l.hasSnowflake => + val l1 = l.getSnowflake + new SnowflakeTableLocation( + l1.getDatabase, + l1.getUser, + l1.getPassword, + l1.getAccountIdentifier, + l1.getParametersMap, schema, table )( programContext.settings ) case Some(_) => return Left("not a Snowflake server") - case None => return Left(s"unknown database credential: $db") + case None => return Left(s"unknown credential: $db") } } Right(SqlTableInferrerProperties(location, None)) @@ -488,13 +490,19 @@ class SnowflakeInferAndQueryEntry extends SugarEntryExtension { getStringValue(optionalArgs.find(_._1 == "password").getOrElse(return Left("password is required"))._2) new SnowflakeServerLocation(db, username, password, accountID, parameters.toMap)(programContext.settings) } else { - programContext.programEnvironment.jdbcServers.get(db) match { - case Some(l: SnowflakeJdbcLocation) => - new SnowflakeServerLocation(l.database, l.username, l.password, l.accountIdentifier, l.parameters)( + programContext.programEnvironment.locationConfigs.get(db) match { + case Some(l) if l.hasSnowflake => + val l1 = l.getSnowflake + new SnowflakeServerLocation( + l1.getDatabase, + l1.getUser, + l1.getPassword, + l1.getAccountIdentifier, + l1.getParametersMap, programContext.settings ) case Some(_) => return Left("not a Snowflake server") - case None => return Left(s"unknown database credential: $db") + case None => return Left(s"unknown credential: $db") } } Right(SqlQueryInferrerProperties(location, query, None)) diff --git a/snapi-frontend/src/main/scala/raw/compiler/rql2/source/SourceTree.scala b/snapi-frontend/src/main/scala/raw/compiler/rql2/source/SourceTree.scala index 5fb832feb..da92d63f4 100644 --- a/snapi-frontend/src/main/scala/raw/compiler/rql2/source/SourceTree.scala +++ b/snapi-frontend/src/main/scala/raw/compiler/rql2/source/SourceTree.scala @@ -15,7 +15,6 @@ package raw.compiler.rql2.source import org.bitbucket.inkytonik.kiama.output._ import raw.compiler.base.source.Type import raw.compiler.common.source._ -import raw.sources.api.Location /////////////////////////////////////////////////////////////////////////// // RQL2 diff --git a/snapi-truffle/src/main/java/module-info.java b/snapi-truffle/src/main/java/module-info.java index 46ea59b40..cd51588f5 100644 --- a/snapi-truffle/src/main/java/module-info.java +++ b/snapi-truffle/src/main/java/module-info.java @@ -26,6 +26,7 @@ requires scala.library; requires com.ctc.wstx; requires raw.utils; + requires raw.protocol; requires raw.client; requires raw.sources; requires raw.snapi.frontend; diff --git a/snapi-truffle/src/main/java/raw/runtime/truffle/RawContext.java b/snapi-truffle/src/main/java/raw/runtime/truffle/RawContext.java index d45b92a6d..3d7f2476b 100644 --- a/snapi-truffle/src/main/java/raw/runtime/truffle/RawContext.java +++ b/snapi-truffle/src/main/java/raw/runtime/truffle/RawContext.java @@ -18,10 +18,10 @@ import com.oracle.truffle.api.interop.TruffleObject; import com.oracle.truffle.api.nodes.Node; import java.io.OutputStream; -import java.util.Map; import java.util.Set; import raw.client.api.*; import raw.inferrer.api.InferrerService; +import raw.protocol.LocationConfig; import raw.runtime.truffle.runtime.exceptions.RawTruffleRuntimeException; import raw.runtime.truffle.runtime.function.RawFunctionRegistry; import raw.utils.RawSettings; @@ -97,16 +97,6 @@ public RawSettings getSettings() { return rawSettings; } - @CompilerDirectives.TruffleBoundary - public Map getHttpHeaders(String name) { - scala.Option> maybeHttpHeaders = - programEnvironment.httpHeaders().get(name); - if (maybeHttpHeaders.isEmpty()) { - throw new RawTruffleRuntimeException("unknown http credential: " + name); - } - return JavaConverters.mapAsJavaMap(maybeHttpHeaders.get()); - } - @CompilerDirectives.TruffleBoundary public boolean existsSecret(String key) { return programEnvironment.secrets().contains(key); @@ -122,31 +112,18 @@ public String getSecret(String key) { } @CompilerDirectives.TruffleBoundary - public boolean existsJdbcCredential(String name) { - return programEnvironment.jdbcServers().contains(name); - } - - @CompilerDirectives.TruffleBoundary - public JdbcLocation getJdbcLocation(String name) { - scala.Option maybeJdbcLocation = programEnvironment.jdbcServers().get(name); - if (maybeJdbcLocation.isEmpty()) { - throw new RawTruffleRuntimeException("unknown database credential: " + name); - } - return maybeJdbcLocation.get(); - } - - @CompilerDirectives.TruffleBoundary - public boolean existsS3Credential(String bucket) { - return programEnvironment.s3Credentials().contains(bucket); + public boolean existsLocationConfig(String name) { + return programEnvironment.locationConfigs().contains(name); } @CompilerDirectives.TruffleBoundary - public S3Credential getS3Credential(String bucket) { - scala.Option maybeCred = programEnvironment.s3Credentials().get(bucket); - if (maybeCred.isEmpty()) { - throw new RawTruffleRuntimeException("unknown S3 bucket: " + bucket); + public LocationConfig getLocationConfig(String name) { + scala.Option maybeLocationConfig = + programEnvironment.locationConfigs().get(name); + if (maybeLocationConfig.isEmpty()) { + throw new RawTruffleRuntimeException("unknown credential: " + name); } - return maybeCred.get(); + return maybeLocationConfig.get(); } @CompilerDirectives.TruffleBoundary diff --git a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromHttpNode.java b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromHttpNode.java index d679334ed..f002b608c 100644 --- a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromHttpNode.java +++ b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromHttpNode.java @@ -21,6 +21,8 @@ import java.net.HttpURLConnection; import java.util.Base64; import java.util.Map; +import raw.protocol.HttpHeadersConfig; +import raw.protocol.LocationConfig; import raw.runtime.truffle.ExpressionNode; import raw.runtime.truffle.RawContext; import raw.runtime.truffle.runtime.exceptions.RawTruffleInternalErrorException; @@ -162,14 +164,22 @@ public Object executeGeneric(VirtualFrame frame) { .encodeToString((username + ":" + password).getBytes()))); } + RawContext context = RawContext.get(this); + // Append any additional headers related to the authentication (if credential name is defined) if (this.authCredentialName != null) { String authCredentialName = (String) this.authCredentialName.executeGeneric(frame); - Map credHeaders = RawContext.get(this).getHttpHeaders(authCredentialName); - for (Map.Entry entry : credHeaders.entrySet()) { - headersBuilder = - (ArrayBuilder>) - headersBuilder.$plus$eq(Tuple2.apply(entry.getKey(), entry.getValue())); + LocationConfig l = context.getLocationConfig(authCredentialName); + if (l.hasHttpHeaders()) { + HttpHeadersConfig l1 = l.getHttpHeaders(); + Map credHeaders = l1.getHeadersMap(); + for (Map.Entry entry : credHeaders.entrySet()) { + headersBuilder = + (ArrayBuilder>) + headersBuilder.$plus$eq(Tuple2.apply(entry.getKey(), entry.getValue())); + } + } else { + throw new RawTruffleInternalErrorException("credential is not an HTTP headers"); } } @@ -189,7 +199,7 @@ public Object executeGeneric(VirtualFrame frame) { } } - RawSettings rawSettings = RawContext.get(this).getSettings(); + RawSettings rawSettings = context.getSettings(); HttpByteStreamLocation location = new HttpByteStreamLocation( diff --git a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromMySQLCredentialNode.java b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromMySQLCredentialNode.java index bf9aa0c93..0c48ef2ee 100644 --- a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromMySQLCredentialNode.java +++ b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromMySQLCredentialNode.java @@ -15,11 +15,11 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.NodeInfo; -import raw.client.api.JdbcLocation; -import raw.compiler.rql2.api.LocationDescription$; -import raw.compiler.rql2.api.MySqlServerLocationDescription; +import raw.protocol.LocationConfig; +import raw.protocol.MySqlConfig; import raw.runtime.truffle.ExpressionNode; import raw.runtime.truffle.RawContext; +import raw.runtime.truffle.runtime.exceptions.RawTruffleRuntimeException; import raw.runtime.truffle.runtime.primitives.*; import raw.sources.jdbc.api.JdbcServerLocation; import raw.sources.jdbc.mysql.MySqlServerLocation; @@ -39,17 +39,25 @@ public Object executeGeneric(VirtualFrame frame) { RawContext context = RawContext.get(this); String credentialName = (String) this.credentialName.executeGeneric(frame); - JdbcLocation l = context.getJdbcLocation(credentialName); + LocationConfig l = context.getLocationConfig(credentialName); JdbcServerLocation location = getJdbcServerLocation(l, context.getSettings()); return new LocationObject(location, "mysql:" + credentialName); } @CompilerDirectives.TruffleBoundary - public JdbcServerLocation getJdbcServerLocation(JdbcLocation l, RawSettings rawSettings) { - MySqlServerLocationDescription d = - (MySqlServerLocationDescription) LocationDescription$.MODULE$.toLocationDescription(l); - return new MySqlServerLocation( - d.host(), d.port(), d.dbName(), d.username(), d.password(), rawSettings); + public JdbcServerLocation getJdbcServerLocation(LocationConfig l, RawSettings rawSettings) { + if (l.hasMysql()) { + MySqlConfig mysql = l.getMysql(); + return new MySqlServerLocation( + mysql.getHost(), + mysql.getPort(), + mysql.getDatabase(), + mysql.getUser(), + mysql.getPassword(), + rawSettings); + } else { + throw new RawTruffleRuntimeException("credential is not a MySQL server"); + } } } diff --git a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromOracleCredentialNode.java b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromOracleCredentialNode.java index d26242d83..532a64f50 100644 --- a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromOracleCredentialNode.java +++ b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromOracleCredentialNode.java @@ -15,11 +15,11 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.NodeInfo; -import raw.client.api.JdbcLocation; -import raw.compiler.rql2.api.LocationDescription$; -import raw.compiler.rql2.api.OracleServerLocationDescription; +import raw.protocol.LocationConfig; +import raw.protocol.OracleConfig; import raw.runtime.truffle.ExpressionNode; import raw.runtime.truffle.RawContext; +import raw.runtime.truffle.runtime.exceptions.RawTruffleRuntimeException; import raw.runtime.truffle.runtime.primitives.*; import raw.sources.jdbc.api.JdbcServerLocation; import raw.sources.jdbc.oracle.OracleServerLocation; @@ -39,17 +39,25 @@ public Object executeGeneric(VirtualFrame frame) { RawContext context = RawContext.get(this); String credentialName = (String) this.credentialName.executeGeneric(frame); - JdbcLocation l = context.getJdbcLocation(credentialName); + LocationConfig l = context.getLocationConfig(credentialName); JdbcServerLocation location = getJdbcServerLocation(l, context.getSettings()); return new LocationObject(location, "oracle:" + credentialName); } @CompilerDirectives.TruffleBoundary - public JdbcServerLocation getJdbcServerLocation(JdbcLocation l, RawSettings rawSettings) { - OracleServerLocationDescription d = - (OracleServerLocationDescription) LocationDescription$.MODULE$.toLocationDescription(l); - return new OracleServerLocation( - d.host(), d.port(), d.dbName(), d.username(), d.password(), rawSettings); + public JdbcServerLocation getJdbcServerLocation(LocationConfig l, RawSettings rawSettings) { + if (l.hasOracle()) { + OracleConfig oracle = l.getOracle(); + return new OracleServerLocation( + oracle.getHost(), + oracle.getPort(), + oracle.getDatabase(), + oracle.getUser(), + oracle.getPassword(), + rawSettings); + } else { + throw new RawTruffleRuntimeException("credential is not an Oracle server"); + } } } diff --git a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromPostgreSQLCredentialNode.java b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromPostgreSQLCredentialNode.java index fe2bb1e68..dc729cd46 100644 --- a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromPostgreSQLCredentialNode.java +++ b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromPostgreSQLCredentialNode.java @@ -15,11 +15,11 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.NodeInfo; -import raw.client.api.JdbcLocation; -import raw.compiler.rql2.api.LocationDescription$; -import raw.compiler.rql2.api.PostgresqlServerLocationDescription; +import raw.protocol.LocationConfig; +import raw.protocol.PostgreSQLConfig; import raw.runtime.truffle.ExpressionNode; import raw.runtime.truffle.RawContext; +import raw.runtime.truffle.runtime.exceptions.RawTruffleRuntimeException; import raw.runtime.truffle.runtime.primitives.*; import raw.sources.jdbc.api.JdbcServerLocation; import raw.sources.jdbc.pgsql.PostgresqlServerLocation; @@ -39,17 +39,25 @@ public Object executeGeneric(VirtualFrame frame) { RawContext context = RawContext.get(this); String credentialName = (String) this.credentialName.executeGeneric(frame); - JdbcLocation l = context.getJdbcLocation(credentialName); + LocationConfig l = context.getLocationConfig(credentialName); JdbcServerLocation location = getJdbcServerLocation(l, context.getSettings()); return new LocationObject(location, "pgsql:" + credentialName); } @CompilerDirectives.TruffleBoundary - public JdbcServerLocation getJdbcServerLocation(JdbcLocation l, RawSettings rawSettings) { - PostgresqlServerLocationDescription d = - (PostgresqlServerLocationDescription) LocationDescription$.MODULE$.toLocationDescription(l); - return new PostgresqlServerLocation( - d.host(), d.port(), d.dbName(), d.username(), d.password(), rawSettings); + public JdbcServerLocation getJdbcServerLocation(LocationConfig l, RawSettings rawSettings) { + if (l.hasPostgresql()) { + PostgreSQLConfig postgresql = l.getPostgresql(); + return new PostgresqlServerLocation( + postgresql.getHost(), + postgresql.getPort(), + postgresql.getDatabase(), + postgresql.getUser(), + postgresql.getPassword(), + rawSettings); + } else { + throw new RawTruffleRuntimeException("credential is not a PostgreSQL server"); + } } } diff --git a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromS3Node.java b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromS3Node.java index 92b920212..ef34ea126 100644 --- a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromS3Node.java +++ b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromS3Node.java @@ -14,7 +14,8 @@ import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.NodeInfo; -import raw.client.api.S3Credential; +import raw.protocol.LocationConfig; +import raw.protocol.S3Config; import raw.runtime.truffle.ExpressionNode; import raw.runtime.truffle.RawContext; import raw.runtime.truffle.runtime.exceptions.RawTruffleRuntimeException; @@ -70,16 +71,22 @@ public Object executeGeneric(VirtualFrame frame) { RawContext context = RawContext.get(this); S3Path location; - if (RawContext.get(this).existsS3Credential(bucket)) { - S3Credential cred = context.getS3Credential(bucket); + if (context.existsLocationConfig(bucket) && context.getLocationConfig(bucket).hasS3()) { + LocationConfig l = context.getLocationConfig(bucket); + S3Config s3Config = l.getS3(); + Option maybeAccessKey = + (s3Config.hasAccessSecretKey()) + ? new Some(s3Config.getAccessSecretKey().getAccessKey()) + : None$.empty(); + Option maybeSecretKey = + (s3Config.hasAccessSecretKey()) + ? new Some(s3Config.getAccessSecretKey().getSecretKey()) + : None$.empty(); + Option maybeRegion = + (s3Config.hasRegion()) ? new Some(s3Config.getRegion()) : None$.empty(); location = new S3Path( - bucket, - cred.region(), - cred.accessKey(), - cred.secretKey(), - path, - context.getSettings()); + bucket, maybeRegion, maybeAccessKey, maybeSecretKey, path, context.getSettings()); } else { // We actually do NOT throw an exception if the accessKey is not passed. // Instead, we go without it, which triggers anonymous access to the S3 bucket. diff --git a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromSQLServerCredentialNode.java b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromSQLServerCredentialNode.java index 7364846db..be8c6a3d5 100644 --- a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromSQLServerCredentialNode.java +++ b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromSQLServerCredentialNode.java @@ -15,11 +15,11 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.NodeInfo; -import raw.client.api.JdbcLocation; -import raw.compiler.rql2.api.LocationDescription$; -import raw.compiler.rql2.api.SqlServerServerLocationDescription; +import raw.protocol.LocationConfig; +import raw.protocol.SQLServerConfig; import raw.runtime.truffle.ExpressionNode; import raw.runtime.truffle.RawContext; +import raw.runtime.truffle.runtime.exceptions.RawTruffleRuntimeException; import raw.runtime.truffle.runtime.primitives.*; import raw.sources.jdbc.api.JdbcServerLocation; import raw.sources.jdbc.sqlserver.SqlServerServerLocation; @@ -39,17 +39,25 @@ public Object executeGeneric(VirtualFrame frame) { RawContext context = RawContext.get(this); String credentialName = (String) this.credentialName.executeGeneric(frame); - JdbcLocation l = context.getJdbcLocation(credentialName); + LocationConfig l = context.getLocationConfig(credentialName); JdbcServerLocation location = getJdbcServerLocation(l, context.getSettings()); return new LocationObject(location, "sqlserver:" + credentialName); } @CompilerDirectives.TruffleBoundary - public JdbcServerLocation getJdbcServerLocation(JdbcLocation l, RawSettings rawSettings) { - SqlServerServerLocationDescription d = - (SqlServerServerLocationDescription) LocationDescription$.MODULE$.toLocationDescription(l); - return new SqlServerServerLocation( - d.host(), d.port(), d.dbName(), d.username(), d.password(), rawSettings); + public JdbcServerLocation getJdbcServerLocation(LocationConfig l, RawSettings rawSettings) { + if (l.hasSqlserver()) { + SQLServerConfig sqlserver = l.getSqlserver(); + return new SqlServerServerLocation( + sqlserver.getHost(), + sqlserver.getPort(), + sqlserver.getDatabase(), + sqlserver.getUser(), + sqlserver.getPassword(), + rawSettings); + } else { + throw new RawTruffleRuntimeException("credential is not a SQL Server server"); + } } } diff --git a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromSnowflakeCredentialNode.java b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromSnowflakeCredentialNode.java index 0b2e17927..c90cb81e2 100644 --- a/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromSnowflakeCredentialNode.java +++ b/snapi-truffle/src/main/java/raw/runtime/truffle/ast/expressions/builtin/location_package/LocationFromSnowflakeCredentialNode.java @@ -15,11 +15,11 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.NodeInfo; -import raw.client.api.JdbcLocation; -import raw.compiler.rql2.api.LocationDescription$; -import raw.compiler.rql2.api.SnowflakeServerLocationDescription; +import raw.protocol.LocationConfig; +import raw.protocol.SnowflakeConfig; import raw.runtime.truffle.ExpressionNode; import raw.runtime.truffle.RawContext; +import raw.runtime.truffle.runtime.exceptions.RawTruffleRuntimeException; import raw.runtime.truffle.runtime.primitives.*; import raw.sources.jdbc.api.JdbcServerLocation; import raw.sources.jdbc.snowflake.SnowflakeServerLocation; @@ -39,17 +39,25 @@ public Object executeGeneric(VirtualFrame frame) { RawContext context = RawContext.get(this); String credentialName = (String) this.credentialName.executeGeneric(frame); - JdbcLocation l = context.getJdbcLocation(credentialName); + LocationConfig l = context.getLocationConfig(credentialName); JdbcServerLocation location = getJdbcServerLocation(l, context.getSettings()); return new LocationObject(location, "snowflake:" + credentialName); } @CompilerDirectives.TruffleBoundary - public JdbcServerLocation getJdbcServerLocation(JdbcLocation l, RawSettings rawSettings) { - SnowflakeServerLocationDescription d = - (SnowflakeServerLocationDescription) LocationDescription$.MODULE$.toLocationDescription(l); - return new SnowflakeServerLocation( - d.dbName(), d.username(), d.password(), d.accountIdentifier(), d.parameters(), rawSettings); + public JdbcServerLocation getJdbcServerLocation(LocationConfig l, RawSettings rawSettings) { + if (l.hasSnowflake()) { + SnowflakeConfig snowflake = l.getSnowflake(); + return new SnowflakeServerLocation( + snowflake.getDatabase(), + snowflake.getUser(), + snowflake.getPassword(), + snowflake.getAccountIdentifier(), + snowflake.getParameters(), + rawSettings); + } else { + throw new RawTruffleRuntimeException("credential is not a Snowflake server"); + } } } diff --git a/sources/src/main/scala/raw/sources/jdbc/snowflake/SnowflakeTableLocation.scala b/sources/src/main/scala/raw/sources/jdbc/snowflake/SnowflakeTableLocation.scala index a9b3a0bf0..28159eff0 100644 --- a/sources/src/main/scala/raw/sources/jdbc/snowflake/SnowflakeTableLocation.scala +++ b/sources/src/main/scala/raw/sources/jdbc/snowflake/SnowflakeTableLocation.scala @@ -15,6 +15,8 @@ package raw.sources.jdbc.snowflake import raw.sources.jdbc.api.JdbcTableLocation import raw.utils.RawSettings +import scala.collection.JavaConverters._ + class SnowflakeTableLocation( cli: SnowflakeClient, val schema: String, @@ -53,4 +55,26 @@ class SnowflakeTableLocation( ) } + def this( + dbName: String, + username: String, + password: String, + accountIdentifier: String, + parameters: java.util.Map[String, String], + schema: String, + tableName: String + )(implicit settings: RawSettings) = { + this( + new SnowflakeClient( + dbName, + username, + password, + accountIdentifier, + parameters.asScala.toMap + ), + schema, + tableName + ) + } + } diff --git a/sql-client/src/test/scala/raw/client/sql/TestSqlCompilerServiceAirports.scala b/sql-client/src/test/scala/raw/client/sql/TestSqlCompilerServiceAirports.scala index abb545854..9c18a31a2 100644 --- a/sql-client/src/test/scala/raw/client/sql/TestSqlCompilerServiceAirports.scala +++ b/sql-client/src/test/scala/raw/client/sql/TestSqlCompilerServiceAirports.scala @@ -80,8 +80,6 @@ class TestSqlCompilerServiceAirports scopes, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "json"), jdbcUrl = Some(jdbcUrl) ) @@ -93,8 +91,6 @@ class TestSqlCompilerServiceAirports scopes, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "csv"), jdbcUrl = Some(jdbcUrl) ) diff --git a/sql-client/src/test/scala/raw/client/sql/TestSqlConnectionFailures.scala b/sql-client/src/test/scala/raw/client/sql/TestSqlConnectionFailures.scala index 7627d6250..f9d07d3d7 100644 --- a/sql-client/src/test/scala/raw/client/sql/TestSqlConnectionFailures.scala +++ b/sql-client/src/test/scala/raw/client/sql/TestSqlConnectionFailures.scala @@ -476,8 +476,6 @@ class TestSqlConnectionFailures Set.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "json"), jdbcUrl = Some(jdbcUrl(user)) ) @@ -501,8 +499,6 @@ class TestSqlConnectionFailures Set.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "json"), jdbcUrl = Some(jdbcUrl(user)) ) @@ -522,8 +518,6 @@ class TestSqlConnectionFailures Set.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "json"), jdbcUrl = Some(jdbcUrl(user)) ) @@ -542,8 +536,6 @@ class TestSqlConnectionFailures Set.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "json"), jdbcUrl = Some(jdbcUrl(user)) ) @@ -561,8 +553,6 @@ class TestSqlConnectionFailures Set.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "json"), jdbcUrl = Some(jdbcUrl(user)) ) @@ -580,8 +570,6 @@ class TestSqlConnectionFailures Set.empty, Map.empty, Map.empty, - Map.empty, - Map.empty, Map("output-format" -> "json"), jdbcUrl = Some(jdbcUrl(user)) )