Commit 31b5023a authored by Mathieu's avatar Mathieu

Add -kubeOff option

parent 49ab9b61
package org.openmoleconnect.application
import org.openmoleconnect.server.DB.UUID
import org.openmoleconnect.server._
object Application extends App {
......@@ -12,6 +13,7 @@ object Application extends App {
case class Config(
tokenSecret: String = "",
kubeOff: Boolean = false,
launchMode: LaunchMode = ServerMode
)
......@@ -25,6 +27,7 @@ object Application extends App {
else {
args match {
case "--secret" :: tail parse(tail.tail, c.copy(tokenSecret = tail.head))
case "-kubeOff" :: tail parse(List(), c.copy(kubeOff = true))
case "--help" :: tail => c.copy(launchMode = HelpMode)
case _ => c.copy(launchMode = HelpMode)
}
......@@ -39,10 +42,18 @@ object Application extends App {
if (!Settings.location.exists)
Settings.location.mkdirs()
DB.initDB
val server = new ConnectServer(secret = config.tokenSecret)
val server = new ConnectServer(secret = config.tokenSecret, config.kubeOff)
server.start()
}
DB.addUser("Moo",DB.Email("moo@moo.com"), DB.Password("moo"), Utils.openmoleversion.stable, 900009870L, DB.simpleUser)
// DB.addUser(
// "Moo",
// DB.Email("moo@moo.com"),
// DB.Password("moo"),
// Utils.openmoleversion.stable,
// 900009870L,
// DB.simpleUser,
// UUID("foo-123-567-foo")
// )
}
......@@ -12,7 +12,7 @@ import org.scalatra.servlet.ScalatraListener
object ConnectServer {
val servletArguments = "servletArguments"
case class ServletArguments(secret: String, resourceBase: java.io.File)
case class ServletArguments(secret: String, resourceBase: java.io.File, kubeOff: Boolean)
}
......@@ -23,7 +23,7 @@ class ConnectBootstrap extends LifeCycle {
}
}
class ConnectServer(secret: String) {
class ConnectServer(secret: String, kubeOff: Boolean) {
def start() = {
......@@ -35,7 +35,7 @@ class ConnectServer(secret: String) {
val startingContext = new WebAppContext()
startingContext.setResourceBase("application/target/webapp")
startingContext.setAttribute(ConnectServer.servletArguments, ConnectServer.ServletArguments(secret, new java.io.File(new URI(startingContext.getResourceBase))))
startingContext.setAttribute(ConnectServer.servletArguments, ConnectServer.ServletArguments(secret, new java.io.File(new URI(startingContext.getResourceBase)), kubeOff))
startingContext.setInitParameter(ScalatraListener.LifeCycleKey, classOf[ConnectBootstrap].getCanonicalName)
startingContext.setContextPath("/")
startingContext.addEventListener(new ScalatraListener)
......
......@@ -60,11 +60,11 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
}
}
def withAdminRights(action: TokenData=> ActionResult): Serializable = {
def withAdminRights(action: TokenData => ActionResult): Serializable = {
withAccesToken { tokenData =>
DB.isAdmin(tokenData.email) match {
case true=> action(tokenData)
case false=> Unauthorized("You seem unauthorized to do this !")
case true => action(tokenData)
case false => Unauthorized("You seem unauthorized to do this !")
}
}
}
......@@ -164,8 +164,13 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
else {
DB.uuid(DB.Email(email), DB.Password(password)) match {
case Some(uuid) =>
//val host = Host(uuid, K8sService.hostIP(uuid))
val host = Host(uuid, None)
// Hack to desactivate K8s when necessary
val host = {
if (arguments.kubeOff) Host(uuid, None)
else {
Host(uuid, K8sService.hostIP(uuid))
}
}
buildAndAddCookieToHeader(TokenData.accessToken(host, DB.Email(email)))
buildAndAddCookieToHeader(TokenData.refreshToken(host, DB.Email(email)))
redirect("/")
......
......@@ -95,7 +95,9 @@ object DB {
}
def addUser(name: String, email: Email, password: Password, omVersion: Version, lastAccess: Long, role: Role = simpleUser): Unit = {
addUser(name, email, password, omVersion, lastAccess, role, UUID(util.UUID.randomUUID().toString))
if (!exists(email)) {
addUser(name, email, password, omVersion, lastAccess, role, UUID(util.UUID.randomUUID().toString))
}
}
def addUser(name: String, email: Email, password: Password, omVersion: Version, lastAccess: Long, role: Role, uuid: UUID): Unit = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment