Skip to content

Commit a3b4b62

Browse files
committed
update: video record standalone with GraphQL endpoint needs basic auth
Signed-off-by: Viet Nguyen Duc <[email protected]>
1 parent 89a9729 commit a3b4b62

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

Video/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ RUN --mount=type=secret,id=SEL_PASSWD \
7373
# Add Supervisor configuration files
7474
#======================================
7575
COPY supervisord.conf /etc
76-
COPY --chown="${SEL_UID}:${SEL_GID}" entry_point.sh video.sh video_ready.py video_graphQLQuery.sh video_gridUrl.sh /opt/bin/
76+
COPY --chown="${SEL_UID}:${SEL_GID}" entry_point.sh validate_endpoint.sh video.sh video_ready.py video_graphQLQuery.sh video_gridUrl.sh /opt/bin/
7777

7878
#======================================
7979
# Add RCLONE for uploading videos

Video/validate_endpoint.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
endpoint=$1
4+
graphql_endpoint=${2:-false}
5+
max_time=1
6+
process_name="endpoint.checks"
7+
8+
BASIC_AUTH="$(echo -n "${SE_ROUTER_USERNAME}:${SE_ROUTER_PASSWORD}" | base64)"
9+
10+
if [ "${graphql_endpoint}" = "true" ]; then
11+
endpoint_checks=$(curl --noproxy "*" -m ${max_time} -k -X POST \
12+
-H "Content-Type: application/json" \
13+
-H "Authorization: Basic ${BASIC_AUTH}" \
14+
--data '{"query":"{ grid { sessionCount } }"}' \
15+
-s "${endpoint}" -o /dev/null -w "%{http_code}")
16+
else
17+
endpoint_checks=$(curl --noproxy "*" -H "Authorization: Basic ${BASIC_AUTH}" -m ${max_time} -s -k -o /dev/null -w "%{http_code}" "${endpoint}")
18+
fi
19+
20+
if [[ "$endpoint_checks" = "404" ]]; then
21+
echo "$(date +%FT%T%Z) [${process_name}] - Endpoint ${endpoint} is not found - status code: ${endpoint_checks}"
22+
elif [[ "$endpoint_checks" = "401" ]]; then
23+
echo "$(date +%FT%T%Z) [${process_name}] - Endpoint ${endpoint} requires authentication - status code: ${endpoint_checks}. Please provide valid credentials via SE_ROUTER_USERNAME and SE_ROUTER_PASSWORD environment variables."
24+
elif [[ "$endpoint_checks" != "200" ]]; then
25+
echo "$(date +%FT%T%Z) [${process_name}] - Endpoint ${endpoint} is not available - status code: ${endpoint_checks}"
26+
fi

Video/video.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ else
2828
NODE_STATUS_ENDPOINT="${SE_SERVER_PROTOCOL}://${DISPLAY_CONTAINER_NAME}:${SE_NODE_PORT}/status"
2929
fi
3030

31+
/opt/bin/validate_endpoint.sh "${NODE_STATUS_ENDPOINT}"
32+
BASIC_AUTH="$(echo -n "${SE_ROUTER_USERNAME}:${SE_ROUTER_PASSWORD}" | base64)"
33+
3134
if [ -d "${VIDEO_FOLDER}" ]; then
3235
echo "$(date +%FT%T%Z) [${process_name}] - Video folder exists: ${VIDEO_FOLDER}"
3336
else
@@ -70,7 +73,7 @@ function wait_for_display() {
7073
}
7174

7275
function check_if_api_respond() {
73-
endpoint_checks=$(curl --noproxy "*" -sk -o /dev/null -w "%{http_code}" "${NODE_STATUS_ENDPOINT}")
76+
endpoint_checks=$(curl --noproxy "*" -H "Authorization: Basic ${BASIC_AUTH}" -sk -o /dev/null -w "%{http_code}" "${NODE_STATUS_ENDPOINT}")
7477
if [[ "${endpoint_checks}" != "200" ]]; then
7578
return 1
7679
fi
@@ -198,20 +201,15 @@ else
198201
recorded_count=0
199202

200203
wait_for_api_respond
201-
while curl --noproxy "*" -sk --request GET ${NODE_STATUS_ENDPOINT} >/tmp/status.json; do
204+
while curl --noproxy "*" -H "Authorization: Basic ${BASIC_AUTH}" -sk --request GET ${NODE_STATUS_ENDPOINT} >/tmp/status.json; do
202205
session_id=$(jq -r "${JQ_SESSION_ID_QUERY}" /tmp/status.json)
203206
if [[ "$session_id" != "null" && "$session_id" != "" && "$session_id" != "reserved" && "$recording_started" = "false" ]]; then
204207
echo "$(date +%FT%T%Z) [${process_name}] - Session: $session_id is created"
205208
return_list=($(bash ${VIDEO_CONFIG_DIRECTORY}/video_graphQLQuery.sh "$session_id"))
206209
caps_se_video_record="${return_list[0]}"
207210
video_file_name="${return_list[1]}.mp4"
208-
endpoint_status="${return_list[2]}"
209-
endpoint_url="${return_list[3]}"
210-
if [[ "${endpoint_status}" = "401" ]]; then
211-
echo "$(date +%FT%T%Z) [${process_name}] - GraphQL endpoint requires authentication, please set env variables SE_ROUTER_USERNAME and SE_ROUTER_PASSWORD"
212-
elif [[ "${endpoint_status}" = "404" ]]; then
213-
echo "$(date +%FT%T%Z) [${process_name}] - GraphQL endpoint could not be found, please check the endpoint ${endpoint_url}"
214-
fi
211+
endpoint_url="${return_list[2]}"
212+
/opt/bin/validate_endpoint.sh "${endpoint_url}" "true"
215213
echo "$(date +%FT%T%Z) [${process_name}] - Start recording: $caps_se_video_record, video file name: $video_file_name"
216214
log_node_response
217215
fi

Video/video_graphQLQuery.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ if [ -n "${GRAPHQL_ENDPOINT}" ]; then
3434
-s "${GRAPHQL_ENDPOINT}" -o "/tmp/graphQL_${SESSION_ID}.json" -w "%{http_code}")
3535
current_check=$((current_check + 1))
3636
# Check if the response contains "capabilities"
37-
if [[ "$endpoint_checks" = "404" ]] || [[ $current_check -eq $retry_time ]]; then
38-
break
39-
elif [[ "$endpoint_checks" = "401" ]] || [[ $current_check -eq $retry_time ]]; then
37+
if [[ $current_check -eq $retry_time ]]; then
4038
break
4139
elif [[ "$endpoint_checks" = "200" ]] && [[ $(jq -e '.data.session.capabilities | fromjson | ."'se:vncEnabled'"' /tmp/graphQL_${SESSION_ID}.json >/dev/null) -eq 0 ]]; then
4240
break
@@ -78,7 +76,7 @@ fi
7876
# Normalize the video file name
7977
TEST_NAME="$(echo "${TEST_NAME}" | tr ' ' '_' | tr -dc "${VIDEO_FILE_NAME_TRIM}" | cut -c 1-251)"
8078

81-
return_array=("${RECORD_VIDEO}" "${TEST_NAME}" "${endpoint_checks}" "${GRAPHQL_ENDPOINT}")
79+
return_array=("${RECORD_VIDEO}" "${TEST_NAME}" "${GRAPHQL_ENDPOINT}")
8280

8381
# stdout the values for other scripts consuming
8482
echo "${return_array[@]}"

0 commit comments

Comments
 (0)