Skip to content

Commit 43f168b

Browse files
authored
allow multiple objects in challenge.yaml (#322)
1 parent 27d3e8d commit 43f168b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

dist/activate

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ function _kctf_set_active_challenge {
208208
current_dir="${PWD}"
209209
while [[ "${current_dir}" == "${KCTF_CTF_DIR}"/* ]]; do
210210
if [[ -e "${current_dir}/challenge.yaml" ]]; then
211-
CHALLENGE_NAME=$("${KCTF_BIN}/yq" eval --exit-status '.metadata.name' "${current_dir}/challenge.yaml" 2>/dev/null)
211+
CHALLENGE_NAME=$("${KCTF_BIN}/yq" eval --exit-status 'select(.kind == "Challenge") | .metadata.name' "${current_dir}/challenge.yaml" 2>/dev/null)
212212
if [[ $? -ne 0 ]]; then
213213
unset CHALLENGE_NAME
214214
fi
215215
CHALLENGE_NAMESPACE="default"
216-
if "${KCTF_BIN}/yq" eval --exit-status '.metadata.namespace' "${current_dir}/challenge.yaml" >/dev/null 2>/dev/null; then
217-
CHALLENGE_NAMESPACE=$("${KCTF_BIN}/yq" eval '.metadata.namespace' "${current_dir}/challenge.yaml" 2>/dev/null)
216+
if "${KCTF_BIN}/yq" eval --exit-status 'select(.kind == "Challenge") | .metadata.namespace' "${current_dir}/challenge.yaml" >/dev/null 2>/dev/null; then
217+
CHALLENGE_NAMESPACE=$("${KCTF_BIN}/yq" eval 'select(.kind == "Challenge") | .metadata.namespace' "${current_dir}/challenge.yaml" 2>/dev/null)
218218
fi
219219
export CHALLENGE_DIR="${current_dir}"
220220
export CHALLENGE_NAME

dist/bin/kctf-challenge

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function build_image {
133133
}
134134

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

139139
function build_images {
@@ -184,9 +184,9 @@ function kctf_chal_start {
184184
push_images || return
185185

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

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

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

0 commit comments

Comments
 (0)