Skip to content

Commit 91c4a7b

Browse files
committed
Added: Changes for Dedi Registry Integration
1 parent 7042c53 commit 91c4a7b

File tree

4 files changed

+116
-35
lines changed

4 files changed

+116
-35
lines changed

install/beckn-onix.sh

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
source scripts/variables.sh
33
source scripts/get_container_details.sh
4+
source scripts/registry_entry.sh
45

56
# Function to start a specific service inside docker-compose file
67
install_package() {
@@ -130,17 +131,24 @@ install_layer2_config() {
130131

131132
# Function to install BAP Protocol Server
132133
install_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}"

install/scripts/generate_keys.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ if [ $? -eq 0 ]; then
1818
public_key=$(echo "$public_key" | tr -d '[:space:]')
1919
private_key=$(echo "$private_key" | tr -d '[:space:]')
2020

21+
# Export public key as global variable
22+
# Export both variables
23+
export public_key
24+
export public_key_global="$public_key"
25+
echo "Public Key inside generate_keys.sh: $public_key"
26+
2127
else
2228
# Print an error message if the script failed
2329
echo "${RED}Error: Key generation script failed. Please check the script output.${NC}"

install/scripts/registry_entry.sh

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,41 @@ create_network_participant() {
1515
type="${10}"
1616
api_key="${11}"
1717
np_domain="${12}"
18-
18+
1919
json_data=$(cat <<EOF
2020
{
2121
"subscriber_id": "$subscriber_id",
22-
"pub_key_id": "$pub_key_id",
23-
"unique_key_id": "$pub_key_id",
24-
"subscriber_url": "$subscriber_url",
25-
"domain": "$np_domain",
26-
"extended_attributes": {"domains": []},
27-
"encr_public_key": "$encr_public_key",
22+
"url": "$subscriber_url",
23+
"type": "$type",
24+
"domain": "${np_domain}",
25+
"location": {
26+
"city": {
27+
"name": "Bangalore",
28+
"code": "BLR"
29+
},
30+
"country": {
31+
"name": "India",
32+
"code": "IN"
33+
}
34+
},
35+
"key_id": "$pub_key_id",
2836
"signing_public_key": "$signing_public_key",
37+
"encr_public_key": "$encr_public_key",
2938
"valid_from": "$valid_from",
3039
"valid_until": "$valid_until",
31-
"type": "$type",
32-
"country": "IND",
33-
"status": "SUBSCRIBED"
34-
}
40+
"created": "$valid_from",
41+
"updated": "$valid_from",
42+
"nonce": "$pub_key_id"
43+
}
44+
3545
EOF
3646
)
47+
echo "json_data: $json_data"
3748

38-
response=$(curl --location --request POST "$registry_url/register" \
39-
--header "ApiKey:$api_key" --header "Content-Type: $content_type" \
40-
--data-raw "$json_data" 2>&1)
49+
response=$(curl --location "$registry_url/subscribers/subscribe" \
50+
--header "Authorization: Bearer $api_key" \
51+
--header "Content-Type: $content_type" \
52+
--data "$json_data" 2>&1)
4153
if [ $? -eq 0 ]; then
4254

4355
echo "${GREEN}Network Participant Entry is created. Please login to registry $registry_url and subscribe you Network Participant.${NC}"

install/scripts/update_bap_config.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ else
119119
done
120120
fi
121121

122-
echo "Registering BAP protocol server on the registry"
123122

124-
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"
123+
# Commenting out the create_network_participant function call from here as it will be called after the container is started
124+
# echo "Registering BAP protocol server on the registry"
125+
126+
# 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"

0 commit comments

Comments
 (0)