Skip to content

Commit

Permalink
moved createJWTPath to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterITA committed Sep 11, 2023
1 parent 8853fc8 commit dda8f71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit dda8f71

Please sign in to comment.