From dda8f7109f462513af1fa29c8d1ab605f95ca7b8 Mon Sep 17 00:00:00 2001 From: Fabrizio Musella Date: Mon, 11 Sep 2023 17:24:28 +0200 Subject: [PATCH] moved createJWTPath to utils --- .../files/service/impl/S3ManagerImpl.scala | 16 ++-------------- .../interop/commons/utils/JWTPathGenerator.scala | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 utils/src/main/scala/it/pagopa/interop/commons/utils/JWTPathGenerator.scala diff --git a/file-manager/src/main/scala/it/pagopa/interop/commons/files/service/impl/S3ManagerImpl.scala b/file-manager/src/main/scala/it/pagopa/interop/commons/files/service/impl/S3ManagerImpl.scala index c558e9cf..53eb4224 100644 --- a/file-manager/src/main/scala/it/pagopa/interop/commons/files/service/impl/S3ManagerImpl.scala +++ b/file-manager/src/main/scala/it/pagopa/interop/commons/files/service/impl/S3ManagerImpl.scala @@ -4,7 +4,6 @@ import akka.http.scaladsl.server.directives.FileInfo import cats.implicits._ import it.pagopa.interop.commons.files.StorageConfiguration import it.pagopa.interop.commons.files.service.FileManager -import it.pagopa.interop.commons.utils.service.OffsetDateTimeSupplier import org.apache.commons.codec.binary.Base64 import org.apache.commons.codec.digest.DigestUtils import org.slf4j.{Logger, LoggerFactory} @@ -14,18 +13,14 @@ import software.amazon.awssdk.core.client.config.{ClientAsyncConfiguration, SdkA import software.amazon.awssdk.http.async.SdkAsyncHttpClient import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient import software.amazon.awssdk.services.s3.model._ -import software.amazon.awssdk.services.s3.{S3AsyncClient, S3Configuration} +import software.amazon.awssdk.services.s3.{S3AsyncClient, S3AsyncClientBuilder, S3Configuration} import java.io.{ByteArrayOutputStream, File} import java.nio.file.Files import java.util.concurrent.Executor import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future} -import scala.jdk.FutureConverters._ import scala.jdk.CollectionConverters._ -import software.amazon.awssdk.services.s3.S3AsyncClientBuilder - -import java.time.format.DateTimeFormatter -import java.util.UUID +import scala.jdk.FutureConverters._ final class S3ManagerImpl(blockingExecutionContext: ExecutionContextExecutor)( confOverride: S3AsyncClientBuilder => S3AsyncClientBuilder = identity @@ -167,11 +162,4 @@ final class S3ManagerImpl(blockingExecutionContext: ExecutionContextExecutor)( def calcContentMd5(file: File): String = calcContentMd5(Files.readAllBytes(file.toPath)) def calcContentMd5(byteArray: Array[Byte]): String = new String(Base64.encodeBase64(DigestUtils.md5(byteArray))) - - def createJWTPath(): String = { - val now = OffsetDateTimeSupplier.get() - val formattedDate = now.format(DateTimeFormatter.ofPattern("yyyyMMdd")) - val formattedDateTime = now.format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss")) - s"token-details/$formattedDate/${formattedDateTime}_${UUID.randomUUID()}.ndjson" - } } diff --git a/utils/src/main/scala/it/pagopa/interop/commons/utils/JWTPathGenerator.scala b/utils/src/main/scala/it/pagopa/interop/commons/utils/JWTPathGenerator.scala new file mode 100644 index 00000000..a8e40913 --- /dev/null +++ b/utils/src/main/scala/it/pagopa/interop/commons/utils/JWTPathGenerator.scala @@ -0,0 +1,15 @@ +package it.pagopa.interop.commons.utils + +import it.pagopa.interop.commons.utils.service.OffsetDateTimeSupplier + +import java.time.format.DateTimeFormatter +import java.util.UUID + +object JWTPathGenerator { + def createJWTPath(dateTimeSupplier: OffsetDateTimeSupplier): String = { + val now = dateTimeSupplier.get() + val formattedDate = now.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + val formattedDateTime = now.format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss")) + s"token-details/$formattedDate/${formattedDateTime}_${UUID.randomUUID()}.ndjson" + } +}