[polari] utils: Add keyring helper methods
- From: Florian MĂźllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] utils: Add keyring helper methods
- Date: Wed, 10 Feb 2016 23:19:12 +0000 (UTC)
commit b3d7f447d321530b19f0d6b4c91e533fddd853ba
Author: Florian MĂźllner <fmuellner gnome org>
Date: Tue Feb 2 08:32:34 2016 +0100
utils: Add keyring helper methods
We will soon start to support server passwords, which should be stored
in the user's keyring, so add appropriate helper methods.
https://bugzilla.gnome.org/show_bug.cgi?id=709824
src/utils.js | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/utils.js b/src/utils.js
index 3961b01..e9643b8 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -25,11 +25,17 @@ const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Soup = imports.gi.Soup;
+const Secret = imports.gi.Secret;
const Tp = imports.gi.TelepathyGLib;
const AppNotifications = imports.appNotifications;
const Signals = imports.signals;
+const SECRET_SCHEMA = new Secret.Schema(
+ 'org.gnome.Polari.Account', Secret.SchemaFlags.NONE,
+ { 'account-id': Secret.SchemaAttributeType.STRING }
+);
+
const GPASTE_BASEURL = 'https://paste.gnome.org/'
// http://daringfireball.net/2010/07/improved_regex_for_matching_urls
@@ -109,6 +115,38 @@ function getTpEventTime() {
return Tp.user_action_time_from_x11 (time);
}
+function storeAccountPassword(account, password, callback) {
+ let attr = { 'account-id': account.get_path_suffix() };
+ let label = _("Polari server password for %s").format(account.display_name);
+ Secret.password_store(SECRET_SCHEMA, attr, Secret.COLLECTION_DEFAULT,
+ label, password, null,
+ function(o, res) {
+ try {
+ let success = Secret.password_store_finish(res);
+ callback(success);
+ } catch(e) {
+ log('Failed to store password for account "%s": %s'.format(
+ account.display_name, e.message));
+ callback(false);
+ }
+ });
+}
+
+function lookupAccountPassword(account, callback) {
+ let attr = { 'account-id': account.get_path_suffix() };
+ Secret.password_lookup(SECRET_SCHEMA, attr, null,
+ function(o, res) {
+ try {
+ let password = Secret.password_lookup_finish(res);
+ callback(password);
+ } catch(e) {
+ log('Failed to lookup password for account "%s": %s'.format(
+ account.display_name, e.message));
+ callback(null);
+ }
+ });
+}
+
// findUrls:
// @str: string to find URLs in
//
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]