forked from jan/debianmemberportfolio
Jan Dittberner
6d9b5b85c8
- the email address is enough information for DDs - default to JSON mode - use text/javascript content type for JSON response in ddportfolio controller
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
# -*- python -*-
|
|
# -*- coding: utf-8 -*-
|
|
#
|
|
# DDPortfolio service key finder module
|
|
# Copyright (c) 2009 Jan Dittberner <jan@dittberner.info>
|
|
#
|
|
# This file is part of DDPortfolio service.
|
|
#
|
|
# DDPortfolio service is free software: you can redistribute it and/or
|
|
# modify it under the terms of the GNU Affero General Public License
|
|
# as published by the Free Software Foundation, either version 3 of
|
|
# the License, or (at your option) any later version.
|
|
#
|
|
# DDPortfolio service is distributed in the hope that it will be
|
|
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public
|
|
# License along with this program. If not, see
|
|
# <http://www.gnu.org/licenses/>.
|
|
#
|
|
"""
|
|
This module provides tools for finding PGP key information from a
|
|
given keyring.
|
|
"""
|
|
|
|
db = None
|
|
|
|
def _get_keyring_cache():
|
|
global db
|
|
if not db:
|
|
import anydbm
|
|
import pkg_resources
|
|
import os.path
|
|
filename = pkg_resources.resource_filename(__name__,
|
|
'keyringcache')
|
|
assert os.path.exists(filename) and os.path.isfile(filename)
|
|
db = anydbm.open(filename, 'r')
|
|
return db
|
|
|
|
def _get_cached(cachekey):
|
|
cache = _get_keyring_cache()
|
|
if cachekey in cache:
|
|
return cache[cachekey]
|
|
return None
|
|
|
|
def getFingerprintByEmail(email):
|
|
"""Gets the fingerprints associated with the given email address
|
|
if available."""
|
|
return _get_cached('fpr:email:%s' % email)
|
|
|
|
|
|
def getRealnameByEmail(email):
|
|
"""Gets the real names associated with the given email address if
|
|
available."""
|
|
return _get_cached('name:email:%s' % email)
|
|
|
|
|
|
def getLoginByEmail(email):
|
|
"""Gets the logins associated with the given email address if
|
|
available."""
|
|
return _get_cached('login:email:%s' % email)
|
|
|
|
|
|
def getLoginByFingerprint(fpr):
|
|
"""Gets the login associated with the given fingerprint if
|
|
available."""
|
|
return _get_cached('login:fpr:%s' % fpr)
|