-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Misk metadata for registered backfills (#392)
<img width="1108" alt="Screenshot 2024-06-27 at 17 10 37" src="https://github.com/cashapp/backfila/assets/8827217/48bb8037-1535-4e54-842c-1b0dcfc16ec5">
- Loading branch information
Showing
12 changed files
with
95 additions
and
17 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
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
43 changes: 43 additions & 0 deletions
43
client-misk/src/main/kotlin/app/cash/backfila/client/misk/BackfillMetadata.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,43 @@ | ||
package app.cash.backfila.client.misk | ||
|
||
import app.cash.backfila.client.spi.BackfillBackend | ||
import app.cash.backfila.client.spi.BackfillRegistration | ||
import jakarta.inject.Inject | ||
import misk.web.metadata.Metadata | ||
import misk.web.metadata.MetadataProvider | ||
import misk.web.metadata.toFormattedJson | ||
import wisp.moshi.adapter | ||
import wisp.moshi.defaultKotlinMoshi | ||
|
||
internal data class BackfillMetadata( | ||
val name: String, | ||
val description: String?, | ||
val parametersClass: String?, | ||
) | ||
|
||
internal data class BackfillsMetadata( | ||
val backfills: Map<String, List<BackfillMetadata>>, | ||
) : Metadata( | ||
metadata = backfills, | ||
prettyPrint = defaultKotlinMoshi | ||
.adapter<Map<String, List<BackfillMetadata>>>() | ||
.toFormattedJson(backfills), | ||
descriptionString = "Backfill classes registered with Backfila.", | ||
) | ||
|
||
internal class BackfillMetadataProvider : MetadataProvider<BackfillsMetadata> { | ||
@Inject lateinit var backends: Set<BackfillBackend> | ||
|
||
override val id = "backfila" | ||
|
||
override fun get(): BackfillsMetadata { | ||
val backfills = backends.associate { it::class.simpleName!! to it.backfills().map { it.toMetadata() } } | ||
return BackfillsMetadata(backfills) | ||
} | ||
|
||
private fun BackfillRegistration.toMetadata() = BackfillMetadata( | ||
name = name, | ||
description = description, | ||
parametersClass = parametersClass.simpleName, | ||
) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...backfill/src/main/kotlin/app/cash/backfila/service/selfbackfill/LocalBackfillingModule.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
2 changes: 1 addition & 1 deletion
2
...kfill/src/test/kotlin/app/cash/backfila/service/selfbackfill/SelfBackfillTestingModule.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
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
32 changes: 32 additions & 0 deletions
32
service/src/test/kotlin/app/cash/backfila/development/DevelopmentAdminDashboardModule.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,32 @@ | ||
package app.cash.backfila.development | ||
|
||
import misk.MiskCaller | ||
import misk.inject.KAbstractModule | ||
import misk.security.authz.AccessAnnotationEntry | ||
import misk.security.authz.DevelopmentOnly | ||
import misk.web.dashboard.AdminDashboardAccess | ||
import misk.web.dashboard.AdminDashboardModule | ||
import misk.web.metadata.all.AllMetadataAccess | ||
import misk.web.metadata.all.AllMetadataModule | ||
import misk.web.metadata.config.ConfigMetadataAction | ||
|
||
class DevelopmentAdminDashboardModule : KAbstractModule() { | ||
override fun configure() { | ||
install(AdminDashboardModule(isDevelopment = true, configTabMode = ConfigMetadataAction.ConfigTabMode.SHOW_REDACTED_EFFECTIVE_CONFIG)) | ||
install(AllMetadataModule()) | ||
multibind<AccessAnnotationEntry>().toInstance( | ||
AccessAnnotationEntry<AdminDashboardAccess>( | ||
capabilities = listOf("admin_console"), | ||
), | ||
) | ||
multibind<AccessAnnotationEntry>().toInstance( | ||
AccessAnnotationEntry<AllMetadataAccess>( | ||
capabilities = listOf("admin_console"), | ||
services = listOf(), | ||
), | ||
) | ||
// Setup authentication in the development environment | ||
bind<MiskCaller>().annotatedWith<DevelopmentOnly>() | ||
.toInstance(MiskCaller(user = "testfila", capabilities = setOf("admin_console", "users"))) | ||
} | ||
} |
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