berkshelf / ridley

A reliable Chef API client with a clean syntax
Other
231 stars 85 forks source link

can't convert Proc into String #285

Closed ng-pgill closed 9 years ago

ng-pgill commented 9 years ago

Ruby version: 1.9.3-p547 Ridley version: 4.1.0

gems/ridley-4.1.0/lib/ridley/client.rb:145:in `expand_path': can't convert Proc into String (TypeError)

in client.rb (line 141):

unless verify_client_key(@options[:client_key])
    @options[:client_key] = File.expand_path(@options[:client_key])
    raise Errors::ClientKeyFileNotFoundOrInvalid, "client key is invalid or not found at: '#{@options[:client_key]}'" unless File.exist?(@options[:client_key]) && verify_client_key(::IO.read(@options[:client_key]))
end

if the :client_key refers to a Proc object, the expand_path call will fail and the error will be can't convert Proc into String.

Would have expect this error: Ridley::Errors::ClientKeyFileNotFoundOrInvalid client key is invalid or not found at: '/etc/chef/client.pem'

in config.rb (line 50): we see that a Proc is defined for :client_key

   attribute :client_key,
      default: -> { platform_specific_path('/etc/chef/client.pem') }

I patched client.rb this way for testing:

unless verify_client_key(@options[:client_key])
    if @options[:client_key].kind_of? Proc
        @options[:client_key] = @options[:client_key].call()
    end
    @options[:client_key] = File.expand_path(@options[:client_key])
    raise Errors::ClientKeyFileNotFoundOrInvalid, "client key is invalid or not found at: '#{@options[:client_key]}'" unless File.exist?(@options[:client_key]) && verify_client_key(::IO.read(@options[:client_key]))
end
andrewgross commented 9 years ago

Had this same issue hit me. An unfortunate error message.

sethvargo commented 9 years ago

@pgddevil @andrewgross what command/code are you running that causes this data to be passed in like this? That's true that it's defined as a proc, but varia_model is smart enough to call that proc under certain situations. I'm having trouble finding the code path to make this happen...

andrewgross commented 9 years ago

Hey @sethvargo, here is a rundown of the simplest way to cause the issue for me.

Berkshelf 3.1.5 (via ChefDK) Running Berkshelf API Local Server (hooked up to my hosted Chef server) PATH: /opt/chefdk/bin:/Users/awgross/.chefdk/gem/ruby/2.1.0/bin:/opt/chefdk/embedded/bin:/Users/awgross/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/awgross/bin

  1. Create a new cookbook using ChefDK, chef generate cookbook foobar
  2. Point the Berksfile to my local API server, source "http://127.0.0.1:26200"
  3. Add a public (supermarket) dependency in the metadata. I am unsure if this last step is required.
  4. Run berks upload foobar

This will trigger the linked stacktrace. At the time I had this issue, I did not have any file at ~/.berkshelf/config.json, nor did I have any knife configuration files, or any Chef files in /etc. As far as I can tell I had no Chef configuration files in scope.

Stacktrace: https://gist.github.com/andrewgross/95cc2fb31b20a9bd59c1

Let me know if you need more info, or you suspect I am mistaken about how I have my environment setup.

legal90 commented 9 years ago

I have the same issue too.

@reset Could you please check this out?

matt-richardson commented 9 years ago

Any progress on this one? Just started facing this one in multiple places (not sure what changed to make it start happening though).

Is the code by @pgddevil acceptable? Can we turn it into a PR and get a fix out?

brandt commented 9 years ago

@matt-richardson I've created a PR to fix this issue in #295