Skip to content

Commit 8111314

Browse files
new snapshots
1 parent 81a4ff2 commit 8111314

15 files changed

Lines changed: 394 additions & 92 deletions

ci/get_dd_api_key.sh

Lines changed: 0 additions & 79 deletions
This file was deleted.

ci/get_secrets.sh

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,72 @@
55
# This product includes software developed at Datadog (https://www.datadoghq.com/).
66
# Copyright 2023 Datadog, Inc.
77

8+
# Loads secrets for CI jobs from Vault (gitlab-runner path below).
9+
#
10+
# Full mode (default): requires EXTERNAL_ID_NAME, ROLE_TO_ASSUME, and AWS_ACCOUNT.
11+
# Fetches the external ID and DD API key, then assumes the AWS deployer role.
12+
#
13+
# API-key-only mode: set GET_SECRETS_API_KEY_ONLY=1 when sourcing.
14+
# Loads DD_API_KEY only (e.g. unit-test Test Optimization). Uses DD_API_KEY from
15+
# the environment when set; otherwise reads from Vault. Installs the vault CLI
16+
# on slim images that do not include it.
17+
818
set -e
919

20+
VAULT_SECRETS_PATH="kv/k8s/gitlab-runner/datadog-lambda-python/secrets"
21+
VAULT_CLI_VERSION="${VAULT_CLI_VERSION:-1.18.5}"
22+
23+
_ensure_vault_cli() {
24+
command -v vault >/dev/null 2>&1 && return
25+
26+
local arch install_dir
27+
case "$(uname -m)" in
28+
x86_64 | amd64) arch=amd64 ;;
29+
aarch64 | arm64) arch=arm64 ;;
30+
*) printf "[Error] Unsupported architecture: %s\n" "$(uname -m)" >&2; exit 1 ;;
31+
esac
32+
33+
install_dir="${TMPDIR:-/tmp}/vault-cli-${VAULT_CLI_VERSION}-${arch}"
34+
if [ -x "${install_dir}/vault" ]; then
35+
export PATH="${install_dir}:${PATH}"
36+
return
37+
fi
38+
39+
apt-get update -qq && apt-get install -y -qq curl unzip
40+
printf "Installing vault CLI %s (%s)...\n" "$VAULT_CLI_VERSION" "$arch"
41+
mkdir -p "$install_dir"
42+
curl -fsSL \
43+
"https://releases.hashicorp.com/vault/${VAULT_CLI_VERSION}/vault_${VAULT_CLI_VERSION}_linux_${arch}.zip" \
44+
-o "${install_dir}/vault.zip"
45+
unzip -qo "${install_dir}/vault.zip" -d "$install_dir"
46+
rm -f "${install_dir}/vault.zip"
47+
export PATH="${install_dir}:${PATH}"
48+
}
49+
50+
_get_dd_api_key() {
51+
if [ -n "${DD_API_KEY:-}" ]; then
52+
printf "Using DD_API_KEY from environment.\n"
53+
else
54+
printf "Getting DD API KEY...\n"
55+
_ensure_vault_cli
56+
DD_API_KEY=$(vault kv get -field=dd-api-key "$VAULT_SECRETS_PATH")
57+
if [ -z "$DD_API_KEY" ]; then
58+
printf "[Error] DD_API_KEY is empty after Vault lookup.\n" >&2
59+
return 1 2>/dev/null || exit 1
60+
fi
61+
export DD_API_KEY
62+
fi
63+
64+
if [ -n "${GITLAB_ENV:-}" ]; then
65+
echo "DD_API_KEY=${DD_API_KEY}" >>"$GITLAB_ENV"
66+
fi
67+
}
68+
69+
if [ -n "${GET_SECRETS_API_KEY_ONLY:-}" ]; then
70+
_get_dd_api_key
71+
return 0 2>/dev/null || exit 0
72+
fi
73+
1074
if [ -z "$EXTERNAL_ID_NAME" ]; then
1175
printf "[Error] No EXTERNAL_ID_NAME found.\n"
1276
printf "Exiting script...\n"
@@ -19,13 +83,13 @@ if [ -z "$ROLE_TO_ASSUME" ]; then
1983
exit 1
2084
fi
2185

22-
printf "Getting AWS External ID...\n"
86+
_ensure_vault_cli
2387

24-
EXTERNAL_ID=$(vault kv get -field="$EXTERNAL_ID_NAME" kv/k8s/gitlab-runner/datadog-lambda-python/secrets)
88+
printf "Getting AWS External ID...\n"
2589

26-
printf "Getting DD API KEY...\n"
90+
EXTERNAL_ID=$(vault kv get -field="$EXTERNAL_ID_NAME" "$VAULT_SECRETS_PATH")
2791

28-
export DD_API_KEY=$(vault kv get -field=dd-api-key kv/k8s/gitlab-runner/datadog-lambda-python/secrets)
92+
_get_dd_api_key
2993

3094
printf "Assuming role...\n"
3195

