mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 09:42:38 +00:00
[WIFI-6183] Chg: cli review and usage enhancement
Signed-off-by: Dmitry Dunaev <dmitry@opsfleet.com>
This commit is contained in:
@@ -34,13 +34,20 @@ fi
|
||||
|
||||
token=""
|
||||
result_file=result.json
|
||||
# username="tip@ucentral.com"
|
||||
# password="Ninja650!!!"
|
||||
username="stephane.bourque@gmail.com"
|
||||
password="Snoopy99!!!"
|
||||
browser_list=(firefox sensible-browser xdg-open w3m links links2 lynx youtube-dl)
|
||||
browser=""
|
||||
|
||||
if [ -z ${OWSEC_USERNAME+x} ]; then
|
||||
username="script.runner@arilia.com"
|
||||
else
|
||||
username=${OWSEC_USERNAME}
|
||||
fi
|
||||
if [ -z ${OWSEC_PASSWORD+x} ]; then
|
||||
password="Snoopy99!!!"
|
||||
else
|
||||
password=${OWSEC_PASSWORD}
|
||||
fi
|
||||
|
||||
login() {
|
||||
payload="{ \"userId\" : \"$username\" , \"password\" : \"$password\" }"
|
||||
token=$(curl ${FLAGS} -X POST -H "Content-Type: application/json" -d "$payload" "https://${OWSEC}/api/v1/oauth2" | jq -r '.access_token')
|
||||
@@ -75,34 +82,29 @@ findbrowser() {
|
||||
}
|
||||
|
||||
setprov() {
|
||||
if [ -z ${OWPROV_OVERRIDE+x} ]; then
|
||||
curl ${FLAGS} -X GET "https://${OWSEC}/api/v1/systemEndpoints" \
|
||||
-H "accept: application/json" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file}
|
||||
# jq < ${result_file}
|
||||
|
||||
for index in {0..10}
|
||||
do
|
||||
endpointlocation=".endpoints[${index}].uri"
|
||||
endpointlocationtype=".endpoints[${index}].type"
|
||||
rawurl="$(cat ${result_file} | jq -r ${endpointlocation})"
|
||||
svctype="$(cat ${result_file} | jq -r ${endpointlocationtype})"
|
||||
proto="$(echo $rawurl | grep :// | sed -e's,^\(.*://\).*,\1,g')"
|
||||
url="$(echo ${rawurl/$proto/})"
|
||||
user="$(echo $url | grep @ | cut -d@ -f1)"
|
||||
hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
|
||||
host="$(echo $hostport | sed -e 's,:.*,,g')"
|
||||
port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"
|
||||
path="$(echo $url | grep / | cut -d/ -f2-)"
|
||||
if [[ ${url} != "null" ]]
|
||||
then
|
||||
if [[ ${svctype} == "owprov" ]]
|
||||
then
|
||||
OWPROV="${url}"
|
||||
break
|
||||
fi
|
||||
rawurl="$(cat ${result_file} | jq -r '.endpoints[] | select( .type == "owprov" ) | .uri')"
|
||||
if [[ ! -z "${rawurl}" ]]; then
|
||||
proto="$(echo $rawurl | grep :// | sed -e's,^\(.*://\).*,\1,g')"
|
||||
url="$(echo ${rawurl/$proto/})"
|
||||
user="$(echo $url | grep @ | cut -d@ -f1)"
|
||||
hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
|
||||
host="$(echo $hostport | sed -e 's,:.*,,g')"
|
||||
port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"
|
||||
path="$(echo $url | grep / | cut -d/ -f2-)"
|
||||
export OWPROV=${url}
|
||||
echo "Using ${OWPROV}..."
|
||||
else
|
||||
echo "OWPROV endpoint is not found:"
|
||||
jq < ${result_file}
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo "Using ${OWPROV}..."
|
||||
else
|
||||
export OWPROV=${OWPROV_OVERRIDE}
|
||||
fi
|
||||
}
|
||||
|
||||
logout() {
|
||||
|
||||
Reference in New Issue
Block a user