Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "547 gjøre tables config basert" #589

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions backend/src/main/kotlin/no/bekk/Application.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.bekk

import io.ktor.client.*
import no.bekk.plugins.*
import io.ktor.server.application.*
import io.ktor.server.plugins.contentnegotiation.*
Expand All @@ -21,29 +20,23 @@ private fun loadAppConfig(config: ApplicationConfig) {
airTable = AirTableConfig.apply {
baseUrl = config.propertyOrNull("airTable.baseUrl")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.baseUrl\"")
}
sikkerhetskontroller = AirTableInstanceConfig(
accessToken = config.propertyOrNull("airTable.sikkerhetskontroller.accessToken")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.sikkerhetskontroller.accessToken\""),
baseId = config.propertyOrNull("airTable.sikkerhetskontroller.baseId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.sikkerhetskontroller.baseId\""),
tableId = config.propertyOrNull("airTable.sikkerhetskontroller.tableId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.sikkerhetskontroller.tableId\""),
viewId = config.propertyOrNull("airTable.sikkerhetskontroller.viewId")?.getString(),
webhookId = config.propertyOrNull("airTable.sikkerhetskontroller.webhookId")?.getString(),
webhookSecret = config.propertyOrNull("airTable.sikkerhetskontroller.webhookSecret")?.getString(),

tables = config.configList("tables").map { table ->

when (table.propertyOrNull("type")?.getString()) {
"AIRTABLE" -> AirTableInstanceConfig(
id = table.propertyOrNull("id")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"id\""),
accessToken = table.propertyOrNull("accessToken")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"accessToken\""),
baseId = table.propertyOrNull("baseId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"baseId\""),
tableId = table.propertyOrNull("tableId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"tableId\""),
viewId = table.propertyOrNull("viewId")?.getString(),
webhookId = table.propertyOrNull("webhookId")?.getString(),
webhookSecret = table.propertyOrNull("webhookSecret")?.getString(),
)
"YAML" -> YAMLInstanceConfig(
id = table.propertyOrNull("id")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"id\""),
endpoint = table.propertyOrNull("endpoint")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"baseId\""),
resourcePath = table.propertyOrNull("resourcePath")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"tableId\""),
)
else -> throw IllegalStateException("Illegal type \"type\"")

}

}
)
driftskontinuitet = AirTableInstanceConfig(
accessToken = config.propertyOrNull("airTable.driftskontinuitet.accessToken")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.driftskontinuitet.accessToken\""),
baseId = config.propertyOrNull("airTable.driftskontinuitet.baseId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.driftskontinuitet.baseId\""),
tableId = config.propertyOrNull("airTable.driftskontinuitet.tableId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.driftskontinuitet.tableId\""),
viewId = config.propertyOrNull("airTable.driftskontinuitet.viewId")?.getString(),
webhookId = config.propertyOrNull("airTable.driftskontinuitet.webhookId")?.getString(),
webhookSecret = config.propertyOrNull("airTable.driftskontinuitet.webhookSecret")?.getString(),
)
}

// MicrosoftGraph config
Expand Down
20 changes: 3 additions & 17 deletions backend/src/main/kotlin/no/bekk/configuration/AppConfig.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package no.bekk.configuration

import io.ktor.client.*

