Skip to content

Commit

Permalink
PIN-4312 Rid of FileManager (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli authored Jan 15, 2024
1 parent 67a08ca commit ea9ce7c
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 46 deletions.
2 changes: 0 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ object Dependencies {
namespace %% "interop-be-authorization-management-client" % authorizationManagementVersion

lazy val commonsUtils = namespace %% "interop-commons-utils" % commonsVersion
lazy val fileManager = namespace %% "interop-commons-file-manager" % commonsVersion
lazy val commonsJWT = namespace %% "interop-commons-jwt" % commonsVersion
lazy val commonsCqrs = namespace %% "interop-commons-cqrs" % commonsVersion
lazy val riskAnalysis = namespace %% "interop-commons-risk-analysis" % commonsVersion
Expand Down Expand Up @@ -120,7 +119,6 @@ object Dependencies {
pagopa.authorizationManagementClient % Compile,
pagopa.tenantManagementModels % Compile,
pagopa.commonsUtils % Compile,
pagopa.fileManager % Compile,
pagopa.commonsJWT % Compile,
pagopa.commonsCqrs % Compile,
pagopa.riskAnalysis % Compile,
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/application-standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ catalog-process {
jwt {
audience = ${ACCEPTED_AUDIENCES}
}
storage {
kind = "file"
container = "local"
}

read-model {
db {
Expand Down
6 changes: 1 addition & 5 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ catalog-process {
jwt {
audience = ${ACCEPTED_AUDIENCES}
}
storage {
kind = "S3"
container = ${STORAGE_CONTAINER}
}


read-model {
db {
name = ${READ_MODEL_DB_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import it.pagopa.interop.catalogprocess.errors.CatalogProcessErrors._
import it.pagopa.interop.catalogprocess.model._
import it.pagopa.interop.catalogprocess.service._
import it.pagopa.interop.commons.cqrs.service.ReadModelService
import it.pagopa.interop.commons.files.service.FileManager
import it.pagopa.interop.commons.jwt._
import it.pagopa.interop.commons.logging.{CanLogContextFields, ContextFieldsToLog}
import it.pagopa.interop.commons.riskanalysis.api.impl.RiskAnalysisValidation
Expand All @@ -46,8 +45,7 @@ final case class ProcessApiServiceImpl(
agreementManagementService: AgreementManagementService,
authorizationManagementService: AuthorizationManagementService,
attributeRegistryManagementService: AttributeRegistryManagementService,
tenantManagementService: TenantManagementService,
fileManager: FileManager
tenantManagementService: TenantManagementService
)(implicit ec: ExecutionContext, readModel: ReadModelService)
extends ProcessApiService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ object ApplicationConfiguration {

val jwtAudience: Set[String] = config.getString("catalog-process.jwt.audience").split(",").toSet.filter(_.nonEmpty)

val storageKind: String = config.getString("catalog-process.storage.kind")

val storageContainer: String = config.getString("catalog-process.storage.container")

val readModelConfig: ReadModelConfig = {
val connectionString: String = config.getString("catalog-process.read-model.db.connection-string")
val dbName: String = config.getString("catalog-process.read-model.db.name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import it.pagopa.interop.catalogprocess.api.impl.ResponseHandlers.serviceCode
import it.pagopa.interop.catalogprocess.service._
import it.pagopa.interop.catalogprocess.service.impl._
import it.pagopa.interop.commons.cqrs.service.{MongoDbReadModelService, ReadModelService}
import it.pagopa.interop.commons.files.service.FileManager
import it.pagopa.interop.commons.jwt.service.JWTReader
import it.pagopa.interop.commons.jwt.service.impl.{DefaultJWTReader, getClaimsVerifier}
import it.pagopa.interop.commons.jwt.{JWTConfiguration, KID, PublicKeysHolder, SerializedKey}
Expand All @@ -39,13 +38,6 @@ trait Dependencies {
implicit val loggerTI: LoggerTakingImplicit[ContextFieldsToLog] =
Logger.takingImplicit[ContextFieldsToLog]("OAuth2JWTValidatorAsContexts")

def getFileManager(blockingEc: ExecutionContextExecutor): FileManager =
FileManager.get(ApplicationConfiguration.storageKind match {
case "S3" => FileManager.S3
case "file" => FileManager.File
case _ => throw new Exception("Incorrect File Manager")
})(blockingEc)

def getJwtReader(): Future[JWTReader] = JWTConfiguration.jwtReader
.loadKeyset()
.map(keyset =>
Expand All @@ -61,7 +53,7 @@ trait Dependencies {
ApplicationConfiguration.readModelConfig
)

def processApi(jwtReader: JWTReader, fileManager: FileManager, blockingEc: ExecutionContextExecutor)(implicit
def processApi(jwtReader: JWTReader, blockingEc: ExecutionContextExecutor)(implicit
ec: ExecutionContext,
actorSystem: ActorSystem[_]
): ProcessApi =
Expand All @@ -71,7 +63,6 @@ trait Dependencies {
agreementManagementService = AgreementManagementServiceImpl,
authorizationManagementService = authorizationManagementService(blockingEc),
attributeRegistryManagementService = AttributeRegistryManagementServiceImpl,
fileManager = fileManager,
tenantManagementService = TenantManagementServiceImpl
),
ProcessApiMarshallerImpl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ object Main extends App with CORSSupport with Dependencies {

val serverBinding: Future[Http.ServerBinding] = for {
jwtReader <- getJwtReader()
fileManager = getFileManager(blockingEc)
controller = new Controller(
healthApi,
processApi(jwtReader, fileManager, blockingEc),
validationExceptionToRoute.some
)(actorSystem.classicSystem)
controller = new Controller(healthApi, processApi(jwtReader, blockingEc), validationExceptionToRoute.some)(
actorSystem.classicSystem
)
binding <-
Http().newServerAt("0.0.0.0", ApplicationConfiguration.serverPort).bind(corsHandler(controller.routes))
} yield binding
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/application-test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ akka {
catalog-process {
url = "http://localhost:18088/catalog-process"
port = 18088
storage.kind = "file"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.scalamock.scalatest.MockFactory
import com.typesafe.config.{Config, ConfigFactory}

import it.pagopa.interop.commons.cqrs.service.ReadModelService
import it.pagopa.interop.commons.files.service.FileManager
import it.pagopa.interop.catalogprocess.service._
import it.pagopa.interop.catalogprocess.model._
import it.pagopa.interop.catalogprocess.api.ProcessApiService
Expand All @@ -24,7 +23,6 @@ trait SpecHelper extends SprayJsonSupport with DefaultJsonProtocol with MockFact
.resolve()

implicit val mockReadModel: ReadModelService = mock[ReadModelService]
val mockfileManager: FileManager = mock[FileManager]
val mockAuthorizationManagementService: AuthorizationManagementService = mock[AuthorizationManagementService]
val mockCatalogManagementService: CatalogManagementService = mock[CatalogManagementService]
val mockAgreementManagementService: AgreementManagementService = mock[AgreementManagementService]
Expand All @@ -37,8 +35,7 @@ trait SpecHelper extends SprayJsonSupport with DefaultJsonProtocol with MockFact
mockAgreementManagementService,
mockAuthorizationManagementService,
mockAttributeRegistryManagementService,
mockTenantManagementService,
mockfileManager
mockTenantManagementService
)(ExecutionContext.global, mockReadModel)

implicit def fromResponseUnmarshallerProblem: FromEntityUnmarshaller[Problem] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import it.pagopa.interop.catalogprocess.util.FakeDependencies._
import it.pagopa.interop.catalogprocess.util.{AuthorizedRoutes, AuthzScalatestRouteTest}
import it.pagopa.interop.commons.cqrs.service.{ReadModelService, MongoDbReadModelService}
import it.pagopa.interop.commons.cqrs.model.ReadModelConfig
import it.pagopa.interop.commons.files.service.FileManager

import org.scalatest.BeforeAndAfterAll
import org.scalatest.wordspec.AnyWordSpecLike

import java.util.concurrent.{ExecutorService, Executors}
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
import scala.concurrent.ExecutionContext
import java.util.UUID

class ProcessApiAuthzSpec extends AnyWordSpecLike with BeforeAndAfterAll with AuthzScalatestRouteTest {
Expand All @@ -26,9 +26,7 @@ class ProcessApiAuthzSpec extends AnyWordSpecLike with BeforeAndAfterAll with Au
new FakeAttributeRegistryManagementService()
val fakeTenantManagementService: TenantManagementService = new FakeTenantManagementService()
private val threadPool: ExecutorService = Executors.newSingleThreadExecutor()
private val blockingEc: ExecutionContextExecutor = ExecutionContext.fromExecutorService(threadPool)
val fakeFileManager: FileManager = FileManager.get(FileManager.File)(blockingEc)
implicit val fakeReadModel: ReadModelService = new MongoDbReadModelService(
implicit val fakeReadModel: ReadModelService = new MongoDbReadModelService(
ReadModelConfig(
"mongodb://localhost/?socketTimeoutMS=1&serverSelectionTimeoutMS=1&connectTimeoutMS=1&&autoReconnect=false&keepAlive=false",
"db"
Expand All @@ -43,8 +41,7 @@ class ProcessApiAuthzSpec extends AnyWordSpecLike with BeforeAndAfterAll with Au
fakeAgreementManagementService,
fakeAuthorizationManagementService,
fakeAttributeRegistryManagementService,
fakeTenantManagementService,
fakeFileManager
fakeTenantManagementService
)(ExecutionContext.global, fakeReadModel)

"E-Service api operation authorization spec" should {
Expand Down

0 comments on commit ea9ce7c

Please sign in to comment.