Class: ObjectStorage::CDN::GoogleIpCache

Inherits:
Object
  • Object
show all
Defined in:
app/uploaders/object_storage/cdn/google_ip_cache.rb

Constant Summary collapse

GOOGLE_CDN_LIST_KEY =
'google_cdn_ip_list'
CACHE_EXPIRATION_TIME =
1.day

Class Method Summary collapse

Class Method Details

.async_refreshObject



27
28
29
# File 'app/uploaders/object_storage/cdn/google_ip_cache.rb', line 27

def async_refresh
  ::GoogleCloud::FetchGoogleIpListWorker.perform_async
end

.google_ip?(request_ip) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'app/uploaders/object_storage/cdn/google_ip_cache.rb', line 19

def google_ip?(request_ip)
  google_ip_ranges = cached_value(GOOGLE_CDN_LIST_KEY)

  return false unless google_ip_ranges

  google_ip_ranges.any? { |range| range.include?(request_ip) }
end

.ready?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/uploaders/object_storage/cdn/google_ip_cache.rb', line 15

def ready?
  caches.any? { |cache| cache.exist?(GOOGLE_CDN_LIST_KEY) }
end

.update!(subnets) ⇒ Object



11
12
13
# File 'app/uploaders/object_storage/cdn/google_ip_cache.rb', line 11

def update!(subnets)
  caches.each { |cache| cache.write(GOOGLE_CDN_LIST_KEY, subnets) }
end