Skip to content

Commit 88af2d4

Browse files
authored
Add files via upload
## Version 1.0.8 (13/10/2025) 1. Updated common.py to include an optioal timeout parameter for web requests within the ClearPassAPILogin class. 2. API code includes new, modified or deleted API that is implemented in Aruba ClearPass v6.12.6. 3. Updated Readme 4. Included new function within new Utils class to pull token from token file. 5. Updated __init__.py file.
1 parent f0fcc3d commit 88af2d4

File tree

7 files changed

+127
-9
lines changed

7 files changed

+127
-9
lines changed

pyclearpass/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
from pyclearpass.api_sessioncontrol import *
1616
from pyclearpass.api_toolsandutilities import *
1717
from pyclearpass.common import *
18+
from pyclearpass.utils import *

pyclearpass/api_globalserverconfiguration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ def replace_cluster_parameters(self, body=({})):
946946
"PolicyResultCacheTimeout" : 0, #Policy result cache timeout in minutes. Object Type: integer
947947
"PostAuthUnsubscribeEndpoints" : "", #No Desc. Object Type: string
948948
"PostAuthV2" : "", #Enable Post-Auth v2. Object Type: string
949+
"PostAuthV2CombineEventsToPAN" : "", #Post-Authentication v2 Combine Session Notification Events to PAN. Object Type: string
949950
"PostAuthV2HttpEnforcement" : "", #Enable Post-Auth v2 HTTP enforcement. Object Type: string
950951
"ProcessWiredFromIfMap" : "", #Process wired device information from IF-MAP interface. Object Type: string
951952
"ProfiledKnownEndpointsCleanupOption" : "", #Profiled Known endpoints cleanup option in days. Object Type: string
@@ -1043,6 +1044,7 @@ def update_cluster_parameters(self, body=({})):
10431044
"PolicyResultCacheTimeout" : 0, #Policy result cache timeout in minutes. Object Type: integer
10441045
"PostAuthUnsubscribeEndpoints" : "", #No Desc. Object Type: string
10451046
"PostAuthV2" : "", #Enable Post-Auth v2. Object Type: string
1047+
"PostAuthV2CombineEventsToPAN" : "", #Post-Authentication v2 Combine Session Notification Events to PAN. Object Type: string
10461048
"PostAuthV2HttpEnforcement" : "", #Enable Post-Auth v2 HTTP enforcement. Object Type: string
10471049
"ProcessWiredFromIfMap" : "", #Process wired device information from IF-MAP interface. Object Type: string
10481050
"ProfiledKnownEndpointsCleanupOption" : "", #Profiled Known endpoints cleanup option in days. Object Type: string

pyclearpass/api_guestactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_guest_by_guest_id_pass_id(self, guest_id="", id=""):
1717
HTTP Response Codes: 200 OK, 400 Bad Request, 404 Not Found, 406 Not Acceptable, 415 Unsupported Media Type, 422 Unprocessable Entity
1818
Parameter Type: path, Name: guest_id, Description: Numeric ID of the guest account
1919
Parameter Type: path, Name: id, Description: Numeric ID of the digital pass template
20-
"""
20+
"""
2121
url_path = "/guest/{guest_id}/pass/{id}"
2222
dict_path = {"guest_id": guest_id, "id": id}
2323
for item in dict_path:

pyclearpass/api_identities.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ def new_endpoint(self, body=({})):
598598
"randomized_mac" : False, #Is MAC address randomized?. Object Type: boolean
599599
"device_insight_tags" : "", #List of Device Insight Tags. Object Type: string
600600
"attributes" : {}, #Additional attributes(key/value pairs) may be stored with the endpoint. Object Type: object
601+
"added_at" : "", #Timestamp of endpoint addition. Object Type: string
602+
"updated_at" : "", #Timestamp of endpoint updation. Object Type: string
601603
602604
}
603605
"""
@@ -638,7 +640,9 @@ def update_endpoint_by_endpoint_id(self, endpoint_id="", body=({})):
638640
"randomized_mac" : False, #Is MAC address randomized?. Object Type: boolean
639641
"device_insight_tags" : "", #List of Device Insight Tags. Object Type: string
640642
"attributes" : {}, #Additional attributes(key/value pairs) may be stored with the endpoint. Object Type: object
641-
"profile" : {}, #Endpoint Profile. Object Type: ProfileUpdate
643+
"added_at" : "", #Timestamp of endpoint addition. Object Type: string
644+
"updated_at" : "", #Timestamp of endpoint updation. Object Type: string
645+
"profile" : "", #Endpoint Profile. Object Type: ProfileUpdate
642646
643647
}
644648
"""
@@ -667,7 +671,9 @@ def replace_endpoint_by_endpoint_id(self, endpoint_id="", body=({})):
667671
"randomized_mac" : False, #Is MAC address randomized?. Object Type: boolean
668672
"device_insight_tags" : "", #List of Device Insight Tags. Object Type: string
669673
"attributes" : {}, #Additional attributes(key/value pairs) may be stored with the endpoint. Object Type: object
670-
"profile" : {}, #Endpoint Profile. Object Type: ProfileReplace
674+
"added_at" : "", #Timestamp of endpoint addition. Object Type: string
675+
"updated_at" : "", #Timestamp of endpoint updation. Object Type: string
676+
"profile" : "", #Endpoint Profile. Object Type: ProfileReplace
671677
672678
}
673679
"""
@@ -725,7 +731,9 @@ def update_endpoint_mac_address_by_mac_address(self, mac_address="", body=({})):
725731
"randomized_mac" : False, #Is MAC address randomized?. Object Type: boolean
726732
"device_insight_tags" : "", #List of Device Insight Tags. Object Type: string
727733
"attributes" : {}, #Additional attributes(key/value pairs) may be stored with the endpoint. Object Type: object
728-
"profile" : {}, #Endpoint Profile. Object Type: ProfileUpdate
734+
"added_at" : "", #Timestamp of endpoint addition. Object Type: string
735+
"updated_at" : "", #Timestamp of endpoint updation. Object Type: string
736+
"profile" : "", #Endpoint Profile. Object Type: ProfileUpdate
729737
730738
}
731739
"""
@@ -754,7 +762,9 @@ def replace_endpoint_mac_address_by_mac_address(self, mac_address="", body=({}))
754762
"randomized_mac" : False, #Is MAC address randomized?. Object Type: boolean
755763
"device_insight_tags" : "", #List of Device Insight Tags. Object Type: string
756764
"attributes" : {}, #Additional attributes(key/value pairs) may be stored with the endpoint. Object Type: object
757-
"profile" : {}, #Endpoint Profile. Object Type: ProfileReplace
765+
"added_at" : "", #Timestamp of endpoint addition. Object Type: string
766+
"updated_at" : "", #Timestamp of endpoint updation. Object Type: string
767+
"profile" : "", #Endpoint Profile. Object Type: ProfileReplace
758768
759769
}
760770
"""

pyclearpass/api_sessioncontrol.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,48 @@ def new_session_by_id_reauthorize(self, id="", body=({})):
109109
self, url=url_path, method="post", query=body
110110
)
111111

112+
# API Service: Change of Authorization by MAC without enabling Insight
113+
def get_active_session_by_mac_address(self, interval="", mac_address=""):
114+
"""
115+
Operation: Get a list of Enforcement Profiles for the given MAC
116+
HTTP Response Codes: 200 OK, 401 Unauthorized, 403 Forbidden, 404 Not Found, 406 Not Acceptable, 415 Unsupported Media Type
117+
Parameter Type (Optional): query, Name: interval, Description: interval to get active session
118+
Parameter Type: path, Name: mac_address, Description: filter by mac-address
119+
"""
120+
url_path = "/active-session/{mac_address}"
121+
dict_query = {"interval": interval}
122+
url_path = _generate_parameterised_url(parameters=dict_query, url=url_path)
123+
dict_path = {"mac_address": mac_address}
124+
for item in dict_path:
125+
url_path = url_path.replace("{" + item + "}", dict_path[item])
126+
return ClearPassAPILogin._send_request(self, url=url_path, method="get")
127+
128+
def new_active_session_by_mac_address(self, interval="", mac_address="", body=({})):
129+
"""
130+
Operation: Change of Authorization of active session for the given MAC
131+
HTTP Response Codes: 201 Created, 401 Unauthorized, 403 Forbidden, 404 Not Found, 406 Not Acceptable, 415 Unsupported Media Type, 422 Unprocessable Entity
132+
Parameter Type (Optional): query, Name: interval, Description: interval to get active session
133+
Parameter Type: path, Name: mac_address, Description: filter by mac-address
134+
Required Body Parameters: None listed
135+
Parameter Type: body, Name: body
136+
Body example with descriptions and object types below (type(dict):
137+
138+
body={
139+
"enforcement_profile" : "", #When performing CoA, the 'enforcement_profile' parameter MUST be provided. Object Type: string
140+
141+
}
142+
"""
143+
url_path = "/active-session/{mac_address}"
144+
dict_query = {"interval": interval}
145+
url_path = _generate_parameterised_url(parameters=dict_query, url=url_path)
146+
dict_path = {"mac_address": mac_address}
147+
for item in dict_path:
148+
url_path = url_path.replace("{" + item + "}", dict_path[item])
149+
body = _remove_empty_keys(keys=body)
150+
return ClearPassAPILogin._send_request(
151+
self, url=url_path, method="post", query=body
152+
)
153+
112154
# API Service: Manage Session Action Methods
113155
def new_session_action_disconnect(self, async_="", body=({})):
114156
"""

pyclearpass/common.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def __init__(
1616
server="",
1717
api_token="",
1818
verify_ssl=False,
19+
timeout=None
1920
):
2021
"""
2122
This is the class constructor for the ClearPassModule.
@@ -24,16 +25,19 @@ def __init__(
2425
2526
Mandatory Parameters:
2627
server (string): Website for ClearPass services example - https://yourserver.network.local:443/api
27-
verify_ssl (boolean, optional): default value False. Allows use of an invalid SSL certificate.
2828
29-
Option 1 Parameters -
29+
Option 1 Parameters:-
3030
granttype (string) = ['client_credentials' or 'password' or 'refresh_token']: OAuth2 authentication method,client_id (string): Client ID defined in API Clients,
3131
clientsecret (string, optional): Client secret, required if the API client is not a public client,
3232
username (string, optional): Username for authentication, required for grant_type "password",
3333
password (string, optional): Password for authentication, required for grant_type "password",
3434
35-
Option 2 Parameters-
35+
Option 2 Parameters:
3636
api_token = Provide the api_token which is the 'access token'.
37+
38+
Optional Parameters:
39+
verify_ssl (boolean, optional): default value False. Allows use of an invalid SSL certificate.
40+
timeout (int, optional): default value none. Allows to adjust the timeout value for the web request in seconds.
3741
3842
}
3943
@@ -45,7 +49,8 @@ def __init__(
4549
self.password = password
4650
self.server = server
4751
self.api_token = api_token
48-
self.verify_ssl = False
52+
self.verify_ssl = verify_ssl
53+
self.timeout = timeout
4954

5055
def _send_request(
5156
self, url, method, query="", content_response_type="application/json"
@@ -79,34 +84,39 @@ def _send_request(
7984
json=query,
8085
headers=header,
8186
verify=self.verify_ssl,
87+
timeout=self.timeout,
8288
)
8389
if method == "patch":
8490
response = requests.patch(
8591
url=full_url_path,
8692
json=query,
8793
headers=header,
8894
verify=self.verify_ssl,
95+
timeout=self.timeout,
8996
)
9097
if method == "put":
9198
response = requests.put(
9299
url=full_url_path,
93100
json=query,
94101
headers=header,
95102
verify=self.verify_ssl,
103+
timeout=self.timeout,
96104
)
97105
if method == "get":
98106
response = requests.get(
99107
url=full_url_path,
100108
json=query,
101109
headers=header,
102110
verify=self.verify_ssl,
111+
timeout=self.timeout,
103112
)
104113
if method == "delete":
105114
response = requests.delete(
106115
url=full_url_path,
107116
json=query,
108117
headers=header,
109118
verify=self.verify_ssl,
119+
timeout=self.timeout,
110120
)
111121
if method == "":
112122
print(

pyclearpass/utils.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# (C) Copyright 2019-2025 Hewlett Packard Enterprise Development LP.
2+
# Apache License 2.0
3+
4+
import json
5+
import csv
6+
import os
7+
8+
9+
class Utils:
10+
def get_token_from_file(fileName):
11+
"""
12+
Use this function to retrieve the access_token from a file which is located in the working directory of the script.
13+
The file must use the following structure:
14+
{"access_token":"your_secret_token"}
15+
"""
16+
try:
17+
f = open(fileName, "r")
18+
content = f.read()
19+
jsonContent = json.loads(content)
20+
if jsonContent["access_token"]:
21+
return jsonContent["access_token"]
22+
else:
23+
raise ValueError(
24+
{"status": "Error", "message": "Missing Access Token."}
25+
)
26+
27+
except KeyError as e:
28+
raise Exception(
29+
{
30+
"status": "Error",
31+
"Message": "Missing 'access_token' key name. Ensure key name exists as per the function usage details.",
32+
}
33+
)
34+
except json.JSONDecodeError as e:
35+
raise Exception(
36+
{
37+
"status": "Error",
38+
"Message": "Ensure a valid json file as described in the function usage details.",
39+
}
40+
)
41+
except FileNotFoundError as e:
42+
raise Exception(
43+
{
44+
"status": "Error",
45+
"Message": "Ensure the token file '"
46+
+ fileName
47+
+ "' exists. "
48+
+ e.strerror,
49+
}
50+
)
51+
52+
except Exception as e:
53+
raise Exception({"status": "Error", "Message": e})

0 commit comments

Comments
 (0)