ci/input_files/build.yaml.tpl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,13 @@ unit-test ({{ $runtime.name }}-{{ $runtime.arch }}):
8787
DD_SERVICE: "datadog-lambda-python-{{ $runtime.python_version }}-{{ $runtime.arch }}"
8888
DD_ENV: "ci"
8989
before_script:
90-
- source ./ci/get_dd_api_key.sh
90+
- GET_SECRETS_API_KEY_ONLY=1 source ./ci/get_secrets.sh
9191
- PYTHON_VERSION={{ $runtime.python_version }} ARCH={{ $runtime.arch }} ./scripts/setup_python_env.sh
9292
script:
93-
- |
94-
set -e
95-
source ./ci/get_dd_api_key.sh
96-
source venv/bin/activate
97-
pytest -vv --ddtrace
93+
- set -e
94+
- GET_SECRETS_API_KEY_ONLY=1 source ./ci/get_secrets.sh
95+
- source venv/bin/activate
96+
- pytest -vv --ddtrace
9897
retry: 2
9998

10099
integration-test ({{ $runtime.name }}-{{ $runtime.arch }}):

pyproject.toml.bak

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[tool.poetry]
2+
name = "datadog_lambda"
3+
version = "8.126.0.dev0"
4+
description = "The Datadog AWS Lambda Library"
5+
authors = ["Datadog, Inc. <dev@datadoghq.com>"]
6+
license = "Apache-2.0"
7+
readme = "README.md"
8+
repository = "https://github.com/DataDog/datadog-lambda-python"
9+
keywords = [
10+
"datadog",
11+
"aws",
12+
"lambda",
13+
"layer",
14+
]
15+
packages = [
16+
{ include = "datadog_lambda" }
17+
]
18+
classifiers = [
19+
"Programming Language :: Python :: 3.8",
20+
"Programming Language :: Python :: 3.9",
21+
"Programming Language :: Python :: 3.10",
22+
"Programming Language :: Python :: 3.11",
23+
"Programming Language :: Python :: 3.12",
24+
"Programming Language :: Python :: 3.13",
25+
"Programming Language :: Python :: 3.14",
26+
]
27+
28+
[tool.poetry.dependencies]
29+
python = ">=3.8.0,<3.15"
30+
datadog = ">=0.51.0,<1.0.0"
31+
wrapt = "^1.11.2"
32+
ddtrace = [
33+
{version = ">=3.19.1,<4", python = ">=3.8,<3.10"},
34+
{version = ">=4.1.1,<5,!=4.6.*", python = ">=3.10"}
35+
]
36+
ujson = [
37+
{version = ">=5.10.0,<5.12.0", python = ">=3.8,<3.10"},
38+
{version = "^5.12.0", python = ">=3.10"},
39+
]
40+
urllib3 = [
41+
{version = ">=1.25.4,<1.27", python = ">=3.8,<3.10"},
42+
{version = "^2.6.3", python = ">=3.10"},
43+
]
44+
botocore = { version = "^1.34.0", optional = true }
45+
requests = [
46+
{ version = "^2.22.0", optional = true, python = ">=3.8,<3.10" },
47+
{ version = "^2.33.0", optional = true, python = ">=3.10" },
48+
]
49+
pytest = [
50+
{ version = "^8.3.4", optional = true, python = ">=3.8,<3.10" },
51+
{ version = "^9.0.3", optional = true, python = ">=3.10" },
52+
]
53+
pytest-benchmark = { version = "^4.0", optional = true }
54+
flake8 = { version = "^5.0.4", optional = true }
55+
56+
[tool.poetry.extras]
57+
dev = [
58+
"botocore",
59+
"flake8",
60+
"pytest",
61+
"pytest-benchmark",
62+
"requests",
63+
]
64+
65+
[build-system]
66+
requires = ["poetry-core>=1.0.0"]
67+
build-backend = "poetry.core.masonry.api"
68+
69+
[tool.pytest.ini_options]
70+
addopts = "--benchmark-disable --benchmark-autosave"

scripts/run_integration_tests.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ for handler_name in "${LAMBDA_HANDLERS[@]}"; do
220220
# Normalize python-requests version
221221
sed -E "s/(User-Agent:python-requests\/)[0-9]+\.[0-9]+\.[0-9]+/\1X\.X\.X/g" |
222222
sed -E "s/(\"http.useragent\"\: \"python-requests\/)[0-9]+\.[0-9]+\.[0-9]+/\1X\.X\.X/g" |
223-
# ddtrace 4.x adds http.status_msg (derived from http.status_code); omit from snapshots
224-
sed '/"http\.status_msg"/d' |
225223
# Strip out trace/span/parent/timestamps
226224
sed -E "s/(\"trace_id\"\: \")[A-Z0-9\.\-]+/\1XXXX/g" |
227225
sed -E "s/(\"span_id\"\: \")[A-Z0-9\.\-]+/\1XXXX/g" |

0 commit comments

Comments
 (0)