68
69
class CredentialsManagement(dbus.service.Object):
69
70
"""DBus object that manages Ubuntu One credentials."""
71
def __init__(self, *args, **kwargs):
72
def __init__(self, timeout_func=lambda *a: None,
73
shutdown_func=lambda *a: None, *args, **kwargs):
72
74
super(CredentialsManagement, self).__init__(*args, **kwargs)
76
self.timeout_func = timeout_func
77
self.shutdown_func = shutdown_func
73
79
self.sso_match = None
74
80
self.sso_proxy = self._get_sso_proxy()
122
def _get_ref_count(self):
123
"""Get value of ref_count."""
124
logger.debug('ref_count is %r.', self._ref_count)
125
return self._ref_count
127
def _set_ref_count(self, new_value):
128
"""Set a new value to ref_count."""
129
logger.debug('ref_count is %r, changing value to %r.',
130
self._ref_count, new_value)
133
msg = 'Attempting to decrease ref_count to a negative value (%r).'
134
logger.warning(msg, new_value)
136
self._ref_count = new_value
138
if self._ref_count == 0:
139
self.timeout_func(TIMEOUT_INTERVAL, self.shutdown_func)
141
ref_count = property(fget=_get_ref_count, fset=_set_ref_count)
116
143
# Operator not preceded by a space (fails with dbus decorators)
117
144
# pylint: disable=C0322
119
146
@dbus.service.signal(DBUS_CREDENTIALS_IFACE)
120
147
def AuthorizationDenied(self):
121
148
"""Signal thrown when the user denies the authorization."""
122
150
logger.info('%s: emitting AuthorizationDenied.',
123
151
self.__class__.__name__)
125
153
@dbus.service.signal(DBUS_CREDENTIALS_IFACE, signature='a{ss}')
126
154
def CredentialsFound(self, credentials):
127
155
"""Signal thrown when the credentials are found."""
128
157
logger.info('%s: emitting CredentialsFound.',
129
158
self.__class__.__name__)
131
160
@dbus.service.signal(DBUS_CREDENTIALS_IFACE)
132
161
def CredentialsNotFound(self):
133
162
"""Signal thrown when the credentials are not found."""
134
164
logger.info('%s: emitting CredentialsNotFound.',
135
165
self.__class__.__name__)
137
167
@dbus.service.signal(DBUS_CREDENTIALS_IFACE)
138
168
def CredentialsCleared(self):
139
169
"""Signal thrown when the credentials were cleared."""
140
171
logger.info('%s: emitting CredentialsCleared.',
141
172
self.__class__.__name__)
143
174
@dbus.service.signal(DBUS_CREDENTIALS_IFACE)
144
175
def CredentialsStored(self):
145
176
"""Signal thrown when the credentials were cleared."""
146
178
logger.info('%s: emitting CredentialsStored.',
147
179
self.__class__.__name__)
149
181
@dbus.service.signal(DBUS_CREDENTIALS_IFACE, signature='a{ss}')
150
182
def CredentialsError(self, error_dict):
151
183
"""Signal thrown when there is a problem getting the credentials."""
152
185
logger.error('%s: emitting CredentialsError with error_dict %r.',
153
186
self.__class__.__name__, error_dict)
156
189
async_callbacks=("reply_handler", "error_handler"))
157
190
def find_credentials(self, reply_handler=NO_OP, error_handler=NO_OP):
158
191
"""Ask the Ubuntu One credentials."""
159
193
self.sso_proxy.find_credentials(APP_NAME, {},
160
194
reply_handler=reply_handler, error_handler=error_handler)
164
198
async_callbacks=("reply_handler", "error_handler"))
165
199
def clear_credentials(self, reply_handler=NO_OP, error_handler=NO_OP):
166
200
"""Clear the Ubuntu One credentials."""
167
202
self.sso_proxy.clear_credentials(APP_NAME, {},
168
203
reply_handler=reply_handler, error_handler=error_handler)
173
208
def store_credentials(self, credentials,
174
209
reply_handler=NO_OP, error_handler=NO_OP):
175
210
"""Store the token for Ubuntu One application."""
176
212
self.sso_proxy.store_credentials(APP_NAME, credentials,
177
213
reply_handler=reply_handler, error_handler=error_handler)
180
216
async_callbacks=("reply_handler", "error_handler"))
181
217
def register(self, reply_handler=NO_OP, error_handler=NO_OP):
182
218
"""Get credentials if found else prompt to register to Ubuntu One."""
183
220
params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL,
184
221
PING_URL_KEY: PING_URL, WINDOW_ID_KEY: '0'}
185
222
self.sso_proxy.register(APP_NAME, params,