Skip to content

Commit

Permalink
feat(lambda): falls back to default Lambda bundle config dir if no co…
Browse files Browse the repository at this point in the history
…nfig dir set.
  • Loading branch information
outofcoffee committed Sep 23, 2023
1 parent 1c25142 commit afbadad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2021.
* Copyright (c) 2021-2023.
*
* This file is part of Imposter.
*
Expand Down Expand Up @@ -63,11 +63,13 @@ import org.apache.logging.log4j.Logger
* @author Pete Cornish
*/
abstract class AbstractHandler<Request, Response>(
eventType: LambdaServerFactory.EventType
eventType: LambdaServerFactory.EventType,
) {
protected val logger: Logger = LogManager.getLogger(AbstractHandler::class.java)
protected val server: LambdaServer<Request, Response>

private val defaultLambdaBundleConfigDir = "/var/task/config"

init {
// lambda functions are only allowed write access to /tmp
System.setProperty("vertx.cacheDirBase", "/tmp/.vertx")
Expand All @@ -78,11 +80,14 @@ abstract class AbstractHandler<Request, Response>(

LambdaServerFactory.eventType = eventType

@Suppress("DEPRECATION")
val configDir = Settings.configDir ?: Settings.s3ConfigUrl ?: defaultLambdaBundleConfigDir

ImposterBuilderKt()
.withPluginClass(OpenApiPluginImpl::class.java)
.withPluginClass(RestPluginImpl::class.java)
.apply { if (Settings.metaInfScan) withPluginClass(MetaInfPluginDetectorImpl::class.java) }
.withConfigurationDir(Settings.configDir ?: Settings.s3ConfigUrl)
.withConfigurationDir(configDir)
.withEngineOptions { options ->
options.serverFactory = LambdaServerFactory::class.qualifiedName
options.requestHandlingMode = RequestHandlingMode.SYNC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ object Settings {
val pluginDiscoveryStrategyClass: String? get() =
EnvVars.getEnv("IMPOSTER_PLUGIN_DISCOVERY_STRATEGY")

val s3ConfigUrl: String get() =
@Deprecated("Use configDir instead", ReplaceWith("Settings.configDir", "io.gatehill.imposter.awslambda.config.Settings"))
val s3ConfigUrl: String? get() =
EnvVars.getEnv("IMPOSTER_S3_CONFIG_URL")
?: throw IllegalStateException("Missing S3 configuration URL")

val metaInfScan: Boolean get() =
EnvVars.getEnv("IMPOSTER_METAINF_SCAN")?.toBoolean() ?: false
Expand Down

0 comments on commit afbadad

Please sign in to comment.