Skip to content

Commit

Permalink
allow multiple objects in challenge.yaml (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
sroettger authored Jul 8, 2021
1 parent 27d3e8d commit 43f168b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dist/activate
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ function _kctf_set_active_challenge {
current_dir="${PWD}"
while [[ "${current_dir}" == "${KCTF_CTF_DIR}"/* ]]; do
if [[ -e "${current_dir}/challenge.yaml" ]]; then
CHALLENGE_NAME=$("${KCTF_BIN}/yq" eval --exit-status '.metadata.name' "${current_dir}/challenge.yaml" 2>/dev/null)
CHALLENGE_NAME=$("${KCTF_BIN}/yq" eval --exit-status 'select(.kind == "Challenge") | .metadata.name' "${current_dir}/challenge.yaml" 2>/dev/null)
if [[ $? -ne 0 ]]; then
unset CHALLENGE_NAME
fi
CHALLENGE_NAMESPACE="default"
if "${KCTF_BIN}/yq" eval --exit-status '.metadata.namespace' "${current_dir}/challenge.yaml" >/dev/null 2>/dev/null; then
CHALLENGE_NAMESPACE=$("${KCTF_BIN}/yq" eval '.metadata.namespace' "${current_dir}/challenge.yaml" 2>/dev/null)
if "${KCTF_BIN}/yq" eval --exit-status 'select(.kind == "Challenge") | .metadata.namespace' "${current_dir}/challenge.yaml" >/dev/null 2>/dev/null; then
CHALLENGE_NAMESPACE=$("${KCTF_BIN}/yq" eval 'select(.kind == "Challenge") | .metadata.namespace' "${current_dir}/challenge.yaml" 2>/dev/null)
fi
export CHALLENGE_DIR="${current_dir}"
export CHALLENGE_NAME
Expand Down
8 changes: 4 additions & 4 deletions dist/bin/kctf-challenge
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function build_image {
}

function healthcheck_enabled {
[[ $("${KCTF_BIN}/yq" eval '.spec.healthcheck.enabled' "${CHALLENGE_DIR}/challenge.yaml") == "true" ]]
[[ $("${KCTF_BIN}/yq" eval 'select(.kind == "Challenge") | .spec.healthcheck.enabled' "${CHALLENGE_DIR}/challenge.yaml") == "true" ]]
}

function build_images {
Expand Down Expand Up @@ -184,9 +184,9 @@ function kctf_chal_start {
push_images || return

# update challenge.yaml with the image urls
"${KCTF_BIN}/yq" eval ".spec.image = \"${CHALLENGE_IMAGE_REMOTE}\"" --inplace "${CHALLENGE_DIR}/challenge.yaml"
"${KCTF_BIN}/yq" eval "select(.kind == \"Challenge\") | .spec.image = \"${CHALLENGE_IMAGE_REMOTE}\", select(.kind == \"Challenge\" | not)" --inplace "${CHALLENGE_DIR}/challenge.yaml"
if healthcheck_enabled; then
"${KCTF_BIN}/yq" eval ".spec.healthcheck.image = \"${HEALTHCHECK_IMAGE_REMOTE}\"" --inplace "${CHALLENGE_DIR}/challenge.yaml"
"${KCTF_BIN}/yq" eval "select(.kind == \"Challenge\") | .spec.healthcheck.image = \"${HEALTHCHECK_IMAGE_REMOTE}\", select(.kind == \"Challenge\" | not)" --inplace "${CHALLENGE_DIR}/challenge.yaml"
fi

"${KCTF_BIN}/kubectl" apply -f "${CHALLENGE_DIR}/challenge.yaml" || return
Expand Down Expand Up @@ -549,7 +549,7 @@ function kctf_chal_list {
echo '== challenges in repository =='

for challenge_yaml in $(find "${KCTF_CTF_DIR}" -path "${KCTF_CTF_DIR}/kctf" -prune -false -o -name "challenge.yaml"); do
challenge_name=$(${KCTF_BIN}/yq eval ".metadata.name" "${challenge_yaml}")
challenge_name=$(${KCTF_BIN}/yq eval "select(.kind == \"Challenge\") | .metadata.name" "${challenge_yaml}")
challenge_dir=$(realpath --relative-to "${KCTF_CTF_DIR}" $(dirname "${challenge_yaml}"))
if [[ "${challenge_name}" == ${challenge_dir} ]]; then
echo "${challenge_name}"
Expand Down

0 comments on commit 43f168b

Please sign in to comment.