Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify quick start bash script #85

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions cloudtower-api-doc/docs/getting-started/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,38 @@ import TabItem from '@theme/TabItem';

```bash
#!/bin/bash
for arg in "$@"; do
index=$(echo $arg | cut -f1 -d=)
val=$(echo $arg | cut -f2 -d=)
case $index in
--username) ;&
-u)
# 登陆 cloudtower 的用户名
username=$val
;;
--password) ;&
-p)
# 登陆 cloudtower 的密码
password=$val
;;
--endpoint) ;&
-e)
# cloudtower api 的地址,举例 http://tower.smartx.com
endpoint=$val
;;
*) ;;
while getopts u:p:e: flag
do
case "${flag}" in
u) username=${OPTARG};;
p) password=${OPTARG};;
e) endpoint=${OPTARG};;
esac
done

if [ -z "$username" ]; then
echo "username is required"
echo "-u username is required"
exit 1
fi
if [ -z "$password" ]; then
echo "password is required"
echo "-p password is required"
exit 1
fi
if [ -z "$endpoint" ]; then
echo "endpoint is required"
echo "-e endpoint is required"
exit 1
fi


# 通过 /v2/api/login 进行登录,并获取 token
token = curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"username":"'$username'","password":"'$password'","source":"LOCAL"}' $endpoint/v2/api/login | jq ".data.token" -r
token=$(curl -X POST -H "Content-Type: application/json" -d '{"username":"'$username'","password":"'$password'","source":"LOCAL"}' $endpoint/v2/api/login | jq -r ".data.token")

# 通过 Authorization header 携带 token 并为请求完成鉴权, 通过 /v2/api/get-vms 来获取虚拟机列表
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: $token" \
-d '{"where":}' $endpoint/v2/api/get-vms | jq ".data.vms"
-d '{"where":{}}' http://192.168.27.57/v2/api/get-vms | jq ".[]"

```
</TabItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,38 @@ You can execute the following script by running `./test.sh -u <username> -p <pas

```bash
#!/bin/bash
for arg in "$@"; do
index=$(echo $arg | cut -f1 -d=)
val=$(echo $arg | cut -f2 -d=)
case $index in
--username) ;&
-u)
# username for loginning cloudtower
username=$val
;;
--password) ;&
-p)
# password for loginning cloudtower
password=$val
;;
--endpoint) ;&
-e)
# api address of cloudtower api , for example http://tower.smartx.com
endpoint=$val
;;
*) ;;
while getopts u:p:e: flag
do
case "${flag}" in
u) username=${OPTARG};;
p) password=${OPTARG};;
e) endpoint=${OPTARG};;
esac
done

if [ -z "$username" ]; then
echo "username is required"
echo "-u username is required"
exit 1
fi
if [ -z "$password" ]; then
echo "password is required"
echo "-p password is required"
exit 1
fi
if [ -z "$endpoint" ]; then
echo "endpoint is required"
echo "-e endpoint is required"
exit 1
fi

# use /v2/api/login to login and get token
token = curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"username":"'$username'","password":"'$password'","source":"LOCAL"}' $endpoint/v2/api/login | jq ".data.token" -r

# You can obtain a list of virtual machines by using the /v2/api/get-vms endpoint and including the token in the Authorization header for authentication.
# 通过 /v2/api/login 进行登录,并获取 token
token=$(curl -X POST -H "Content-Type: application/json" -d '{"username":"'$username'","password":"'$password'","source":"LOCAL"}' $endpoint/v2/api/login | jq -r ".data.token")

# 通过 Authorization header 携带 token 并为请求完成鉴权, 通过 /v2/api/get-vms 来获取虚拟机列表
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: $token" \
-d '{"where":}' $endpoint/v2/api/get-vms | jq ".data.vms"
-d '{"where":{}}' http://192.168.27.57/v2/api/get-vms | jq ".[]"

```

Expand Down
Loading