Skip to content

Commit

Permalink
change to suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
robinAwallace committed Oct 17, 2024
1 parent 5ea9fde commit 5b5a532
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
12 changes: 9 additions & 3 deletions bin/update-ips.bash
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,15 @@ get_swift_url() {
log_error "Could not find Swift credentials in ${swift_config_option}"
exit 1
fi
body=$(echo "${response}" | tr '\r\n' '!' | sed 's/!!/\n/g' | tail -n 1 | tr '!!' '\n')
os_token=$(echo "${response}" | grep -oP "x-subject-token:\s+\K\S+")
swift_url=$(echo "${body}" | jq -r '.token.catalog[] | select( .type == "object-store" and .name == "swift") | .endpoints[] | select(.interface == "public" and .region == "'"${swift_region}"'") | .url')

{
# shellcheck disable=SC2162
while read -d $'\n\r' header value; do
[[ -z "${header}" ]] && break
[[ "${header}" == "x-subject-token:" ]] && os_token="${value}"
done
swift_url=$(jq -r '.token.catalog[] | select( .type == "object-store" and .name == "swift") | .endpoints[] | select(.interface == "public" and .region == "'"${swift_region}"'") | .url')
} <<< "${response}"

curl -i -s -X DELETE -H "X-Auth-Token: ${os_token}" -H "X-Subject-Token: ${os_token}" "${auth_url}/auth/tokens" >/dev/null

Expand Down
66 changes: 59 additions & 7 deletions tests/common/bats/update-ips.bash
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ update_ips.mock_maximal() {
# main swift

# GET /auth/tokens
mock_set_output "${mock_curl}" '{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com:91011"}]}]}}' 1
mock_set_output "${mock_curl}" 'HTTP/2 200
date: Wed, 09 Oct 2024 14:14:40 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
x-subject-token: 123456789
accept-ranges: none
vary: Accept-Encoding
\r\n
{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com:91011"}]}]}}' 1
# DELETE /auth/tokens
mock_set_output "${mock_curl}" "" 2
mock_set_output "${mock_dig}" "127.1.0.4" 4 # keystone endpoint
Expand All @@ -76,7 +85,16 @@ update_ips.mock_maximal() {
# rclone sync swift

# GET /auth/tokens
mock_set_output "${mock_curl}" '{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com"}]}]}}' 3
mock_set_output "${mock_curl}" 'HTTP/2 200
date: Wed, 09 Oct 2024 14:14:40 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
x-subject-token: 123456789
accept-ranges: none
vary: Accept-Encoding
\r\n
{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com"}]}]}}' 3
# DELETE /auth/tokens
mock_set_output "${mock_curl}" "" 4

Expand All @@ -98,7 +116,16 @@ update_ips.mock_rclone_s3_and_swift() {
update_ips.mock_rclone_s3

# GET /auth/tokens
mock_set_output "${mock_curl}" '{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com"}]}]}}' 1
mock_set_output "${mock_curl}" 'HTTP/2 200
date: Wed, 09 Oct 2024 14:14:40 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
x-subject-token: 123456789
accept-ranges: none
vary: Accept-Encoding
\r\n
{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com"}]}]}}' 1
mock_set_output "${mock_curl}" "" 2 # DELETE /auth/tokens

mock_set_output "${mock_dig}" "127.0.0.5" 5 # networkPolicies.rclone.sync.objectStorageSwift.ips keystone endpoint
Expand All @@ -109,7 +136,16 @@ update_ips.mock_rclone_swift() {
update_ips.mock_minimal

# GET /auth/tokens
mock_set_output "${mock_curl}" '{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com"}]}]}}' 1
mock_set_output "${mock_curl}" 'HTTP/2 200
date: Wed, 09 Oct 2024 14:14:40 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
x-subject-token: 123456789
accept-ranges: none
vary: Accept-Encoding
\r\n
{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com"}]}]}}' 1
mock_set_output "${mock_curl}" "" 2 # DELETE /auth/tokens

mock_set_output "${mock_dig}" "127.0.0.5" 4 # networkPolicies.rclone.sync.objectStorageSwift.ips keystone endpoint
Expand All @@ -120,8 +156,15 @@ update_ips.mock_swift() {
update_ips.mock_minimal

# GET /auth/tokens
mock_set_output "${mock_curl}" 'x-subject-token: 123456789
mock_set_output "${mock_curl}" 'HTTP/2 200
date: Wed, 09 Oct 2024 14:14:40 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
x-subject-token: 123456789
accept-ranges: none
vary: Accept-Encoding
\r\n
{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com:91011"}]}]}}' 1
mock_set_output "${mock_curl}" "" 2 # DELETE /auth/tokens

Expand Down Expand Up @@ -226,7 +269,16 @@ update_ips.assert_rclone_swift() {
assert_equal "$(yq4 '.networkPolicies.rclone.sync.objectStorage' "${CK8S_CONFIG_PATH}/sc-config.yaml")" "null"

# GET /auth/tokens
mock_set_output "${mock_curl}" '{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com"}]}]}}' 1
mock_set_output "${mock_curl}" 'HTTP/2 200
date: Wed, 09 Oct 2024 14:14:40 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
x-subject-token: 123456789
accept-ranges: none
vary: Accept-Encoding
\r\n
{"token":{"catalog":[{"type": "object-store", "name": "swift", "endpoints": [{"interface":"public", "region": "swift-region", "url": "https://swift.foo.dev-ck8s.com"}]}]}}' 1
mock_set_output "${mock_curl}" "" 2 # DELETE /auth/tokens
mock_set_output "${mock_dig}" "127.0.0.4" 4 # keystone endpoint
mock_set_output "${mock_dig}" "127.0.0.5" 5 # swift endpoint
Expand Down

0 comments on commit 5b5a532

Please sign in to comment.