GIA openapi doc
README
Zenconsole API defines Zenconsole resources behaviors
Verification method
Authentication must include Authorization
and X-Auth-Datetime
header information. Authorization as follows:
Authorization: access_id:signature
access_id
is Access ID,The signature
is calculated as follows:
signature = base64(hmac-sha1(access_key,
utf8_encode(VERB + "\n" +
X-Auth-Datetime + "\n" +
CanonicalizedResource)).digest())
access_key
: Access KeyVERB
: HTTP method,such as: "GET"
, "POST"
X-Auth-Datetime
: X-Auth-Datetime
current request time such as "2020-01-01T00:00:00+0800"
,"1603071843497"
CanonicalizedResource
: request URL,such as: "/api/gia/whiteip"
,"/api/gia/whiteip/1118c45f-816d-49d3-8aa8-79e9c5d58de5"
, no request parameters required
example:
Suppose Access ID
: 2RlZEW9exZJfcprb, Access Key
: OnxXfpNyetatZJDbXVjNgXFjxvILNmClear text
:POST\n2020-01-01T00:00:00+0800\n/api/gia/whiteip
Authorization = 2RlZEW9exZJfcprb:oeOF8mWeJHgFamu1N9Sl3oKOU84=
request example:
curl -X "POST" "https://gia.zenlayer.net/api/gia/whiteip" \
-H "Content-type:application/json" \
-H "Accept:application/json" \
-H "Authorization:2RlZEW9exZJfcprb:oeOF8mWeJHgFamu1N9Sl3oKOU84=" \
-H "X-Auth-Datetime:2020-01-01T00:00:00+0800" \
-d $'{
...
}'
golang example:
var (
accessID = "3wKQoceIYF0sQdjA"
accessKey = "1RmPnxxCMmtuFvFcNhUNQ3M3TMiquQ"
)
client := &http.Client{}
req, err := http.NewRequest("GET", "https://gia.zenlayer.net/api/gia/whiteip/1118c45f-816d-49d3-8aa8-79e9c5d58de5", nil)
if err != nil {
return
}
// 生成鉴权token
datetime := time.Now().Format("2006-01-02T15:04:05.000+0000")
mac := hmac.New(sha1.New, []byte(accessKey))
mac.Write([]byte(fmt.Sprintf("%s\n%s\n%s", "GET", datetime, "/api/gia/whiteip/1118c45f-816d-49d3-8aa8-79e9c5d58de5")))
authorization := accessID + ":" + base64.StdEncoding.EncodeToString(mac.Sum(nil))
// 添加header
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", authorization)
req.Header.Set("X-Auth-Datetime", datetime)
req.Header.Set("Accept", "application/json")
resp, err := client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
fmt.Println(string(body))
get whiteip bash:
#!/bin/bash
accessID="";
accessKey="";
projectUUID="";
host="gia.zenlayer.net";
while [ $# -ge 2 ] ; do
case "$1" in
--access-id) accessID="$2"; shift 2;;
--access-key) accessKey="$2"; shift 2;;
--project-uuid) projectUUID="$2"; shift 2;;
--host) host="$2"; shift 2;;
*) echo "unknown parameter $1." ; exit 1 ; break;;
esac
done
if [ -z $accessID ];then
echo "accessID is null"
exit 1
fi
if [ -z $accessKey ];then
echo "accessKey is null"
exit 1
fi
if [ -z $projectUUID ];then
echo "projectUUID is null"
exit 1
fi
date=`date "+%Y-%m-%dT%H:%M:%S.000+0000"`
path="/api/gia/whiteip/$projectUUID"
verb="GET"
token=`echo -n -e "$verb\n$date\n$path" | openssl sha1 -hmac $accessKey -binary | base64`
curl -X $verb "https://$host$path" -H "Authorization:$accessID:$token" -H "X-Auth-Datetime:$date"
how to use script:
bash script.bash --access-id 3wKQoceIYF0sQdjA --access-key 1RmPnxxCMmtuFvFcNhUNQ3M3TMiquQ --project-uuid 35cf4caa-e765-4680-9fa5-0cee96324eeb
add whiteip bash:
#!/bin/bash
accessID="";
accessKey="";
projectUUID="";
whiteIpList="";
enable="true"
host="gia.zenlayer.net";
while [ $# -ge 2 ] ; do
case "$1" in
--access-id) accessID="$2"; shift 2;;
--access-key) accessKey="$2"; shift 2;;
--project-uuid) projectUUID="$2"; shift 2;;
--host) host="$2"; shift 2;;
--whiteip-list) whiteIpList="$2"; shift 2;;
--enable) enable="$2"; shift 2;;
*) echo "unknown parameter $1." ; exit 1 ; break;;
esac
done
if [ -z $accessID ];then
echo "accessID is null"
exit 1
fi
if [ -z $accessKey ];then
echo "accessKey is null"
exit 1
fi
if [ -z $projectUUID ];then
echo "projectUUID is null"
exit 1
fi
date=`date "+%Y-%m-%dT%H:%M:%S.000+0000"`
path="/api/gia/whiteip"
verb="POST"
token=`echo -n -e "$verb\n$date\n$path" | openssl sha1 -hmac $accessKey -binary | base64`
curl -X $verb "https://$host$path" -H "Authorization:$accessID:$token" -H "X-Auth-Datetime:$date" -H "Content-type:application/json" -H "Accept:application/json" -d "{\"project_uuid\": \"$projectUUID\",\"security_ip_list\": \"$whiteIpList\",\"enable\": $enable}"
how to use script:
bash script.bash --access-id 3wKQoceIYF0sQdjA --access-key 1RmPnxxCMmtuFvFcNhUNQ3M3TMiquQ --project-uuid 35cf4caa-e765-4680-9fa5-0cee96324eeb --whiteip-list 127.0.0.1 --enable true
GIA whiteip
GIA whiteip management