-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
88 changed files
with
2,081 additions
and
13,464 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version = "2.0.0-RC7" | ||
align = more # For pretty alignment. | ||
assumeStandardLibraryStripMargin = true | ||
style = defaultWithAlign | ||
maxColumn = 150 | ||
|
||
align.openParenCallSite = false | ||
align.openParenDefnSite = false | ||
newlines.alwaysBeforeTopLevelStatements = true | ||
rewrite.rules = [ | ||
# ExpandImportSelectors | ||
RedundantBraces | ||
RedundantParens | ||
SortModifiers | ||
PreferCurlyFors | ||
SortImports | ||
] | ||
|
||
includeCurlyBraceInSelectChains = true | ||
includeNoParensInSelectChains = true | ||
|
||
rewriteTokens { | ||
"=>" : "⇒" | ||
"<-" : "←" | ||
"->": "→" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,56 @@ | ||
package org.thp.cortex.controllers | ||
|
||
import javax.inject.{ Inject, Singleton } | ||
import scala.concurrent.{ ExecutionContext, Future } | ||
import javax.inject.{Inject, Singleton} | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
import play.api.libs.json.JsObject | ||
import play.api.mvc.{ AbstractController, Action, AnyContent, ControllerComponents } | ||
import play.api.mvc.{AbstractController, Action, AnyContent, ControllerComponents} | ||
|
||
import org.thp.cortex.models.{ BaseConfig, Roles } | ||
import org.thp.cortex.services.{ AnalyzerConfigSrv, UserSrv } | ||
import org.thp.cortex.models.{BaseConfig, Roles} | ||
import org.thp.cortex.services.{AnalyzerConfigSrv, UserSrv} | ||
|
||
import org.elastic4play.BadRequestError | ||
import org.elastic4play.controllers.{ Authenticated, Fields, FieldsBodyParser, Renderer } | ||
import org.elastic4play.controllers.{Authenticated, Fields, FieldsBodyParser, Renderer} | ||
|
||
@Singleton | ||
class AnalyzerConfigCtrl @Inject() ( | ||
class AnalyzerConfigCtrl @Inject()( | ||
analyzerConfigSrv: AnalyzerConfigSrv, | ||
userSrv: UserSrv, | ||
authenticated: Authenticated, | ||
fieldsBodyParser: FieldsBodyParser, | ||
renderer: Renderer, | ||
components: ControllerComponents, | ||
implicit val ec: ExecutionContext) extends AbstractController(components) { | ||
implicit val ec: ExecutionContext | ||
) extends AbstractController(components) { | ||
|
||
def get(analyzerConfigName: String): Action[AnyContent] = authenticated(Roles.orgAdmin).async { request ⇒ | ||
analyzerConfigSrv.getForUser(request.userId, analyzerConfigName) | ||
analyzerConfigSrv | ||
.getForUser(request.userId, analyzerConfigName) | ||
.map(renderer.toOutput(OK, _)) | ||
} | ||
|
||
def list(): Action[AnyContent] = authenticated(Roles.orgAdmin).async { request ⇒ | ||
analyzerConfigSrv.listConfigForUser(request.userId) | ||
analyzerConfigSrv | ||
.listConfigForUser(request.userId) | ||
.map { bc ⇒ | ||
renderer.toOutput(OK, bc.sortWith { | ||
case (BaseConfig("global", _, _, _), _) ⇒ true | ||
case (_, BaseConfig("global", _, _, _)) ⇒ false | ||
case (BaseConfig(a, _, _, _), BaseConfig(b, _, _, _)) ⇒ a.compareTo(b) < 0 | ||
}) | ||
renderer.toOutput( | ||
OK, | ||
bc.sortWith { | ||
case (BaseConfig("global", _, _, _), _) ⇒ true | ||
case (_, BaseConfig("global", _, _, _)) ⇒ false | ||
case (BaseConfig(a, _, _, _), BaseConfig(b, _, _, _)) ⇒ a.compareTo(b) < 0 | ||
} | ||
) | ||
} | ||
} | ||
|
||
def update(analyzerConfigName: String): Action[Fields] = authenticated(Roles.orgAdmin).async(fieldsBodyParser) { implicit request ⇒ | ||
request.body.getValue("config").flatMap(_.asOpt[JsObject]) match { | ||
case Some(config) ⇒ analyzerConfigSrv.updateOrCreate(request.userId, analyzerConfigName, config) | ||
.map(renderer.toOutput(OK, _)) | ||
case Some(config) ⇒ | ||
analyzerConfigSrv | ||
.updateOrCreate(request.userId, analyzerConfigName, config) | ||
.map(renderer.toOutput(OK, _)) | ||
case None ⇒ Future.failed(BadRequestError("attribute config has invalid format")) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.