digitalocean / droplet_kit

DropletKit is the official DigitalOcean API client for Ruby.
MIT License
515 stars 152 forks source link

Action 'delete' is already defined on `DropletKit::CDNResource` #305

Open ivs opened 2 years ago

ivs commented 2 years ago

Hi! Any call to droplet_kit api gives me this error:

ArgumentError: Action 'delete' is already defined on `DropletKit::CDNResource`
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/resource_kit-0.1.8/lib/resource_kit/method_factory.rb:6:in `block in construct'
C:/Ruby31-x64/lib/ruby/3.1.0/forwardable.rb:238:in `each'
C:/Ruby31-x64/lib/ruby/3.1.0/forwardable.rb:238:in `each'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/resource_kit-0.1.8/lib/resource_kit/method_factory.rb:4:in `construct'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/resource_kit-0.1.8/lib/resource_kit/resource.rb:20:in `resources'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/droplet_kit-3.18.0/lib/droplet_kit/resources/cdn_resource.rb:7:in `<class:CDNResource>'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/droplet_kit-3.18.0/lib/droplet_kit/resources/cdn_resource.rb:4:in `<module:DropletKit>'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/droplet_kit-3.18.0/lib/droplet_kit/resources/cdn_resource.rb:3:in `<top (required)>'
<internal:C:/Ruby31-x64/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
<internal:C:/Ruby31-x64/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/droplet_kit-3.18.0/lib/droplet_kit/client.rb:34:in `resources'
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/droplet_kit-3.18.0/lib/droplet_kit/client.rb:69:in `method_missing'

I've commented out this exception in resource_kit/method_factory.rb like this:

module ResourceKit
  class MethodFactory
    def self.construct(object, resource_collection, invoker = ActionInvoker)
      resource_collection.each do |action|
        if object.method_defined?(action.name)
          # raise ArgumentError, "Action '#{action.name}' is already defined on `#{object}`"
          next
        end

And it works fine. Exception raised for delete action for each resource.

andrewsomething commented 2 years ago

Hi @ivs,

I am unable to reproduce this issue. Can you share anything more about your code and environment that might help use reproduce the problem?

ivs commented 2 years ago

I'm using lib from capistrano like this:

require "droplet_kit"
do_client = DropletKit::Client.new(access_token: '')
task :create_nodes do
    locations = ['nyc3', 'lon1', 'lon1']
    locations.each_with_index do |loc, i|
        droplet = DropletKit::Droplet.new(name: "relay#{i}", region: loc, image: 'ubuntu-22-04-x64', size: 's-1vcpu-1gb', tags: ["web"], ssh_keys: [123])   
        do_client.droplets.create droplet
    end
end

Capistrano Version: 3.17.1 (Rake Version: 13.0.6)