11#! /bin/bash
22source scripts/variables.sh
33source scripts/get_container_details.sh
4+ source scripts/registry_entry.sh
45
56# Function to start a specific service inside docker-compose file
67install_package () {
@@ -130,17 +131,24 @@ install_layer2_config() {
130131
131132# Function to install BAP Protocol Server
132133install_bap_protocol_server () {
133- start_support_services
134+ # start_support_services # Start MongoDB, RabbitMQ, and Redis services
135+ # POST containers are started, now update the configuration
134136 if [[ $1 ]]; then
137+ # If parameters are provided, use them to update the configuration
135138 registry_url=$1
136139 bap_subscriber_id=$2
137140 bap_subscriber_key_id=$3
138141 bap_subscriber_url=$4
139- bash scripts/update_bap_config.sh $registry_url $bap_subscriber_id $bap_subscriber_key_id $bap_subscriber_url $api_key $np_domain
142+ source scripts/update_bap_config.sh $registry_url $bap_subscriber_id $bap_subscriber_key_id $bap_subscriber_url $api_key " $np_domain "
140143 else
141- bash scripts/update_bap_config.sh
144+ # If no parameters are provided, use the default configuration
145+ source scripts/update_bap_config.sh
142146 fi
147+
148+
143149 sleep 10
150+ return
151+
144152 docker volume create bap_client_config_volume
145153 docker volume create bap_network_config_volume
146154 docker run --rm -v $SCRIPT_DIR /../protocol-server-data:/source -v bap_client_config_volume:/target busybox cp /source/bap-client.yml /target/default.yml
@@ -161,6 +169,42 @@ install_bap_protocol_server() {
161169 install_layer2_config bap-client
162170 install_layer2_config bap-network
163171 fi
172+
173+
174+
175+ # Keep trying API call until we get 200 status
176+ status_code=0
177+ attempt=1
178+ max_attempts=5
179+
180+ while [ $status_code -ne 200 ] && [ $attempt -le $max_attempts ]; do
181+ echo " Attempt $attempt of $max_attempts to verify BAP protocol server..."
182+
183+ response=$( curl -s -w " %{http_code}" --location " $bap_subscriber_url /status" \
184+ -H " Content-Type: application/json" )
185+
186+ status_code=" ${response: -3} "
187+
188+ if [ $status_code -eq 200 ]; then
189+ echo " ${GREEN} BAP protocol server is up and running${NC} "
190+ break
191+ else
192+ echo " ${YELLOW} BAP protocol server not ready yet (status: $status_code ). Retrying in 5 seconds...${NC} "
193+ sleep 5
194+ (( attempt++ ))
195+ fi
196+ done
197+
198+ if [ $status_code -ne 200 ]; then
199+ echo " ${RED} Failed to verify BAP protocol server after $max_attempts attempts${NC} "
200+ exit 1
201+ fi
202+
203+
204+ echo " ${BLUE} Registering BAP protocol server on the registry${NC} "
205+ create_network_participant " $registry_url " " application/json" " $bap_subscriber_id " " $bap_subscriber_key_id " " $bap_subscriber_url " " $public_key " " $public_key " " $valid_from " " $valid_until " " $type " " $api_key " " $np_domain "
206+
207+
164208 echo " Protocol server BAP installation successful"
165209}
166210
@@ -328,29 +372,32 @@ validate_user() {
328372 echo # Move to a new line after input
329373
330374 # Replace '/subscribers' with '/login' for validation
331- local login_url=" ${registry_url%/ subscribers} /login"
332-
375+ local login_url=" ${registry_url%/ subscribers} /auth/local"
376+ echo " login_url: $login_url "
377+
333378 # Validate credentials using a POST request
334379 local response
335- response=$( curl -s -w " %{http_code}" -X POST " $login_url " \
380+ response=$( curl -s -w " %{http_code}" --location " $login_url " \
336381 -H " Content-Type: application/json" \
337- -d ' { "Name" : "' " $username " ' ", "Password" : "' " $password " ' " }' )
338-
382+ -d ' { "identifier": "' " $username " ' ", "password": "' " $password " ' " }' )
383+
384+
339385 # Check if the HTTP response is 200 (success)
340386 status_code=" ${response: -3} "
341387 if [ " $status_code " -eq 200 ]; then
342388 response_body=" ${response% ???} "
343- api_key=$( echo " $response_body " | jq -r ' .api_key' )
389+ api_key=$( echo " $response_body " | jq -r ' .jwt' )
390+ echo " api_key: $api_key "
344391 return 0
345392 else
346- response=$( curl -s -w " %{http_code}" -X POST " $login_url " \
347- -H " Content-Type: application/json" \
348- -d ' { "User" : { "Name" : " ' " $username " ' ", "Password" : "' " $password " ' " } }' )
393+ response=$( curl -s -w " %{http_code}" --location " $login_url " \
394+ -H " Content-Type: application/json" \
395+ -d ' { "identifier": " ' " $username " ' ", "password" : "' " $password " ' " }' )
349396
350397 status_code=" ${response: -3} "
351398 if [ " $status_code " -eq 200 ]; then
352399 response_body=" ${response% ???} "
353- api_key=$( echo " $response_body " | jq -r ' .api_key ' )
400+ api_key=$( echo " $response_body " | jq -r ' .jwt ' )
354401 return 0
355402 fi
356403 fi
@@ -368,15 +415,18 @@ get_np_domain() {
368415 if [[ " $dchoice " == " Y" || " $dchoice " == " y" ]]; then
369416 local login_url=" ${registry_url%/ subscribers} "
370417 read -p " Enter the domain name for $1 : " np_domain
371- domain_present=$( curl -s -H " ApiKey:$api_key " --header ' Content-Type: application/json' $login_url /network_domains/index | jq -r ' .[].name' | tr ' \n' ' ' )
418+ echo " login_url: $login_url /network_domains/index"
419+
420+ domain_present=$( curl -s --header ' Content-Type: application/json' $login_url /network_domains | jq -r ' .[].name' | tr ' \n' ' ' )
372421 if echo " $domain_present " | grep -Fqw " $np_domain " ; then
422+ echo " The domain '$np_domain ' is present in the network domains."
373423 return 0
374424 else
375425 echo " ${BoldRed} The domain '$np_domain ' is NOT present in the network domains.${NC} "
376426 echo " ${BoldGreen} Available network domains: $domain_present ${NC} "
377427 fi
378428 else
379- np_domain=" " # If user don't want to add specific domain then save empty string
429+ np_domain=" * " # If user don't want to add specific domain then save "*"
380430 return 0
381431 fi
382432}
@@ -430,31 +480,40 @@ completeSetup() {
430480 install_gateway $registry_url $gateway_url
431481 ;;
432482 " BAP" )
483+ # Display installation header
433484 echo " ${GREEN} ................Installing Protocol Server for BAP................${NC} "
434485
486+ # Step 1: Get BAP Subscriber ID
435487 read -p " Enter BAP Subscriber ID: " bap_subscriber_id
488+
489+ # Step 2: Get and validate BAP Subscriber URL
436490 while true ; do
437491 read -p " Enter BAP Subscriber URL: " bap_subscriber_url
438492 if [[ $bap_subscriber_url =~ ^(http| https):// ]]; then
439- break
493+ break # Valid URL format, exit loop
440494 else
441495 echo " ${RED} Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC} "
442496 fi
443497 done
444498
499+ # Step 3: Get and validate Registry URL
445500 while true ; do
446501 read -p " Enter the registry URL (e.g., https://registry.becknprotocol.io/subscribers): " registry_url
447- if [[ $registry_url =~ ^(http| https):// ]] && [[ $registry_url == * /subscribers ]]; then
448- break
502+ # Check if URL starts with http/https AND ends with /subscribers
503+ if [[ $registry_url =~ ^(http| https):// ]]; then
504+ break # Valid URL format, exit loop
449505 else
450506 echo " ${RED} Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC} "
451507 fi
452508 done
509+
510+ # Step 4: Validate user credentials
453511 validate_user
454512 if [ $? -eq 1 ]; then
455513 exit
456514 fi
457515
516+ # Step 5: Get and validate NP Domain
458517 get_np_domain $bap_subscriber_id
459518 if [ $? -eq 1 ]; then
460519 exit
@@ -464,8 +523,10 @@ completeSetup() {
464523 public_address=$bap_subscriber_url
465524
466525 layer2_config
467- install_package
526+ # install_package
468527 install_bap_protocol_server $registry_url $bap_subscriber_id $bap_subscriber_key_id $bap_subscriber_url
528+
529+
469530 ;;
470531 " BPP" )
471532 echo " ${GREEN} ................Installing Protocol Server for BPP................${NC} "
0 commit comments