/usr/share/pyshared/wader/common/secrets.py is in python-wader 0.5.12-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | # -*- coding: utf-8 -*-
# Copyright (C) 2008-2009 Warp Networks, S.L.
# Author: Pablo MartÃ
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
Classes that mediate access to the secrets. This is done through the
:mod:`~wader.common.keyring` module.
"""
from wader.common import keyring
class ProfileSecrets(object):
"""
I mediate access to the secrets associated with a profile
I provide a uniform API to interact with the different keyrings.
"""
def __init__(self, connection, manager):
self.connection = connection
self.uuid = connection.get_settings()['connection']['uuid']
self.manager = manager
self.temporal_secrets = {}
def get(self, ask=True):
"""
Returns the secrets associated with the profile
:param ask: Should we ask the user if the keyring is closed?
"""
if self.is_open():
try:
return self.manager.get_secrets(self.uuid)
except keyring.KeyringNoMatchError:
# None signals that something went wrong
if self.temporal_secrets:
self.update(self.temporal_secrets, False)
return self.temporal_secrets
else:
return {}
else:
if ask:
self.manager.KeyNeeded(self.connection)
return self.temporal_secrets
def update(self, secrets, ask=False):
"""
Updates the secrets associated with the profile
:param secrets: The new password to use
:param ask: Should we ask the user if the keyring is closed?
"""
_id = self.connection.get_settings()['connection']['id']
if self.is_open():
self.manager.update_secret(self.uuid, _id, secrets)
else:
if ask:
self.manager.KeyNeeded(self.connection)
self.register_open_callback(lambda:
self.manager.update_secret(self.uuid, _id,
self.temporal_secrets))
self.temporal_secrets.update(secrets)
def open(self, password):
"""Opens the keyring backend using ``password``"""
self.manager.open(password)
def clean(self):
"""Cleans up the profile secrets"""
if self.is_open():
self.manager.delete_secret(self.uuid)
self.manager.write()
self.temporal_secrets = {}
def is_open(self):
return self.manager.is_open()
def is_new(self):
return self.manager.is_new()
def register_open_callback(self, callback):
"""Registers ``callback`` to be executed when the keyring is open"""
self.manager.register_open_callback(callback)
|