Skip to content

Commit

Permalink
Merge pull request #270 from beckn/registry-role
Browse files Browse the repository at this point in the history
Registry role
  • Loading branch information
prasad-takale-eminds authored Nov 27, 2024
2 parents d248339 + 7c000e1 commit 6d96cf4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions install/beckn-onix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ install_registry() {
start_container $registry_docker_compose_file registry
sleep 10
echo "Registry installation successful"

#Update Role Permission for registry.
bash scripts/registry_role_permissions.sh
}

# Function to install Layer2 Config
Expand Down
Binary file added install/registry_data/RolePermission.xlsx
Binary file not shown.
63 changes: 63 additions & 0 deletions install/scripts/registry_role_permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source scripts/variables.sh

# Function to log in and get the API key
get_api_key() {
local login_url="$registry_url"
local username="$1"
local password="$2"

# Call the login API and extract the api_key from the response
local response=$(curl -s -H 'ACCEPT: application/json' \
-H 'CONTENT-TYPE: application/json' \
-d '{"User" : { "Name" : "'"$username"'", "Password" : "'"$password"'" } }' \
"$login_url")

# Check if the curl command was successful
if [ $? -ne 0 ]; then
echo "${BoldRed}Error logging in to get API key${NC}"
return 1
fi

# Extract the api_key from the response
local api_key=$(echo "$response" | jq -r '.api_key')

# Check if api_key is not null
if [ "$api_key" == "null" ] || [ -z "$api_key" ]; then
echo "${BoldRed}Failed to retrieve API key${NC}"
return 1
fi
}

# Function to upload the RolePermission.xlsx file
upload_role_permission() {
local api_key="$1"
local upload_url="$registry_url/role_permissions/importxls"

# Use curl to upload the file
curl -s -H "ApiKey:$api_key" \
-F "datafile=@$REGISTRY_FILE_PATH" \
"$upload_url"

# Check if the curl command was successful
if [ $? -ne 0 ]; then
echo "${BoldRed}Error uploading RolePermission.xlsx${NC}"
return 1
fi
}


echo $REGISTRY_FILE_PATH

# Get the API key
API_KEY=$(get_api_key "$USERNAME" "$PASSWORD")
if [ $? -ne 0 ]; then
echo "${BoldRed}Role permission update failed. Please upload Role Permission manually.${NC}"
else
# Upload the file using the retrieved API key
upload_role_permission "$API_KEY"
if [ $? -ne 0 ]; then
echo "${GREEN}Role permission updated in registry${NC}"
fi
fi
7 changes: 7 additions & 0 deletions install/scripts/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ BoldRed="${BOLD}$(tput setaf 1)"

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Default registry and gateway username and password
USERNAME="root"
PASSWORD="root"

# Registry Role Permission file path
REGISTRY_FILE_PATH="../registry_data/RolePermission.xlsx"

#Comman Variables with Default values
mongo_initdb_root_username="beckn"
mongo_initdb_root_password="beckn123"
Expand Down

0 comments on commit 6d96cf4

Please sign in to comment.