mirror of
https://github.com/jlengrand/engine.git
synced 2026-03-10 08:11:21 +00:00
fix: remove semver lib usage as AWS do not respect it
This commit is contained in:
committed by
Pierre Mavro
parent
703a4ea022
commit
45dc03345c
23
Cargo.lock
generated
23
Cargo.lock
generated
@@ -1729,7 +1729,6 @@ dependencies = [
|
||||
"rusoto_s3",
|
||||
"rusoto_sts",
|
||||
"rust-crypto",
|
||||
"semver 0.11.0",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
@@ -2253,7 +2252,7 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
dependencies = [
|
||||
"semver 0.9.0",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2316,16 +2315,7 @@ version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
dependencies = [
|
||||
"semver-parser 0.7.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6"
|
||||
dependencies = [
|
||||
"semver-parser 0.10.1",
|
||||
"semver-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2334,15 +2324,6 @@ version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428"
|
||||
dependencies = [
|
||||
"pest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.117"
|
||||
|
||||
@@ -19,7 +19,6 @@ retry = "1.0.0"
|
||||
dns-lookup = "1.0.3"
|
||||
rand = "0.7.3"
|
||||
gethostname = "0.2.1"
|
||||
semver = "0.11.0"
|
||||
reqwest = { version = "0.10.8", features = ["blocking"] }
|
||||
# FIXME use https://crates.io/crates/blocking instead of runtime.rs
|
||||
|
||||
|
||||
@@ -11,9 +11,8 @@ use crate::cloud_provider::service::{
|
||||
use crate::cloud_provider::DeploymentTarget;
|
||||
use crate::cmd::helm::Timeout;
|
||||
use crate::constants::{AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY};
|
||||
use crate::error::{cast_simple_error_to_engine_error, EngineError, EngineErrorCause};
|
||||
use crate::error::{cast_simple_error_to_engine_error, EngineError, EngineErrorCause, StringError};
|
||||
use crate::models::Context;
|
||||
use semver::SemVerError;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct Redis {
|
||||
@@ -581,17 +580,17 @@ impl Backup for Redis {
|
||||
fn get_redis_version(
|
||||
requested_version: &str,
|
||||
is_managed_service: bool,
|
||||
) -> Result<String, SemVerError> {
|
||||
) -> Result<String, StringError> {
|
||||
let mut supported_redis_versions = HashMap::with_capacity(2);
|
||||
|
||||
if is_managed_service {
|
||||
// https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/supported-engine-versions.html
|
||||
supported_redis_versions.insert(5, "5.0.6");
|
||||
supported_redis_versions.insert(6, "6.x");
|
||||
supported_redis_versions.insert("5", "5.0.6");
|
||||
supported_redis_versions.insert("6", "6.x");
|
||||
} else {
|
||||
// https://hub.docker.com/r/bitnami/redis/tags?page=1&ordering=last_updated
|
||||
supported_redis_versions.insert(5, "5.0.10-debian-10-r28");
|
||||
supported_redis_versions.insert(6, "6.0.9-debian-10-r26");
|
||||
supported_redis_versions.insert("5", "5.0.10-debian-10-r28");
|
||||
supported_redis_versions.insert("6", "6.0.9-debian-10-r26");
|
||||
}
|
||||
|
||||
match utilities::get_supported_version_to_use(supported_redis_versions, requested_version) {
|
||||
|
||||
@@ -3,10 +3,17 @@ use crate::cloud_provider::environment::Environment;
|
||||
use crate::cloud_provider::kubernetes::Kubernetes;
|
||||
use crate::cmd::kubectl::{kubectl_exec_create_namespace, kubectl_exec_delete_secret};
|
||||
use crate::constants::{AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY};
|
||||
use crate::error::SimpleError;
|
||||
use semver::{SemVerError, Version};
|
||||
use crate::error::{SimpleError, StringError};
|
||||
use std::collections::HashMap;
|
||||
|
||||
// unfortunately some proposed versions are not SemVer like Elasticache (6.x)
|
||||
// this is why we need ot have our own structure
|
||||
pub struct VersionsNumber {
|
||||
major: String,
|
||||
minor: Option<String>,
|
||||
patch: Option<String>,
|
||||
}
|
||||
|
||||
// generate the kubernetes config path
|
||||
pub fn get_kubernetes_config_path(
|
||||
workspace: &str,
|
||||
@@ -77,16 +84,52 @@ pub fn delete_terraform_tfstate_secret(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_version_semver(version: &str) -> Result<VersionsNumber, StringError> {
|
||||
let mut version_split = version.split(".");
|
||||
|
||||
let major = match version_split.next() {
|
||||
Some(major) => major.to_string(),
|
||||
_ => {
|
||||
return Err(StringError::new(
|
||||
"please check the version you've sent, it can't be checked".to_string(),
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
let minor = match version_split.next() {
|
||||
Some(minor) => Some(minor.to_string()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let patch = match version_split.next() {
|
||||
Some(patch) => Some(patch.to_string()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
Ok(VersionsNumber {
|
||||
major,
|
||||
minor,
|
||||
patch,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_supported_version_to_use(
|
||||
all_supported_versions: HashMap<u64, &str>,
|
||||
all_supported_versions: HashMap<&str, &str>,
|
||||
version_to_check: &str,
|
||||
) -> Result<String, SemVerError> {
|
||||
match Version::parse(version_to_check) {
|
||||
Ok(version) => match all_supported_versions.get(&version.major) {
|
||||
Some(version) => Ok(version.to_string()),
|
||||
None => Err(SemVerError::ParseError("version not supported".to_string())),
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
) -> Result<String, StringError> {
|
||||
let version = match get_version_semver(version_to_check) {
|
||||
Ok(version) => version,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
match all_supported_versions.get(version.major.as_str()) {
|
||||
Some(version) => Ok(version.to_string()),
|
||||
None => {
|
||||
return Err(StringError::new(format!(
|
||||
"this {} version is not supported",
|
||||
version_to_check
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,17 +141,24 @@ mod tests {
|
||||
#[test]
|
||||
fn check_redis_version() {
|
||||
let mut redis_managed_versions = HashMap::with_capacity(1);
|
||||
redis_managed_versions.insert(6, "6.x");
|
||||
redis_managed_versions.insert("6", "6.x");
|
||||
let mut redis_self_hosted_versions = HashMap::with_capacity(1);
|
||||
redis_self_hosted_versions.insert(6, "6.0.9-debian-10-r26");
|
||||
redis_self_hosted_versions.insert("6", "6.0.9-debian-10-r26");
|
||||
|
||||
assert_eq!(
|
||||
get_supported_version_to_use(redis_managed_versions.clone(), "6.0.0").unwrap(),
|
||||
get_supported_version_to_use(redis_managed_versions.clone(), "6").unwrap(),
|
||||
"6.x"
|
||||
);
|
||||
assert_eq!(
|
||||
get_supported_version_to_use(redis_self_hosted_versions.clone(), "6.0.0").unwrap(),
|
||||
"6.0.9-debian-10-r26"
|
||||
);
|
||||
assert_eq!(
|
||||
get_supported_version_to_use(redis_managed_versions.clone(), "1")
|
||||
.unwrap_err()
|
||||
.message
|
||||
.as_str(),
|
||||
"this 1 version is not supported"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
17
src/error.rs
17
src/error.rs
@@ -62,6 +62,11 @@ pub struct SimpleError {
|
||||
pub message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StringError {
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SimpleErrorKind {
|
||||
Command(ExitStatus),
|
||||
@@ -80,12 +85,24 @@ impl SimpleError {
|
||||
}
|
||||
}
|
||||
|
||||
impl StringError {
|
||||
pub fn new(message: String) -> Self {
|
||||
StringError { message }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for SimpleError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
SimpleError::new(SimpleErrorKind::Other, Some(err.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for StringError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
StringError::new(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cast_simple_error_to_engine_error<X, T: Into<String>>(
|
||||
scope: EngineErrorScope,
|
||||
execution_id: T,
|
||||
|
||||
Reference in New Issue
Block a user