|
|
590d18 |
From 0fac76b07e7b15eb46e4db942d5c9890b704549d Mon Sep 17 00:00:00 2001
|
|
|
590d18 |
From: Christian Heimes <cheimes@redhat.com>
|
|
|
590d18 |
Date: Wed, 19 Aug 2015 13:32:01 +0200
|
|
|
590d18 |
Subject: [PATCH] Add flag to list all service and user vaults
|
|
|
590d18 |
|
|
|
590d18 |
The vault-find plugin has two additional arguments to list all
|
|
|
590d18 |
service vaults or user vaults. Since the name of a vault is only unique
|
|
|
590d18 |
for a particular user or service, the commands also print the vault user
|
|
|
590d18 |
or vault service. The virtual attributes were added in rev
|
|
|
590d18 |
01dd951ddc0181b559eb3dd5ff0336c81e245628.
|
|
|
590d18 |
|
|
|
590d18 |
Example:
|
|
|
590d18 |
|
|
|
590d18 |
$ ipa vault-find --users
|
|
|
590d18 |
----------------
|
|
|
590d18 |
2 vaults matched
|
|
|
590d18 |
----------------
|
|
|
590d18 |
Vault name: myvault
|
|
|
590d18 |
Type: standard
|
|
|
590d18 |
Vault user: admin
|
|
|
590d18 |
|
|
|
590d18 |
Vault name: UserVault
|
|
|
590d18 |
Type: standard
|
|
|
590d18 |
Vault user: admin
|
|
|
590d18 |
----------------------------
|
|
|
590d18 |
Number of entries returned 2
|
|
|
590d18 |
----------------------------
|
|
|
590d18 |
|
|
|
590d18 |
$ ipa vault-find --services
|
|
|
590d18 |
----------------
|
|
|
590d18 |
2 vaults matched
|
|
|
590d18 |
----------------
|
|
|
590d18 |
Vault name: myvault
|
|
|
590d18 |
Type: standard
|
|
|
590d18 |
Vault service: HTTP/ipatest.freeipa.local@FREEIPA.LOCAL
|
|
|
590d18 |
|
|
|
590d18 |
Vault name: myvault
|
|
|
590d18 |
Type: standard
|
|
|
590d18 |
Vault service: ldap/ipatest.freeipa.local@FREEIPA.LOCAL
|
|
|
590d18 |
----------------------------
|
|
|
590d18 |
Number of entries returned 2
|
|
|
590d18 |
----------------------------
|
|
|
590d18 |
|
|
|
590d18 |
https://fedorahosted.org/freeipa/ticket/5150
|
|
|
590d18 |
|
|
|
590d18 |
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
|
|
|
590d18 |
---
|
|
|
590d18 |
API.txt | 4 +++-
|
|
|
590d18 |
VERSION | 4 ++--
|
|
|
590d18 |
ipalib/plugins/vault.py | 48 +++++++++++++++++++++++++++++++++---------------
|
|
|
590d18 |
3 files changed, 38 insertions(+), 18 deletions(-)
|
|
|
590d18 |
|
|
|
590d18 |
diff --git a/API.txt b/API.txt
|
|
|
590d18 |
index a39b22b602e0baf5d283732d18d83b2a25d5cf50..f23d9a40c647a3c4d209419631794cd36e8e5e2f 100644
|
|
|
590d18 |
--- a/API.txt
|
|
|
590d18 |
+++ b/API.txt
|
|
|
590d18 |
@@ -5508,7 +5508,7 @@ output: Output('result', <type 'dict'>, None)
|
|
|
590d18 |
output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), None)
|
|
|
590d18 |
output: ListOfPrimaryKeys('value', None, None)
|
|
|
590d18 |
command: vault_find
|
|
|
590d18 |
-args: 1,13,4
|
|
|
590d18 |
+args: 1,15,4
|
|
|
590d18 |
arg: Str('criteria?', noextrawhitespace=False)
|
|
|
590d18 |
option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui')
|
|
|
590d18 |
option: Str('cn', attribute=True, autofill=False, cli_name='name', maxlength=255, multivalue=False, pattern='^[a-zA-Z0-9_.-]+$', primary_key=True, query=True, required=False)
|
|
|
590d18 |
@@ -5518,10 +5518,12 @@ option: Flag('no_members', autofill=True, default=False, exclude='webui')
|
|
|
590d18 |
option: Flag('pkey_only?', autofill=True, default=False)
|
|
|
590d18 |
option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui')
|
|
|
590d18 |
option: Str('service?')
|
|
|
590d18 |
+option: Flag('services?', autofill=True, default=False)
|
|
|
590d18 |
option: Flag('shared?', autofill=True, default=False)
|
|
|
590d18 |
option: Int('sizelimit?', autofill=False, minvalue=0)
|
|
|
590d18 |
option: Int('timelimit?', autofill=False, minvalue=0)
|
|
|
590d18 |
option: Str('username?', cli_name='user')
|
|
|
590d18 |
+option: Flag('users?', autofill=True, default=False)
|
|
|
590d18 |
option: Str('version?', exclude='webui')
|
|
|
590d18 |
output: Output('count', <type 'int'>, None)
|
|
|
590d18 |
output: ListOfEntries('result', (<type 'list'>, <type 'tuple'>), Gettext('A list of LDAP entries', domain='ipa', localedir=None))
|
|
|
590d18 |
diff --git a/VERSION b/VERSION
|
|
|
590d18 |
index 6569eeb70fa4e8065b5abb9dc89bd4cc6d42bd15..31a4af4a819415740e5c8db9259f934e13418cb5 100644
|
|
|
590d18 |
--- a/VERSION
|
|
|
590d18 |
+++ b/VERSION
|
|
|
590d18 |
@@ -90,5 +90,5 @@ IPA_DATA_VERSION=20100614120000
|
|
|
590d18 |
# #
|
|
|
590d18 |
########################################################
|
|
|
590d18 |
IPA_API_VERSION_MAJOR=2
|
|
|
590d18 |
-IPA_API_VERSION_MINOR=150
|
|
|
590d18 |
-# Last change: pvoborni - change type of vault type option to StrEnum
|
|
|
590d18 |
+IPA_API_VERSION_MINOR=151
|
|
|
590d18 |
+# Last change: cheimes - Add flag to list all service and user vaults
|
|
|
590d18 |
diff --git a/ipalib/plugins/vault.py b/ipalib/plugins/vault.py
|
|
|
590d18 |
index 712e2d5ddfa723eb84b80a261289a7cf1c75674f..83dc085b5aadb4e2878e29d17449f0808cc7a9c2 100644
|
|
|
590d18 |
--- a/ipalib/plugins/vault.py
|
|
|
590d18 |
+++ b/ipalib/plugins/vault.py
|
|
|
590d18 |
@@ -343,21 +343,11 @@ class vault(LDAPObject):
|
|
|
590d18 |
"""
|
|
|
590d18 |
Generates vault DN from parameters.
|
|
|
590d18 |
"""
|
|
|
590d18 |
-
|
|
|
590d18 |
service = options.get('service')
|
|
|
590d18 |
shared = options.get('shared')
|
|
|
590d18 |
user = options.get('username')
|
|
|
590d18 |
|
|
|
590d18 |
- count = 0
|
|
|
590d18 |
- if service:
|
|
|
590d18 |
- count += 1
|
|
|
590d18 |
-
|
|
|
590d18 |
- if shared:
|
|
|
590d18 |
- count += 1
|
|
|
590d18 |
-
|
|
|
590d18 |
- if user:
|
|
|
590d18 |
- count += 1
|
|
|
590d18 |
-
|
|
|
590d18 |
+ count = (bool(service) + bool(shared) + bool(user))
|
|
|
590d18 |
if count > 1:
|
|
|
590d18 |
raise errors.MutuallyExclusiveError(
|
|
|
590d18 |
reason=_('Service, shared, and user options ' +
|
|
|
590d18 |
@@ -387,8 +377,10 @@ class vault(LDAPObject):
|
|
|
590d18 |
parent_dn = DN(('cn', service), ('cn', 'services'), container_dn)
|
|
|
590d18 |
elif shared:
|
|
|
590d18 |
parent_dn = DN(('cn', 'shared'), container_dn)
|
|
|
590d18 |
- else:
|
|
|
590d18 |
+ elif user:
|
|
|
590d18 |
parent_dn = DN(('cn', user), ('cn', 'users'), container_dn)
|
|
|
590d18 |
+ else:
|
|
|
590d18 |
+ raise RuntimeError
|
|
|
590d18 |
|
|
|
590d18 |
return DN(rdns, parent_dn)
|
|
|
590d18 |
|
|
|
590d18 |
@@ -814,7 +806,16 @@ class vault_del(LDAPDelete):
|
|
|
590d18 |
class vault_find(LDAPSearch):
|
|
|
590d18 |
__doc__ = _('Search for vaults.')
|
|
|
590d18 |
|
|
|
590d18 |
- takes_options = LDAPSearch.takes_options + vault_options
|
|
|
590d18 |
+ takes_options = LDAPSearch.takes_options + vault_options + (
|
|
|
590d18 |
+ Flag(
|
|
|
590d18 |
+ 'services?',
|
|
|
590d18 |
+ doc=_('List all service vaults'),
|
|
|
590d18 |
+ ),
|
|
|
590d18 |
+ Flag(
|
|
|
590d18 |
+ 'users?',
|
|
|
590d18 |
+ doc=_('List all user vaults'),
|
|
|
590d18 |
+ ),
|
|
|
590d18 |
+ )
|
|
|
590d18 |
|
|
|
590d18 |
has_output_params = LDAPSearch.has_output_params
|
|
|
590d18 |
|
|
|
590d18 |
@@ -832,9 +833,26 @@ class vault_find(LDAPSearch):
|
|
|
590d18 |
raise errors.InvocationError(
|
|
|
590d18 |
format=_('KRA service is not enabled'))
|
|
|
590d18 |
|
|
|
590d18 |
- base_dn = self.obj.get_dn(None, **options)
|
|
|
590d18 |
+ if options.get('users') or options.get('services'):
|
|
|
590d18 |
+ mutex = ['service', 'services', 'shared', 'username', 'users']
|
|
|
590d18 |
+ count = sum(bool(options.get(option)) for option in mutex)
|
|
|
590d18 |
+ if count > 1:
|
|
|
590d18 |
+ raise errors.MutuallyExclusiveError(
|
|
|
590d18 |
+ reason=_('Service(s), shared, and user(s) options ' +
|
|
|
590d18 |
+ 'cannot be specified simultaneously'))
|
|
|
590d18 |
+
|
|
|
590d18 |
+ scope = ldap.SCOPE_SUBTREE
|
|
|
590d18 |
+ container_dn = DN(self.obj.container_dn,
|
|
|
590d18 |
+ self.api.env.basedn)
|
|
|
590d18 |
+
|
|
|
590d18 |
+ if options.get('services'):
|
|
|
590d18 |
+ base_dn = DN(('cn', 'services'), container_dn)
|
|
|
590d18 |
+ else:
|
|
|
590d18 |
+ base_dn = DN(('cn', 'users'), container_dn)
|
|
|
590d18 |
+ else:
|
|
|
590d18 |
+ base_dn = self.obj.get_dn(None, **options)
|
|
|
590d18 |
|
|
|
590d18 |
- return (filter, base_dn, scope)
|
|
|
590d18 |
+ return filter, base_dn, scope
|
|
|
590d18 |
|
|
|
590d18 |
def post_callback(self, ldap, entries, truncated, *args, **options):
|
|
|
590d18 |
for entry in entries:
|
|
|
590d18 |
--
|
|
|
590d18 |
2.4.3
|
|
|
590d18 |
|