From 470872ba5d6c43b7acac2e0173080a20c5358f79 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Thu, 6 Jan 2022 21:56:22 +0800 Subject: [PATCH] add auth support to raft-tools.sh Change-Id: I65fbed8e18d9b04393aa26f5008397cc9b9fc065 --- .../src/assembly/static/bin/raft-tools.sh | 43 +++++++++++-------- .../assembly/travis/run-api-test-for-raft.sh | 2 + 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/hugegraph-dist/src/assembly/static/bin/raft-tools.sh b/hugegraph-dist/src/assembly/static/bin/raft-tools.sh index 10d460f8c1..34a7582dc8 100755 --- a/hugegraph-dist/src/assembly/static/bin/raft-tools.sh +++ b/hugegraph-dist/src/assembly/static/bin/raft-tools.sh @@ -14,6 +14,11 @@ LOG_PATH=${HOME_PATH}/logs . ${BIN_PATH}/util.sh +#export HUGEGRAPH_URL= +#export HUGEGRAPH_GRAPH= +#export HUGEGRAPH_USERNAME= +#export HUGEGRAPH_PASSWORD= + function print_usage() { echo "usage: raft-tools.sh [options]" echo "options: " @@ -33,56 +38,58 @@ fi function list_peers() { local graph=$1 - local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/list_peers + local url=${HUGEGRAPH_URL}/graphs/${graph}/raft/list_peers - curl ${url} + curl ${url} --user ${HUGEGRAPH_USERNAME}:${HUGEGRAPH_PASSWORD} } function get_leader() { local graph=$1 - local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/get_leader + local url=${HUGEGRAPH_URL}/graphs/${graph}/raft/get_leader - curl ${url} + curl ${url} --user ${HUGEGRAPH_USERNAME}:${HUGEGRAPH_PASSWORD} } function set_leader() { local graph=$1 local endpoint=$2 - local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/set_leader?endpoint=${endpoint} + local url=${HUGEGRAPH_URL}/graphs/${graph}/raft/set_leader?endpoint=${endpoint} - curl -X POST ${url} + curl -X POST ${url} --user ${HUGEGRAPH_USERNAME}:${HUGEGRAPH_PASSWORD} } function transfer_leader() { local graph=$1 local endpoint=$2 - local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/transfer_leader?endpoint=${endpoint} + local url=${HUGEGRAPH_URL}/graphs/${graph}/raft/transfer_leader?endpoint=${endpoint} - curl -X POST ${url} + curl -X POST ${url} --user ${HUGEGRAPH_USERNAME}:${HUGEGRAPH_PASSWORD} } function add_peer() { local graph=$1 local endpoint=$2 - local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/add_peer?endpoint=${endpoint} + local url=${HUGEGRAPH_URL}/graphs/${graph}/raft/add_peer?endpoint=${endpoint} - curl -X POST ${url} + curl -X POST ${url} --user ${HUGEGRAPH_USERNAME}:${HUGEGRAPH_PASSWORD} } function remove_peer() { local graph=$1 local endpoint=$2 - local rest_server_url=`read_property ${CONF_PATH}/rest-server.properties restserver.url` - local url=${rest_server_url}/graphs/${graph}/raft/remove_peer?endpoint=${endpoint} + local url=${HUGEGRAPH_URL}/graphs/${graph}/raft/remove_peer?endpoint=${endpoint} - curl -X POST ${url} + curl -X POST ${url} --user ${HUGEGRAPH_USERNAME}:${HUGEGRAPH_PASSWORD} } +if [ "${HUGEGRAPH_URL}" = "" ]; then + HUGEGRAPH_URL=`read_property ${CONF_PATH}/rest-server.properties restserver.url` +fi + +if [ "${HUGEGRAPH_GRAPH}" = "" ]; then + HUGEGRAPH_GRAPH="hugegraph" +fi + case $1 in # help --help|-h) diff --git a/hugegraph-dist/src/assembly/travis/run-api-test-for-raft.sh b/hugegraph-dist/src/assembly/travis/run-api-test-for-raft.sh index ddd7d959f9..2c2739e438 100755 --- a/hugegraph-dist/src/assembly/travis/run-api-test-for-raft.sh +++ b/hugegraph-dist/src/assembly/travis/run-api-test-for-raft.sh @@ -35,6 +35,8 @@ $TRAVIS_DIR/start-server.sh $RAFT1_DIR $BACKEND $JACOCO_PORT || (cat $RAFT1_DIR/ $TRAVIS_DIR/start-server.sh $RAFT2_DIR $BACKEND || (cat $RAFT2_DIR/logs/hugegraph-server.log && exit 1) & $TRAVIS_DIR/start-server.sh $RAFT3_DIR $BACKEND || (cat $RAFT3_DIR/logs/hugegraph-server.log && exit 1) +export HUGEGRAPH_USERNAME=admin +export HUGEGRAPH_PASSWORD=pa $RAFT_TOOLS --set-leader "hugegraph" "$RAFT_LEADER" # run api-test