Skip to content

Commit 495623e

Browse files
author
João Abreu
committed
Add scanning agent API examples
1 parent 3df9935 commit 495623e

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
"""
3+
Create a scanning agent using the API and assign it to a target
4+
5+
This action may only be performed by users with the required permissions.
6+
Target API keys will not be able to create targets.
7+
8+
At the moment scanning agents are only available for Probely + accounts.
9+
If you require this feature please contact our support at
10+
support@probely.com.
11+
12+
This example is for python 3.5
13+
"""
14+
import getpass
15+
from urllib.parse import urljoin
16+
17+
import requests
18+
19+
username = input("Username: ")
20+
password = getpass.getpass()
21+
22+
api_base_url = "https://api.probely.com"
23+
auth_endpoint = urljoin(api_base_url, "/enterprise/auth/obtain/")
24+
scanning_agent_endpoint = urljoin(api_base_url, "/scanning-agents/")
25+
target_endpoint = urljoin(api_base_url, "/targets/")
26+
27+
# Get login token
28+
response = requests.post(
29+
auth_endpoint, json={"username": username, "password": password}
30+
)
31+
headers = {"Authorization": "JWT {}".format(response.json()["token"])}
32+
33+
# Create scanning agent
34+
response = requests.post(
35+
scanning_agent_endpoint, headers=headers, json={"name": "Agent example"},
36+
)
37+
agent_id = response.json()["id"]
38+
39+
# Create target with agent assigned
40+
target_url = "http://ox-test1.westeurope.cloudapp.azure.com"
41+
response = requests.post(
42+
target_endpoint,
43+
headers=headers,
44+
json={
45+
"site": {"name": "Example", "url": target_url},
46+
"scanning_agent": {"id": agent_id},
47+
},
48+
)
49+
target_id = response.json()["id"]
50+
51+
# Unassign agent
52+
response = requests.patch(
53+
"{}{}/".format(target_endpoint, target_id),
54+
headers=headers,
55+
json={"scanning_agent": {"id": None}},
56+
)
57+
58+
# Reassign agent
59+
response = requests.patch(
60+
"{}{}/".format(target_endpoint, target_id),
61+
headers=headers,
62+
json={"scanning_agent": {"id": agent_id}},
63+
)

0 commit comments

Comments
 (0)