Class: Auric::Vault::Door

Inherits:
Object
  • Object
show all
Defined in:
lib/auric/vault/door.rb,
lib/auric/vault/door/version.rb

Defined Under Namespace

Classes: DecryptionError, EncryptionError

Constant Summary collapse

SANDBOXURLS =
['https://vault01-sb.auricsystems.com/vault/v2/', 'https://vault02-sb.auricsystems.com/vault/v2/']
PRODUCTIONURLS =
['https://vault01.auricsystems.com/vault/v2/', 'https://vault02.auricsystems.com/vault/v2/']
VERSION =
"0.0.6"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Door

Returns a new instance of Door.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/auric/vault/door.rb', line 17

def initialize(args)
  required_args = [:secret, :mtid, :config_id]
  required_args.each do |arg|
    raise ArgumentError, "Required argument: (#{arg}) not provided" unless args.include?(arg)
  end
  @secret = args[:secret]
  @mtid = args[:mtid]
  @config_id = args[:config_id]
  @production = args[:production] || false
  @segment = args[:segment]
  @success = false
  @error = nil
  if @production
    @url = PRODUCTIONURLS
  else
    @url = SANDBOXURLS
  end
end

Instance Attribute Details

#config_idObject

Returns the value of attribute config_id.



12
13
14
# File 'lib/auric/vault/door.rb', line 12

def config_id
  @config_id
end

#errorObject (readonly)

Returns the value of attribute error.



13
14
15
# File 'lib/auric/vault/door.rb', line 13

def error
  @error
end

#mtidObject

Returns the value of attribute mtid.



12
13
14
# File 'lib/auric/vault/door.rb', line 12

def mtid
  @mtid
end

#productionObject

Returns the value of attribute production.



12
13
14
# File 'lib/auric/vault/door.rb', line 12

def production
  @production
end

#secretObject

Returns the value of attribute secret.



12
13
14
# File 'lib/auric/vault/door.rb', line 12

def secret
  @secret
end

#segmentObject

Returns the value of attribute segment.



12
13
14
# File 'lib/auric/vault/door.rb', line 12

def segment
  @segment
end

#successObject (readonly)

Returns the value of attribute success.



13
14
15
# File 'lib/auric/vault/door.rb', line 13

def success
  @success
end

Instance Method Details

#decrypt(token) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/auric/vault/door.rb', line 46

def decrypt(token)
  json = get_data('decrypt', token)
  if @success
    return json['result']['plaintextValue']
  else
    @error = json['error']
    raise DecryptionError, @error
  end
end

#encrypt(data) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/auric/vault/door.rb', line 36

def encrypt(data)
  json = post_data('encrypt', data)
  if @success
    return json['result']['token']
  else
    @error = json['error']
    raise EncryptionError, @error
  end
end