Class: Opr21

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

Constant Summary collapse

CREDENTIALS =

set initial credentials if required…

{
    :domain => "mydom.1password.eu",
    :email => "[email protected]",
    :secret => "12-123456-123456-123456-123456-123456-123456"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(password, hash = {}) ⇒ Opr21

Returns a new instance of Opr21.



18
19
20
21
22
23
# File 'lib/opr21.rb', line 18

def initialize(password, hash={})
  @password = password
  @debug = false
  @tempfile = Tempfile.new('op')
  check_creds(hash)
end

Instance Attribute Details

#debug=(debug) ⇒ Object (writeonly)

Sets the attribute debug

Parameters:

  • value

    the value to set the attribute debug to.



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

def debug=(value)
  @debug = value
end

#expiration_dateObject (readonly)

Returns the value of attribute expiration_date.



15
16
17
# File 'lib/opr21.rb', line 15

def expiration_date
  @expiration_date
end

#passwordObject (readonly)

Returns the value of attribute password.



15
16
17
# File 'lib/opr21.rb', line 15

def password
  @password
end

#tempfileObject (readonly)

Returns the value of attribute tempfile.



15
16
17
# File 'lib/opr21.rb', line 15

def tempfile
  @tempfile
end

Instance Method Details

#getItem(name, fields = "website,username,title,password", vault = "Private") ⇒ Object

gibt die Werte des ersten Elementes mit entsprechenden Namen



35
36
37
38
39
40
41
42
43
# File 'lib/opr21.rb', line 35

def getItem(name, fields = "website,username,title,password", vault = "Private")
  all = self.op "list", "items", "--vault", vault
  arr = all.select{|i| i["overview"]["title"] =~ /#{name}/i}
  if arr.class == Array
      self.op "get", "item", arr[0]["uuid"], "--fields", fields
  else
      {}
  end
end

#getItemList(regex, vault = "Private") ⇒ Object

gibt eine Liste von item.titles aus die matchen



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/opr21.rb', line 46

def getItemList(regex, vault = "Private")
  all = self.op "list", "items", "--vault", vault
  arr = all.select{|i| i["overview"]["title"] =~ /#{regex}/i}
  return_arr = []
  if arr.class == Array
      arr.each do |item|
        return_arr << item["overview"]["title"]
      end
  end
  return_arr
end

#op(*args) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/opr21.rb', line 25

def op(*args)
  check_creds()
  cmd = %(. #{tempfile.path} ; op "#{args.join('" "')}")
  puts cmd if @debug
  output = `#{cmd}`
  puts output if @debug
  JSON.parse(output)
end