object AppConfig {
lateinit var tables: TableConfig
lateinit var microsoftGraph: MicrosoftGraphConfig
Expand All @@ -13,34 +11,22 @@ object AppConfig {

object TableConfig {
lateinit var airTable: AirTableConfig
lateinit var tables: List<TableInstance>
lateinit var sikkerhetskontroller: AirTableInstanceConfig
lateinit var driftskontinuitet: AirTableInstanceConfig
}

object AirTableConfig {
lateinit var baseUrl: String
}

interface TableInstance {
val id: String
}

data class AirTableInstanceConfig (
override val id: String,
val accessToken: String,
val baseId: String,
val tableId: String,
var viewId: String? = null,
var webhookId: String? = null,
var webhookSecret: String? = null,
) : TableInstance

data class YAMLInstanceConfig (
override val id: String,
val endpoint: String? = null,
val resourcePath: String? = null
) : TableInstance


)

object MicrosoftGraphConfig {
lateinit var baseUrl: String
Expand Down
63 changes: 35 additions & 28 deletions backend/src/main/kotlin/no/bekk/services/TableService.kt
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
package no.bekk.services

import io.ktor.client.*
import no.bekk.configuration.AirTableInstanceConfig
import no.bekk.configuration.AppConfig
import no.bekk.configuration.YAMLInstanceConfig
import no.bekk.providers.AirTableProvider
import no.bekk.providers.TableProvider
import no.bekk.providers.YamlProvider
import no.bekk.providers.clients.AirTableClient

object TableService {


private val providers: List<TableProvider> = AppConfig.tables.tables.map { table ->
when (table) {
is AirTableInstanceConfig -> AirTableProvider(
id = table.id,
airtableClient = AirTableClient(
table.accessToken
),
baseId = table.baseId,
tableId = table.tableId,
viewId = table.viewId,
webhookId = table.webhookId,
webhookSecret = table.webhookSecret,
)
is YAMLInstanceConfig -> YamlProvider(
id = table.id,
endpoint = table.endpoint,
resourcePath = table.resourcePath,
)
else -> throw Exception("Valid tabletype not found")

}
}
private val providers: List<TableProvider> = listOf<TableProvider>(
AirTableProvider(
id = "570e9285-3228-4396-b82b-e9752e23cd73",
airtableClient = AirTableClient(
AppConfig.tables.sikkerhetskontroller.accessToken
),
baseId = AppConfig.tables.sikkerhetskontroller.baseId,
tableId = AppConfig.tables.sikkerhetskontroller.tableId,
viewId = AppConfig.tables.sikkerhetskontroller.viewId,
webhookId = AppConfig.tables.sikkerhetskontroller.webhookId,
webhookSecret = AppConfig.tables.sikkerhetskontroller.webhookSecret,
),
AirTableProvider(
id = "816cc808-9188-44a9-8f4b-5642fc2932c4",
airtableClient = AirTableClient(
AppConfig.tables.driftskontinuitet.accessToken
),
baseId = AppConfig.tables.driftskontinuitet.baseId,
tableId = AppConfig.tables.driftskontinuitet.tableId,
viewId = AppConfig.tables.driftskontinuitet.viewId,
webhookId = AppConfig.tables.driftskontinuitet.webhookId,
webhookSecret = AppConfig.tables.driftskontinuitet.webhookSecret,
),
// AirTableProvider(
// id = "test-table",
// airtableClient = AirTableClient(
// System.getenv("AIRTABLE_TEST_TOKEN")
// ),
// baseId = "appJFzRzW8GmaKuz3",
// tableId = "tblbiZLh6qn3k7wdt",
// viewId = "",
// webhookId = "achpY1AcPW93B9ucr",
// webhookSecret = System.getenv("AIRTABLE_WEBHOOK_SECRET")
// ),
)


fun getTableProvider(tableId: String): TableProvider {
Expand Down
17 changes: 0 additions & 17 deletions backend/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,6 @@ airTable:
webhookId: "$DRIFTSKONTINUITET_WEBHOOK_ID:"
webhookSecret: "$DRIFTSKONTINUITET_WEBHOOK_SECRET:"

tables:
- id: "570e9285-3228-4396-b82b-e9752e23cd73"
type : "AIRTABLE"
accessToken: $AIRTABLE_ACCESS_TOKEN
baseId: "appzJQ8Tkmm8DobrJ"
tableId: "tblLZbUqA0XnUgC2v"
viewId: "viw2XliGUJu5448Hk"
webhookId: "$SIKKERHETSKONTROLLER_WEBHOOK_ID:"
webhookSecret: "$SIKKERHETSKONTROLLER_WEBHOOK_SECRET:"
- id: "816cc808-9188-44a9-8f4b-5642fc2932c4"
type: "AIRTABLE"
accessToken: $AIRTABLE_ACCESS_TOKEN
baseId: "appsIiBWlCCSsMmRB"
tableId: "tbl4pNqNp2wLyI6iv"
webhookId: "$DRIFTSKONTINUITET_WEBHOOK_ID:"
webhookSecret: "$DRIFTSKONTINUITET_WEBHOOK_SECRET:"

microsoftGraph:
baseUrl: "https://graph.microsoft.com"
memberOfPath: "/v1.0/me/memberOf/microsoft.graph.group"
Expand Down
Loading