Skip to content

Commit

Permalink
update user tags values to replace single space with double spaces (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
jianli-wei authored and afaranha committed Feb 6, 2024
1 parent 5eb2d86 commit bb861b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,34 @@ fi
function validate_user_tags() {
local -r current_tags="$1"; shift

local ret=0 cnt=1 a_tag_value
printf '%s' "${USER_TAGS:-}" | while read -r PARENT KEY VALUE || [ -n "${PARENT}" ]
do
a_tag_value="${PARENT}/${KEY}/${VALUE}"
space_pattern="\ "
if [[ "${a_tag_value}" =~ ${space_pattern} ]] && [ ${#a_tag_value} -gt 64 ]; then
echo "$(date -u --rfc-3339=seconds) - Truncating tag '${a_tag_value}'"
a_tag_value="${a_tag_value::63}"
a_tag_value="${a_tag_value%* }"
fi
a_tag_value="namespacedTagValue: ${a_tag_value}"
a_tag_value="namespacedTagValue: ${PARENT}/${KEY}/${VALUE}"
if echo "${current_tags}" | grep -Fq "${a_tag_value}"; then
echo "$(date -u --rfc-3339=seconds) - Found tag ${cnt} '${a_tag_value}' (PARENT/KEY/VALUE)."
cnt=$(( $cnt + 1 ))
continue
else
echo "$(date -u --rfc-3339=seconds) - Failed to find tag '${a_tag_value}' (PARENT/KEY/VALUE)."
return 1
ret=1
fi
done
return $ret
}

## Try the validation
ret=0
validation_ret=0

echo "$(date -u --rfc-3339=seconds) - Checking userTags of image-registry buckets..."
readarray -t items < <(gsutil ls | grep "${INFRA_ID}-image-registry")
for line in "${items[@]}"; do
name=$(basename "${line}")
current_tags="$(gcloud resource-manager tags bindings list --parent=//storage.googleapis.com/projects/_/buckets/${name} --location=${GCP_REGION} --effective)"
echo "${current_tags}"
validate_user_tags "${current_tags}" || tmp_ret=$?
if [ $tmp_ret -gt 0 ]; then
validate_user_tags "${current_tags}" || validation_ret=$?
if [ $validation_ret -gt 0 ]; then
echo "$(date -u --rfc-3339=seconds) - FAILED for bucket '${name}'."
ret=1
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ chain:
54643501348 CostCenter 853
54643501348 AppCode GCP-004
openshift-qe Su.Shi-Jiang_Cheng_Zi SHI NIAN
openshift-qe Su.Shi-Die_Lian_Hua-Chun_Jing Hua Tui Can Hong Qing Xing Xiao
openshift-qe Su.Shi-Die_Lian_Hua-Chun_Jing Hua Tui Can Hong Qing Xing Xiao
openshift-qe hello a
openshift-qe hello.Ou_Yang_Xiu No. 4
openshift-qe TEST-KEY03 TEST_VALUE-03
Expand All @@ -41,22 +41,22 @@ chain:
openshift-qe Gao.Shi-Bei_Dong_Da Mo Chou Qian Lu Wu Zhi Ji
openshift-qe DU-FU Du Zi-Mei
openshift-qe Li.Bai-Wang_Lu_Shan_Pu_Bu Fei Liu Zhi Xia
openshift-qe numerical_character.2023-in-middle numerical_character 2023-in-middle
openshift-qe numerical_character.2023-in-middle numerical_character 2023-in-middle
openshift-qe Su-Dong-Po.is.so_great ha-ha-ha
openshift-qe end-with.numerical_character-2023 end-with numerical_character 2023
openshift-qe uppercase_character-IN-middle uppercase_CHARACTER IN-middle
openshift-qe end-with.numerical_character-2023 end-with numerical_character 2023
openshift-qe uppercase_character-IN-middle uppercase_CHARACTER IN-middle
openshift-qe hello.Zeng_Gong No. 2
openshift-qe department marketing
openshift-qe Su.Shi-Ti_Xi_Lin_Bi Heng Kan Cheng Ling Ce Cheng Feng
openshift-qe Su.Shi-Ti_Xi_Lin_Bi Heng Kan Cheng Ling Ce Cheng Feng
openshift-qe a hello
openshift-qe X X
openshift-qe hello.Su_Zhe No. 6
openshift-qe Su.Shi-Ding_Feng_Bo Mo Ting Chuan Lin Da Ye Sheng
openshift-qe This.is.test-message1234567890.1234567890.1234567890.1234567890 hello_a-b.c@d%e=f+g:h,i*j#k&l(m){n}[o](p){q}[r]@@@@@@@@@@@@@@@z
openshift-qe TEST-KEY02 TEST_VALUE-02
openshift-qe hello.Han_Yu No. 8
openshift-qe Li.Bai chuang qian ming yue guang, yi shi di shang shuang
openshift-qe 2023.begin-with-numerical_character 2023 begin-with numerical_character
openshift-qe Li.Bai chuang qian ming yue guang, yi shi di shang shuang
openshift-qe 2023.begin-with-numerical_character 2023 begin-with numerical_character
openshift-qe end-with.uppercase_characteR end-with.uppercase_CHARACTER
openshift-qe Li.Bai-Huang_He_Lou GU-REN_XI_CI
openshift-qe Su.Shi-Chun_Jiang_Wan_Jing Chun Jiang Shui Nuan
Expand Down

0 comments on commit bb861b6

Please sign in to comment.