diff --git a/prism-agent/service/server/openapi/generator-config/config.yaml b/prism-agent/service/server/openapi/generator-config/config.yaml deleted file mode 100644 index 9aa8c34342..0000000000 --- a/prism-agent/service/server/openapi/generator-config/config.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# The folder where templates can be found -# FIXME relate to the project root! -# templateDir: "server/openapi/generator-config/scala-akka-http-server" -templateDir: "prism-agent/service/server/openapi/generator-config/scala-akka-http-server" - -# Only generate output for templates registered with the 'Apis' or 'Models' types -globalProperties: - apis: "" - models: "" - -# Define output packages for generated classes -apiPackage: "io.iohk.atala.agent.openapi.api" -modelPackage: "io.iohk.atala.agent.openapi.model" - -# The generator to use -generatorName: "scala-akka-http-server" -# Use handwritten classes for the types below. This is useful to customize the (de)serialization -#importMappings: diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/README.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/README.mustache deleted file mode 100644 index ff7d54bcb1..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/README.mustache +++ /dev/null @@ -1,32 +0,0 @@ -# {{&appName}} - -{{&appDescription}} - -{{^hideGenerationTimestamp}} - This Scala akka-http framework project was generated by the OpenAPI generator tool at {{generatedDate}}. -{{/hideGenerationTimestamp}} - -{{#generateApis}} - ## API - - {{#apiInfo}} - {{#apis}} - ### {{baseName}} - - |Name|Role| - |----|----| - |`{{importPath}}Controller`|akka-http API controller| - |`{{importPath}}Api`|Representing trait| - {{^skipStubs}} - |`{{importPath}}ApiImpl`|Default implementation| - {{/skipStubs}} - - {{#operations}} - {{#operation}} - * `{{httpMethod}} {{contextPath}}{{path}}{{#queryParams.0}}?{{/queryParams.0}}{{#queryParams}}{{paramName}}=[value]{{^-last}}&{{/-last}}{{/queryParams}}` - {{summary}} - {{/operation}} - {{/operations}} - - {{/apis}} - {{/apiInfo}} -{{/generateApis}} diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/api.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/api.mustache deleted file mode 100644 index 4160a1aacf..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/api.mustache +++ /dev/null @@ -1,96 +0,0 @@ -package {{package}} - -import akka.http.scaladsl.server.Directives._ -import akka.http.scaladsl.server.Route -import akka.http.scaladsl.model.StatusCodes -{{^pathMatcherPatterns.isEmpty}}import akka.http.scaladsl.server.{PathMatcher, PathMatcher1} -{{/pathMatcherPatterns.isEmpty}} -{{#hasMarshalling}}import akka.http.scaladsl.marshalling.ToEntityMarshaller -import akka.http.scaladsl.unmarshalling.FromEntityUnmarshaller -import akka.http.scaladsl.unmarshalling.FromStringUnmarshaller -{{/hasMarshalling}} -{{#hasCookieParams}}import akka.http.scaladsl.model.headers.HttpCookiePair -{{/hasCookieParams}} -{{#hasMultipart}}import {{invokerPackage}}.StringDirectives -import {{invokerPackage}}.MultipartDirectives -import {{invokerPackage}}.FileField -import {{invokerPackage}}.PartsAndFiles -{{/hasMultipart}} -{{#imports}}import {{import}} -{{/imports}} -{{#hasMultipart}}import scala.util.Try -import akka.http.scaladsl.server.MalformedRequestContentRejection -import akka.http.scaladsl.server.directives.FileInfo -{{/hasMultipart}} - - -{{#operations}} -class {{classname}}( - {{classVarName}}Service: {{classname}}Service{{#hasMarshalling}}, - {{classVarName}}Marshaller: {{classname}}Marshaller{{/hasMarshalling}} -) {{#hasMultipart}} extends MultipartDirectives with StringDirectives {{/hasMultipart}}{ - - {{#pathMatcherPatterns}}import {{classname}}Patterns.{{pathMatcherVarName}} - {{/pathMatcherPatterns}} - - {{#hasMarshalling}}import {{classVarName}}Marshaller._ - {{/hasMarshalling}} - - lazy val route: Route = - {{#operation}} - path({{#vendorExtensions.x-paths}}{{#isText}}"{{/isText}}{{value}}{{#isText}}"{{/isText}}{{^-last}} / {{/-last}}{{/vendorExtensions.x-paths}}) { {{^pathParams.isEmpty}}({{#pathParams}}{{paramName}}{{^-last}}, {{/-last}}{{/pathParams}}) => {{/pathParams.isEmpty}} - {{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}} { {{^queryParams.isEmpty}} - parameters({{#queryParams}}"{{baseName}}".as[{{dataType}}]{{^required}}.?{{#vendorExtensions.x-has-default-value}}({{{defaultValue}}}){{/vendorExtensions.x-has-default-value}}{{/required}}{{^-last}}, {{/-last}}{{/queryParams}}) { ({{#queryParams}}{{paramName}}{{^-last}}, {{/-last}}{{/queryParams}}) =>{{/queryParams.isEmpty}} {{^headerParams.isEmpty}} - {{#headerParams}}{{#required}}headerValueByName{{/required}}{{^required}}optionalHeaderValueByName{{/required}}("{{baseName}}") { {{paramName}} => {{/headerParams}}{{/headerParams.isEmpty}}{{^cookieParams.isEmpty}} - {{#cookieParams}}{{#required}}cookie({{/required}}{{^required}}optionalCookie({{/required}}"{{baseName}}"){ {{paramName}} => {{/cookieParams}}{{/cookieParams.isEmpty}}{{#isMultipart}} -{{> multipart}}{{/isMultipart}}{{^isMultipart}}{{> noMultipart}}{{/isMultipart}}{{^cookieParams.isEmpty}} - }{{/cookieParams.isEmpty}}{{^headerParams.isEmpty}} - }{{/headerParams.isEmpty}}{{^queryParams.isEmpty}} - }{{/queryParams.isEmpty}} - } - }{{^-last}} ~{{/-last}} - {{/operation}} -} - -{{^pathMatcherPatterns.isEmpty}} -object {{classname}}Patterns { - - {{#pathMatcherPatterns}}val {{pathMatcherVarName}}: PathMatcher1[String] = PathMatcher("{{pattern}}".r) - {{/pathMatcherPatterns}} -} -{{/pathMatcherPatterns.isEmpty}} - -trait {{classname}}Service { - -{{#operation}} -{{#responses}} def {{operationId}}{{#vendorExtensions.x-is-default}}Default{{/vendorExtensions.x-is-default}}{{^vendorExtensions.x-is-default}}{{code}}{{/vendorExtensions.x-is-default}}{{#baseType}}({{#vendorExtensions.x-is-default}}statusCode: Int, {{/vendorExtensions.x-is-default}}response{{baseType}}{{containerType}}: {{dataType}})(implicit toEntityMarshaller{{baseType}}{{containerType}}: ToEntityMarshaller[{{dataType}}]){{/baseType}}{{^baseType}}{{#vendorExtensions.x-is-default}}(statusCode: Int){{/vendorExtensions.x-is-default}}{{/baseType}}: Route ={{#vendorExtensions.x-empty-response}} - complete({{#vendorExtensions.x-is-default}}statusCode{{/vendorExtensions.x-is-default}}{{^vendorExtensions.x-is-default}}StatusCodes.getForKey({{code}}){{/vendorExtensions.x-is-default}}){{/vendorExtensions.x-empty-response}}{{^vendorExtensions.x-empty-response}} - complete(({{#vendorExtensions.x-is-default}}statusCode{{/vendorExtensions.x-is-default}}{{^vendorExtensions.x-is-default}}{{code}}{{/vendorExtensions.x-is-default}}, {{#baseType}}response{{baseType}}{{containerType}}{{/baseType}}{{^baseType}}"{{message}}"{{/baseType}})){{/vendorExtensions.x-empty-response}} -{{/responses}} - /** -{{#responses}} * {{#code}}Code: {{.}}{{/code}}{{#message}}, Message: {{.}}{{/message}}{{#dataType}}, DataType: {{.}}{{/dataType}} - {{/responses}} - */ - def {{operationId}}({{> operationParam}}){{^vendorExtensions.x-specific-marshallers.isEmpty}} - (implicit {{#vendorExtensions.x-specific-marshallers}}toEntityMarshaller{{varName}}: ToEntityMarshaller[{{dataType}}]{{^-last}}, {{/-last}}{{/vendorExtensions.x-specific-marshallers}}){{/vendorExtensions.x-specific-marshallers.isEmpty}}: Route - -{{/operation}} -} - -{{#hasMarshalling}} -trait {{classname}}Marshaller { -{{#entityUnmarshallers}} implicit def fromEntityUnmarshaller{{varName}}: FromEntityUnmarshaller[{{dataType}}] - -{{/entityUnmarshallers}} - -{{#stringUnmarshallers}} implicit def fromStringUnmarshaller{{varName}}: FromStringUnmarshaller[{{dataType}}] - -{{/stringUnmarshallers}} - -{{#entityMarshallers}} implicit def toEntityMarshaller{{varName}}: ToEntityMarshaller[{{dataType}}] - -{{/entityMarshallers}} -} -{{/hasMarshalling}} - -{{/operations}} diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/build.sbt.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/build.sbt.mustache deleted file mode 100644 index 69788d7e7b..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/build.sbt.mustache +++ /dev/null @@ -1,16 +0,0 @@ -version := "{{artifactVersion}}" -name := "{{artifactId}}" -organization := "{{groupId}}" -scalaVersion := "2.12.8" - -val AkkaVersion = "2.6.19" -val AkkaHttpVersion = "10.2.9" -val LogbackVersion = "1.2.11" - -libraryDependencies ++= Seq( - "com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion, - "com.typesafe.akka" %% "akka-stream" % AkkaVersion, - "com.typesafe.akka" %% "akka-http" % AkkaHttpVersion, - "com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion, - "ch.qos.logback" % "logback-classic" % LogbackVersion % Runtime -) diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/controller.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/controller.mustache deleted file mode 100644 index 344a9112e3..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/controller.mustache +++ /dev/null @@ -1,15 +0,0 @@ -package {{invokerPackage}} - -import akka.actor.typed.ActorSystem -import akka.http.scaladsl.Http -import akka.http.scaladsl.server.Route -{{#apiInfo}}{{#apis}}{{#operations}}import {{package}}.{{classname}} -{{/operations}}{{/apis}}{{/apiInfo}} -import akka.http.scaladsl.server.Directives._ - -class Controller[T]({{#apiInfo}}{{#apis}}{{#operations}}{{classVarName}}: {{classname}}{{^-last}}, {{/-last}}{{/operations}}{{/apis}}{{/apiInfo}})(implicit system: ActorSystem[T]) { - - lazy val routes: Route = {{#apiInfo}}{{#apis}}{{#operations}}{{classVarName}}.route {{^-last}}~ {{/-last}}{{/operations}}{{/apis}}{{/apiInfo}} - - Http().newServerAt("0.0.0.0", 9000).bind(routes) -} \ No newline at end of file diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/helper.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/helper.mustache deleted file mode 100644 index 8aa3c0f8c2..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/helper.mustache +++ /dev/null @@ -1,34 +0,0 @@ -package {{invokerPackage}} - -import akka.http.scaladsl.server.Directives._ -import akka.http.scaladsl.server.{PathMatcher, PathMatcher1} -import scala.util.{Failure, Success, Try} -import scala.util.control.NoStackTrace - -object AkkaHttpHelper { - def optToTry[T](opt: Option[T], err: => String): Try[T] = - opt.map[Try[T]](Success(_)) getOrElse Failure(new RuntimeException(err) with NoStackTrace) - - /** - * A PathMatcher that matches and extracts a Float value. The matched string representation is the pure decimal, - * optionally signed form of a float value, i.e. without exponent. - * - * @group pathmatcher - */ - val FloatNumber: PathMatcher1[Float] = - PathMatcher("""[+-]?\d*\.?\d*""".r) flatMap { string => - try Some(java.lang.Float.parseFloat(string)) - catch { case _: NumberFormatException => None } - } - - /** - * A PathMatcher that matches and extracts a Boolean value. - * - * @group pathmatcher - */ - val Boolean: PathMatcher1[Boolean] = - Segment.flatMap { string => - try Some(string.toBoolean) - catch { case _: IllegalArgumentException => None } - } -} diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/model.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/model.mustache deleted file mode 100644 index 68cafc5f2c..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/model.mustache +++ /dev/null @@ -1,27 +0,0 @@ -package {{package}} - -{{#imports}} -import {{import}} -{{/imports}} - -{{#models}} -{{#model}} -/** -{{#title}} * = {{{.}}} = - * -{{/title}} -{{#description}} * {{{.}}} - * -{{/description}} -{{#vars}} - * @param {{{name}}} {{{description}}}{{#example}} for example: ''{{{.}}}''{{/example}} -{{/vars}} -*/ -final case class {{classname}} ( - {{#vars}} - {{{name}}}: {{^required}}Option[{{/required}}{{datatype}}{{^required}}] = None{{/required}}{{^-last}},{{/-last}} - {{/vars}} -) - -{{/model}} -{{/models}} diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/multipart.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/multipart.mustache deleted file mode 100644 index 1da79aef03..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/multipart.mustache +++ /dev/null @@ -1,12 +0,0 @@ - formAndFiles({{#vendorExtensions.x-file-params}}FileField("{{baseName}}")){{/vendorExtensions.x-file-params}}{{^-last}}, {{/-last}} { partsAndFiles => {{^vendorExtensions.x-file-params.isEmpty}} - val _____ : Try[Route] = for { - {{#vendorExtensions.x-file-params}}{{baseName}} <- optToTry(partsAndFiles.files.get("{{baseName}}"), s"File {{baseName}} missing") - {{/vendorExtensions.x-file-params}} - } yield { {{/vendorExtensions.x-file-params.isEmpty}} - implicit val vp: StringValueProvider = partsAndFiles.form{{^vendorExtensions.x-non-file-params.isEmpty}} - stringFields({{#vendorExtensions.x-non-file-params}}"{{baseName}}".as[{{dataType}}]{{^required}}.?{{#vendorExtensions.x-has-default-value}}({{defaultValue}}){{/vendorExtensions.x-has-default-value}}{{/required}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-non-file-params}}) { ({{#vendorExtensions.x-non-file-params}}{{paramName}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-non-file-params}}) =>{{/vendorExtensions.x-non-file-params.isEmpty}} - {{classVarName}}Service.{{operationId}}({{#allParams}}{{paramName}} = {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){{^vendorExtensions.nonFileFormParams.isEmpty}} - }{{/vendorExtensions.nonFileFormParams.isEmpty}}{{^vendorExtensions.x-file-params.isEmpty}} - } - _____.fold[Route](t => reject(MalformedRequestContentRejection("Missing file.", t)), identity){{/vendorExtensions.x-file-params.isEmpty}} - } \ No newline at end of file diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/multipartDirectives.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/multipartDirectives.mustache deleted file mode 100644 index 6e802204c5..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/multipartDirectives.mustache +++ /dev/null @@ -1,89 +0,0 @@ -package {{invokerPackage}} - -import java.io.File -import java.nio.file.Files - -import akka.annotation.ApiMayChange -import akka.http.scaladsl.model.Multipart.FormData -import akka.http.scaladsl.model.{ContentType, HttpEntity, Multipart} -import akka.http.scaladsl.server.Directive1 -import akka.http.scaladsl.server.directives._ -import akka.stream.Materializer -import akka.stream.scaladsl._ - -import scala.collection.immutable -import scala.concurrent.{ExecutionContextExecutor, Future} - -trait MultipartDirectives { - - import akka.http.scaladsl.server.directives.BasicDirectives._ - import akka.http.scaladsl.server.directives.FutureDirectives._ - import akka.http.scaladsl.server.directives.MarshallingDirectives._ - - @ApiMayChange - def formAndFiles(fileFields: FileField*): Directive1[PartsAndFiles] = - entity(as[Multipart.FormData]).flatMap { - formData => - extractRequestContext.flatMap { ctx => - implicit val mat: Materializer = ctx.materializer - implicit val ec: ExecutionContextExecutor = ctx.executionContext - - val uploadingSink: Sink[FormData.BodyPart, Future[PartsAndFiles]] = - Sink.foldAsync[PartsAndFiles, Multipart.FormData.BodyPart](PartsAndFiles.Empty) { - (acc, part) => - def discard(p: Multipart.FormData.BodyPart): Future[PartsAndFiles] = { - p.entity.discardBytes() - Future.successful(acc) - } - - part.filename.map { - fileName => - fileFields.find(_.fieldName == part.name) - .map { - case FileField(_, destFn) => - val fileInfo = FileInfo(part.name, fileName, part.entity.contentType) - val dest = destFn(fileInfo) - - part.entity.dataBytes.runWith(FileIO.toPath(dest.toPath)).map { _ => - acc.addFile(fileInfo, dest) - } - }.getOrElse(discard(part)) - } getOrElse { - part.entity match { - case HttpEntity.Strict(ct: ContentType.NonBinary, data) => - val charsetName = ct.charset.nioCharset.name - val partContent = data.decodeString(charsetName) - - Future.successful(acc.addForm(part.name, partContent)) - case _ => - discard(part) - } - } - } - - val uploadedF = formData.parts.runWith(uploadingSink) - - onSuccess(uploadedF) - } - } -} - -object MultipartDirectives extends MultipartDirectives with FileUploadDirectives { - val tempFileFromFileInfo: FileInfo => File = { - file: FileInfo => Files.createTempFile(file.fileName, ".tmp").toFile() - } -} - -final case class FileField(fieldName: String, fileNameF: FileInfo => File = MultipartDirectives.tempFileFromFileInfo) - -final case class PartsAndFiles(form: immutable.Map[String, String], files: Map[String, (FileInfo, File)]) { - def addForm(fieldName: String, content: String): PartsAndFiles = this.copy(form.updated(fieldName, content)) - - def addFile(info: FileInfo, file: File): PartsAndFiles = this.copy( - files = files.updated(info.fieldName, (info, file)) - ) -} - -object PartsAndFiles { - val Empty: PartsAndFiles = PartsAndFiles(immutable.Map.empty, immutable.Map.empty) -} \ No newline at end of file diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/noMultipart.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/noMultipart.mustache deleted file mode 100644 index 1d45522d0c..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/noMultipart.mustache +++ /dev/null @@ -1,7 +0,0 @@ -{{^formParams.isEmpty}} - - formFields({{#formParams}}"{{baseName}}".as[{{#isPrimitiveType}}{{dataType}}{{/isPrimitiveType}}{{^isPrimitiveType}}String{{/isPrimitiveType}}]{{^required}}.?{{#vendorExtensions.x-has-default-value}}({{defaultValue}}){{/vendorExtensions.x-has-default-value}}{{/required}}{{^-last}}, {{/-last}}{{/formParams}}) { ({{#formParams}}{{paramName}}{{^-last}}, {{/-last}}{{/formParams}}) =>{{/formParams.isEmpty}} - {{#bodyParam}}{{^isPrimitiveType}}entity(as[{{dataType}}]){ {{paramName}} => - {{/isPrimitiveType}}{{/bodyParam}}{{classVarName}}Service.{{operationId}}({{#allParams}}{{paramName}} = {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){{#bodyParam}}{{^isPrimitiveType}} - }{{/isPrimitiveType}}{{/bodyParam}}{{^formParams.isEmpty}} - }{{/formParams.isEmpty}} \ No newline at end of file diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/operationParam.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/operationParam.mustache deleted file mode 100644 index fc0339da10..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/operationParam.mustache +++ /dev/null @@ -1 +0,0 @@ -{{#allParams}}{{paramName}}: {{#isFile}}(FileInfo, File){{/isFile}}{{^isFile}}{{^required}}{{^vendorExtensions.x-has-default-value}}Option[{{/vendorExtensions.x-has-default-value}}{{/required}}{{dataType}}{{^required}}{{^vendorExtensions.x-has-default-value}}]{{/vendorExtensions.x-has-default-value}}{{/required}}{{/isFile}}{{^-last}}, {{/-last}}{{/allParams}} \ No newline at end of file diff --git a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/stringDirectives.mustache b/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/stringDirectives.mustache deleted file mode 100644 index 5640a9d454..0000000000 --- a/prism-agent/service/server/openapi/generator-config/scala-akka-http-server/stringDirectives.mustache +++ /dev/null @@ -1,127 +0,0 @@ -package {{invokerPackage}} - -import akka.http.scaladsl.common._ -import akka.http.scaladsl.server.{Directive, Directive0, Directive1, InvalidRequiredValueForQueryParamRejection, MalformedFormFieldRejection, MissingFormFieldRejection, MissingQueryParamRejection, UnsupportedRequestContentTypeRejection} -import akka.http.scaladsl.server.directives.BasicDirectives -import akka.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException - -import scala.concurrent.Future -import scala.util.{Failure, Success} - -trait StringDirectives { - implicit def _symbol2NR(symbol: Symbol): NameReceptacle[String] = new NameReceptacle[String](symbol.name) - implicit def _string2NR(string: String): NameReceptacle[String] = new NameReceptacle[String](string) - - import StringDirectives._ - type StringValueProvider = Map[String, String] - - def stringField(pdm: StringMagnet): pdm.Out = pdm() - - def stringFields(pdm: StringMagnet): pdm.Out = pdm() - -} - -object StringDirectives extends StringDirectives { - - sealed trait StringMagnet { - type Out - def apply(): Out - } - object StringMagnet { - implicit def apply[T](value: T)(implicit sdef: StringDef[T]): StringMagnet { type Out = sdef.Out } = - new StringMagnet { - type Out = sdef.Out - def apply(): sdef.Out = sdef(value) - } - } - - type StringDefAux[A, B] = StringDef[A] { type Out = B } - sealed trait StringDef[T] { - type Out - def apply(value: T): Out - } - object StringDef { - protected def stringDef[A, B](f: A => B): StringDefAux[A, B] = - new StringDef[A] { - type Out = B - - def apply(value: A): B = f(value) - } - - import akka.http.scaladsl.server.directives.BasicDirectives._ - import akka.http.scaladsl.server.directives.FutureDirectives._ - import akka.http.scaladsl.server.directives.RouteDirectives._ - import akka.http.scaladsl.unmarshalling._ - - type FSU[T] = FromStringUnmarshaller[T] - type FSOU[T] = Unmarshaller[Option[String], T] - type SFVP = StringValueProvider - - protected def extractField[A, B](f: A => Directive1[B]): StringDefAux[A, Directive1[B]] = stringDef(f) - - protected def handleFieldResult[T](fieldName: String, result: Future[T]): Directive1[T] = onComplete(result).flatMap { - case Success(x) => provide(x) - case Failure(Unmarshaller.NoContentException) => reject(MissingFormFieldRejection(fieldName)){{#akkaHttp10_1_10_plus}} - case Failure(x: UnsupportedContentTypeException) => reject(UnsupportedRequestContentTypeRejection(x.supported, x.actualContentType)){{/akkaHttp10_1_10_plus}}{{^akkaHttp10_1_10_plus}} - case Failure(x: UnsupportedContentTypeException) => reject(UnsupportedRequestContentTypeRejection(x.supported)){{/akkaHttp10_1_10_plus}} - case Failure(x) => reject(MalformedFormFieldRejection(fieldName, if (x.getMessage == null) "" else x.getMessage, Option(x.getCause))) - } - - private def filter[T](paramName: String, fsou: FSOU[T])(implicit vp: SFVP): Directive1[T] = { - extract { ctx => - import ctx.{executionContext, materializer} - handleFieldResult(paramName, fsou(vp.get(paramName))) - }.flatMap(identity) - } - - implicit def forString(implicit fsu: FSU[String], vp: SFVP): StringDefAux[String, Directive1[String]] = - extractField[String, String] { string => filter(string, fsu) } - implicit def forSymbol(implicit fsu: FSU[String], vp: SFVP): StringDefAux[Symbol, Directive1[String]] = - extractField[Symbol, String] { symbol => filter(symbol.name, fsu) } - implicit def forNR[T](implicit fsu: FSU[T], vp: SFVP): StringDefAux[NameReceptacle[T], Directive1[T]] = - extractField[NameReceptacle[T], T] { nr => filter(nr.name, fsu) } - implicit def forNUR[T](implicit vp: SFVP): StringDefAux[NameUnmarshallerReceptacle[T], Directive1[T]] = - extractField[NameUnmarshallerReceptacle[T], T] { nr => filter(nr.name, nr.um) } - implicit def forNOR[T](implicit fsou: FSOU[T], vp: SFVP): StringDefAux[NameOptionReceptacle[T], Directive1[Option[T]]] = - extractField[NameOptionReceptacle[T], Option[T]] { nr => filter[Option[T]](nr.name, fsou) } - implicit def forNDR[T](implicit fsou: FSOU[T], vp: SFVP): StringDefAux[NameDefaultReceptacle[T], Directive1[T]] = - extractField[NameDefaultReceptacle[T], T] { nr => filter[T](nr.name, fsou withDefaultValue nr.default) } - implicit def forNOUR[T](implicit vp: SFVP): StringDefAux[NameOptionUnmarshallerReceptacle[T], Directive1[Option[T]]] = - extractField[NameOptionUnmarshallerReceptacle[T], Option[T]] { nr => filter(nr.name, nr.um: FSOU[T]) } - implicit def forNDUR[T](implicit vp: SFVP): StringDefAux[NameDefaultUnmarshallerReceptacle[T], Directive1[T]] = - extractField[NameDefaultUnmarshallerReceptacle[T], T] { nr => filter[T](nr.name, (nr.um: FSOU[T]) withDefaultValue nr.default) } - - //////////////////// required parameter support //////////////////// - - private def requiredFilter[T](paramName: String, fsou: FSOU[T], requiredValue: Any)(implicit vp: SFVP): Directive0 = { - extract { ctx => - import ctx.{executionContext, materializer} - onComplete(fsou(vp.get(paramName))) flatMap { - case Success(value) if value == requiredValue => pass - case Success(value) => reject(InvalidRequiredValueForQueryParamRejection(paramName, requiredValue.toString, value.toString)).toDirective[Unit] - case _ => reject(MissingQueryParamRejection(paramName)).toDirective[Unit] - } - }.flatMap(identity) - } - - implicit def forRVR[T](implicit fsu: FSU[T], vp: SFVP): StringDefAux[RequiredValueReceptacle[T], Directive0] = - stringDef[RequiredValueReceptacle[T], Directive0] { rvr => requiredFilter(rvr.name, fsu, rvr.requiredValue) } - - implicit def forRVDR[T](implicit vp: SFVP): StringDefAux[RequiredValueUnmarshallerReceptacle[T], Directive0] = - stringDef[RequiredValueUnmarshallerReceptacle[T], Directive0] { rvr => requiredFilter(rvr.name, rvr.um, rvr.requiredValue) } - - //////////////////// tuple support //////////////////// - - import akka.http.scaladsl.server.util.BinaryPolyFunc - import akka.http.scaladsl.server.util.TupleOps._ - - implicit def forTuple[T](implicit fold: FoldLeft[Directive0, T, ConvertStringDefAndConcatenate.type]): StringDefAux[T, fold.Out] = - stringDef[T, fold.Out](fold(BasicDirectives.pass, _)) - - object ConvertStringDefAndConcatenate extends BinaryPolyFunc { - implicit def from[P, TA, TB](implicit sdef: StringDef[P] {type Out = Directive[TB]}, ev: Join[TA, TB]): BinaryPolyFunc.Case[Directive[TA], P, ConvertStringDefAndConcatenate.type] {type Out = Directive[ev.Out]} = - at[Directive[TA], P] { (a, t) => a & sdef(t) } - } - - } -} diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Main.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Main.scala index d6a4d1df71..8ca25a6434 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Main.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Main.scala @@ -75,7 +75,7 @@ object MainApp extends ZIOAppDefault { } yield (myServer) } - def appComponents(didCommServicePort: Int, restServicePort: Int) = for { + def appComponents(didCommServicePort: Int) = for { _ <- Modules.issueCredentialDidCommExchangesJob.debug.fork _ <- Modules.presentProofExchangeJob.debug.fork _ <- Modules.connectDidCommExchangesJob.debug.fork @@ -110,12 +110,6 @@ object MainApp extends ZIOAppDefault { |""".stripMargin) .ignore - restServicePort <- System.env("REST_SERVICE_PORT").map { - case Some(s) if s.toIntOption.isDefined => s.toInt - case _ => 8080 - } - _ <- ZIO.logInfo(s"REST Service port => $restServicePort") - didCommServiceUrl <- System.env("DIDCOMM_SERVICE_URL").map { case Some(s) => s case _ => "http://localhost:8090" @@ -130,7 +124,7 @@ object MainApp extends ZIOAppDefault { _ <- migrations - app <- appComponents(didCommServicePort, restServicePort).provide( + app <- appComponents(didCommServicePort).provide( didCommAgentLayer(didCommServiceUrl), DidCommX.liveLayer, AppModule.didJwtResolverlayer,