Class: GoogleCloud::FetchGoogleIpListService

Inherits:
Object
  • Object
show all
Includes:
BaseServiceUtility
Defined in:
app/services/google_cloud/fetch_google_ip_list_service.rb

Constant Summary collapse

GOOGLE_IP_RANGES_URL =
'https://www.gstatic.com/ipranges/cloud.json'
RESPONSE_BODY_LIMIT =
1.megabyte
EXPECTED_CONTENT_TYPE =
'application/json'
IpListNotRetrievedError =
Class.new(StandardError)

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/google_cloud/fetch_google_ip_list_service.rb', line 13

def execute
  # Prevent too many workers from hitting the same HTTP endpoint
  if ::Gitlab::ApplicationRateLimiter.throttled?(:fetch_google_ip_list, scope: nil)
    return error("#{self.class} was rate limited")
  end

  subnets = fetch_and_update_cache!

  Gitlab::AppJsonLogger.info(
    class: self.class.name,
    message: 'Successfully retrieved Google IP list',
    subnet_count: subnets.count
  )

  success({ subnets: subnets })
rescue IpListNotRetrievedError => err
  Gitlab::ErrorTracking.log_exception(err)
  error('Google IP list not retrieved')
end