Skip to content

Commit 1d2f814

Browse files
chore: we need to specify a provider
1 parent b2d1e7b commit 1d2f814

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

bottlecap-run/runBottlecap.sh

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
11
#!/bin/bash
22

33
set -ex
4-
arch=$(uname -a)
5-
cd ../bottlecap
6-
# build bottlecap in debug mode
7-
if (echo $arch | grep -q "Darwin"); then
8-
PATH=/usr/bin:$PATH cargo zigbuild --target=aarch64-unknown-linux-gnu
9-
build_path=../bottlecap/target/aarch64-unknown-linux-gnu/debug/bottlecap
4+
5+
# Setup cleanup trap to ensure docker container is stopped and removed even if script is interrupted
6+
cleanup() {
7+
if [ -n "${docker_name}" ]; then
8+
echo "Cleaning up Docker container..."
9+
docker stop "${docker_name}" 2>/dev/null || true
10+
docker rm "${docker_name}" 2>/dev/null || true
11+
fi
12+
}
13+
14+
# Register trap for EXIT, INT (Ctrl+C), TERM, and ERR
15+
trap cleanup EXIT INT TERM ERR
16+
17+
if [ -z "$PREBUILT_BUILD_PATH" ]; then
18+
cd ../bottlecap
19+
arch=$(uname -a)
20+
# build bottlecap in debug mode
21+
if (echo $arch | grep -q "Darwin"); then
22+
PATH=/usr/bin:$PATH cargo zigbuild --target=aarch64-unknown-linux-gnu
23+
build_path=../bottlecap/target/aarch64-unknown-linux-gnu/debug/bottlecap
24+
else
25+
cargo build
26+
build_path=../bottlecap/target/debug/bottlecap
27+
fi
28+
cd -
29+
1030
else
11-
cargo build
12-
build_path=../bottlecap/target/debug/bottlecap
31+
echo "using a prebuilt bottlecap from $PREBUILT_BUILD_PATH"
32+
build_path="$PREBUILT_BUILD_PATH"
1333
fi
14-
cd -
1534

1635
# run a hello world function in Lambda RIE (https://github.com/aws/aws-lambda-runtime-interface-emulator)
1736
# the lambda_extension binary is copied to /opt/extensions
1837
docker_name=$(docker create \
1938
--publish 9000:8080 \
2039
-e DD_API_KEY=XXX \
40+
-e DD_SERVERLESS_FLUSH_STRATEGY='periodically,1' \
41+
-e DD_LOG_LEVEL=debug \
42+
-e RUST_BACKTRACE=full \
43+
-e DD_ENV=dev \
44+
-e DD_VERSION=1 \
2145
"public.ecr.aws/lambda/nodejs:20" "index.handler")
2246
echo -e 'export const handler = async () => {\n\tconsole.log("Hello world!");\n};' > /tmp/index.mjs
2347
docker cp "/tmp/index.mjs" "${docker_name}:/var/task/index.mjs"
@@ -26,5 +50,3 @@ docker exec "${docker_name}" mkdir -p /opt/extensions
2650
docker cp "${build_path}" "${docker_name}:/opt/extensions/datadog-agent"
2751
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
2852
docker logs "${docker_name}"
29-
docker stop "${docker_name}"
30-
docker rm "${docker_name}"

bottlecap/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bottlecap/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fips = [
7575
"ddcommon/fips",
7676
"datadog-trace-utils/fips",
7777
"dogstatsd/fips",
78-
"reqwest/rustls-tls-no-provider",
78+
"reqwest/rustls-tls-native-roots-no-provider",
7979
"rustls/fips",
8080
]
8181
force_fallback = []

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ fn log_fips_status() {
8787
debug!("FIPS mode is disabled");
8888
}
8989

90+
/// Sets up the client provider for TLS operations.
91+
/// In FIPS mode, this installs the AWS-LC crypto provider.
92+
/// In non-FIPS mode, this is a no-op.
93+
#[cfg(feature = "fips")]
94+
fn prepare_client_provider() -> Result<()> {
95+
rustls::crypto::CryptoProvider::install_default(rustls::crypto::aws_lc_rs::default_provider())
96+
.map_err(|e| {
97+
Error::new(
98+
std::io::ErrorKind::InvalidData,
99+
format!("Failed to set up crypto provider: {e:?}"),
100+
)
101+
})
102+
}
103+
104+
#[cfg(not(feature = "fips"))]
105+
fn prepare_client_provider() -> Result<()> {
106+
// No-op in non-FIPS mode
107+
Ok(())
108+
}
109+
90110
#[derive(Clone, Deserialize)]
91111
#[serde(rename_all = "camelCase")]
92112
struct RegisterResponse {
@@ -206,6 +226,7 @@ async fn main() -> Result<()> {
206226
log_fips_status();
207227
let version_without_next = EXTENSION_VERSION.split('-').next().unwrap_or("NA");
208228
debug!("Starting Datadog Extension {version_without_next}");
229+
prepare_client_provider()?;
209230
let client = Client::builder().no_proxy().build().map_err(|e| {
210231
Error::new(
211232
std::io::ErrorKind::InvalidData,

0 commit comments

Comments
 (0)