File: gnome-keyring.py

package info (click to toggle)
liferea 1.15.8-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 7,652 kB
  • sloc: ansic: 27,425; javascript: 1,646; python: 1,123; makefile: 657; sh: 115; xml: 13
file content (68 lines) | stat: -rw-r--r-- 2,557 bytes parent folder | download | duplicates (2)
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
"""
Libsecret Plugin

Copyright (C) 2013 Lars Windolf <lars.lindner@gmail.com>
Copyright (C) 2018 Bastian Germann <bastiangermann@fishpost.de>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
"""

import gi
gi.require_version('Peas', '1.0')
gi.require_version('PeasGtk', '1.0')
gi.require_version('Liferea', '3.0')
gi.require_version('Secret', '1')
from gi.repository import GObject, Peas, PeasGtk, Gtk, Liferea, Secret

LABEL = 'liferea'
SCHEMA = Secret.Schema.new(
    "net.sf.liferea.Secret",
    Secret.SchemaFlags.NONE,
    {'id': Secret.SchemaAttributeType.STRING}
)

class LibsecretPlugin(GObject.Object, Liferea.AuthActivatable):
    __gtype_name__ = 'LibsecretPlugin'

    object = GObject.property(type=GObject.Object)

    def get_collection(self):
        service = Secret.Service.get_sync(Secret.ServiceFlags.LOAD_COLLECTIONS, None)
        colls = service.get_collections()
        for c in colls:
            if c.get_label() == LABEL:
                return c
        return None

    def do_deactivate(self):
        window = self.object

    def do_query(self, id):
        coll = self.get_collection()
        if coll:
            items = coll.search_sync(None, {'id': id}, Secret.SearchFlags.UNLOCK, None)
            if items and items[0].load_secret_sync(None):
                username, password = items[0].get_secret().get_text().split('@@@')
                Liferea.auth_info_from_store(id, username, password)

    def do_delete(self, id):
        Secret.password_clear_sync(SCHEMA, {'id': id}, None)

    def do_store(self, id, username, password):
        coll = self.get_collection()
        if not coll:
            coll = Secret.Collection.create_sync(None, LABEL, None, Secret.CollectionCreateFlags(0), None)
        login = '@@@'.join([username, password])
        secret = Secret.Value.new(login, len(login), 'text/plain')
        Secret.Item.create_sync(coll, SCHEMA, {'id': id}, repr(id), secret, Secret.ItemCreateFlags.REPLACE, None)