Class: SecretService::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/secret_service/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, path) ⇒ Item



6
7
8
9
10
# File 'lib/secret_service/item.rb', line 6

def initialize(collection, path)
  @collection = collection
  @path = path
  @proxy = collection.service.get_proxy @path, IFACE[:item]
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/secret_service/item.rb', line 4

def path
  @path
end

Instance Method Details

#attributesObject



41
42
43
# File 'lib/secret_service/item.rb', line 41

def attributes
  get_property(:attributes)
end

#attributes=(new_attrs) ⇒ Object

TODO: this keeps throwing type errors



46
47
48
# File 'lib/secret_service/item.rb', line 46

def attributes= new_attrs
  set_property(:attributes, new_attrs)
end

#createdObject



16
17
18
# File 'lib/secret_service/item.rb', line 16

def created
  Time.at get_property(:created)
end

#get_property(name) ⇒ Object



54
55
56
# File 'lib/secret_service/item.rb', line 54

def get_property name
  @proxy.Get(IFACE[:item], name.to_s.downcase.capitalize)[0]
end

#get_secretObject



62
63
64
# File 'lib/secret_service/item.rb', line 62

def get_secret
  secret_decode(@proxy.GetSecret(session[1]))
end

#labelObject



33
34
35
# File 'lib/secret_service/item.rb', line 33

def label
  get_property(:label)
end

#label=(new_label) ⇒ Object



37
38
39
# File 'lib/secret_service/item.rb', line 37

def label= new_label
  set_property(:label, new_label)
end

#lock!Object



24
25
26
27
28
29
30
31
# File 'lib/secret_service/item.rb', line 24

def lock!
  locked, prompt_path = @collection.service.proxy.Lock [@path]
  return true if prompt_path == "/" and locked.include? @path

  # otherwise we have to handle the prompt
  @collection.service.prompt!(prompt_path)
  get_property(:locked)
end

#locked?Boolean



20
21
22
# File 'lib/secret_service/item.rb', line 20

def locked?
  get_property(:locked)
end

#modifiedObject



12
13
14
# File 'lib/secret_service/item.rb', line 12

def modified
  Time.at get_property(:modified)
end

#secret_decode(secret_arr) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/secret_service/item.rb', line 67

def secret_decode secret_arr
  secret_struct = secret_arr[0]
  s = {}
  [:session, :params, :bytes, :mime].each do |x|
    s[x] = secret_struct.shift
  end

  secret_string = (s[:bytes].map {|x| x.chr}).join
  if(secret_string.respond_to? "encoding" and
     s[:mime] != "application/octet-stream")
    charset = s[:mime].match(/charset=(.+)/)[1]
    unless charset.nil?
      charset.upcase!.sub! /\AUTF([\w\d])/, "UTF-#{$1}"
      secret_string.force_encoding charset
    end
  end
  secret_string
end

#sessionObject



58
59
60
# File 'lib/secret_service/item.rb', line 58

def session
  @collection.session
end

#set_property(name, new_val) ⇒ Object



50
51
52
# File 'lib/secret_service/item.rb', line 50

def set_property name, new_val
  @proxy.Set(IFACE[:item], name.to_s.downcase.capitalize, new_val)
end