summaryrefslogtreecommitdiff
path: root/lib/gitlab/url_blockers/ip_allowlist_entry.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/url_blockers/ip_allowlist_entry.rb')
-rw-r--r--lib/gitlab/url_blockers/ip_allowlist_entry.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/gitlab/url_blockers/ip_allowlist_entry.rb b/lib/gitlab/url_blockers/ip_allowlist_entry.rb
new file mode 100644
index 00000000000..b293afe166c
--- /dev/null
+++ b/lib/gitlab/url_blockers/ip_allowlist_entry.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module UrlBlockers
+ class IpAllowlistEntry
+ attr_reader :ip, :port
+
+ # Argument ip should be an IPAddr object
+ def initialize(ip, port: nil)
+ @ip = ip
+ @port = port
+ end
+
+ def match?(requested_ip, requested_port = nil)
+ return false unless ip.include?(requested_ip)
+ return true if port.nil?
+
+ port == requested_port
+ end
+ end
+ end
+end