Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove creds, auth, and rest packages #474

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/main/scala/raw/client/api/CompilerService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object CompilerService {
"Arguments" -> environment.maybeArguments
.map(args => args.map { case (k, v) => s"$k -> $v" }.mkString("\n"))
.getOrElse("<undefined>"),
"User" -> environment.user.toString,
"Uid" -> environment.uid.toString,
"Scopes" -> environment.scopes.mkString(","),
"Options" -> environment.options.map { case (k, v) => s"$k -> $v" }.mkString("\n")
//"Settings" -> runtimeContext.settings.toString
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/scala/raw/client/api/ProgramEnvironment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import com.fasterxml.jackson.databind.ObjectMapper
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.AuthenticatedUser
import raw.utils.RawUid

final case class ProgramEnvironment(
user: AuthenticatedUser,
uid: RawUid,
maybeArguments: Option[Array[(String, RawValue)]],
scopes: Set[String],
secrets: Map[String, String],
Expand Down
6 changes: 2 additions & 4 deletions launcher/src/main/java/raw/cli/RawLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import raw.client.api.*;
import raw.utils.AuthenticatedUser;
import raw.utils.InteractiveUser;
import raw.utils.RawUid;
import raw.utils.RawException;
import raw.utils.RawSettings;
import scala.Option;
Expand All @@ -44,7 +43,6 @@ public RawLauncher(String language, PrintWriter writer) {
RawSettings rawSettings = new RawSettings(ConfigFactory.load(), ConfigFactory.empty());

this.compilerService = CompilerServiceProvider.apply(language, rawSettings);
AuthenticatedUser user = new InteractiveUser("uid", "name", "email", (Seq<String>) Seq$.MODULE$.empty());

HashMap<String, String> javaOptions = new HashMap<String, String>();
javaOptions.put("output-format", "json");
Expand All @@ -54,7 +52,7 @@ public RawLauncher(String language, PrintWriter writer) {
.asScala()
.toMap(scala.Predef.<scala.Tuple2<String, String>>conforms());

this.env = new ProgramEnvironment(user, Option.empty(), (Set<String>) Set$.MODULE$.empty(), scalaOptions, Option.empty());
this.env = new ProgramEnvironment(RawUid("uid"), Option.empty(), (Set<String>) Set$.MODULE$.empty(), scalaOptions, Option.empty());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
package raw.client.python

import raw.client.api.{CompilerService, ExecutionSuccess, ProgramEnvironment, RawInt}
import raw.utils.{InteractiveUser, RawTestSuite, SettingsTestContext, TrainingWheelsContext, Uid}
import raw.utils.{RawTestSuite, SettingsTestContext, TrainingWheelsContext, RawUid}

import java.io.ByteArrayOutputStream

class TestPythonCompilerService extends RawTestSuite with SettingsTestContext with TrainingWheelsContext {

var compilerService: CompilerService = _

val user = InteractiveUser(Uid("uid"), "name", "email", Seq.empty)
val user = RawUid("uid")

override def beforeAll(): Unit = {
super.beforeAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ package raw.client.rql2.api
import raw.client.api.{CompilerService, Message, ProgramEnvironment}
import raw.compiler.base.source.{BaseNode, Type}
import raw.compiler.common.source.SourceProgram
import raw.utils.AuthenticatedUser
import raw.utils.RawUid

trait Rql2CompilerService extends CompilerService {

def prettyPrint(node: BaseNode, user: AuthenticatedUser): String
def prettyPrint(node: BaseNode, user: RawUid): String

def parseType(tipe: String, user: AuthenticatedUser, internal: Boolean = false): ParseTypeResponse
def parseType(tipe: String, user: RawUid, internal: Boolean = false): ParseTypeResponse

def parse(source: String, environment: ProgramEnvironment): ParseResponse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import raw.compiler.rql2.errors._
import raw.compiler.rql2.lsp.CompilerLspService
import raw.compiler.rql2.source._
import raw.inferrer.api.InferrerServiceProvider
import raw.utils.{AuthenticatedUser, RawSettings, RawUtils}
import raw.utils.{RawSettings, RawUid, RawUtils}

import java.io.{IOException, OutputStream}
import scala.collection.mutable
Expand Down Expand Up @@ -71,33 +71,33 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
override def language: Set[String] = Rql2TruffleCompilerService.LANGUAGE

// Map of users to compiler context.
private val compilerContextCaches = new mutable.HashMap[AuthenticatedUser, CompilerContext]
private val compilerContextCaches = new mutable.HashMap[RawUid, CompilerContext]
private val compilerContextCachesLock = new Object

private def getCompilerContext(user: AuthenticatedUser): CompilerContext = {
private def getCompilerContext(user: RawUid): CompilerContext = {
compilerContextCachesLock.synchronized {
compilerContextCaches.getOrElseUpdate(user, createCompilerContext(user, "rql2-truffle"))
}
}

private def createCompilerContext(user: AuthenticatedUser, language: String): CompilerContext = {
private def createCompilerContext(user: RawUid, language: String): CompilerContext = {
// Initialize inferrer
val inferrer = InferrerServiceProvider()

// Initialize compiler context
new CompilerContext(language, user, inferrer)
}

private def getProgramContext(user: AuthenticatedUser, environment: ProgramEnvironment): ProgramContext = {
private def getProgramContext(user: RawUid, environment: ProgramEnvironment): ProgramContext = {
val compilerContext = getCompilerContext(user)
new Rql2ProgramContext(environment, compilerContext)
}

override def prettyPrint(node: BaseNode, user: AuthenticatedUser): String = {
override def prettyPrint(node: BaseNode, user: RawUid): String = {
SourcePrettyPrinter.format(node)
}

override def parseType(tipe: String, user: AuthenticatedUser, internal: Boolean = false): ParseTypeResponse = {
override def parseType(tipe: String, user: RawUid, internal: Boolean = false): ParseTypeResponse = {
val positions = new Positions()
val parser = new Antlr4SyntaxAnalyzer(positions, !internal)
parser.parseType(tipe) match {
Expand All @@ -107,7 +107,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
}

override def parse(source: String, environment: ProgramEnvironment): ParseResponse = {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
try {
val positions = new Positions()
val parser = new Antlr4SyntaxAnalyzer(positions, true)
Expand All @@ -129,7 +129,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
withTruffleContext(
environment,
_ => {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
try {
val tree = new TreeWithPositions(source, ensureTree = false, frontend = true)(programContext)
if (tree.valid) {
Expand All @@ -151,7 +151,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
withTruffleContext(
environment,
_ => {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
try {
val tree = new TreeWithPositions(source, ensureTree = false, frontend = true)(programContext)
if (tree.valid) {
Expand Down Expand Up @@ -211,7 +211,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
// its type is found in the polyglot bindings as '@type:<name>'
val funType = {
val rawType = ctx.getPolyglotBindings.getMember("@type:" + decl).asString()
val ParseTypeSuccess(tipe: FunType) = parseType(rawType, environment.user, internal = true)
val ParseTypeSuccess(tipe: FunType) = parseType(rawType, environment.uid, internal = true)
tipe
}
// Prior to .execute, some checks on parameters since we may have
Expand Down Expand Up @@ -256,7 +256,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
val result = ctx.eval(truffleSource)
// the value type is found in polyglot bindings after calling eval().
val rawType = ctx.getPolyglotBindings.getMember("@type").asString()
val ParseTypeSuccess(tipe) = parseType(rawType, environment.user, internal = true)
val ParseTypeSuccess(tipe) = parseType(rawType, environment.uid, internal = true)
(result, tipe)
}

Expand All @@ -267,7 +267,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
if (!CsvPackage.outputWriteSupport(tipe)) {
return ExecutionRuntimeFailure("unsupported type")
}
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
val windowsLineEnding = environment.options.get("windows-line-ending") match {
case Some("true") => true
case _ => programContext.settings.config.getBoolean("raw.compiler.windows-line-ending")
Expand Down Expand Up @@ -339,7 +339,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
if (ex.isInternalError) {
// An internal error. It means a regular Exception thrown from the language (e.g. a Java Exception,
// or a RawTruffleInternalErrorException, which isn't an AbstractTruffleException)
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
throw new CompilerServiceException(ex, programContext.dumpDebugInfo)
} else {
val err = ex.getGuestObject
Expand Down Expand Up @@ -384,7 +384,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
maybeIndent: Option[Int],
maybeWidth: Option[Int]
): FormatCodeResponse = {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
try {
val pretty = new SourceCommentsPrettyPrinter(maybeIndent, maybeWidth)
pretty.prettyCode(source) match {
Expand All @@ -404,7 +404,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
withTruffleContext(
environment,
_ => {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
try {
withLspTree(source, lspService => lspService.dotAutoComplete(source, environment, position))(
programContext
Expand All @@ -428,7 +428,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
withTruffleContext(
environment,
_ => {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
try {
withLspTree(source, lspService => lspService.wordAutoComplete(source, environment, prefix, position))(
programContext
Expand All @@ -453,7 +453,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
withTruffleContext(
environment,
_ => {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
try {
withLspTree(source, lspService => lspService.hover(source, environment, position))(programContext) match {
case Right(value) => value
Expand All @@ -470,7 +470,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
withTruffleContext(
environment,
_ => {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
try {
withLspTree(source, lspService => lspService.rename(source, environment, position))(programContext) match {
case Right(value) => value
Expand All @@ -491,7 +491,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
withTruffleContext(
environment,
_ => {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
try {
withLspTree(source, lspService => lspService.definition(source, environment, position))(
programContext
Expand All @@ -510,7 +510,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
withTruffleContext(
environment,
_ => {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
try {
withLspTree(
source,
Expand All @@ -530,7 +530,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean))(implicit p
withTruffleContext(
environment,
_ => {
val programContext = getProgramContext(environment.user, environment)
val programContext = getProgramContext(environment.uid, environment)
// Will analyze the code and return only unknown declarations errors.
val positions = new Positions()
val parser = new Antlr4SyntaxAnalyzer(positions, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ import scala.io.Source

object TestCredentials {

private def getEnv(name: String): String = sys.env.getOrElse(name, "credential_not_defined_missing_env_file")

/////////////////////////////////////////////////////////////////////////////
// HTTP Headers
/////////////////////////////////////////////////////////////////////////////

val dropboxLongLivedAccessToken = sys.env("RAW_DROPBOX_TEST_LONG_LIVED_ACCESS_TOKEN")
val dropboxLongLivedAccessToken = getEnv("RAW_DROPBOX_TEST_LONG_LIVED_ACCESS_TOKEN")
// The client ID to use for Dropbox API calls, once the access token is obtained.
val dropboxClientId = sys.env("RAW_DROPBOX_TEST_CLIENT_ID")
val dropboxClientId = getEnv("RAW_DROPBOX_TEST_CLIENT_ID")

/////////////////////////////////////////////////////////////////////////////
// S3 Credentials
/////////////////////////////////////////////////////////////////////////////

val accessKeyId = sys.env("RAW_AWS_ACCESS_KEY_ID")
val secretKeyId = sys.env("RAW_AWS_SECRET_ACCESS_KEY")
val accessKeyId = getEnv("RAW_AWS_ACCESS_KEY_ID")
val secretKeyId = getEnv("RAW_AWS_SECRET_ACCESS_KEY")

// Bucket with public access
val UnitTestPublicBucket = "rawlabs-public-test-data"
Expand All @@ -70,36 +72,36 @@ object TestCredentials {
// Jdbc Credentials
///////////////////////////////////////////////////////////////////////////

val mysqlTestHost = sys.env("RAW_MYSQL_TEST_HOST")
val mysqlTestDB = sys.env("RAW_MYSQL_TEST_DB")
val mysqlTestUser = sys.env("RAW_MYSQL_TEST_USER")
val mysqlTestPassword = sys.env("RAW_MYSQL_TEST_PASSWORD")
val mysqlTestHost = getEnv("RAW_MYSQL_TEST_HOST")
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 pgsqlTestHost = sys.env("RAW_PGSQL_TEST_HOST")
val pgsqlTestDB = sys.env("RAW_PGSQL_TEST_DB")
val pgsqlTestUser = sys.env("RAW_PGSQL_TEST_USER")
val pgsqlTestPassword = sys.env("RAW_PGSQL_TEST_PASSWORD")
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 oracleTestHost = sys.env("RAW_ORACLE_TEST_HOST")
val oracleTestDB = sys.env("RAW_ORACLE_TEST_DB")
val oracleTestUser = sys.env("RAW_ORACLE_TEST_USER")
val oracleTestPassword = sys.env("RAW_ORACLE_TEST_PASSWORD")
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 sqlServerTestHost = sys.env("RAW_SQLSERVER_TEST_HOST")
val sqlserverTestDB = sys.env("RAW_SQLSERVER_TEST_DB")
val sqlServerTestUser = sys.env("RAW_SQLSERVER_TEST_USER")
val sqlServerTestPassword = sys.env("RAW_SQLSERVER_TEST_PASSWORD")
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 snowflakeTestHost = sys.env("RAW_SNOWFLAKE_TEST_HOST")
val snowflakeTestDB = sys.env("RAW_SNOWFLAKE_TEST_DB")
val snowflakeTestUser = sys.env("RAW_SNOWFLAKE_TEST_USER")
val snowflakeTestPassword = sys.env("RAW_SNOWFLAKE_TEST_PASSWORD")
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,
Expand Down Expand Up @@ -132,7 +134,7 @@ trait Rql2CompilerTestContext

protected val programOptions = new mutable.HashMap[String, String]()

def authorizedUser: InteractiveUser = InteractiveUser(Uid("janeUid"), "Jane Smith", "jane@example.com")
def authorizedUser: RawUid = RawUid("janeUid")

def runnerScopes: Set[String] = Set.empty

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
package raw.compiler.rql2.tests.regressions

import raw.compiler.utils._
import raw.creds.s3.S3TestCreds
import raw.compiler.rql2.truffle.Rql2TruffleCompilerTestContext
import raw.testing.tags.TruffleTests

@TruffleTests class RD5932Test extends Rql2TruffleCompilerTestContext with S3TestCreds {
@TruffleTests class RD5932Test extends Rql2TruffleCompilerTestContext {

val data = tempFile("""[
| {"id": 1, "network_interface": "eni-08b85cc07294f82bf"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import raw.utils._
*/
class CompilerContext(
val language: String,
val user: AuthenticatedUser,
val user: RawUid,
val inferrer: InferrerService
)(
implicit val settings: RawSettings
Expand Down
Loading