netcmd: models: rename lookup methods to find for consistency
authorRob van der Linde <rob@catalyst.net.nz>
Tue, 27 Feb 2024 03:58:56 +0000 (16:58 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 1 Mar 2024 04:45:36 +0000 (04:45 +0000)
There are a mixture of methods called either 'lookup' or 'find'.

This dates back to when they raised LookupError, but these now raise NotFound.

They should be all called 'find' for consistency.

Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/netcmd/domain/auth/silo.py
python/samba/netcmd/domain/claim/claim_type.py
python/samba/netcmd/domain/models/auth_policy.py
python/samba/netcmd/domain/models/schema.py
python/samba/netcmd/domain/models/value_type.py

index 52a5523847cb2b02ea57cf02b16f35473eaff339..f792e8a85420c3c1278c82da47813ea79ea2de82 100644 (file)
@@ -147,7 +147,7 @@ class cmd_domain_auth_silo_create(Command):
         :param name: Either the DN or name of authentication policy
         """
         try:
-            return AuthenticationPolicy.lookup(ldb, name)
+            return AuthenticationPolicy.find(ldb, name)
         except (ModelError, ValueError) as e:
             raise CommandError(e)
 
@@ -264,7 +264,7 @@ class cmd_domain_auth_silo_modify(Command):
         :param name: Either the DN or name of authentication policy
         """
         try:
-            return AuthenticationPolicy.lookup(ldb, name)
+            return AuthenticationPolicy.find(ldb, name)
         except (ModelError, ValueError) as e:
             raise CommandError(e)
 
index 3b82b06405d3f3860402887397ebafc70a1fd482..092cd4aa46c7cfd184e328d58c7bb20c7929078e 100644 (file)
@@ -88,9 +88,9 @@ class cmd_domain_claim_claim_type_create(Command):
 
         # Lookup attribute and class names in schema.
         try:
-            applies_to = [ClassSchema.lookup(ldb, name) for name in class_names]
-            attribute = AttributeSchema.lookup(ldb, attribute_name)
-            value_type = ValueType.lookup(ldb, attribute)
+            applies_to = [ClassSchema.find(ldb, name) for name in class_names]
+            attribute = AttributeSchema.find(ldb, attribute_name)
+            value_type = ValueType.find(ldb, attribute)
         except (ModelError, ValueError) as e:
             raise CommandError(e)
 
@@ -206,8 +206,7 @@ class cmd_domain_claim_claim_type_modify(Command):
         # Change class names for claim type.
         if class_names is not None:
             try:
-                applies_to = [ClassSchema.lookup(ldb, name)
-                              for name in class_names]
+                applies_to = [ClassSchema.find(ldb, name) for name in class_names]
             except (ModelError, ValueError) as e:
                 raise CommandError(e)
 
index a41c43a90b170af6c4bf0d2b0d75c8deac3ee9b3..3ee6231568c9ae3e3791ec58ca5ae3f2d0616495 100644 (file)
@@ -85,7 +85,7 @@ class AuthenticationPolicy(Model):
         return "msDS-AuthNPolicy"
 
     @staticmethod
-    def lookup(ldb, name):
+    def find(ldb, name):
         """Helper function to return auth policy or raise NotFound.
 
         :param ldb: Ldb connection
index 221cd73eaf8291233e8884b7b69fc1090a6e4080..e70b737c0483859d0e453fc355cbd290d26c2ff0 100644 (file)
@@ -58,8 +58,8 @@ class ClassSchema(Model):
         return "classSchema"
 
     @classmethod
-    def lookup(cls, ldb, name):
-        """Helper function to lookup class or raise NotFound.
+    def find(cls, ldb, name):
+        """Helper function to find class by name or raise NotFound.
 
         :param ldb: Ldb connection
         :param name: Class name
@@ -107,8 +107,8 @@ class AttributeSchema(Model):
         return "attributeSchema"
 
     @classmethod
-    def lookup(cls, ldb, name):
-        """Helper function to lookup attribute or raise NotFound.
+    def find(cls, ldb, name):
+        """Helper function to find attribute by name or raise NotFound.
 
         :param ldb: Ldb connection
         :param name: Attribute name
index 84fe27995ccd1c59fb05e5d463970d38f581a834..36363f88b916aa5baee584ebc0834d9431b76bb4 100644 (file)
@@ -67,7 +67,7 @@ class ValueType(Model):
         return "msDS-ValueType"
 
     @classmethod
-    def lookup(cls, ldb, attribute):
+    def find(cls, ldb, attribute):
         """Helper function to get ValueType by attribute or raise NotFound.
 
         :param ldb: Ldb connection
@@ -91,6 +91,3 @@ class ValueType(Model):
             raise NotFound(f"Could not find claim value type for {attribute}.")
 
         return value_type
-
-    def __str__(self):
-        return str(self.display_name)