diff --git a/secrets/file/src/main/kotlin/FileBasedSecretsProvider.kt b/secrets/file/src/main/kotlin/FileBasedSecretsProvider.kt index 1aec15194..a7a2dc170 100644 --- a/secrets/file/src/main/kotlin/FileBasedSecretsProvider.kt +++ b/secrets/file/src/main/kotlin/FileBasedSecretsProvider.kt @@ -116,29 +116,4 @@ class FileBasedSecretsProvider(config: Config) : SecretsProvider { secrets -= path writeSecrets(secrets) } - - override fun createPath( - organizationId: Long?, - productId: Long?, - repositoryId: Long?, - secretName: String - ): Path { - val secretType = when { - organizationId != null -> "organization" - productId != null -> "product" - repositoryId != null -> "repository" - else -> throw IllegalArgumentException( - "Either one of organizationId, productId or repositoryId should be specified to create a path." - ) - } - return Path( - listOfNotNull( - secretType, - organizationId, - productId, - repositoryId, - secretName - ).joinToString("_") - ) - } } diff --git a/secrets/spi/src/main/kotlin/SecretsProvider.kt b/secrets/spi/src/main/kotlin/SecretsProvider.kt index 70a13dfab..bde0668f0 100644 --- a/secrets/spi/src/main/kotlin/SecretsProvider.kt +++ b/secrets/spi/src/main/kotlin/SecretsProvider.kt @@ -51,7 +51,18 @@ interface SecretsProvider { /** * Generate a [Path] for the secret belonging to the given [organizationId], [productId] and [repositoryId], as well - * as the [secretName]. + * as the [secretName]. The default implementation concatenates these properties with underscores. */ - fun createPath(organizationId: Long?, productId: Long?, repositoryId: Long?, secretName: String): Path + fun createPath(organizationId: Long?, productId: Long?, repositoryId: Long?, secretName: String): Path { + val secretType = when { + organizationId != null -> "organization" + productId != null -> "product" + repositoryId != null -> "repository" + else -> throw IllegalArgumentException( + "Either one of organizationId, productId or repositoryId should be specified to create a path." + ) + } + + return Path(listOfNotNull(secretType, organizationId, productId, repositoryId, secretName).joinToString("_")) + } } diff --git a/secrets/spi/src/testFixtures/kotlin/SecretsProviderFactoryForTesting.kt b/secrets/spi/src/testFixtures/kotlin/SecretsProviderFactoryForTesting.kt index 0056a863a..59e7720ce 100644 --- a/secrets/spi/src/testFixtures/kotlin/SecretsProviderFactoryForTesting.kt +++ b/secrets/spi/src/testFixtures/kotlin/SecretsProviderFactoryForTesting.kt @@ -103,31 +103,6 @@ class SecretsProviderFactoryForTesting : SecretsProviderFactory { override fun removeSecret(path: Path) { storage -= checkPath(path) } - - override fun createPath( - organizationId: Long?, - productId: Long?, - repositoryId: Long?, - secretName: String - ): Path { - val secretType = when { - organizationId != null -> "organization" - productId != null -> "product" - repositoryId != null -> "repository" - else -> throw IllegalArgumentException( - "Either one of organizationId, productId or repositoryId should be specified to create a path." - ) - } - return Path( - listOfNotNull( - secretType, - organizationId, - productId, - repositoryId, - secretName - ).joinToString("_") - ) - } }.also { latestInstance = it } } } diff --git a/secrets/vault/src/main/kotlin/VaultSecretsProvider.kt b/secrets/vault/src/main/kotlin/VaultSecretsProvider.kt index 553ab4720..931a5a1f2 100644 --- a/secrets/vault/src/main/kotlin/VaultSecretsProvider.kt +++ b/secrets/vault/src/main/kotlin/VaultSecretsProvider.kt @@ -118,18 +118,6 @@ class VaultSecretsProvider( } } - override fun createPath(organizationId: Long?, productId: Long?, repositoryId: Long?, secretName: String): Path { - val secretType = when { - organizationId != null -> "organization" - productId != null -> "product" - repositoryId != null -> "repository" - else -> throw IllegalArgumentException( - "Either one of organizationId, productId or repositoryId should be specified to create a path." - ) - } - return Path(listOfNotNull(secretType, organizationId, productId, repositoryId, secretName).joinToString("_")) - } - /** * Create an [HttpClient] with a configuration to communicate with the Vault service. The client is prepared to * obtain a new client token if necessary.