-
Notifications
You must be signed in to change notification settings - Fork 51
Add unit tests to Ci Visibility #828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
499d3f0
try adding ci viz
rithikanarayan 2dcd124
cleanup
rithikanarayan b1a6c71
use agentless
rithikanarayan 8dff4e6
getting dd api key
rithikanarayan 8833adc
install vault
rithikanarayan 6fb13e6
don't end early
rithikanarayan c956ade
fix log injection assertions
rithikanarayan 81a4ff2
remove status msg
rithikanarayan 8111314
new snapshots
rithikanarayan c673264
remove extra file
rithikanarayan 9b83f43
Responding to reviews
rithikanarayan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Unless explicitly stated otherwise all files in this repository are licensed | ||
| # under the Apache License Version 2.0. | ||
| # This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
|
|
||
| # Loads DD_API_KEY for CI jobs that need Datadog API access without assuming an | ||
| # AWS role (e.g. unit-test Test Optimization agentless reporting). | ||
| # | ||
| # Resolution order: | ||
| # 1. Use DD_API_KEY if already set (e.g. GitLab CI/CD project variable). | ||
| # 2. Read from Vault via the gitlab-runner secrets path (requires vault CLI). | ||
| # | ||
| # Slim python CI images do not ship vault; the script installs a static binary | ||
| # when needed. Runners must provide VAULT_ADDR / VAULT_TOKEN for Vault auth. | ||
|
|
||
| set -e | ||
|
|
||
| VAULT_SECRETS_PATH="kv/k8s/gitlab-runner/datadog-lambda-python/secrets" | ||
| VAULT_CLI_VERSION="${VAULT_CLI_VERSION:-1.18.5}" | ||
|
|
||
| _ensure_vault_cli() { | ||
| if command -v vault >/dev/null 2>&1; then | ||
| return 0 | ||
| fi | ||
|
|
||
| local arch | ||
| case "$(uname -m)" in | ||
| x86_64 | amd64) arch=amd64 ;; | ||
| aarch64 | arm64) arch=arm64 ;; | ||
| *) | ||
| printf "[Error] Unsupported architecture for vault install: %s\n" "$(uname -m)" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| local install_dir="${TMPDIR:-/tmp}/vault-cli-${VAULT_CLI_VERSION}-${arch}" | ||
| mkdir -p "$install_dir" | ||
|
|
||
| if [ ! -x "${install_dir}/vault" ]; then | ||
| if ! command -v curl >/dev/null 2>&1 || ! command -v unzip >/dev/null 2>&1; then | ||
| apt-get update -qq | ||
| apt-get install -y -qq curl unzip | ||
| fi | ||
|
|
||
| local zip_url="https://releases.hashicorp.com/vault/${VAULT_CLI_VERSION}/vault_${VAULT_CLI_VERSION}_linux_${arch}.zip" | ||
| printf "Installing vault CLI %s (%s)...\n" "$VAULT_CLI_VERSION" "$arch" | ||
| curl -fsSL "$zip_url" -o "${install_dir}/vault.zip" | ||
| unzip -qo "${install_dir}/vault.zip" -d "$install_dir" | ||
| rm -f "${install_dir}/vault.zip" | ||
| fi | ||
|
|
||
| export PATH="${install_dir}:${PATH}" | ||
| } | ||
|
|
||
| _export_dd_api_key() { | ||
| export DD_API_KEY | ||
|
|
||
| if [ -n "${GITLAB_ENV:-}" ]; then | ||
| echo "DD_API_KEY=${DD_API_KEY}" >>"$GITLAB_ENV" | ||
| fi | ||
| } | ||
|
|
||
| if [ -n "${DD_API_KEY:-}" ]; then | ||
| printf "Using DD_API_KEY from environment.\n" | ||
| else | ||
| printf "Getting DD API KEY from Vault...\n" | ||
|
|
||
| _ensure_vault_cli | ||
|
|
||
| DD_API_KEY=$(vault kv get -field=dd-api-key "$VAULT_SECRETS_PATH") | ||
|
|
||
| if [ -z "$DD_API_KEY" ]; then | ||
| printf "[Error] DD_API_KEY is empty after Vault lookup.\n" >&2 | ||
| return 1 2>/dev/null || exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| _export_dd_api_key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.