class SecretService::Collection
Attributes
name[RW]
path[RW]
service[RW]
Public Class Methods
new(service, name = DEFAULT_COLLECTION, path=nil)
click to toggle source
# File lib/secret_service/collection.rb, line 5 def initialize(service, name = DEFAULT_COLLECTION, path=nil) @service = service @name = name @path = path || "#{COLLECTION_PREFIX}#{name}" @proxy = @service.get_proxy(@path, IFACE[:collection]) end
Public Instance Methods
all_items()
click to toggle source
# File lib/secret_service/collection.rb, line 80 def all_items @proxy.Get(IFACE[:collection], Items).map { |item_path| SecretService::Item.new(self, item_path) } end
create_item(name, secret, properties=nil, replace=true)
click to toggle source
# File lib/secret_service/collection.rb, line 54 def create_item name, secret, properties=nil, replace=true if properties.nil? # ruby-dbus's type inference system doesn't handle recursion for # vaguely complicated structs, yet the protocol requires # explicit type annotation. Consequently, nontrivial structs # require the user to provide their own annotation attrs = ["a{ss}", {"name" => name.to_s }] properties = {"#{SS_PREFIX}Item.Label" => name.to_s, "#{SS_PREFIX}Item.Attributes" => attrs } end result = @proxy.CreateItem(properties, secret_encode(secret), replace) new_item_path = result[0] Item.new(self, new_item_path) end
get_item(name)
click to toggle source
# File lib/secret_service/collection.rb, line 72 def get_item name (unlocked_items({"name" => name})[0]) end
get_property(name)
click to toggle source
# File lib/secret_service/collection.rb, line 38 def get_property name @proxy.Get(IFACE[:collection], name.to_s.downcase.capitalize)[0] end
get_secret(name)
click to toggle source
# File lib/secret_service/collection.rb, line 76 def get_secret name get_item(name).get_secret end
lock!()
click to toggle source
# File lib/secret_service/collection.rb, line 12 def lock! locked_objs, prompt_path = @service.proxy.Lock [@path] return true if prompt_path == "/" and locked_objs.include?(@path) # need to do the prompt dance @service.prompt!(prompt_path) locked? end
locked?()
click to toggle source
# File lib/secret_service/collection.rb, line 30 def locked? get_property(:locked) end
locked_items(search_pref = {})
click to toggle source
# File lib/secret_service/collection.rb, line 50 def locked_items(search_pref = {}) @proxy.SearchItems(search_pred)[1].map {|path| Item.new self, path } end
secret_encode(secret_string)
click to toggle source
# File lib/secret_service/collection.rb, line 86 def secret_encode secret_string mime_type = "application/octet-stream" if(secret_string.respond_to? "encoding" and secret_string.encoding.to_s != "ASCII-8BIT") secret_string.encode! "UTF-8" #mime_type = "text/plain; charset=utf8" end [session[1], [], secret_string.bytes.to_a, mime_type] end
session()
click to toggle source
# File lib/secret_service/collection.rb, line 42 def session @service.session end
set_property(name, new_val)
click to toggle source
# File lib/secret_service/collection.rb, line 34 def set_property name, new_val @proxy.Set(IFACE[:item], name.to_s.downcase.capitalize, new_val) end
unlock!()
click to toggle source
# File lib/secret_service/collection.rb, line 21 def unlock! unlocked_objs, prompt_path = @service.proxy.Unlock [@path] return true if prompt_path == "/" and unlocked_objs.include?(@path) #nuts, stupid prompt @service.prompt!(prompt_path) ! locked? end
unlocked_items(search_pred = {})
click to toggle source
# File lib/secret_service/collection.rb, line 46 def unlocked_items(search_pred = {}) @proxy.SearchItems(search_pred)[0].map {|path| Item.new self, path } end