Skip to content

Commit 7545d70

Browse files
Use a common function to set auth header and make curl requests
1 parent 6082817 commit 7545d70

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

data/data/agent/files/usr/local/bin/add-node.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
set -e
33

44
# shellcheck disable=SC1091
5-
source issue_status.sh
6-
7-
BASE_URL="${SERVICE_BASE_URL}api/assisted-install/v2"
5+
source "common.sh"
6+
# shellcheck disable=SC1091
7+
source "issue_status.sh"
88

99
cluster_id=""
1010
while [[ "${cluster_id}" = "" ]]
1111
do
1212
# Get cluster id
13-
cluster_id=$(curl -s -S "${BASE_URL}/clusters" -H "Authorization: ${AGENT_AUTH_TOKEN}" | jq -r .[].id)
13+
cluster_id=$(curl_assisted_service "/clusters" | jq -r .[].id)
1414
if [[ "${cluster_id}" = "" ]]; then
1515
sleep 2
1616
fi
@@ -24,7 +24,7 @@ status_issue="90_add-node"
2424
host_ready=false
2525
while [[ $host_ready == false ]]
2626
do
27-
host_status=$(curl -s -S "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts" -H "Authorization: ${AGENT_AUTH_TOKEN}" | jq -r ".[].status")
27+
host_status=$(curl_assisted_service "/infra-envs/${INFRA_ENV_ID}/hosts" | jq -r ".[].status")
2828
if [[ "${host_status}" != "known" ]]; then
2929
printf '\\e{yellow}Waiting for the host to be ready' | set_issue "${status_issue}"
3030
sleep 10
@@ -33,12 +33,12 @@ do
3333
fi
3434
done
3535

36-
HOST_ID=$(curl -s "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts" -H "Authorization: ${AGENT_AUTH_TOKEN}" | jq -r '.[].id')
36+
HOST_ID=$(curl_assisted_service "/infra-envs/${INFRA_ENV_ID}/hosts" | jq -r '.[].id')
3737
printf '\nHost %s is ready for installation\n' "${HOST_ID}" 1>&2
3838
clear_issue "${status_issue}"
3939

4040
# Add the current host to the cluster
41-
res=$(curl -X POST -s -S -w "%{http_code}\\n" -o /dev/null "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts/${HOST_ID}/actions/install" -H "Authorization: ${AGENT_AUTH_TOKEN}")
41+
res=$(curl_assisted_service "/infra-envs/${INFRA_ENV_ID}/hosts/${HOST_ID}/actions/install" POST -w "%{http_code}" -o /dev/null)
4242
if [[ $res = "202" ]]; then
4343
printf '\nHost installation started\n' 1>&2
4444
else
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
curl_assisted_service() {
4+
local endpoint=$1
5+
local method=${2:-GET}
6+
local additional_options=("${@:3}") # Capture all arguments starting from the third one
7+
local baseURL="${SERVICE_BASE_URL}api/assisted-install/v2"
8+
9+
case "${method}" in
10+
"POST")
11+
curl -s -S -X POST "${additional_options[@]}" "${baseURL}${endpoint}" \
12+
-H "Authorization: ${AGENT_AUTH_TOKEN}" \
13+
-H "accept: application/json" \
14+
-H "Content-Type: application/json" \
15+
;;
16+
"GET")
17+
curl -s -S -X GET "${additional_options[@]}" "${baseURL}${endpoint}" \
18+
-H "Authorization: ${AGENT_AUTH_TOKEN}" \
19+
-H "Accept: application/json"
20+
;;
21+
esac
22+
}

data/data/agent/files/usr/local/bin/start-cluster-installation.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
set -e
33

44
# shellcheck disable=SC1091
5-
source issue_status.sh
6-
7-
BASE_URL="${SERVICE_BASE_URL}api/assisted-install/v2"
5+
source "common.sh"
6+
# shellcheck disable=SC1091
7+
source "issue_status.sh"
88

99
cluster_id=""
1010
while [[ "${cluster_id}" = "" ]]
1111
do
1212
# Get cluster id
13-
cluster_id=$(curl -s -S "${BASE_URL}/clusters" -H "Authorization: ${AGENT_AUTH_TOKEN}" | jq -r .[].id)
13+
cluster_id=$(curl_assisted_service "/clusters" GET | jq -r .[].id)
1414
if [[ "${cluster_id}" = "" ]]; then
1515
sleep 2
1616
fi
@@ -28,7 +28,7 @@ status_issue="90_start-install"
2828
num_known_hosts() {
2929
local known_hosts=0
3030
local insufficient_hosts=0
31-
host_status=$(curl -s -S "${BASE_URL}/infra-envs/${INFRA_ENV_ID}/hosts" -H "Authorization: ${AGENT_AUTH_TOKEN}" | jq -r .[].status)
31+
host_status=$(curl_assisted_service "/infra-envs/${INFRA_ENV_ID}/hosts" GET | jq -r .[].status)
3232
if [[ -n ${host_status} ]]; then
3333
for status in ${host_status}; do
3434
if [[ "${status}" == "known" ]]; then
@@ -58,18 +58,17 @@ clear_issue "${status_issue}"
5858
while [[ "${cluster_status}" != "installed" ]]
5959
do
6060
sleep 5
61-
cluster_status=$(curl -s -S "${BASE_URL}/clusters" -H "Authorization: ${AGENT_AUTH_TOKEN}" | jq -r .[].status)
61+
cluster_status=$(curl_assisted_service "/clusters" GET | jq -r .[].status)
6262
echo "Cluster status: ${cluster_status}" 1>&2
6363
# Start the cluster install, if it transitions back to Ready due to a failure,
6464
# then it will be restarted
6565
case "${cluster_status}" in
6666
"ready")
6767
echo "Starting cluster installation..." 1>&2
68-
curl -s -S -X POST "${BASE_URL}/clusters/${cluster_id}/actions/install" \
69-
-H "Authorization: ${AGENT_AUTH_TOKEN}" \
70-
-H 'accept: application/json' \
71-
-d ''
72-
echo "Cluster installation started" 1>&2
68+
res=$(curl_assisted_service "/clusters/${cluster_id}/actions/install" POST -w "%{http_code}" -o /dev/null)
69+
if [[ $res = "202" ]]; then
70+
printf '\nCluster installation started\n' 1>&2
71+
fi
7372
;&
7473
"installed" | "preparing-for-installation" | "installing")
7574
printf '\\e{lightgreen}Cluster installation in progress\\e{reset}' | set_issue "${status_issue}"
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/bin/bash
22
set -e
33

4+
# shellcheck disable=SC1091
5+
source "common.sh"
6+
47
echo "Waiting for assisted-service to be ready"
5-
until curl --output /dev/null --silent --fail "${SERVICE_BASE_URL}/api/assisted-install/v2/infra-envs" -H "Authorization: ${AGENT_AUTH_TOKEN}"; do
8+
9+
until curl_assisted_service "/infra-envs" GET -o /dev/null --silent --fail; do
610
printf '.'
711
sleep 5
812
done

pkg/asset/agent/image/ignition_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ func commonFiles() []string {
393393
"/usr/local/bin/load-config-iso.sh",
394394
"/etc/udev/rules.d/80-agent-config-image.rules",
395395
"/usr/local/bin/add-node.sh",
396+
"/usr/local/bin/common.sh",
396397
}
397398
}
398399

0 commit comments

Comments
 (0)