-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if mongodump and mongorestore exist (#23)
* Check if mongodump and mongorestore exist This checks if we have the binaries existing, so we can fail early on, instead of silently synchronizing collections without a restore first. Closes #9 * No need to run ktlint and detekt on CI We run them as part of another workflow, so no need to repeat them. * Add tools validator to CLI defaults
- Loading branch information
Showing
7 changed files
with
99 additions
and
5 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
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
36 changes: 36 additions & 0 deletions
36
...c/main/kotlin/pl/allegro/tech/mongomigrationstream/core/validation/MongoToolsValidator.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,36 @@ | ||
package pl.allegro.tech.mongomigrationstream.core.validation | ||
|
||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import io.github.oshai.kotlinlogging.withLoggingContext | ||
import pl.allegro.tech.mongomigrationstream.configuration.ApplicationProperties | ||
import java.nio.file.Paths | ||
import kotlin.io.path.exists | ||
import kotlin.io.path.isExecutable | ||
|
||
private val logger = KotlinLogging.logger { } | ||
|
||
internal class MongoToolsValidator(private val applicationProperties: ApplicationProperties) : Validator { | ||
|
||
private fun check(binary: String): Boolean { | ||
withLoggingContext("binary" to binary) { | ||
val binaryPath = Paths.get(applicationProperties.performerProperties.mongoToolsPath).resolve(binary) | ||
return if (binaryPath.exists() && binaryPath.isExecutable()) { | ||
logger.info { "$binary at $binaryPath exists and is executable" } | ||
true | ||
} else { | ||
logger.error { "$binary at $binaryPath doesn't exist or isn't executable" } | ||
false | ||
} | ||
} | ||
} | ||
|
||
override fun validate(): ValidationResult { | ||
val mongoDump = check("mongodump") | ||
val mongoRestore = check("mongorestore") | ||
return if (mongoDump && mongoRestore) { | ||
ValidationSuccess | ||
} else { | ||
ValidationFailure("MongoDB tools installation isn't working or doesn't exist") | ||
} | ||
} | ||
} |