Class: RemoteImageFetch::UriRestrictions

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

Overview

Wrap cURL response as if it’s an error

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ UriRestrictions

Returns a new instance of UriRestrictions.



7
8
9
10
11
12
13
# File 'lib/remote_image_fetch/uri_restrictions.rb', line 7

def initialize(options = {})
  @schemes = options[:schemes] || ['http', 'https']
  @ports   = options[:ports] || [80, 443, 8080]

  @ip_blacklist = options[:ip_blacklist]
  @host_blacklist = options[:host_blacklist]
end

Instance Method Details

#check(url) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/remote_image_fetch/uri_restrictions.rb', line 15

def check(url)
  uri = URI.parse(url)

  check_scheme! uri
  check_port! uri
  check_host! uri

  Resolv.each_address(uri.hostname) do |addr|
    raise "IP blacklisted - #{addr} for #{url}" if ip_blacklist_matches?(addr)
  end
end