Skip to content

Commit

Permalink
RD-11102: Added getUserJdbc to the Credentials API (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgaidioz committed Jul 2, 2024
1 parent 6bb3c87 commit 5f22150
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
17 changes: 13 additions & 4 deletions sources/src/main/scala/raw/creds/api/CredentialsService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,20 @@ trait CredentialsService extends RawService {
def unregisterSecret(user: AuthenticatedUser, name: String): Boolean

/**
* Returns a PostgreSQL FDW database for the given user. If that database does not exist, then it should be
* automatically generated. This call is meant to be used by the SQL compiler in order to execute user-defined SQL queries.
* Returns a PostgreSQL FDW database for the given user, creating the database
* if it does not already exist.
*
* @param user the Authenticated User which corresponds to the combination of RAW Organization and Repository
* @return the database name the corresponds to the given user.
* @param user the AuthenticatedUser which corresponds to the combination of RAW Organization and Repository
* @return the database name that corresponds to the given user.
*/
def getUserDb(user: AuthenticatedUser): String

/**
* Returns a JDBC connection string for the specified user, creating the corresponding database
* if it does not already exist.
*
* @param user the AuthenticatedUser we need the JDBC connection string for
* @return the JDBC connection string for the specified user
*/
def getUserJdbc(user: AuthenticatedUser): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ class ClientCredentials(serverAddress: URI)(implicit settings: RawSettings) exte
)
}

def getUserJdbc(user: AuthenticatedUser): String = {
restClient.doJsonPost[String](
"2/fdw/user-jdbc",
ProvisionFdwDbCredentials(user),
withAuth = false
)
}

def close(): Unit = {
restClient.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ class ClientCredentialsService(implicit settings: RawSettings) extends Credentia
client.getUserDb(user)
}

override def getUserJdbc(user: AuthenticatedUser): String = {
client.getUserJdbc(user)
}

override def doStop(): Unit = {
client.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ class LocalCredentialsService extends CredentialsService {
}

override def getUserDb(user: AuthenticatedUser): String = {
sys.env.getOrElse("FDW_DATABASE", "raw")
???
}

override def getUserJdbc(user: AuthenticatedUser): String = {
???
}

override def doStop(): Unit = {}
Expand Down

0 comments on commit 5f22150

Please sign in to comment.