-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDeleteAssets.py
48 lines (44 loc) · 2.08 KB
/
DeleteAssets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Script to Delete the assets from CCS system
# For more details Refer the CCS REST API document at : https://apidocs.symantec.com/home/CCS
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Variable
# Replace the <hostname> with CCS application server host name
# Replace the <port number> with the configured port number for REST API, Default Port Number : 12431
# Replace the <user name> and <password> with valid CCS user name and password for example: UserName = domain1\\administrator, password = pass@123
HostName = '<hostname>'
PortNumber = '<port number>'
UserName = '<user name>'
Password = '<password>'
# Function to generate CCS REST API access token
def getToken():
urlToken = "https://" + HostName + ":" + PortNumber + "/ccs/api/v1/oauth/tokens"
payload = "grant_type=password&username=" + UserName + "&password=" + Password +""
headers = {'Content-Type': "application/json"}
responseToken = requests.request("POST", urlToken, data=payload, headers=headers, verify=False)
autheticationresult = responseToken.status_code
if (autheticationresult!=200) :
print("\nToken Generation Failed. Please check if the REST API is enabled and User name and password is correct\n")
exit()
tokenDict = responseToken.json()
token = tokenDict['access_token']
refreshToken = tokenDict['refresh_token']
print("bearer Token is:\n")
print(token)
print("\n Refresh Token is:\n")
print(refreshToken)
return token
# CCS Asset URI
url = "https://" + HostName + ":" + PortNumber + "/ccs/api/v1/assets"
# provide the asset GUIDs which need to be deleted. Like
# payload = "[\"19cdaca5-ae26-422b-a07a-936599134768\",\"1e80bf4e-afaa-4b83-ae4b-a02b42be4045\"]"
payload = "[\"<Asset GUID>\",\"<Asset GUID>\"]"
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
bearertoken = "Bearer " + getToken()
headers = {
'Authorization': bearertoken ,
'Content-Type': "application/json"
}
response = requests.request("DELETE", url, data=payload, headers=headers, verify=False)
print(response.text)
print(responce.json)