bmarini / knife-inspect

Inspect your chef repo as is compares to what is on your chef server
MIT License
55 stars 13 forks source link

Add metadata.json support in cookbooks #26

Closed kamaradclimber closed 10 years ago

kamaradclimber commented 10 years ago

Berkshelf vendors cookbooks with compiled metadata file (in json) instead of metadata.rb. We test for both and prefer rb format

fixes bmarini/knife-inspect#5

gregkare commented 10 years ago

I'm going to try to refactor that code, it was already a mess before. We should be able to use classes from Chef to avoid reinventing the wheel. Thanks for the pull request!

kamaradclimber commented 10 years ago

@gregkare agreed that some of this code duplicate chef code

gregkare commented 10 years ago

Here's what I came up with:

      def local_items
        cl = Chef::CookbookLoader.new(@context.cookbook_path)
        cl.load_cookbooks

        cl.inject({}) do |hash, (name, cookbook_version)|
          hash[name] = Chef::Version.new(cookbook_version.version)

          hash
        end
      end

It still passes the tests, now checking how it behaves when there's both a json and rb file

gregkare commented 10 years ago

It loads the metadata.rb first when it exists, nice. Do you want to rebase your pull request to do this instead? I'm always happy to see some code get deleted :)

Edit: Chef::CookbookLoader exists in Chef 10 too, so it should work there too

kamaradclimber commented 10 years ago

https://github.com/opscode/chef/blob/master/lib/chef/cookbook/cookbook_version_loader.rb#L107

rb first, then json, then a new object that I didn't know about: uploaded_cookbook_version_file

kamaradclimber commented 10 years ago

this PR can be closed then

gregkare commented 10 years ago

Ok, I'll do a pull request then, I've also used a metadata.json file in spec/chef-repo/cookbooks/cookbook_two. Thanks!