From d39b6de7efc760782c2d46dd94a327a536c39420 Mon Sep 17 00:00:00 2001 From: Garfield Lee Freeman Date: Tue, 30 Nov 2021 13:31:19 -0800 Subject: [PATCH] feat: Add Local User Database objects (#385) This adds the following: * `panos.device.LocalUserDatabaseUser` * `panos.device.LocalUserDatabaseGroup` --- panos/device.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++ panos/firewall.py | 2 ++ 2 files changed, 77 insertions(+) diff --git a/panos/device.py b/panos/device.py index 8142d42c..d179e6c6 100644 --- a/panos/device.py +++ b/panos/device.py @@ -121,6 +121,8 @@ class Vsys(VersionedPanObject): "device.LogSettingsConfig", "device.CertificateProfile", "device.SslDecrypt", + "device.LocalUserDatabaseUser", + "device.LocalUserDatabaseGroup", "objects.AddressObject", "objects.AddressGroup", "objects.ServiceObject", @@ -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) diff --git a/panos/firewall.py b/panos/firewall.py index 1ca099c6..5164af6f 100644 --- a/panos/firewall.py +++ b/panos/firewall.py @@ -74,6 +74,8 @@ class Firewall(PanDevice): "device.HttpServerProfile", "device.CertificateProfile", "device.SslDecrypt", + "device.LocalUserDatabaseUser", + "device.LocalUserDatabaseGroup", "ha.HighAvailability", "objects.AddressObject", "objects.AddressGroup",