Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into add-standard-devia…
Browse files Browse the repository at this point in the history
…tion-and-variance-aggregations
  • Loading branch information
Pawel Czajka committed Dec 18, 2024
2 parents eb5650f + a5d5305 commit a7cd9d8
Show file tree
Hide file tree
Showing 119 changed files with 1,157 additions and 803 deletions.
54 changes: 34 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import com.typesafe.sbt.packager.SettingsHelper
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.dockerUsername
import pl.project13.scala.sbt.JmhPlugin
import pl.project13.scala.sbt.JmhPlugin._
import sbt.Keys._
import sbt._
import pl.project13.scala.sbt.JmhPlugin.*
import sbt.*
import sbt.Keys.*
import sbtassembly.AssemblyPlugin.autoImport.assembly
import sbtassembly.MergeStrategy
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations.*

import scala.language.postfixOps
import scala.sys.process._
import scala.sys.process.*
import scala.util.Try
import scala.xml.Elem
import scala.xml.transform.{RewriteRule, RuleTransformer}
Expand Down Expand Up @@ -1913,6 +1913,18 @@ lazy val listenerApi = (project in file("designer/listener-api"))
)
.dependsOn(extensionsApi)

lazy val configLoaderApi = (project in file("designer/config-loader-api"))
.settings(commonSettings)
.settings(
name := "nussknacker-config-loader-api",
libraryDependencies ++= {
Seq(
"org.typelevel" %% "cats-effect" % catsEffectV
)
}
)
.dependsOn(extensionsApi)

