Skip to content

Commit

Permalink
feat: Add Local User Database objects (#385)
Browse files Browse the repository at this point in the history
This adds the following:
* `panos.device.LocalUserDatabaseUser`
* `panos.device.LocalUserDatabaseGroup`
  • Loading branch information
shinmog authored Nov 30, 2021
1 parent f89ff82 commit d39b6de
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
75 changes: 75 additions & 0 deletions panos/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class Vsys(VersionedPanObject):
"device.LogSettingsConfig",
"device.CertificateProfile",
"device.SslDecrypt",
"device.LocalUserDatabaseUser",
"device.LocalUserDatabaseGroup",
"objects.AddressObject",
"objects.AddressGroup",
"objects.ServiceObject",
Expand Down Expand Up @@ -2331,3 +2333,76 @@ def _setup(self):
params.append(VersionedParamPath("exclude", vartype="yesno", path="exclude",))

self._params = tuple(params)


class LocalUserDatabaseUser(VersionedPanObject):
"""A Local User Database User.
Args:
name (str): Name.
password_hash (str): The password hash.
disabled (bool): Set to True if the user is disabled.
"""

ROOT = Root.VSYS
SUFFIX = ENTRY

def _setup(self):
# xpaths
self._xpaths.add_profile(value="/local-user-database/user")
self._xpaths.add_profile(
value="{0}/local-user-database/user".format(self._TEMPLATE_VSYS_XPATH),
parents=("Template",),
)

# params
params = []

params.append(
VersionedParamPath("password_hash", vartype="encrypted", path="phash",)
)
params.append(VersionedParamPath("disabled", vartype="yesno", path="disabled",))

self._params = tuple(params)

def change_password(self, new_password):
"""Update the password.
**Modifies the live device**
Args:
new_password (str): The new password for this user.
"""
dev = self.nearest_pandevice()
self.password_hash = dev.request_password_hash(new_password)
self.update("password_hash")


class LocalUserDatabaseGroup(VersionedPanObject):
"""A Local User Database group.
Args:
name (str): Name.
users (list): The local users in this group.
"""

ROOT = Root.VSYS
SUFFIX = ENTRY

def _setup(self):
# xpaths
self._xpaths.add_profile(value="/local-user-database/user-group")
self._xpaths.add_profile(
value="{0}/local-user-database/user".format(self._TEMPLATE_VSYS_XPATH),
parents=("Template",),
)

# params
params = []

params.append(VersionedParamPath("users", vartype="member", path="user",))

self._params = tuple(params)
2 changes: 2 additions & 0 deletions panos/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class Firewall(PanDevice):
"device.HttpServerProfile",
"device.CertificateProfile",
"device.SslDecrypt",
"device.LocalUserDatabaseUser",
"device.LocalUserDatabaseGroup",
"ha.HighAvailability",
"objects.AddressObject",
"objects.AddressGroup",
Expand Down

0 comments on commit d39b6de

Please sign in to comment.