Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
Add parameter to kokoro/testutils/copy_credentials.sh to select for w…
Browse files Browse the repository at this point in the history
…hich KMS service copying credentials.

PiperOrigin-RevId: 466274850
  • Loading branch information
morambro authored and copybara-github committed Aug 9, 2022
1 parent 826e8b7 commit cb0a9b6
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 47 deletions.
2 changes: 1 addition & 1 deletion kokoro/gcp_ubuntu_per_language/cross_language/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use_bazel() {
main() {
if [[ -n "${KOKORO_ROOT:-}" ]] ; then
cd "${KOKORO_ARTIFACTS_DIR}/git/tink"
./kokoro/testutils/copy_credentials.sh "tools/testdata"
./kokoro/testutils/copy_credentials.sh "tools/testdata" "all"
./kokoro/testutils/update_android_sdk.sh
# Sourcing required to update callers environment.
source ./kokoro/testutils/install_python3.sh
Expand Down
2 changes: 1 addition & 1 deletion kokoro/gcp_ubuntu_per_language/go/bazel/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [[ -n "${KOKORO_ROOT:-}" ]]; then
use_bazel.sh "$(cat go/.bazelversion)"
fi

./kokoro/testutils/copy_credentials.sh "go/testdata"
./kokoro/testutils/copy_credentials.sh "go/testdata" "all"
# Sourcing required to update callers environment.
source ./kokoro/testutils/install_go.sh

Expand Down
2 changes: 1 addition & 1 deletion kokoro/gcp_ubuntu_per_language/go/gomod/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if [[ -n "${KOKORO_ROOT:-}" ]]; then
fi
readonly REPO_DIR

./kokoro/testutils/copy_credentials.sh "go/testdata"
./kokoro/testutils/copy_credentials.sh "go/testdata" "all"
./kokoro/testutils/update_certs.sh
# Sourcing required to update callers environment.
source ./kokoro/testutils/install_go.sh
Expand Down
2 changes: 1 addition & 1 deletion kokoro/gcp_ubuntu_per_language/java_src/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if [[ -n "${KOKORO_ROOT:-}" ]] ; then
use_bazel.sh "$(cat java_src/.bazelversion)"
fi

./kokoro/testutils/copy_credentials.sh "java_src/testdata"
./kokoro/testutils/copy_credentials.sh "java_src/testdata" "all"
./kokoro/testutils/update_android_sdk.sh

# Run manual tests which rely on key material injected into the Kokoro
Expand Down
2 changes: 1 addition & 1 deletion kokoro/gcp_ubuntu_per_language/python/bazel/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [[ -n "${KOKORO_ROOT:-}" ]]; then
cd "${KOKORO_ARTIFACTS_DIR}/git/tink"
fi

./kokoro/testutils/copy_credentials.sh "python/testdata"
./kokoro/testutils/copy_credentials.sh "python/testdata" "all"
# Sourcing required to update callers environment.
source ./kokoro/testutils/install_python3.sh

Expand Down
2 changes: 1 addition & 1 deletion kokoro/gcp_ubuntu_per_language/python/pip/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if [[ -n "${KOKORO_ROOT:-}" ]]; then
use_bazel.sh "$(cat python/.bazelversion)"
fi

./kokoro/testutils/copy_credentials.sh "python/testdata"
./kokoro/testutils/copy_credentials.sh "python/testdata" "all"
# Sourcing required to update callers environment.
source ./kokoro/testutils/install_python3.sh
source ./kokoro/testutils/install_protoc.sh
Expand Down
2 changes: 1 addition & 1 deletion kokoro/gcp_ubuntu_per_language/tools/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -euo pipefail

cd ${KOKORO_ARTIFACTS_DIR}/git/tink

./kokoro/testutils/copy_credentials.sh "tools/testdata"
./kokoro/testutils/copy_credentials.sh "tools/testdata" "all"
./kokoro/testutils/update_android_sdk.sh
# Sourcing required to update callers environment.
source ./kokoro/testutils/install_python3.sh
Expand Down
2 changes: 1 addition & 1 deletion kokoro/macos_external/go/bazel/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [[ -n "${KOKORO_ROOT:-}" ]]; then
use_bazel.sh "$(cat go/.bazelversion)"
fi

./kokoro/testutils/copy_credentials.sh "go/testdata"
./kokoro/testutils/copy_credentials.sh "go/testdata" "all"
# Sourcing required to update callers environment.
source ./kokoro/testutils/install_go.sh

Expand Down
2 changes: 1 addition & 1 deletion kokoro/macos_external/go/gomod/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -euo pipefail
REPO_DIR="${KOKORO_ARTIFACTS_DIR}/git/tink"

cd "${REPO_DIR}"
./kokoro/testutils/copy_credentials.sh "go/testdata"
./kokoro/testutils/copy_credentials.sh "go/testdata" "all"
# Sourcing required to update callers environment.
source ./kokoro/testutils/install_go.sh

Expand Down
2 changes: 1 addition & 1 deletion kokoro/macos_external/java_src/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST_FLAGS=(
readonly TEST_FLAGS

cd ${KOKORO_ARTIFACTS_DIR}/git/tink
./kokoro/testutils/copy_credentials.sh "java_src/testdata"
./kokoro/testutils/copy_credentials.sh "java_src/testdata" "all"
./kokoro/testutils/update_android_sdk.sh

cd java_src
Expand Down
2 changes: 1 addition & 1 deletion kokoro/macos_external/python/bazel/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [[ -n "${KOKORO_ROOT:-}" ]]; then
cd "${KOKORO_ARTIFACTS_DIR}/git/tink"
fi

./kokoro/testutils/copy_credentials.sh "python/testdata"
./kokoro/testutils/copy_credentials.sh "python/testdata" "gcp"
# Install protobuf pip packages.
pip3 install protobuf --user

Expand Down
2 changes: 1 addition & 1 deletion kokoro/macos_external/python/pip/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [[ -n "${KOKORO_ROOT:-}" ]]; then
use_bazel.sh "$(cat python/.bazelversion)"
fi

./kokoro/testutils/copy_credentials.sh "python/testdata"
./kokoro/testutils/copy_credentials.sh "python/testdata" "all"
source ./kokoro/testutils/install_protoc.sh
source ./kokoro/testutils/install_tink_via_pip.sh "${PWD}/python"

Expand Down
2 changes: 1 addition & 1 deletion kokoro/macos_external/tools/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export ANDROID_HOME="/Users/kbuilder/Library/Android/sdk"
export COURSIER_OPTS="-Djava.net.preferIPv6Addresses=true"

cd "${KOKORO_ARTIFACTS_DIR}/git/tink"
./kokoro/testutils/copy_credentials.sh "tools/testdata"
./kokoro/testutils/copy_credentials.sh "tools/testdata" "all"
./kokoro/testutils/update_android_sdk.sh
# Sourcing required to update callers environment.
source ./kokoro/testutils/install_go.sh
Expand Down
12 changes: 6 additions & 6 deletions kokoro/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ main() {
pip3 install --user protobuf
fi

./kokoro/testutils/copy_credentials.sh "go/testdata"
./kokoro/testutils/copy_credentials.sh "java_src/examples/testdata"
./kokoro/testutils/copy_credentials.sh "java_src/testdata"
./kokoro/testutils/copy_credentials.sh "python/examples/testdata"
./kokoro/testutils/copy_credentials.sh "python/testdata"
./kokoro/testutils/copy_credentials.sh "tools/testdata"
./kokoro/testutils/copy_credentials.sh "go/testdata" "all"
./kokoro/testutils/copy_credentials.sh "java_src/examples/testdata" "gcp"
./kokoro/testutils/copy_credentials.sh "java_src/testdata" "all"
./kokoro/testutils/copy_credentials.sh "python/examples/testdata" "gcp"
./kokoro/testutils/copy_credentials.sh "python/testdata" "all"
./kokoro/testutils/copy_credentials.sh "tools/testdata" "all"

./kokoro/testutils/update_android_sdk.sh
# Sourcing required to update callers environment.
Expand Down
118 changes: 90 additions & 28 deletions kokoro/testutils/copy_credentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,111 @@
####################################################################################

# This script takes credentials injected into the environment via the Kokoro job
# configuration and copies them to the expected locations to facilitate
# continuous integration testing.
# configuration and copies them to the expected locations.
#
# The second argument indicates whether all KMS service credentials should be
# copied (all) or only credentials for a specific KMS service (gcp|aws).
#
# Usage insructions:
#
# ./kokoro/testutils/copy_credentials.sh <testdata dir>
# ./kokoro/testutils/copy_credentials.sh <testdata dir> <all|aws|gcp>
#

TESTDATA_DIR=
KMS_SERVICE=

if [[ -z "${KOKORO_ROOT}" ]]; then
exit 0
fi
#######################################
# Process command line arguments.
#
# Globals:
# TESTDATA_DIR
# KMS_SERVICE
#######################################
process_args() {
TESTDATA_DIR="$1"
readonly TESTDATA_DIR
KMS_SERVICE="$2"
readonly KMS_SERVICE

readonly TESTDATA_DIR="${1}"
if [[ -z "${TESTDATA_DIR}" ]]; then
echo "Testdata directory must be set" >&2
exit 1
fi

if [[ -z "${TESTDATA_DIR}" ]]; then
echo "Testdata directory must be set" >&2
exit 1
fi
if [[ ! -d "${TESTDATA_DIR}" ]]; then
echo "Testdata directory \"${TESTDATA_DIR}\" doesn't exist" >&2
exit 1
fi

if [[ ! -d "${TESTDATA_DIR}" ]]; then
echo "Testdata directory \"${TESTDATA_DIR}\" doesn't exist" >&2
exit 1
fi
if [[ -z "${KMS_SERVICE}" ]]; then
echo "KMS service must be specified" >&2
exit 1
fi
}

cp "${TINK_TEST_SERVICE_ACCOUNT}" "${TESTDATA_DIR}/gcp/credential.json"
#######################################
# Copy GCP credentials.
#
# Globals:
# TESTDATA_DIR
# TINK_TEST_SERVICE_ACCOUNT
#######################################
copy_gcp_credentials() {
cp "${TINK_TEST_SERVICE_ACCOUNT}" "${TESTDATA_DIR}/gcp/credential.json"
}

# Create the different format for the AWS credentials
readonly AWS_KEY_ID="AKIATNYZMJOHVMN7MSYH"
readonly AWS_KEY="$(cat ${AWS_TINK_TEST_SERVICE_ACCOUNT})"
#######################################
# Copy AWS credentials.
#
# Globals:
# TESTDATA_DIR
# AWS_TINK_TEST_SERVICE_ACCOUNT
#######################################
copy_aws_credentials() {
# Create the different format for the AWS credentials
local -r aws_key_id="AKIATNYZMJOHVMN7MSYH"
local -r aws_key="$(cat ${AWS_TINK_TEST_SERVICE_ACCOUNT})"

cat <<END > "${TESTDATA_DIR}/aws/credentials.ini"
cat <<END > "${TESTDATA_DIR}/aws/credentials.ini"
[default]
aws_access_key_id = ${AWS_KEY_ID}
aws_secret_access_key = ${AWS_KEY}
aws_access_key_id = ${aws_key_id}
aws_secret_access_key = ${aws_key}
END

cat <<END > "${TESTDATA_DIR}/aws/credentials.cred"
cat <<END > "${TESTDATA_DIR}/aws/credentials.cred"
[default]
accessKey = ${AWS_KEY_ID}
secretKey = ${AWS_KEY}
accessKey = ${aws_key_id}
secretKey = ${aws_key}
END


cat <<END > "${TESTDATA_DIR}/aws/credentials.csv"
cat <<END > "${TESTDATA_DIR}/aws/credentials.csv"
User name,Password,Access key ID,Secret access key,Console login link
tink-user1,,${AWS_KEY_ID},${AWS_KEY},https://235739564943.signin.aws.amazon.com/console
tink-user1,,${aws_key_id},${aws_key},https://235739564943.signin.aws.amazon.com/console
END
}

main() {
if [[ -z "${KOKORO_ROOT}" ]]; then
exit 0
fi

process_args "$@"

case "${KMS_SERVICE}" in
aws)
copy_aws_credentials
;;
gcp)
copy_gcp_credentials
;;
all)
copy_aws_credentials
copy_gcp_credentials
;;
*)
echo "Invalid KMS service \"${KMS_SERVICE}\"" >&2
exit 1
esac
}

main "$@"

0 comments on commit cb0a9b6

Please sign in to comment.