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

refactor(secrets): Make common createPath() code the default #288

Merged
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
25 changes: 0 additions & 25 deletions secrets/file/src/main/kotlin/FileBasedSecretsProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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("_")
)
}
}
15 changes: 13 additions & 2 deletions secrets/spi/src/main/kotlin/SecretsProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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("_"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
12 changes: 0 additions & 12 deletions secrets/vault/src/main/kotlin/VaultSecretsProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading