Created
February 9, 2010 21:56
-
-
Save chef/299719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given /^an? '(.+)' named '(.+)' exists$/ do |stash_name, stash_key| | |
http_method = "post" | |
case stash_name | |
when "registration" | |
r = Chef::REST.new("http://localhost/organizations/clownco", 'clownco-validator', "#{tmpdir}/validation.pem") | |
r.register("bobo", "#{tmpdir}/bobo.pem") | |
# set default rest client to the registration | |
@rest = Chef::REST.new("http://localhost/organizations/clownco", 'bobo', "#{tmpdir}/bobo.pem") | |
@stash['bobo'] = { :user_id => 'bobo', :secret_key_filename => "#{tmpdir}/bobo.pem" } | |
when "user" | |
self.response = self.inflated_response = Chef::REST.new('http://localhost', "clownco" , File.join(Dir.tmpdir, "clownco.pem")).post_rest("/users", get_fixture(stash_name,stash_key)) | |
File.open(File.join(Dir.tmpdir,"#{stash_key}.pem"), "w") { |f| f.write(self.inflated_response["private_key"])} | |
@stash[stash_key] = { :user_id=>stash_key, :secret_key_filename => File.join(Dir.tmpdir,"#{stash_key}.pem")} | |
else | |
@stash[stash_name] = get_fixture(stash_name, stash_key) | |
@rest = Chef::REST.new("http://localhost/organizations/clownco", 'bobo', "#{tmpdir}/bobo.pem") | |
request_uri = case stash_name | |
when "data_bag" | |
"/data" | |
when "data_bag_item" | |
http_method = "put" | |
"/data/#{@stash['data_bag'].name}/#{stash_key}" | |
else | |
"/#{stash_name.pluralize}" | |
end | |
begin | |
self.response = self.inflated_response = @rest.send("#{http_method}_rest".to_sym, request_uri, @stash[stash_name]) | |
rescue | |
self.exception = $! | |
raise | |
nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment