Class: Evervault::Http::RequestIntercept

Inherits:
Object
  • Object
show all
Defined in:
lib/evervault/http/request_intercept.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request:, config:) ⇒ RequestIntercept

Returns a new instance of RequestIntercept.



82
83
84
85
86
87
88
89
90
# File 'lib/evervault/http/request_intercept.rb', line 82

def initialize(request:, config:)
  @config = config
  NetHTTPOverride.set_api_key(config.api_key)
  NetHTTPOverride.set_relay_url(config.relay_url)

  @request = request
  @expire_date = nil
  @initial_date = nil
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



80
81
82
# File 'lib/evervault/http/request_intercept.rb', line 80

def config
  @config
end

Instance Method Details

#get_certObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/evervault/http/request_intercept.rb', line 117

def get_cert
  ca_content = nil
  i = 0

  while !ca_content && i < 1
    i += 1
    begin
      ca_content = @request.execute('get', config.ca_host).body
    rescue StandardError
    end
  end

  if !ca_content || ca_content == ''
    raise Evervault::Errors::EvervaultError,
          "Unable to install the Evervault root certificate from #{config.ca_host}"
  end

  cert = OpenSSL::X509::Certificate.new ca_content
  set_cert_expire_date(cert)
  NetHTTPOverride.set_cert(cert)
end

#is_certificate_expiredObject



92
93
94
95
96
97
98
# File 'lib/evervault/http/request_intercept.rb', line 92

def is_certificate_expired
  if @expire_date
    now = Time.now
    return true if now > @expire_date || now < @initial_date
  end
  false
end

#set_cert_expire_date(cert) ⇒ Object



139
140
141
142
143
144
# File 'lib/evervault/http/request_intercept.rb', line 139

def set_cert_expire_date(cert)
  @expire_date = cert.not_after
  @initial_date = cert.not_before
rescue StandardError
  @expire_date = nil
end

#setupObject



113
114
115
# File 'lib/evervault/http/request_intercept.rb', line 113

def setup
  get_cert
end

#setup_decryption_domains(decryption_domains) ⇒ Object



100
101
102
103
104
# File 'lib/evervault/http/request_intercept.rb', line 100

def setup_decryption_domains(decryption_domains)
  NetHTTPOverride.add_get_decryption_domains_func(lambda {
    decryption_domains
  })
end

#setup_outbound_relay_configObject



106
107
108
109
110
111
# File 'lib/evervault/http/request_intercept.rb', line 106

def setup_outbound_relay_config
  @relay_outbound_config = Evervault::Http::RelayOutboundConfig.new(base_url: config.base_url, request: @request)
  NetHTTPOverride.add_get_decryption_domains_func(lambda {
    @relay_outbound_config.get_destination_domains
  })
end