generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified code to move the health check on cloud schema loader to sche…
…ma validation lib. Also, added the AWS S3 and Azure BLOB configuration on its own as opposed to being in the Azure SBUS and AWS SQS config respectively
- Loading branch information
1 parent
25f65e8
commit ce4419c
Showing
17 changed files
with
179 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...validation/src/main/kotlin/gov/cdc/ocio/reportschemavalidator/utils/AWSS3Configuration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package gov.cdc.ocio.reportschemavalidator.utils | ||
|
||
import io.ktor.server.config.* | ||
|
||
/** | ||
* AWS S3 configuration class | ||
* @param config ApplicationConfig | ||
* @param configurationPath String? | ||
*/ | ||
class AWSS3Configuration(config: ApplicationConfig, configurationPath: String? = null) { | ||
private val configPath = if (configurationPath != null) "$configurationPath." else "" | ||
val s3Bucket = config.tryGetString("${configPath}s3.report_schema_bucket") ?: "" | ||
val s3Region = config.tryGetString("${configPath}s3.report_schema_region") ?: "" | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...src/main/kotlin/gov/cdc/ocio/reportschemavalidator/utils/AzureBlobStorageConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package gov.cdc.ocio.reportschemavalidator.utils | ||
|
||
import io.ktor.server.config.* | ||
|
||
/** | ||
* Blob storage configuration class | ||
* @param config ApplicationConfig | ||
* @param configurationPath String? | ||
*/ | ||
class AzureBlobStorageConfiguration(config: ApplicationConfig, configurationPath: String? = null) { | ||
private val configPath = if (configurationPath != null) "$configurationPath." else "" | ||
val connectionString = config.tryGetString("${configPath}blob_storage.connection_string") ?: "" | ||
val container = config.tryGetString("${configPath}blob_storage.container") ?: "" | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...rc/main/kotlin/gov/cdc/ocio/reportschemavalidator/utils/CloudSchemaLoaderConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gov.cdc.ocio.reportschemavalidator.utils | ||
|
||
|
||
import gov.cdc.ocio.reportschemavalidator.loaders.CloudSchemaLoader | ||
import io.ktor.server.application.* | ||
import io.ktor.server.config.* | ||
|
||
class CloudSchemaLoaderConfiguration(environment: ApplicationEnvironment){ | ||
private val schemaLoaderSystem = environment.config.tryGetString("ktor.schema_loader_system")?: "" | ||
private val s3Bucket = environment.config.tryGetString("aws.s3.report_schema_bucket") ?: "" | ||
private val s3Region = environment.config.tryGetString("aws.s3.report_schema_region") ?: "" | ||
private val connectionString = environment.config.tryGetString("azure.blob_storage.connection_string") ?: "" | ||
private val container = environment.config.tryGetString("azure.blob_storage.container") ?: "" | ||
|
||
fun createSchemaLoader(): CloudSchemaLoader { | ||
when (schemaLoaderSystem.lowercase()) { | ||
SchemaLoaderSystemType.S3.toString().lowercase() -> { | ||
val config = mapOf( | ||
"REPORT_SCHEMA_S3_BUCKET" to s3Bucket, | ||
"REPORT_SCHEMA_S3_REGION" to s3Region | ||
) | ||
return CloudSchemaLoader(schemaLoaderSystem, config) | ||
} | ||
|
||
SchemaLoaderSystemType.BLOB_STORAGE.toString().lowercase() -> { | ||
val config = mapOf( | ||
"REPORT_SCHEMA_BLOB_CONNECTION_STR" to connectionString, | ||
"REPORT_SCHEMA_BLOB_CONTAINER" to container | ||
) | ||
return CloudSchemaLoader(schemaLoaderSystem, config) | ||
} | ||
else ->throw IllegalArgumentException( "Unsupported schema loader type: $schemaLoaderSystem") | ||
|
||
} | ||
|
||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...lin/gov/cdc/ocio/reportschemavalidator/utils/CloudSchemaLoaderConfigurationKoinCreator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package gov.cdc.ocio.reportschemavalidator.utils | ||
|
||
import io.ktor.server.application.* | ||
import mu.KotlinLogging | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.module | ||
|
||
/** | ||
* Helper class for creating koin modules for a report schema loader. | ||
*/ | ||
class CloudSchemaLoaderConfigurationKoinCreator { | ||
|
||
companion object { | ||
|
||
/** | ||
* The class which loads the specific cloud schema loader configuration based on the env vars | ||
* @param environment ApplicationEnvironment | ||
* @return SchemaLoader | ||
*/ | ||
fun getSchemaLoaderConfigurationFromAppEnv(environment: ApplicationEnvironment): Module { | ||
val logger = KotlinLogging.logger {} | ||
|
||
val schemaLoaderSystemModule = module { | ||
val schemaLoaderSystem = environment.config.property("ktor.schema_loader_system").getString() | ||
val schemaLoaderSystemType: SchemaLoaderSystemType | ||
when (schemaLoaderSystem.lowercase()) { | ||
SchemaLoaderSystemType.S3.toString().lowercase() -> { | ||
single { AWSS3Configuration(environment.config,configurationPath = "aws") } | ||
schemaLoaderSystemType = SchemaLoaderSystemType.S3 | ||
} | ||
|
||
SchemaLoaderSystemType.BLOB_STORAGE.toString().lowercase() -> { | ||
single { AzureBlobStorageConfiguration(environment.config,configurationPath = "azure") } | ||
schemaLoaderSystemType = SchemaLoaderSystemType.BLOB_STORAGE | ||
} | ||
|
||
else -> { | ||
val msg = "Unsupported schema loader type: $schemaLoaderSystem" | ||
logger.error { msg } | ||
throw IllegalArgumentException(msg) | ||
} | ||
|
||
} | ||
single { schemaLoaderSystemType } // add databaseType to Koin Modules | ||
} | ||
return schemaLoaderSystemModule | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...dation/src/main/kotlin/gov/cdc/ocio/reportschemavalidator/utils/SchemaLoaderSystemType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package gov.cdc.ocio.reportschemavalidator.utils | ||
|
||
enum class SchemaLoaderSystemType { | ||
S3, | ||
BLOB_STORAGE, | ||
UNKNOWN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.