lazy val deploymentManagerApi = (project in file("designer/deployment-manager-api"))
.settings(commonSettings)
.settings(
Expand Down Expand Up @@ -1985,21 +1997,21 @@ lazy val designer = (project in file("designer/server"))
assembly / assemblyMergeStrategy := designerMergeStrategy,
libraryDependencies ++= {
Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpV,
"com.typesafe.akka" %% "akka-slf4j" % akkaV,
"com.typesafe.akka" %% "akka-stream" % akkaV,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV % Test,
"com.typesafe.akka" %% "akka-testkit" % akkaV % Test,
"de.heikoseeberger" %% "akka-http-circe" % akkaHttpCirceV,
"com.softwaremill.sttp.client3" %% "akka-http-backend" % sttpV,
"ch.qos.logback" % "logback-core" % logbackV,
"ch.qos.logback" % "logback-classic" % logbackV,
"ch.qos.logback.contrib" % "logback-json-classic" % logbackJsonV,
"ch.qos.logback.contrib" % "logback-jackson" % logbackJsonV,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonV,
"org.slf4j" % "log4j-over-slf4j" % slf4jV,
"com.carrotsearch" % "java-sizeof" % "0.0.5",
"org.typelevel" %% "case-insensitive" % "1.4.0",
"com.typesafe.akka" %% "akka-http" % akkaHttpV,
"com.typesafe.akka" %% "akka-slf4j" % akkaV,
"com.typesafe.akka" %% "akka-stream" % akkaV,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV % Test,
"com.typesafe.akka" %% "akka-testkit" % akkaV % Test,
"de.heikoseeberger" %% "akka-http-circe" % akkaHttpCirceV,
"com.softwaremill.sttp.client3" %% "async-http-client-backend-cats" % sttpV,
"ch.qos.logback" % "logback-core" % logbackV,
"ch.qos.logback" % "logback-classic" % logbackV,
"ch.qos.logback.contrib" % "logback-json-classic" % logbackJsonV,
"ch.qos.logback.contrib" % "logback-jackson" % logbackJsonV,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonV,
"org.slf4j" % "log4j-over-slf4j" % slf4jV,
"com.carrotsearch" % "java-sizeof" % "0.0.5",
"org.typelevel" %% "case-insensitive" % "1.4.0",

// It's needed by flinkDeploymentManager which has disabled includingScala
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
Expand Down Expand Up @@ -2053,6 +2065,7 @@ lazy val designer = (project in file("designer/server"))
deploymentManagerApi,
restmodel,
listenerApi,
configLoaderApi,
defaultHelpers % Test,
testUtils % Test,
flinkTestUtils % Test,
Expand Down Expand Up @@ -2193,6 +2206,7 @@ lazy val modules = List[ProjectReference](
httpUtils,
restmodel,
listenerApi,
configLoaderApi,
deploymentManagerApi,
designer,
sqlComponents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import pl.touk.nussknacker.engine.util.service.EagerServiceWithStaticParametersA
import pl.touk.nussknacker.http.backend.FixedAsyncHttpClientBackendProvider
import pl.touk.nussknacker.openapi.enrichers.{SwaggerEnricherCreator, SwaggerEnrichers}
import pl.touk.nussknacker.openapi.parser.SwaggerParser
import pl.touk.nussknacker.openapi.{ApiKeyConfig, OpenAPIServicesConfig}
import pl.touk.nussknacker.openapi.{ApiKeySecret, OpenAPIServicesConfig, SecurityConfig, SecuritySchemeName}
import pl.touk.nussknacker.test.PatientScalaFutures

import java.net.URL
Expand All @@ -44,10 +44,10 @@ class OpenAPIServiceSpec
val client = new DefaultAsyncHttpClient()
try {
new StubService().withCustomerService { port =>
val securities = Map("apikey" -> ApiKeyConfig("TODO"))
val secretBySchemeName = Map(SecuritySchemeName("apikey") -> ApiKeySecret("TODO"))
val config = OpenAPIServicesConfig(
new URL("http://foo"),
security = Some(securities),
security = secretBySchemeName,
rootUrl = Some(new URL(s"http://localhost:$port"))
)
val services = SwaggerParser.parse(definition, config).collect { case Valid(service) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import pl.touk.nussknacker.engine.api.CirceUtil
import pl.touk.nussknacker.engine.api.component.{ComponentDefinition, ComponentProvider, NussknackerVersion}
import pl.touk.nussknacker.engine.api.process.ProcessObjectDependencies
import pl.touk.nussknacker.engine.util.config.ConfigEnrichments._
import pl.touk.nussknacker.openapi.OpenAPIsConfig._
import pl.touk.nussknacker.openapi.OpenAPIServicesConfig._
import pl.touk.nussknacker.openapi.discovery.SwaggerOpenApiDefinitionDiscovery
import pl.touk.nussknacker.openapi.enrichers.{SwaggerEnricherCreator, SwaggerEnrichers}
import pl.touk.nussknacker.openapi.parser.ServiceParseError
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package pl.touk.nussknacker.openapi

import com.typesafe.config.Config
import io.swagger.v3.oas.models.PathItem.HttpMethod
import net.ceedubs.ficus.readers.{ArbitraryTypeReader, ValueReader}
import pl.touk.nussknacker.http.backend.{DefaultHttpClientConfig, HttpClientConfig}
import sttp.model.StatusCode

import java.net.URL
import scala.util.matching.Regex

final case class OpenAPIServicesConfig(
url: URL,
// by default we allow only GET, as enrichers should be idempotent and not change data
allowedMethods: List[String] = List(HttpMethod.GET.name()),
codesToInterpretAsEmpty: List[Int] = List(StatusCode.NotFound.code),
namePattern: Regex = ".*".r,
rootUrl: Option[URL] = None,
// For backward compatibility it is called security. We should probably rename it and bundle together with secret
private val security: Map[SecuritySchemeName, Secret] = Map.empty,
private val secret: Option[Secret] = None,
httpClientConfig: HttpClientConfig = DefaultHttpClientConfig()
) {
def securityConfig: SecurityConfig =
new SecurityConfig(secretBySchemeName = security, commonSecretForAnyScheme = secret)
}

final class SecurityConfig(
secretBySchemeName: Map[SecuritySchemeName, Secret],
commonSecretForAnyScheme: Option[Secret]
) {

def secret(schemeName: SecuritySchemeName): Option[Secret] =
secretBySchemeName.get(schemeName) orElse commonSecretForAnyScheme

}

object SecurityConfig {
def empty: SecurityConfig = new SecurityConfig(Map.empty, None)
}

final case class SecuritySchemeName(value: String)

sealed trait Secret

final case class ApiKeySecret(apiKeyValue: String) extends Secret

object OpenAPIServicesConfig {

import net.ceedubs.ficus.Ficus._
import pl.touk.nussknacker.engine.util.config.ConfigEnrichments._
import HttpClientConfig._

implicit val securitySchemeNameVR: ValueReader[SecuritySchemeName] =
ValueReader[String].map(SecuritySchemeName(_))

implicit val regexReader: ValueReader[Regex] = (config: Config, path: String) => new Regex(config.getString(path))

implicit val apiKeyVR: ValueReader[ApiKeySecret] = ValueReader.relative { conf =>
ApiKeySecret(
apiKeyValue = conf.as[String]("apiKeyValue")
)
}

implicit val secretVR: ValueReader[Secret] = ValueReader.relative { conf =>
conf.as[String]("type") match {
case "apiKey" => conf.rootAs[ApiKeySecret]
case typ => throw new Exception(s"Not supported swagger security type '$typ' in the configuration")
}
}

implicit val secretBySchemeNameVR: ValueReader[Map[SecuritySchemeName, Secret]] =
ValueReader[Map[String, Secret]].map { secretBySchemeName =>
secretBySchemeName.map { case (schemeNameString, secret) =>
SecuritySchemeName(schemeNameString) -> secret
}
}

implicit val openAPIServicesConfigVR: ValueReader[OpenAPIServicesConfig] =
ArbitraryTypeReader.arbitraryTypeValueReader[OpenAPIServicesConfig]

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ private[parser] class ParseToSwaggerService(openapi: OpenAPI, openAPIsConfig: Op
Option(operation.getSecurity).orElse(Option(openapi.getSecurity)).map(_.asScala.toList).getOrElse(Nil)
val securitySchemes =
Option(openapi.getComponents).flatMap(c => Option(c.getSecuritySchemes)).map(_.asScala.toMap)
val securities = openAPIsConfig.security.getOrElse(Map.empty)
SecuritiesParser.parseSwaggerSecurities(securityRequirements, securitySchemes, securities)
SecuritiesParser.parseOperationSecurities(securityRequirements, securitySchemes, openAPIsConfig.securityConfig)
}

private def prepareParameters(operation: Operation): ValidationResult[List[SwaggerParameter]] = {
Expand Down
Loading

0 comments on commit a7cd9d8

Please sign in to comment.