fog / fog-rackspace

Rackspace provider gem for Fog ecosystem
MIT License
8 stars 35 forks source link

Error: wrong constant name CDN v2 (NameError) #43

Open vyankateshmadgundi-ayla opened 10 months ago

vyankateshmadgundi-ayla commented 10 months ago

lib/fog/rackspace.rb service has a wrong model name

service(:cdn_v2, 'CDN v2') service(:compute_v2, 'Compute v2')

Should replace with

service(:cdn_v2, 'CDNV2') service(:compute_v2, 'ComputeV2')

Throwing an error: /usr/local/bundle/ruby/2.6.0/gems/fog-core-2.3.0/lib/fog/core/provider.rb:49:in `const_defined?': wrong constant name CDN v2 (NameError)

shoutsid commented 5 months ago

We have also experienced this, to work around this issue, the following is what we have implemented for now.

# file: lib/patches/fog/provider.rb
# frozen_string_literal: true

# This is a monkeypatch to workaround this bug in the Fog-Rackspace gem:
# https://github.com/fog/fog-rackspace/issues/43

module Fog
  module Provider
    # Intercepts constant definition check to correct broken name in Fog gem
    def const_defined?(name, inherit = true)
      Object.const_defined? fixed_constant_name(name), inherit
    end

    # Intercepts constant get to correct broken name in Fog gem
    def const_get(name, inherit = true)
      Object.const_get fixed_constant_name(name), inherit
    end

    private

    # @param [String] name The requested constant name
    # @return [String] The corrected constant name
    def fixed_constant_name(name)
      return 'Fog::Rackspace::CDNV2' if name == 'Fog::Rackspace::CDN v2'
      return 'Fog::Rackspace::ComputeV2' if name == 'Fog::Rackspace::Compute v2'

      name
    end
  end
end
# file: config/application.rb

# Monkeypatch for a bug in the Fog-Rackspace gem
require_relative '../lib/patches/fog/provider'

# Rest of file here....

Looking forward to a fix! 🥳