Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookbook enumerator methods 'all', 'each' fail #65

Open
rjhornsby opened this issue Jul 20, 2018 · 0 comments
Open

Cookbook enumerator methods 'all', 'each' fail #65

rjhornsby opened this issue Jul 20, 2018 · 0 comments

Comments

@rjhornsby
Copy link

Iterating over all the clients works fine:

Client.each do |client|
  pp client
end

However, attempting to iterate (.all, .each) over all the cookbooks the same way fails. It seems like chef-api is trying to process the JSON response as if it is a URL.

Cookbook.each do |cookbook|
  pp cookbook
end
/opt/chefdk/embedded/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/rhornsby/projects/git/cookbook_version_check/analyze.rb
             ChefAPI::Connection | ===> GET cookbooks...
             ChefAPI::Connection |      Chef flavor: :open_source
             ChefAPI::Connection | ===> Building URI...
             ChefAPI::Connection |      Detected URI is relative
             ChefAPI::Connection |      Appending cookbooks to https://chef.ourdomain.org/organizations/our_org
             ChefAPI::Connection | ===> Adding request headers...
             ...
             ChefAPI::Connection |      Raw response:
/opt/chefdk/embedded/lib/ruby/2.5.0/uri/rfc3986_parser.rb:18:in `rescue in split': bad URI(is not URI?): {"url"=>"https://chef.ourdomain.org/organizations/our_org/cookbooks/vagrant", "versions"=>[{"version"=>"0.8.0", "url"=>"https://chef.ourdomain.org/organizations/our_org/cookbooks/vagrant/0.8.0"}]} (URI::InvalidURIError)
	from /opt/chefdk/embedded/lib/ruby/2.5.0/uri/rfc3986_parser.rb:15:in `split'
	from /opt/chefdk/embedded/lib/ruby/2.5.0/uri/rfc3986_parser.rb:73:in `parse'
	from /opt/chefdk/embedded/lib/ruby/2.5.0/uri/common.rb:237:in `parse'
	from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-api-0.8.0/lib/chef-api/connection.rb:340:in `build_uri'
	from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-api-0.8.0/lib/chef-api/connection.rb:204:in `request'
	from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-api-0.8.0/lib/chef-api/connection.rb:108:in `get'
	from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-api-0.8.0/lib/chef-api/resources/base.rb:366:in `block in each'
	from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-api-0.8.0/lib/chef-api/resources/base.rb:365:in `each'
	from /opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-api-0.8.0/lib/chef-api/resources/base.rb:365:in `each'
	from /Users/rhornsby/projects/git/cookbook_version_check/analyze.rb:24:in `<top (required)>'
	from -e:1:in `load'
	from -e:1:in `<main>'
             ChefAPI::Connection |

             ### ***** JSON object containing entire(?) cookbook list **** ###

             ChefAPI::Connection | ===> Parsing response as success...
             ChefAPI::Connection |      Detected response as JSON
             ChefAPI::Connection |      Parsing response body as JSON
             ChefAPI::Connection | ===> GET {"url"=>"https://chef.ourdomain.org/organizations/our_org/cookbooks/vagrant", "versions"=>[{"version"=>"0.8.0", "url"=>"https://chef.ourdomain.org/organizations/our_org/cookbooks/vagrant/0.8.0"}]}...
             ChefAPI::Connection |      Chef flavor: :open_source
             ChefAPI::Connection | ===> Building URI...

Process finished with exit code 1

The intermediate workaround is to a two step process. Use .list, which gives back just the cookbook names, and then iterate over those names calling Cookbook.fetch. In terms of workarounds, it's not horrible.

@rjhornsby rjhornsby changed the title Cookbook enumerator methods all, each fail Cookbook enumerator methods 'all', 'each' fail Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant