Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Add update endpoint method #171

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions ise.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,91 @@ def add_endpoint(
return result
else:
return ERS._pass_ersresponse(result, resp)

def update_endpoint(
self,
name,
mac,
group_id,
static_profile_assigment="false",
static_group_assignment="true",
profile_id="",
description="",
portalUser="",
customAttributes={},
):
"""
Update a user to the local user store.

:param name: Name
:param mac: Macaddress
:param group_id: OID of group to add endpoint in
:param static_profile_assigment: Set static profile
:param static_group_assignment: Set static group
:param profile_id: OID of profile
:param description: User description
:param portaluser: Portal username
:param customAttributes: key value pairs of custom attributes
:return: result dictionary
"""
is_valid = ERS._mac_test(mac)
if not is_valid:
raise InvalidMacAddress(
"{0}. Must be in the form of AA:BB:CC:00:11:22".format(mac)
)
else:
self.ise.headers.update(
{"ACCEPT": "application/json", "Content-Type": "application/json"}
)

result = {
"success": False,
"response": "",
"error": "",
}

resp = self.ise.get(
"{0}/config/endpoint?filter=mac.EQ.{1}".format(self.url_base, mac)
)
found_endpoint = resp.json()

if found_endpoint["SearchResult"]["total"] == 1:
endpoint_oid = found_endpoint["SearchResult"]["resources"][0]["id"]
data = {
"ERSEndPoint": {
"name": name,
"description": description,
"mac": mac,
"profileId": profile_id,
"staticProfileAssignment": static_profile_assigment,
"groupId": group_id,
"staticGroupAssignment": static_group_assignment,
"portalUser": portalUser,
"customAttributes": {"customAttributes": customAttributes},
}
}

resp = self._request(
"{0}/config/endpoint/{1}".format(self.url_base, endpoint_oid),
method="put",
data=json.dumps(data),
)
if resp.status_code == 200:
result["success"] = True
result["response"] = "{0} Updated Successfully".format(name)
return result
else:
return ERS._pass_ersresponse(result, resp)
elif found_endpoint["SearchResult"]["total"] == 0:
result["response"] = "{0} not found".format(mac)
result["error"] = 404
return result

else:
result["response"] = "{0} not found".format(mac)
result["error"] = resp.status_code
return result


def delete_endpoint(self, mac):
"""
Expand Down
7 changes: 7 additions & 0 deletions test/test_ise_27.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ def test_get_endpoint(): # noqa D103
assert "'name': 'AA:BB:CC:00:11:22'" in str(r1["response"])


@pytest.mark.vcr
def test_update_endpoint(): # noqa D103
r1 = ise.update_endpoint(endpoint["mac"])
assert r1["success"] is True
assert r1["response"] == "AA:BB:CC:00:11:22 Updated Successfully"


@pytest.mark.vcr
def test_delete_endpoint(): # noqa D103
r1 = ise.delete_endpoint(endpoint["mac"])
Expand Down
8 changes: 8 additions & 0 deletions test/test_ise_30.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def test_get_endpoint(): # noqa D103
assert "'name': 'AA:BB:CC:00:11:22'" in str(r1["response"])



@pytest.mark.vcr
def test_update_endpoint(): # noqa D103
r1 = ise.update_endpoint(endpoint["mac"])
assert r1["success"] is True
assert r1["response"] == "AA:BB:CC:00:11:22 Updated Successfully"


@pytest.mark.vcr
def test_delete_endpoint(): # noqa D103
r1 = ise.delete_endpoint(endpoint["mac"])
Expand Down