-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Invoking flank yml on gcloud cli (#1041)
* Fast fail when cannot create bucket * added tests and fix device version * update tests * Fix NPE when no devices or Version node * Update Debug.kt * fix imports * Review fixes * Set extension funcs to extension properties * Update Doctor.kt * Update test_runner/src/main/kotlin/ftl/args/yml/YamlDeviceFix.kt Co-authored-by: Jan Góral <60390247+jan-gogo@users.noreply.github.com> Co-authored-by: Jan Góral <60390247+jan-gogo@users.noreply.github.com>
- Loading branch information
1 parent
2e46fbb
commit d04f827
Showing
7 changed files
with
113 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ftl.args.yml | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.fasterxml.jackson.databind.node.ObjectNode | ||
import ftl.args.ArgsHelper.yamlMapper | ||
import ftl.run.exception.FlankGeneralError | ||
import ftl.util.loadFile | ||
import java.nio.file.Path | ||
|
||
fun fixDevices(yamlPath: Path) = | ||
if (yamlPath.toFile().exists().not()) throw FlankGeneralError("Flank yml doesn't exist at path $yamlPath") | ||
else yamlPath.loadYml().fixDevices().saveFixedYml(yamlPath) | ||
|
||
private fun Path.loadYml() = yamlMapper.readTree(loadFile(this)) | ||
|
||
private fun JsonNode.fixDevices() = also { | ||
devicesNode.notValidDevices.forEach { device -> | ||
device.fixDeviceVersion() | ||
} | ||
} | ||
|
||
internal val JsonNode.devicesNode | ||
get() = get(GCLOUD_NODE).get(DEVICES_NODE) | ||
|
||
internal val JsonNode.notValidDevices | ||
get() = filterNot { it.deviceVersionValid() } | ||
|
||
private fun JsonNode.deviceVersionValid() = get(VERSION_NODE)?.isTextual ?: false | ||
|
||
private fun JsonNode.fixDeviceVersion() = get(VERSION_NODE)?.let { | ||
(this as ObjectNode).put(VERSION_NODE, it.asText()) | ||
} | ||
|
||
private fun JsonNode.saveFixedYml(yamlPath: Path) = yamlMapper.writerWithDefaultPrettyPrinter().writeValue(yamlPath.toFile(), this) | ||
|
||
const val MODEL_NODE = "model" | ||
const val GCLOUD_NODE = "gcloud" | ||
const val DEVICES_NODE = "device" | ||
const val VERSION_NODE = "version" |
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