Class: CloudSeed::GoogleCloud::FetchGoogleIpListService

Inherits:
Object
  • Object
show all
Includes:
BaseServiceUtility
Defined in:
app/services/cloud_seed/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?, #can_all?, #can_any?

Instance Method Details

#executeObject



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

def execute
  # Prevent too many workers from hitting the same HTTP endpoint
  if ::Gitlab::ApplicationRateLimiter.throttled?(:fetch_google_ip_list, scope: :global)
    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