Question

Droplet Kit Gem not returning anything useful - can't see firewalls, nothing.

Posted June 23, 2020 83 views
APIFirewall

So I’m in the process of implementing the droplet_kit gem within my Ruby on Rails application and I’m having issues just performing very basic commands.

I’m following the instructions here for getting started: https://github.com/digitalocean/droplet_kit

According to the “Usage” section, you just simply need to generate an access token at that URL, which I have done. Now, when I try to access some of the methods like client.firewalls.all(), I don’t get anything useful back.

For example:

[2] pry(#<DigitalOcean>)> @client.firewalls.all()
=> #<DropletKit::PaginatedResource:0x000056478a6ad5b0
 @action=
  #<ResourceKit::Action:0x000056478a9a5358
   @handlers=
    {:any=>#<Proc:0x000056478a9a6410@/usr/local/rvm/gems/ruby-2.5.8/gems/droplet_kit-3.8.0/lib/droplet_kit/error_handling_resourcable.rb:4>,
     200=>#<Proc:0x000056478a9a5128@/usr/local/rvm/gems/ruby-2.5.8/gems/droplet_kit-3.8.0/lib/droplet_kit/resources/firewall_resource.rb:24>},
   @name=:all,
   @path="/v2/firewalls",
   @query_keys=[:per_page, :page],
   @verb=:get>,
 @args=[],
 @collection=[],
 @current_page=0,
 @options={},
 @resource=
  #<DropletKit::FirewallResource:0x000056478a8a6ab0
   @connection=
    #<Faraday::Connection:0x000056478a8b5600
     @builder=#<Faraday::RackBuilder:0x000056478a8b5088 @adapter=Faraday::Adapter::NetHttp, @handlers=[]>,
     @default_parallel_manager=nil,
     @headers={"Content-Type"=>"application/json", "Authorization"=>"Bearer [redacted]", "User-Agent"=>"DropletKit/3.8.0 Faraday/1.0.1"},
     @manual_proxy=false,
     @options=#<struct Faraday::RequestOptions params_encoder=nil, proxy=nil, bind=nil, timeout=120, open_timeout=60, read_timeout=nil, write_timeout=nil, boundary=nil, oauth=nil, context=nil, on_data=nil>,
     @parallel_manager=nil,
     @params={},
     @proxy=nil,
     @ssl=
      #<struct Faraday::SSLOptions
       verify=nil,
       ca_file=nil,
       ca_path=nil,
       verify_mode=nil,
       cert_store=nil,
       client_cert=nil,
       client_key=nil,
       certificate=nil,
       private_key=nil,
       verify_depth=nil,
       version=nil,
       min_version=nil,
       max_version=nil>,
     @url_prefix=#<URI::HTTPS https://api.digitalocean.com/>>,
   @scope=nil>,
 @total=nil>

Here’s how I’m establishing the @client variable:

class DigitalOcean
    def initialize
        token = Rails.application.credentials.digital_ocean
        @client = DropletKit::Client.new(access_token: token)
        @firewalls = list_firewalls
    end

    def list_firewalls
        binding.pry
    end

    def add_whitelist(ip)
    end

    def remove_whitelist(ip)
    end
end

I have verified that my token is accessible and is the same access token generated by DigitalOcean, but yet I can’t see anything.

Any help would be greatly appreciated.

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Nevermind. I just realized that the variable itself doesn’t show anything valuable, but you can iterate through the actual firewalls just fine if you put it inside of a loop.

Submit an Answer