Class: PaypalAPI::WebhookVerifier::CertsCache Private

Inherits:
Object
  • Object
show all
Defined in:
lib/paypal-api/webhook_verifier/certs_cache.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Stores certifiactes in-memory.

New values are added to this in-memory cache and application cache. When fetching value it firstly looks to the memory cache and then to the app cache.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_cache) ⇒ CertsCache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes certificates cache

Parameters:

  • app_cache (#fetch, nil)

    Application cache that can store certificates between redeploys



28
29
30
31
# File 'lib/paypal-api/webhook_verifier/certs_cache.rb', line 28

def initialize(app_cache)
  @app_cache = app_cache || NullCache
  @storage = {}
end

Instance Attribute Details

#app_cacheObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Current application cache



16
17
18
# File 'lib/paypal-api/webhook_verifier/certs_cache.rb', line 16

def app_cache
  @app_cache
end

#storageObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Hash storage of certificate public keys



20
21
22
# File 'lib/paypal-api/webhook_verifier/certs_cache.rb', line 20

def storage
  @storage
end

Instance Method Details

#fetch(key, &block) ⇒ OpenSSL::PKey::PKey

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Fetches value from cache

Parameters:

  • key (String)

    Cache key

  • block (Proc)

    Proc to fetch certificate text

Returns:

  • (OpenSSL::PKey::PKey)

    Certificate Public Key



39
40
41
42
43
44
45
46
47
# File 'lib/paypal-api/webhook_verifier/certs_cache.rb', line 39

def fetch(key, &block)
  openssl_pub_key = read(key)
  return openssl_pub_key if openssl_pub_key

  cert_string = app_cache.fetch(key, &block)
  cert = OpenSSL::X509::Certificate.new(cert_string)

  write(key, cert.public_key)
end