Skip to content

Commit

Permalink
[SPARTA-854]Feature/redirection virtual path sparta needed for oauth (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Frannie-Ludmilla authored and compae committed May 17, 2017
1 parent 087be07 commit 452879d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docker/sparta-server-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function oauthOptions() {
sed -i "s|.*oauth2.url.authorize.*|oauth2.url.authorize = \""${OAUTH2_SSL_AUTHORIZE}"\"|" ${SPARTA_CONF_FILE}
fi

if [ ! -v OAUTH2_URL_ACCESS_TOKEN ] && [ ${#OAUTH2_URL_ACCESS_TOKEN} != 0 ]; then
if [ -v OAUTH2_URL_ACCESS_TOKEN ] && [ ${#OAUTH2_URL_ACCESS_TOKEN} != 0 ]; then
sed -i "s|.*oauth2.url.accessToken.*|oauth2.url.accessToken = \""${OAUTH2_URL_ACCESS_TOKEN}"\"|" ${SPARTA_CONF_FILE}
fi

Expand Down Expand Up @@ -170,7 +170,7 @@ function configOptions() {
sed -i "s|.*sparta.config.driverURI.*|sparta.config.driverURI = \""${SPARTA_DRIVER_URI}"\"|" ${SPARTA_CONF_FILE}

if [[ ! -v SPARTA_PLUGIN_PACKAGE_LOCATION ]]; then
SPARTA_PLUGIN_PACKAGE_LOCATION="/opt/sds/plugins/"
SPARTA_PLUGIN_PACKAGE_LOCATION="/opt/sds/sparta/plugins/"
fi
sed -i "s|.*sparta.config.pluginPackageLocation.*|sparta.config.pluginPackageLocation = \""${SPARTA_PLUGIN_PACKAGE_LOCATION}"\"|" ${SPARTA_CONF_FILE}

Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion serving-api/src/main/resources/swagger-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
url: "/api-docs",
url: "/sparta/api-docs",
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import com.stratio.sparta.serving.core.models.dto.LoggedUser
import com.stratio.spray.oauth2.client.OauthClient
import com.typesafe.config.Config
import org.apache.curator.framework.CuratorFramework
import spray.http.StatusCodes.Unauthorized
import spray.http.StatusCodes._
import spray.routing._
import scala.util.Properties


import scala.util.Try

Expand All @@ -52,7 +54,19 @@ class ControllerActor(actorsMap: Map[String, ActorRef], curatorFramework: Curato
def receive: Receive = runRoute(handleExceptions(exceptionHandler)(getRoutes))

def getRoutes: Route = cors{
secRoute ~ staticRoutes ~ dynamicRoutes
redirectToRoot ~
pathPrefix(HttpConstant.SpartaRootPath){
secRoute ~ staticRoutes ~ dynamicRoutes
} ~ secRoute ~ staticRoutes ~ dynamicRoutes
}

private def redirectToRoot: Route =
path(HttpConstant.SpartaRootPath){
get{
requestUri{ uri =>
redirect(s"${uri.toString}/", Found)
}
}
}

private def staticRoutes: Route = {
Expand Down Expand Up @@ -130,6 +144,15 @@ class ServiceRoutes(actorsMap: Map[String, ActorRef], context: ActorContext, cur

def swaggerRoute: Route = swaggerService.routes

def getMarathonLBPath: Option[String] = {
val marathonLB_host = Properties.envOrElse("MARATHON_APP_LABEL_HAPROXY_0_VHOST","")
val marathonLB_path = Properties.envOrElse("MARATHON_APP_LABEL_HAPROXY_0_PATH", "")

if(marathonLB_host.nonEmpty && marathonLB_path.nonEmpty)
Some("https://" + marathonLB_host + marathonLB_path)
else None
}

private val fragmentService = new FragmentHttpService {
implicit val actors = actorsMap
override val supervisor = actorsMap(AkkaConstant.FragmentActorName)
Expand Down Expand Up @@ -175,5 +198,9 @@ class ServiceRoutes(actorsMap: Map[String, ActorRef], context: ActorContext, cur

private val swaggerService = new SwaggerService {
override implicit def actorRefFactory: ActorRefFactory = context
override def baseUrl: String = getMarathonLBPath match {
case Some(marathonLBpath) => marathonLBpath
case None => "/"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.stratio.sparta.serving.api.constants

object HttpConstant {
final val SpartaRootPath = "sparta"
final val DriverPath = "driver"
final val PluginsPath = "plugins"
final val FragmentPath = "fragment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ trait SwaggerService extends SwaggerHttpService {

override def apiVersion: String = "1.0"

override def baseUrl: String = "/"

// let swagger-ui determine the host and port
override def docsPath: String = "api-docs"

Expand Down
6 changes: 3 additions & 3 deletions web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<title>Stratio Sparta</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="icon" type="image/png" href="/favicon-16.png" sizes="16x16">
<link rel="icon" type="image/png" href="/favicon-24.png" sizes="24x24">
<link rel="icon" type="image/png" href="/favicon-32.png" sizes="32x32">
<link rel="icon" type="image/png" href="favicon-16.png" sizes="16x16">
<link rel="icon" type="image/png" href="favicon-24.png" sizes="24x24">
<link rel="icon" type="image/png" href="favicon-32.png" sizes="32x32">
<!-- build:css(.tmp) styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
Expand Down

0 comments on commit 452879d

Please sign in to comment.