diff --git a/Gemfile b/Gemfile index 1a3ad75b5cd..0178ca9f352 100644 --- a/Gemfile +++ b/Gemfile @@ -95,7 +95,9 @@ gem 'mini_magick' # for backups gem 'fog-aws', '~> 3.3' -gem 'fog-core', '~> 2.1' +# Locked until fog-google resolves https://github.com/fog/fog-google/issues/421. +# Also see config/initializers/fog_core_patch.rb. +gem 'fog-core', '= 2.1.0' gem 'fog-google', '~> 1.8' gem 'fog-local', '~> 0.6' gem 'fog-openstack', '~> 1.0' diff --git a/Gemfile.lock b/Gemfile.lock index ef201cfebaa..92944a32d82 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1005,7 +1005,7 @@ DEPENDENCIES flowdock (~> 0.7) fog-aliyun (~> 0.3) fog-aws (~> 3.3) - fog-core (~> 2.1) + fog-core (= 2.1.0) fog-google (~> 1.8) fog-local (~> 0.6) fog-openstack (~> 1.0) diff --git a/config/initializers/fog_core_patch.rb b/config/initializers/fog_core_patch.rb new file mode 100644 index 00000000000..9669f332611 --- /dev/null +++ b/config/initializers/fog_core_patch.rb @@ -0,0 +1,50 @@ +# fog-core v2 changed the namespace format: +# +# Old: Fog:::: (e.g. Fog::Storage::AWS). +# New: Fog:::: (e.g. Fog::AWS::Storage) +# +# To preserve backwards compatibility, fog-core v2.1.0 tries to load the +# old schema first, but falls back to the older version if that +# fails. This creates misleading warnings with fog-aws. See +# https://github.com/fog/fog-aws/issues/504#issuecomment-468067991 for +# more details. +# +# fog-core v2.1.2 reverses the load order +# (https://github.com/fog/fog-core/pull/229), which works for fog-aws +# but causes a stream of deprecation warnings for fog-google. +# fog-google locked the dependency on fog-core v2.1.0 as a result +# (https://github.com/fog/fog-google/issues/421) until the new namespace +# is supported. +# +# Since we currently have some Fog gems that have not been updated, this +# monkey patch makes a smarter decision about which namespace to try +# first. This squelches a significant number of warning messages. +# +# Since this patch is mostly cosmetic, it can be removed safely at any +# time, but it's probably best to wait until the following issues are +# closed: +# +# fog-google: https://github.com/fog/fog-google/issues/421 +# fog-rackspace: https://github.com/fog/fog-rackspace/issues/29 +# fog-aliyun: https://github.com/fog/fog-aliyun/issues/23 +module Fog + module ServicesMixin + # Gems that have not yet updated with the new fog-core namespace + LEGACY_FOG_PROVIDERS = %w(google rackspace aliyun).freeze + + def service_provider_constant(service_name, provider_name) + args = service_provider_search_args(service_name, provider_name) + Fog.const_get(args.first).const_get(*const_get_args(args.second)) + rescue NameError # Try to find the constant from in an alternate location + Fog.const_get(args.second).const_get(*const_get_args(args.first)) + end + + def service_provider_search_args(service_name, provider_name) + if LEGACY_FOG_PROVIDERS.include?(provider_name.downcase) + [service_name, provider_name] + else + [provider_name, service_name] + end + end + end +end