]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
netcmd: domain: claims: use consistent naming for options
authorRob van der Linde <rob@catalyst.net.nz>
Tue, 16 May 2023 00:56:09 +0000 (12:56 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 25 Jun 2023 23:29:32 +0000 (23:29 +0000)
The name of the option should be the same as the attribute name.

You can still tell where it's being used (display_name), especially
now with the model layer:

    ClaimType.get(ldb, display_name=name)

The silo commands tend to use the `cn` field, while the claims
commands use the `displayName` field, but the option is always called
`name` for consistency.

Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
python/samba/netcmd/domain/claim/claim_type.py
python/samba/netcmd/domain/claim/value_type.py

index 81822abe58ad4ce6b75bb1ec2b89acc50bb6b3ef..3f92f1a04100a86bd41d8a978dd5f0892cd6cba4 100644 (file)
@@ -61,7 +61,7 @@ class cmd_domain_claim_claim_type_create(ClaimCommand):
         Option("--class", help="Object classes to set claim type to.",
                dest="class_names", action="append", type=str),
         Option("--name", help="Optional display name or use attribute name.",
-               dest="display_name", action="store", type=str),
+               dest="name", action="store", type=str),
         Option("--description",
                help="Optional description or use from attribute.",
                dest="description", action="store", type=str),
@@ -99,10 +99,9 @@ class cmd_domain_claim_claim_type_create(ClaimCommand):
         claim_type_cn = SYNTAX_TO_CLAIM_TYPE_CN[attribute_syntax]
         return self.claim_value_types[claim_type_cn].claim_value_type
 
-    def run(self, ldap_url=None, sambaopts=None, credopts=None,
-            attribute_name=None, class_names=None, display_name=None,
-            description=None, disable=None, enable=None, protect=None,
-            unprotect=None):
+    def run(self, ldap_url=None, sambaopts=None, credopts=None, name=None,
+            attribute_name=None, class_names=None, description=None,
+            disable=None, enable=None, protect=None, unprotect=None):
 
         # required attributes
         if not attribute_name:
@@ -120,7 +119,7 @@ class cmd_domain_claim_claim_type_create(ClaimCommand):
 
         # Check if a claim type with this display name already exists.
         # Note: you can register the same claim type under another display name.
-        display_name = display_name or attribute_name
+        display_name = name or attribute_name
         claim_type = ClaimType.get(self.ldb, display_name=display_name)
         if claim_type:
             raise CommandError(f"Claim type {display_name} already exists, "
@@ -196,7 +195,7 @@ class cmd_domain_claim_claim_type_modify(ClaimCommand):
         Option("-H", "--URL", help="LDB URL for database or target server.",
                type=str, metavar="URL", dest="ldap_url"),
         Option("--name", help="Display name of claim type to modify (required).",
-               dest="display_name", action="store", type=str),
+               dest="name", action="store", type=str),
         Option("--class", help="Object classes to set claim type to.",
                dest="class_names", action="append", type=str),
         Option("--description", help="Set the claim type description.",
@@ -215,11 +214,11 @@ class cmd_domain_claim_claim_type_modify(ClaimCommand):
                dest="unprotect", action="store_true")
     ]
 
-    def run(self, ldap_url=None, sambaopts=None, credopts=None,
-            display_name=None, class_names=None, description=None,
-            enable=None, disable=None, protect=None, unprotect=None):
+    def run(self, ldap_url=None, sambaopts=None, credopts=None, name=None,
+            class_names=None, description=None, enable=None, disable=None,
+            protect=None, unprotect=None):
 
-        if not display_name:
+        if not name:
             raise CommandError("Argument --name is required.")
         if enable and disable:
             raise CommandError("--enable and --disable cannot be used together.")
@@ -229,9 +228,9 @@ class cmd_domain_claim_claim_type_modify(ClaimCommand):
         self.ldb = self.ldb_connect(ldap_url, sambaopts, credopts)
 
         # Check if claim type exists.
-        claim_type = ClaimType.get(self.ldb, display_name=display_name)
+        claim_type = ClaimType.get(self.ldb, display_name=name)
         if not claim_type:
-            raise CommandError(f"Claim type {display_name} not found.")
+            raise CommandError(f"Claim type {name} not found.")
 
         # Either --enable will be set or --disable but never both.
         if enable:
