Skip to content

Commit 77336f9

Browse files
committed
Try using authanywhere again
1 parent e61f806 commit 77336f9

2 files changed

Lines changed: 49 additions & 6 deletions

File tree

.gitlab/benchmarks.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ debugger-benchmarks:
9494
when: never
9595
- when: on_success
9696
script:
97+
- |
98+
if [ "$(uname -m)" = "x86_64" ]; then AAA="amd64"; else AAA="arm64"; fi
99+
wget -O /tmp/authanywhere "https://binaries.ddbuild.io/dd-source/authanywhere/LATEST/authanywhere-linux-${AAA}"
100+
chmod +x /tmp/authanywhere
101+
mv /tmp/authanywhere /usr/local/bin/authanywhere
97102
- mkdir -p "$(pwd)/reports/${BENCHMARK_TYPE}"
98103
- .gitlab/scripts/get-baseline-commit-info.sh "$(pwd)/reports/${BENCHMARK_TYPE}"
99104
- .gitlab/scripts/benchmark-compare.sh "${BENCHMARK_TYPE}"
@@ -156,6 +161,11 @@ benchmarks-debug-baseline:
156161
rules:
157162
- when: on_success
158163
script:
164+
- |
165+
if [ "$(uname -m)" = "x86_64" ]; then AAA="amd64"; else AAA="arm64"; fi
166+
wget -O /tmp/authanywhere "https://binaries.ddbuild.io/dd-source/authanywhere/LATEST/authanywhere-linux-${AAA}"
167+
chmod +x /tmp/authanywhere
168+
mv /tmp/authanywhere /usr/local/bin/authanywhere
159169
- mkdir -p reports/debug
160170
- .gitlab/scripts/get-baseline-commit-info.sh "reports/debug"
161171
- echo "Resolved baseline:"

.gitlab/scripts/get-baseline-commit-info.sh

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ readonly TARGET_BRANCH="${TARGET_BRANCH:-master}"
1111
mkdir -p "${OUTPUT_DIR}"
1212
rm -f "${FALLBACK_MARKER_FILE}"
1313

14-
if [[ -z "${CI_PROJECT_ID:-}" || -z "${CI_API_V4_URL:-}" || -z "${CI_JOB_TOKEN:-}" ]]; then
15-
echo "Missing CI_PROJECT_ID/CI_API_V4_URL/CI_JOB_TOKEN environment variables." >&2
14+
if [[ -z "${CI_PROJECT_ID:-}" || -z "${CI_API_V4_URL:-}" ]]; then
15+
echo "Missing CI_PROJECT_ID/CI_API_V4_URL environment variables." >&2
1616
exit 1
1717
fi
1818

1919
readonly PROJECT_API_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}"
20+
readonly BTI_TOKEN_URL="https://bti-ci-api.us1.ddbuild.io/internal/ci/gitlab/token?owner=DataDog&repository=apm-reliability/dd-trace-java"
2021

2122
log_debug() {
2223
echo "[baseline-debug] $*" >&2
@@ -27,13 +28,44 @@ response_snippet() {
2728
echo "${response}" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g' | cut -c1-220
2829
}
2930

31+
get_private_token() {
32+
local auth_header bti_response http_status response_body private_token
33+
34+
if ! auth_header="$(authanywhere --audience sdm 2>&1)"; then
35+
echo "Failed to get authanywhere token: ${auth_header}" >&2
36+
return 1
37+
fi
38+
39+
bti_response="$(
40+
curl -w "\nHTTP_STATUS:%{http_code}" --silent --show-error \
41+
--header "${auth_header}" \
42+
"${BTI_TOKEN_URL}" 2>&1
43+
)"
44+
http_status="$(echo "${bti_response}" | grep "HTTP_STATUS:" | sed 's/HTTP_STATUS://')"
45+
response_body="$(echo "${bti_response}" | sed '/HTTP_STATUS:/d')"
46+
47+
if [[ "${http_status}" != "200" ]]; then
48+
echo "BTI token request failed: status=${http_status}, body='$(response_snippet "${response_body}")'" >&2
49+
return 1
50+
fi
51+
52+
private_token="$(echo "${response_body}" | grep -o '"token":"[^"]*"' | sed 's/"token":"\([^"]*\)"/\1/')"
53+
if [[ -z "${private_token}" ]]; then
54+
echo "Failed to parse private token from BTI response." >&2
55+
return 1
56+
fi
57+
58+
echo "${private_token}"
59+
}
60+
3061
get_pipeline_id_for_commit() {
3162
local commit_sha="$1"
3263
local api_url="${PROJECT_API_URL}/repository/commits/${commit_sha}"
33-
local response pipeline_id
64+
local response pipeline_id private_token
3465

3566
log_debug "query commit endpoint: ${api_url}"
36-
response="$(curl --request GET --silent --show-error --header "JOB-TOKEN: ${CI_JOB_TOKEN}" "${api_url}" || true)"
67+
private_token="$(get_private_token)" || return 1
68+
response="$(curl --request GET --silent --show-error --header "PRIVATE-TOKEN: ${private_token}" "${api_url}" || true)"
3769
pipeline_id="$(echo "${response}" | grep -o '"last_pipeline"[^}]*"id":[0-9]*' | grep -o '[0-9]*$' | head -1 || true)"
3870
if [[ -n "${pipeline_id}" && "${pipeline_id}" != "null" ]]; then
3971
log_debug "found pipeline_id=${pipeline_id} for commit_sha=${commit_sha}"
@@ -48,10 +80,11 @@ get_pipeline_id_for_commit() {
4880
get_latest_pipeline_id_for_branch() {
4981
local branch="$1"
5082
local api_url="${PROJECT_API_URL}/pipelines?ref=${branch}&order_by=id&sort=desc&per_page=1"
51-
local response pipeline_id
83+
local response pipeline_id private_token
5284

5385
log_debug "query pipelines endpoint: ${api_url}"
54-
response="$(curl --request GET --silent --show-error --header "JOB-TOKEN: ${CI_JOB_TOKEN}" "${api_url}" || true)"
86+
private_token="$(get_private_token)" || return 1
87+
response="$(curl --request GET --silent --show-error --header "PRIVATE-TOKEN: ${private_token}" "${api_url}" || true)"
5588
pipeline_id="$(echo "${response}" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*' || true)"
5689
if [[ -n "${pipeline_id}" ]]; then
5790
log_debug "found latest pipeline_id=${pipeline_id} for branch=${branch}"

0 commit comments

Comments
 (0)