lacre.admin: Implement 'identities' sub-command

This commit is contained in:
Piotr F. Mieszkowski 2023-11-25 16:08:54 +01:00
parent 95c5802c38
commit 626fce5f2c
3 changed files with 65 additions and 7 deletions

34
doc/admin.md Normal file
View File

@ -0,0 +1,34 @@
# Lacre administration
## Command-line tool
There's a little tool for administrators. As long as Lacre Python packages
are available via `PYTHONPATH`, you can use it like this:
```sh
python -m lacre.admin -h
```
Of course `-h` displays some help.
## Inspecting key confirmation queue
To find out how many keys are waiting to be confirmed, run:
```sh
python -m lacre.admin queue
```
## Inspecting identities registered
To list all identities, run:
```sh
python -m lacre.admin identities -a
```
To preview a particular identity, run:
```sh
python -m lacre.admin identities -e alice@example.com
```

View File

@ -36,6 +36,12 @@ class KeyCache:
details = ' '.join(self._keys.keys())
return '<KeyCache %s>' % (details)
def __iter__(self):
return iter(self._keys.keys())
def emails(self):
return { email: fingerprint for (fingerprint, email) in self._keys.items() }
class KeyRing:
"""Contract to be implemented by a key-store (a.k.a. keyring)."""

View File

@ -32,6 +32,24 @@ def sub_queue(args):
print(f'Keys in the queue: {cnt}')
def sub_identities(args):
"""Sub-command to inspect identity database."""
LOG.debug('Inspecting identities...')
conn = repo.connect(conf.get_item('database', 'url'))
identities = repo.IdentityRepository(conn)
all_identities = identities.freeze_identities()
if args.all:
for id_ in all_identities:
print('-', all_identities[id_], id_)
elif args.email:
all_rev = all_identities.emails()
print('-', args.email, all_rev[args.email])
else:
exit(lacre.EX_UNAVAILABLE)
def main():
conf.validate_config(additional=conf.SCRIPT_REQUIRED)
@ -54,13 +72,13 @@ def main():
)
cmd_queue.set_defaults(operation=sub_queue)
# cmd_identities = sub_commands.add_parser('identities',
# help='Inspect identity database',
# aliases=['id']
# )
# cmd_identities.add_argument('-e', '--email', help='Check single email')
# cmd_identities.add_argument('-a', '--all', help='List all emails', action='store_true')
# cmd_identities.set_defaults(operation=sub_identities)
cmd_identities = sub_commands.add_parser('identities',
help='Inspect identity database',
aliases=['id']
)
cmd_identities.add_argument('-e', '--email', help='Check single email')
cmd_identities.add_argument('-a', '--all', help='List all emails', action='store_true')
cmd_identities.set_defaults(operation=sub_identities)
user_request = parser.parse_args()
user_request.operation(user_request)