Module: API::Helpers::Packages::DependencyProxyHelpers

Defined in:
lib/api/helpers/packages/dependency_proxy_helpers.rb

Constant Summary collapse

REGISTRY_BASE_URLS =
{
  npm: 'https://registry.npmjs.org/'
}.freeze

Instance Method Summary collapse

Instance Method Details

#redirect_registry_request(forward_to_registry, package_type, options) ⇒ Object


11
12
13
14
15
16
17
18
# File 'lib/api/helpers/packages/dependency_proxy_helpers.rb', line 11

def redirect_registry_request(forward_to_registry, package_type, options)
  if forward_to_registry && redirect_registry_request_available?
    track_event("#{package_type}_request_forward")
    redirect(registry_url(package_type, options))
  else
    yield
  end
end

#redirect_registry_request_available?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/api/helpers/packages/dependency_proxy_helpers.rb', line 31

def redirect_registry_request_available?
  ::Gitlab::CurrentSettings.current_application_settings.npm_package_requests_forwarding
end

#registry_url(package_type, options) ⇒ Object

Raises:

  • (ArgumentError)

20
21
22
23
24
25
26
27
28
29
# File 'lib/api/helpers/packages/dependency_proxy_helpers.rb', line 20

def registry_url(package_type, options)
  base_url = REGISTRY_BASE_URLS[package_type]

  raise ArgumentError, "Can't build registry_url for package_type #{package_type}" unless base_url

  case package_type
  when :npm
    "#{base_url}#{options[:package_name]}"
  end
end