@@ -264,7 +263,7 @@ class cmd_domain_claim_claim_type_modify(ClaimCommand):
             raise CommandError(e)
 
         # Claim type updated successfully.
-        self.outf.write(f"Updated claim type: {display_name}\n")
+        self.outf.write(f"Updated claim type: {name}\n")
 
 
 class cmd_domain_claim_claim_type_delete(ClaimCommand):
@@ -281,23 +280,23 @@ class cmd_domain_claim_claim_type_delete(ClaimCommand):
         Option("-H", "--URL", help="LDB URL for database or target server.",
                type=str, metavar="URL", dest="ldap_url"),
         Option("--name", help="Display name of claim type to delete (required).",
-               dest="display_name", action="store", type=str),
+               dest="name", action="store", type=str),
         Option("--force", help="Force claim type delete even if it is protected.",
                dest="force", action="store_true")
     ]
 
     def run(self, ldap_url=None, sambaopts=None, credopts=None,
-            display_name=None, force=None):
+            name=None, force=None):
 
-        if not display_name:
+        if not name:
             raise CommandError("Argument --name is required.")
 
         self.ldb = self.ldb_connect(ldap_url, sambaopts, credopts)
 
         # Check if claim type exists first.
-        claim_type = ClaimType.get(self.ldb, display_name=display_name)
+        claim_type = ClaimType.get(self.ldb, display_name=name)
         if claim_type is None:
-            raise CommandError(f"Claim type {display_name} not found.")
+            raise CommandError(f"Claim type {name} not found.")
 
         # Delete claim type.
         try:
@@ -313,7 +312,7 @@ class cmd_domain_claim_claim_type_delete(ClaimCommand):
                 raise CommandError(e)
 
         # Claim type deleted successfully.
-        self.outf.write(f"Deleted claim type: {display_name}\n")
+        self.outf.write(f"Deleted claim type: {name}\n")
 
 
 class cmd_domain_claim_claim_type_list(ClaimCommand):
@@ -364,21 +363,20 @@ class cmd_domain_claim_claim_type_view(ClaimCommand):
         Option("-H", "--URL", help="LDB URL for database or target server.",
                type=str, metavar="URL", dest="ldap_url"),
         Option("--name", help="Display name of claim type to view (required).",
-               dest="display_name", action="store", type=str),
+               dest="name", action="store", type=str),
     ]
 
-    def run(self, ldap_url=None, sambaopts=None, credopts=None,
-            display_name=None):
+    def run(self, ldap_url=None, sambaopts=None, credopts=None, name=None):
 
-        if not display_name:
+        if not name:
             raise CommandError("Argument --name is required.")
 
         self.ldb = self.ldb_connect(ldap_url, sambaopts, credopts)
 
         # Check if claim type exists first.
-        claim_type = ClaimType.get(self.ldb, display_name=display_name)
+        claim_type = ClaimType.get(self.ldb, display_name=name)
         if claim_type is None:
-            raise CommandError(f"Claim type {display_name} not found.")
+            raise CommandError(f"Claim type {name} not found.")
 
         # Display claim type as JSON.
         self.print_json(claim_type.as_dict())
index 9f494a67bcfcf98635698a44e829e77c48206496..094788aa22342c63de8d6d75031d2f8820508f3c 100644 (file)
@@ -76,21 +76,20 @@ class cmd_domain_claim_value_type_view(ClaimCommand):
                type=str, metavar="URL", dest="ldap_url"),
         Option("--name",
                help="Display name of claim value type to view (required).",
-               dest="display_name", action="store", type=str),
+               dest="name", action="store", type=str),
     ]
 
-    def run(self, ldap_url=None, sambaopts=None, credopts=None,
-            display_name=None):
+    def run(self, ldap_url=None, sambaopts=None, credopts=None, name=None):
 
-        if not display_name:
+        if not name:
             raise CommandError("Argument --name is required.")
 
         self.ldb = self.ldb_connect(ldap_url, sambaopts, credopts)
 
         # Check if value type exists first.
-        value_type = ValueType.get(self.ldb, display_name=display_name)
+        value_type = ValueType.get(self.ldb, display_name=name)
         if value_type is None:
-            raise CommandError(f"Value type {display_name} not found.")
+            raise CommandError(f"Value type {name} not found.")
 
         # Display vale type as JSON.
         self.print_json(value_type.as_dict())