-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'staging' into integer-dictionary-support-in-fragment-in…
…puts
- Loading branch information
Showing
15 changed files
with
380 additions
and
185 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
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
82 changes: 82 additions & 0 deletions
82
components/openapi/src/main/scala/pl/touk/nussknacker/openapi/OpenAPIServicesConfig.scala
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,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] | ||
|
||
} |
50 changes: 0 additions & 50 deletions
50
components/openapi/src/main/scala/pl/touk/nussknacker/openapi/OpenAPIsConfig.scala
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
36 changes: 36 additions & 0 deletions
36
components/openapi/src/test/resources/swagger/multiple-schemes-for-single-operation.yml
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,36 @@ | ||
openapi: "3.1.0" | ||
info: | ||
title: Simple API overview | ||
version: 2.0.0 | ||
servers: | ||
- url: http://dummy.io | ||
paths: | ||
/: | ||
get: | ||
security: | ||
- headerConfig: [] | ||
- queryConfig: [] | ||
- cookieConfig: [] | ||
responses: | ||
'200': | ||
description: "-" | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
operationId: root | ||
components: | ||
schemas: {} | ||
securitySchemes: | ||
headerConfig: | ||
type: apiKey | ||
name: keyHeader | ||
in: header | ||
queryConfig: | ||
type: apiKey | ||
name: keyParam | ||
in: query | ||
cookieConfig: | ||
type: apiKey | ||
name: keyCookie | ||
in: cookie |
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.