LambdaResourcesFactory.kt

  1. /**
  2.  * This file is part of the pl.wrzasq.cform.
  3.  *
  4.  * @license http://mit-license.org/ The MIT license
  5.  * @copyright 2021, 2024 © by Rafał Wrzeszcz - Wrzasq.pl.
  6.  */

  7. package pl.wrzasq.cform.resource.aws.passwordpolicy.config

  8. import com.fasterxml.jackson.core.type.TypeReference
  9. import pl.wrzasq.cform.commons.config.BaseLambdaResourcesFactory
  10. import pl.wrzasq.cform.resource.aws.passwordpolicy.action.CreateHandler
  11. import pl.wrzasq.cform.resource.aws.passwordpolicy.action.DeleteHandler
  12. import pl.wrzasq.cform.resource.aws.passwordpolicy.action.ReadHandler
  13. import pl.wrzasq.cform.resource.aws.passwordpolicy.model.ResourceModel
  14. import software.amazon.awssdk.regions.Region
  15. import software.amazon.awssdk.services.iam.IamClient
  16. import software.amazon.cloudformation.Action
  17. import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy
  18. import software.amazon.cloudformation.proxy.HandlerRequest
  19. import software.amazon.cloudformation.proxy.ProxyClient
  20. import software.amazon.cloudformation.proxy.StdCallbackContext

  21. /**
  22.  * Resources factory for AWS Lambda environment.
  23.  */
  24. class LambdaResourcesFactory : ResourcesFactory, BaseLambdaResourcesFactory<ResourceModel, Any?>() {
  25.     private val createHandler by lazy { CreateHandler(this, readHandler) }

  26.     private val deleteHandler by lazy { DeleteHandler(this) }

  27.     private val readHandler by lazy { ReadHandler(this) }

  28.     override fun getRequestTypeReference() =
  29.         object : TypeReference<HandlerRequest<ResourceModel?, StdCallbackContext, Any?>>() {}

  30.     override fun getResourceTypeReference() = object : TypeReference<ResourceModel?>() {}

  31.     override fun buildHandlers() = mapOf(
  32.         Action.CREATE to createHandler,
  33.         Action.UPDATE to createHandler,
  34.         Action.READ to readHandler,
  35.         Action.DELETE to deleteHandler,
  36.     )

  37.     override fun getClient(proxy: AmazonWebServicesClientProxy): ProxyClient<IamClient> = proxy.newProxy {
  38.         IamClient.builder()
  39.             .region(Region.AWS_GLOBAL)
  40.             .build()
  41.     }
  42. }