2017-06-21 33 views
1

我使用Python 2.7中的Gtk3中的GnomeKeyring,但几乎所有的方法都被弃用[1]。所以我试图用SecretSecret.Collection [2]如何通过秘密存储集合中的标签找到密钥

import gi 
gi.require_version('Secret', '1.0') 
from gi.repository import Secret 
>> ValueError: Namespace Secret not available 

我发现包 “中的python-secretstorage”[3],并且可以访问现在钥匙圈:

import secretstorage 
bus = secretstorage.dbus_init() 
collection = secretstorage.get_default_collection(bus) ## login keyring 

但我怎么能找到键我正在通过标签搜索,所以我不必遍历所有项目?

items = collection.get_all_items() 
for item in items: 
    if item.get_label() == "most_wanted_key": 
     return item 

这是我试过的,但它不适用于标签,只有属性(s)。

found_items = collection.search_items({"label": "most_wanted_key"}) 
  1. https://lazka.github.io/pgi-docs/GnomeKeyring-1.0/functions.html
  2. https://lazka.github.io/pgi-docs/Secret-1/classes/Collection.html
  3. https://secretstorage.readthedocs.io/en/latest/

回答

0

我还没有想出如何搜索标签两种,但AFAICT,标签由一个属性集通过GUI。这似乎为我工作找网站凭据:

import secretstorage 
bus = secretstorage.dbus_init() 
collection = secretstorage.get_default_collection(bus) ## login keyring 
search={u'action_url': u'https://testapp.example.com:8443/login'} 
items = collection.search_items(search) 
for item in items: 
    print item.get_label() 
    print item.get_secret() 

印刷的标签,其实等同于什么我寻找,我认为这是使用API​​预期的方式。当然,这种扭曲是在找出要搜索的确切属性;对于另一个网站,标识URL存储在“origin_url”下。