教學課程 / Cloud One Workload Security:第 01 課-帳戶與雲端連接器 / Azure 帳戶 API 程式碼(舊版帳戶)
單元 13 / 22

Azure 帳戶 API 程式碼(舊版帳戶)

警告

下列影片與程式碼透過 /rest/authentication/login/ 使用使用者名稱、密碼及 tenant name 登入,屬舊版帳戶的舊式 REST 流程,不適用於新 Cloud One 帳戶。新帳戶應建立 Cloud One API key,使用其帳戶資料所在區域的 Workload Security API 端點,並以 Authorization: ApiKey <your_key_value> 驗證。不要將此範例視為現行帳戶的建議實作。

舊版帳戶的 Workload Security API 程式碼

from __future__ import print_function
import requests
import json

# Set the variables
url = "https://cloudone.trendmicro.com:443"
data = {"dsCredentials":{"userName":"your username","password":"your password","tenantName":"your tenant name"}}
headers = {'Content-type': 'application/json'}

#Log in, get the session ID, and set the cookies for the post request
ses = requests.session()
loginurl = url + "/rest/authentication/login/"
res = ses.post(loginurl,data=json.dumps(data), headers=headers, verify=False)
cookies = {'sID':res.text}

#Add the Azure Account
data2 = {"createCloudAccountRequest":{"cloudAccountElement":{"subscriptionId":"your subscription Id","cloudType":"AZURE_ARM","name":"Automation Azure Account","azureAdTenantId":"Your azure AD tenant ID","azureAdApplicationId":"Your azure AD Application ID","azureAdApplicationPassword":"Your Secret Key"},"sessionId":res.text}}
res2 = ses.post(url + "/rest/cloudaccounts/", data=json.dumps(data2), headers=headers, verify=False)
print(res2.text)

#Log out
logouturl = url + "/rest/authentication/logout/?sID={" + res.text + "}"
print(logouturl)
res3 = ses.delete(logouturl,verify=False)
print(res3.text)
← 上一單元:使用 Cloud One API 新增… 下一單元:使用 Azure CLI 建立 Azu… →

Cloud One Workload Security:第 01 課-帳戶與雲端連接器 · 22 單元