Skip to content

Commit 09cd33a

Browse files
Add should fail if param not found logic (#45)
* Return error is param is not found to fail deployment * create test * ltrace is not installing * add workflow_dispatch to gha * Revert "ltrace is not installing" This reverts commit f52b02b. * fix broken cargo test * revmoe some deprications * remove nightly install * use default stable rustup * lint error
1 parent 1c4dc29 commit 09cd33a

File tree

8 files changed

+34
-15
lines changed

8 files changed

+34
-15
lines changed

.devcontainer/Dockerfile

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
FROM mcr.microsoft.com/vscode/devcontainers/rust:0.202.9-bullseye
1+
FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye
2+
3+
RUN sudo apt-get update -y \
4+
&& sudo apt-get upgrade -y
5+
6+
RUN sudo apt-get install -y --fix-missing zip
27

38
RUN sudo apt-get update -y \
49
&& sudo apt-get upgrade -y \
510
&& sudo apt-get install -y zip ltrace
611

7-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
12+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
813
RUN rustup update \
914
&& rustup target add aarch64-unknown-linux-gnu
1015

16+
RUN rustup default stable
1117
# x86_64 to arm64 support.
1218
RUN sudo apt-get install -y \
1319
qemu \

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Test
2-
on: [push]
2+
on: [push, workflow_dispatch]
33
jobs:
44
image:
55
name: Image

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name = "crypteia"
88

99
[lib]
1010
name = "crypteia"
11-
crate_type = ["cdylib"]
11+
crate-type = ["cdylib"]
1212

1313
[dependencies]
1414
# bin

amzn/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
FROM public.ecr.aws/sam/build-nodejs18.x
22

3-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
3+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
44
ENV PATH="~/.cargo/bin:${PATH}"
55

66
RUN ~/.cargo/bin/rustup update \
77
&& ~/.cargo/bin/rustup target add aarch64-unknown-linux-gnu
88

9+
RUN rustup default stable
910
ENV CRYPTEIA_BUILD_OS=amzn
1011
ENV CRYPTEIA_BUILD_TARGET=x86_64-unknown-linux-gnu

amzn/Dockerfile-arm64

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
FROM public.ecr.aws/sam/build-nodejs18.x:latest-arm64
22

3-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
3+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
44
ENV PATH="~/.cargo/bin:${PATH}"
55

66
RUN ~/.cargo/bin/rustup update \
77
&& ~/.cargo/bin/rustup target add aarch64-unknown-linux-gnu
88

9+
RUN rustup default stable
910
ENV CRYPTEIA_BUILD_OS=amzn
1011
ENV CRYPTEIA_BUILD_TARGET=aarch64-unknown-linux-gnu

bin/build-arch

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ mkdir -p ./build ./target
1313

1414
cargo build \
1515
--release \
16-
--target "${CRYPTEIA_BUILD_TARGET}" \
17-
-Z sparse-registry
16+
--target "${CRYPTEIA_BUILD_TARGET}"
1817

1918
cp "./target/${CRYPTEIA_BUILD_TARGET}/release/crypteia" "./build/${BIN}"
2019
cp ./target/${CRYPTEIA_BUILD_TARGET}/release/libcrypteia.so "./build/${LIB}"

debian/Dockerfile-arm64

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ RUN apt update && apt-get install -y python3-pip
44
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
55
RUN update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
66

7-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
7+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
88
ENV PATH="/root/.cargo/bin:${PATH}"
99

1010
RUN /root/.cargo/bin/rustup update \
1111
&& /root/.cargo/bin/rustup target add aarch64-unknown-linux-gnu
12-
12+
RUN rustup default stable
1313
RUN mkdir /var/task
1414
WORKDIR /var/task
1515

src/ssm.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ pub async fn get_envs(env_vars: HashMap<String, String>) -> Result<HashMap<Strin
3131
results.insert(key, value);
3232
});
3333
}
34-
Err(error) => log::cloudwatch_metric("ssm", "error", true, Some(error.to_string())),
34+
Err(error) => return Err(error), // Return error if parameter is not found
3535
},
36-
Err(error) => log::cloudwatch_metric("ssm", "error", true, Some(error.to_string())),
36+
Err(error) => return Err(anyhow::anyhow!(error.to_string())), // Return error if task fails
3737
}
3838
}
3939
Ok(results)
@@ -67,6 +67,7 @@ async fn ssm_get_parameter(
6767
name, path, error
6868
)),
6969
);
70+
return Err(anyhow::anyhow!(error.to_string())); // Return error
7071
}
7172
}
7273
Ok(items)
@@ -100,7 +101,7 @@ async fn ssm_get_parameters_by_path(
100101
items.insert(env_name, parameter.value.unwrap());
101102
}
102103
}
103-
if response.next_token == None {
104+
if response.next_token.is_none() {
104105
break;
105106
}
106107
token = response.next_token;
@@ -115,7 +116,7 @@ async fn ssm_get_parameters_by_path(
115116
name, path, error
116117
)),
117118
);
118-
break;
119+
return Err(anyhow::anyhow!(error.to_string())); // Return error
119120
}
120121
}
121122
}
@@ -127,6 +128,7 @@ mod test {
127128
use super::*;
128129
use anyhow::Result;
129130
use aws_sdk_ssm::model::ParameterType;
131+
use std::collections::HashMap;
130132

131133
#[tokio::test]
132134
async fn should_parse() -> Result<()> {
@@ -191,4 +193,14 @@ mod test {
191193
assert_eq!(results, expected);
192194
Ok(())
193195
}
194-
}
196+
197+
#[tokio::test]
198+
async fn should_fail_if_param_not_found() {
199+
let env_vars: HashMap<String, String> = HashMap::from([
200+
("NON_EXISTENT_PARAM".to_string(), "x-crypteia-ssm:/crypteia/v5/myapp/NON_EXISTENT_PARAM".to_string()),
201+
]);
202+
203+
let result = get_envs(env_vars).await;
204+
assert!(result.is_err(), "Expected an error when parameter is not found");
205+
}
206+
}

0 commit comments

Comments
 (0)