Class: SecretService
- Inherits:
-
Object
show all
- Defined in:
- lib/secret_service/secret.rb,
lib/secret_service.rb,
lib/secret_service/item.rb,
lib/secret_service/prompt.rb,
lib/secret_service/collection.rb
Overview
Defined Under Namespace
Classes: Collection, Item, NoSessionBus, Prompt, Secret
Constant Summary
collapse
- SECRETS =
'org.freedesktop.secrets'
- SS_PREFIX =
'org.freedesktop.Secret.'
- SS_PATH =
'/org/freedesktop/secrets'
- COLLECTION_PREFIX =
'/org/freedesktop/secrets/aliases/'
- DEFAULT_COLLECTION =
"default"
- ALGO =
"plain"
- DBUS_UNKNOWN_METHOD =
'org.freedesktop.DBus.Error.UnknownMethod'
- DBUS_SERVICE_UNKNOWN =
'org.freedesktop.DBus.Error.ServiceUnknown'
- DBUS_EXEC_FAILED =
'org.freedesktop.DBus.Error.Spawn.ExecFailed'
- DBUS_NO_REPLY =
'org.freedesktop.DBus.Error.NoReply'
- DBUS_NO_SUCH_OBJECT =
'org.freedesktop.Secret.Error.NoSuchObject'
- IFACE =
{}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of SecretService.
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/secret_service.rb', line 33
def initialize
begin
@bus = DBus::SessionBus.instance
@proxy_maker = @bus.service SECRETS
@proxy = get_proxy SS_PATH, IFACE[:service]
@collections = {}
@collection_paths = self.list_collections
rescue
raise NoSessionBus
end
end
|
Instance Attribute Details
#bus ⇒ Object
Returns the value of attribute bus.
28
29
30
|
# File 'lib/secret_service.rb', line 28
def bus
@bus
end
|
#proxy ⇒ Object
Returns the value of attribute proxy.
28
29
30
|
# File 'lib/secret_service.rb', line 28
def proxy
@proxy
end
|
Instance Method Details
#collection(name = DEFAULT_COLLECTION, path = nil) ⇒ Object
58
59
60
|
# File 'lib/secret_service.rb', line 58
def collection(name=DEFAULT_COLLECTION, path=nil)
@collections[name.to_s] ||= Collection.new(self, name, path)
end
|
#create_collection(name, properties = nil) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/secret_service.rb', line 66
def create_collection name, properties=nil
properties ||= {"#{SS_PREFIX}Collection.Label" => name}
coll, prompt_path = @proxy.CreateCollection properties, ""
prompt!(prompt_path) if prompt_path != "/"
collection(name, coll)
end
|
#get_proxy(path, iface = nil) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/secret_service.rb', line 47
def get_proxy path, iface=nil
obj = @proxy_maker.object path
obj.introspect
obj.default_iface = iface unless iface.nil?
obj
end
|
#list_collections ⇒ Object
62
63
64
|
# File 'lib/secret_service.rb', line 62
def list_collections
@proxy.Get(IFACE[:service], 'Collections')
end
|
#prompt!(prompt_path) ⇒ Object
#read_alias(name) ⇒ Object
79
80
81
82
|
# File 'lib/secret_service.rb', line 79
def read_alias name
path = @proxy.ReadAlias name
collection(name, path)
end
|
#search_items(attrs = {}) ⇒ Object
84
85
86
|
# File 'lib/secret_service.rb', line 84
def search_items attrs={}
@proxy.SearchItems(attrs)
end
|
#session ⇒ Object
54
55
56
|
# File 'lib/secret_service.rb', line 54
def session
@session ||= @proxy.OpenSession(ALGO, "")
end
|
#set_alias(name, collection) ⇒ Object
75
76
77
|
# File 'lib/secret_service.rb', line 75
def set_alias name, collection
@proxy.SetAlias name, (collection.class == String ? collection : collection.path)
end
|
#unlock(objects) ⇒ Object
88
89
90
|
# File 'lib/secret_service.rb', line 88
def unlock objects
@proxy.Unlock objects
end
|