diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-10 15:08:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-10 15:08:16 +0300 |
commit | 1fa79760ad2d4bd67f5c5a27f372a7533b9b7c69 (patch) | |
tree | ffdfbd9113743831ff4f1290959a62cf6567fde5 /app/models/application_setting_implementation.rb | |
parent | 82fa8a3d1e8466ef36b58604d20fcc145ea12118 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/application_setting_implementation.rb')
-rw-r--r-- | app/models/application_setting_implementation.rb | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb index 98b8981754f..3f2106c80bf 100644 --- a/app/models/application_setting_implementation.rb +++ b/app/models/application_setting_implementation.rb @@ -219,22 +219,15 @@ module ApplicationSettingImplementation self.outbound_local_requests_whitelist.uniq! end + # This method separates out the strings stored in the + # application_setting.outbound_local_requests_whitelist array into 2 arrays; + # an array of IPAddr objects (`[IPAddr.new('127.0.0.1')]`), and an array of + # domain strings (`['www.example.com']`). def outbound_local_requests_whitelist_arrays strong_memoize(:outbound_local_requests_whitelist_arrays) do next [[], []] unless self.outbound_local_requests_whitelist - ip_whitelist = [] - domain_whitelist = [] - - self.outbound_local_requests_whitelist.each do |str| - ip_obj = Gitlab::Utils.string_to_ip_object(str) - - if ip_obj - ip_whitelist << ip_obj - else - domain_whitelist << str - end - end + ip_whitelist, domain_whitelist = separate_whitelists(self.outbound_local_requests_whitelist) [ip_whitelist, domain_whitelist] end @@ -360,6 +353,20 @@ module ApplicationSettingImplementation private + def separate_whitelists(string_array) + string_array.reduce([[], []]) do |(ip_whitelist, domain_whitelist), string| + ip_obj = Gitlab::Utils.string_to_ip_object(string) + + if ip_obj + ip_whitelist << ip_obj + else + domain_whitelist << string + end + + [ip_whitelist, domain_whitelist] + end + end + def array_to_string(arr) arr&.join("\n") end |