Skip to content

Commit

Permalink
modify quick start bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
netweng committed Oct 20, 2023
1 parent c46899f commit 6d7349b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 58 deletions.
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

1 comment on commit 6d7349b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for cloudtower-api-doc ready!

✅ Preview
https://cloudtower-api-fmavyyt1o-xiaojun.vercel.app

Built with commit 6d7349b.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.