Merb could not be reached"
18 |
--------------------------------------------------------------------------------
/chef-server-slice/lib/chef-server-slice/slicetasks.rb:
--------------------------------------------------------------------------------
1 | namespace :slices do
2 | namespace :chefserverslice do
3 |
4 | # add your own chefserver tasks here
5 |
6 | # # Uncomment the following lines and edit the pre defined tasks
7 | #
8 | # # implement this to test for structural/code dependencies
9 | # # like certain directories or availability of other files
10 | # desc "Test for any dependencies"
11 | # task :preflight do
12 | # end
13 | #
14 | # # implement this to perform any database related setup steps
15 | # desc "Migrate the database"
16 | # task :migrate do
17 | # end
18 |
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/chef-server-slice/spec/requests/openid_register_spec.rb:
--------------------------------------------------------------------------------
1 | require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2 |
3 | describe "/chefserverslice/openid_register" do
4 |
5 | before(:all) do
6 | mount_slice
7 | end
8 |
9 | describe "GET /" do
10 | before(:each) do
11 | @response = request("/chefserverslice/registrations")
12 | end
13 |
14 | it "should be successful" do
15 | @response.status.should be_successful
16 | end
17 |
18 | it "should have registered nodes list" do
19 | @response.should have_tag(:h3, :content=>"Registered OpenID Nodes List")
20 | end
21 | end
22 |
23 | after(:all) do
24 | dismount_slice
25 | end
26 |
27 | end
28 |
--------------------------------------------------------------------------------
/chef/config/server.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Example Chef Server Config
3 |
4 | log_level :debug
5 |
6 | cookbook_path File.join(File.dirname(__FILE__), "..", "examples", "config", "cookbooks")
7 | node_path File.join(File.dirname(__FILE__), "..", "examples", "config", "nodes")
8 | file_store_path File.join(File.dirname(__FILE__), "..", "examples", "store")
9 | openid_store_path File.join(File.dirname(__FILE__), "..", "examples", "openid-db")
10 | openid_cstore_path File.join(File.dirname(__FILE__), "..", "examples", "openid-cstore")
11 | search_index_path File.join(File.dirname(__FILE__), "..", "examples", "search_index")
12 |
13 | # openid_providers [ "localhost:4001", "openid.hjksolutions.com" ]
14 |
15 | Chef::Log::Formatter.show_time = false
16 |
--------------------------------------------------------------------------------
/features/data/cookbooks/manage_files/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: files
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 |
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-72-define/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-72-define
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
--------------------------------------------------------------------------------
/chef/examples/user_index.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | #
3 | # Create a users index, based on /etc/passwd
4 |
5 | require 'etc'
6 | require File.join(File.dirname(__FILE__), "..", "lib", "chef")
7 |
8 | Chef::Config[:log_level] = :info
9 | r = Chef::REST.new("http://localhost:4000")
10 |
11 | users = Array.new
12 | Etc.passwd do |passwd|
13 | Chef::Log.info("Ensuring we have #{passwd.name}")
14 | r.post_rest("search/user/entries",
15 | {
16 | :id => passwd.name,
17 | :name => passwd.name,
18 | :uid => passwd.uid,
19 | :gid => passwd.gid,
20 | :gecos => passwd.gecos,
21 | :dir => passwd.dir,
22 | :shell => passwd.shell,
23 | :change => passwd.change,
24 | :expire => passwd.expire
25 | }
26 | )
27 | end
28 |
--------------------------------------------------------------------------------
/features/data/cookbooks/delayed_notifications/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: delayed_notifications
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
--------------------------------------------------------------------------------
/features/data/cookbooks/transfer_remote_files/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: transfer_remote_files
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
--------------------------------------------------------------------------------
/chef-server/config/rack.rb:
--------------------------------------------------------------------------------
1 | # use PathPrefix Middleware if :path_prefix is set in Merb::Config
2 | if prefix = ::Merb::Config[:path_prefix]
3 | use Merb::Rack::PathPrefix, prefix
4 | end
5 |
6 | # comment this out if you are running merb behind a load balancer
7 | # that serves static files
8 | use Merb::Rack::Static, Merb.dir_for(:public)
9 |
10 | Merb::Slices.config.each do |slice_module, config|
11 | slice_module = Object.full_const_get(slice_module.to_s.camel_case) if slice_module.class.in?(String, Symbol)
12 | slice_module.send("public_components").each do |component|
13 | slice_static_dir = slice_module.send("dir_for", :public)
14 | use Merb::Rack::Static, slice_static_dir
15 | end
16 | end
17 |
18 | # this is our main merb application
19 | run Merb::Rack::Application.new
20 |
--------------------------------------------------------------------------------
/features/data/cookbooks/manage_files/recipes/touch_a_file.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: files
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | file "#{node[:tmpdir]}/touch_test.txt" do
21 | action :touch
22 | end
--------------------------------------------------------------------------------
/features/data/cookbooks/manage_files/recipes/create_a_file.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: files
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | file "#{node[:tmpdir]}/create_a_file.txt" do
21 | action :create
22 | end
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-59/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-59
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | package "zsh" do
21 | action [ :install, :upgrade, :remove, :upgrade, :purge ]
22 | end
--------------------------------------------------------------------------------
/chef-server-slice/spec/requests/main_spec.rb:
--------------------------------------------------------------------------------
1 | require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2 |
3 | describe "/chefserverslice/" do
4 |
5 | before(:all) do
6 | mount_slice
7 | end
8 |
9 | describe "GET /" do
10 |
11 | before(:each) do
12 | @response = request("/chefserverslice/")
13 | end
14 |
15 | it "should be successful" do
16 | @response.status.should be_successful
17 | end
18 |
19 | # This is just an example of what you can do
20 | # You can also use the other webrat methods to click links,
21 | # fill up forms etc...
22 | it "should render the default slice layout" do
23 | @response.should have_tag(:title, :content => "Chef Server")
24 | end
25 |
26 | end
27 |
28 | after(:all) do
29 | dismount_slice
30 | end
31 |
32 | end
33 |
--------------------------------------------------------------------------------
/chef-server/public/merb.fcgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require 'rubygems'
4 | require 'merb-core'
5 |
6 | # this is Merb.root, change this if you have some funky setup.
7 | merb_root = File.expand_path(File.dirname(__FILE__) / '../')
8 |
9 | # If the fcgi process runs as apache, make sure
10 | # we have an inlinedir set for Rubyinline action-args to work
11 | unless ENV["INLINEDIR"] || ENV["HOME"]
12 | tmpdir = merb_root / "tmp"
13 | unless File.directory?(tmpdir)
14 | Dir.mkdir(tmpdir)
15 | end
16 | ENV["INLINEDIR"] = tmpdir
17 | end
18 |
19 | # start merb with the fcgi adapter, add options or change the log dir here
20 | Merb.start(:adapter => 'fcgi',
21 | :merb_root => merb_root,
22 | :log_file => merb_root /'log'/'merb.log')
--------------------------------------------------------------------------------
/chef-server-slice/spec/requests/cookbooks_spec.rb:
--------------------------------------------------------------------------------
1 | require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2 |
3 | describe "/chefserverslice/" do
4 |
5 | before(:all) do
6 | mount_slice
7 | end
8 |
9 | describe "GET /" do
10 |
11 | before(:each) do
12 | @response = request("/chefserverslice/")
13 | end
14 |
15 | it "should be successful" do
16 | @response.status.should be_successful
17 | end
18 |
19 | # This is just an example of what you can do
20 | # You can also use the other webrat methods to click links,
21 | # fill up forms etc...
22 | it "should render the default slice layout" do
23 | @response.should have_tag(:title, :content => "Chef Server")
24 | end
25 |
26 | end
27 |
28 | after(:all) do
29 | dismount_slice
30 | end
31 |
32 | end
33 |
--------------------------------------------------------------------------------
/example-repository/config/server.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Server Config File
3 | #
4 | # Dynamically generated by Chef - local modifications will be replaced
5 | #
6 |
7 |
8 | log_level :info
9 | log_location STDOUT
10 | file_store_path "/var/chef/file_store"
11 | file_cache_path "/var/chef/cache"
12 | ssl_verify_mode :verify_none
13 | registration_url "http://127.0.0.1:4000"
14 | openid_url "http://127.0.0.1:4001"
15 | template_url "http://127.0.0.1:4000"
16 | remotefile_url "http://127.0.0.1:4000"
17 | search_url "http://127.0.0.1:4000"
18 | cookbook_path [ "/var/chef/site-cookbooks", "/var/chef/cookbooks" ]
19 | openid_store_path "/var/chef/openid/store"
20 | openid_cstore_path "/var/chef/openid/cstore"
21 | search_index_path "/var/chef/search_index"
22 |
23 | Chef::Log::Formatter.show_time = false
24 |
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-57/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-57
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | script "boo" do
21 | user 'adam'
22 | code "print 'I like cheese';"
23 | interpreter "perl"
24 | end
--------------------------------------------------------------------------------
/features/data/cookbooks/transfer_remote_files/recipes/transfer_a_file_from_a_specific_cookbook.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: transfer_remote_files
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | transfer_cookbook "from_definition.txt"
21 |
--------------------------------------------------------------------------------
/features/data/cookbooks/manage_files/recipes/delete_a_file_that_does_not_already_exist.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: files
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | file "#{node[:tmpdir]}/create_a_file.txt" do
21 | action :delete
22 | end
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Chef NOTICE
2 | ===========
3 |
4 | Developed at Opscode (http://www.opscode.com).
5 |
6 | Contributors and Copyright holders:
7 |
8 | * Copyright 2008, Adam Jacob
9 | * Copyright 2008, Arjuna Christensen
10 | * Copyright 2008, Bryan McLellan
11 | * Copyright 2008, Ezra Zygmuntowicz
12 | * Copyright 2009, Sean Cribbs
13 | * Copyright 2009, Christopher Brown
14 | * Copyright 2009, Thom May
15 | * Copyright 2009, Joe Williams
16 |
17 | Chef incorporates code modified from Open4 (http://www.codeforpeople.com/lib/ruby/open4/), which was written by Ara T. Howard.
18 |
19 | Chef incorporates code modified from Merb (http://www.merbivore.com), which is Copyright (c) 2008 Engine Yard.
20 |
--------------------------------------------------------------------------------
/features/data/cookbooks/manage_files/recipes/set_the_owner_of_a_created_file.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: files
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | file "#{node[:tmpdir]}/create_a_file.txt" do
21 | owner 'nobody'
22 | action :create
23 | end
--------------------------------------------------------------------------------
/chef-server/config/init.rb:
--------------------------------------------------------------------------------
1 | # Go to http://wiki.merbivore.com/pages/init-rb
2 |
3 | require 'config/dependencies.rb'
4 | require 'chef'
5 |
6 | use_test :rspec
7 | use_template_engine :haml
8 |
9 | Merb::Config.use do |c|
10 | c[:use_mutex] = false
11 | c[:session_id_key] = '_chef_server_session_id'
12 | c[:session_secret_key] = Chef::Config.manage_secret_key
13 | c[:session_store] = 'cookie'
14 | c[:exception_details] = true
15 | c[:reload_classes] = false
16 | c[:log_level] = Chef::Config[:log_level]
17 | c[:log_stream] = Chef::Config[:log_location]
18 | end
19 |
20 | Merb::BootLoader.before_app_loads do
21 | # This will get executed after dependencies have been loaded but before your app's classes have loaded.
22 | end
23 |
24 | Merb::BootLoader.after_app_loads do
25 | # This will get executed after your app's classes have been loaded.
26 | end
27 |
--------------------------------------------------------------------------------
/chef-server-slice/app/views/nodes/_resource.html.haml:
--------------------------------------------------------------------------------
1 | .resource
2 | %h3= "#{h resource.to_s} (#{resource.class})"
3 | %table
4 | - resource.instance_variables.sort.each do |v|
5 | - attr_name = v.gsub(/\@/, "")
6 | - unless attr_name == "collection"
7 | %tr.attr_group
8 | %td.attr_name
9 | = "#{h attr_name}"
10 | %td.attr_value
11 | - value = resource.instance_variable_get(v)
12 | - if value.kind_of?(String)
13 | = "#{h value}"
14 | - elsif value.kind_of?(Array)
15 | = "#{h value.join(", ")}"
16 | - elsif value.kind_of?(Symbol)
17 | = "#{h value.to_s}"
18 | - elsif attr_name == "actions"
19 | = partial(:action, :actions => value)
20 | - else
21 | = "#{h value.inspect}"
22 |
23 |
--------------------------------------------------------------------------------
/features/data/cookbooks/integration_setup/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: integration_setup
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | directory node[:int][:tmpdir] do
21 | owner "root"
22 | mode 1777
23 | action :create
24 | end
25 |
26 |
--------------------------------------------------------------------------------
/features/data/cookbooks/manage_files/recipes/delete_a_file.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: files
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | include_recipe 'manage_files::create_a_file'
21 |
22 | file "#{node[:tmpdir]}/create_a_file.txt" do
23 | action :delete
24 | end
--------------------------------------------------------------------------------
/example-repository/cookbooks/template-test/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: template-test
3 | # Recipe:: default
4 | #
5 | # Copyright 2008, Opscode, Inc.
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | template "/tmp/whazzit" do
21 | variables({
22 | :whosa => "whazzit"
23 | })
24 | source "whazzit.erb"
25 | end
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-56/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-56
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | service "gpm" do
21 | supports :status => true, :restart => true
22 | action [ :restart, :stop, :disable, :start, :enable ]
23 | end
24 |
--------------------------------------------------------------------------------
/chef-server/tasks/merb.thor/utils.rb:
--------------------------------------------------------------------------------
1 | class String
2 | def /(other)
3 | (Pathname.new(self) + other).to_s
4 | end
5 | end
6 |
7 | module ColorfulMessages
8 |
9 | # red
10 | def error(*messages)
11 | puts messages.map { |msg| "\033[1;31m#{msg}\033[0m" }
12 | end
13 |
14 | # yellow
15 | def warning(*messages)
16 | puts messages.map { |msg| "\033[1;33m#{msg}\033[0m" }
17 | end
18 |
19 | # green
20 | def success(*messages)
21 | puts messages.map { |msg| "\033[1;32m#{msg}\033[0m" }
22 | end
23 |
24 | alias_method :message, :success
25 |
26 | # magenta
27 | def note(*messages)
28 | puts messages.map { |msg| "\033[1;35m#{msg}\033[0m" }
29 | end
30 |
31 | # blue
32 | def info(*messages)
33 | puts messages.map { |msg| "\033[1;34m#{msg}\033[0m" }
34 | end
35 |
36 | end
37 |
38 | module ThorUI
39 | extend ColorfulMessages
40 | end
41 |
--------------------------------------------------------------------------------
/features/data/cookbooks/integration_setup/attributes/integration.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: integration_setup
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | require 'tmpdir'
21 |
22 | int(Mash.new)
23 | int[:tmpdir] = File.join(Dir.tmpdir, "chef_integration")
24 |
25 | tmpdir int[:tmpdir]
--------------------------------------------------------------------------------
/features/data/cookbooks/transfer_remote_files/recipes/should_prefer_the_file_for_this_specific_host.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: transfer_remote_files
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | remote_file "#{node[:tmpdir]}/host_specific.txt" do
21 | source "host_specific.txt"
22 | end
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-44/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-44
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 |
21 | execute "sleepy" do
22 | command "echo 'one monster'; sleep 5"
23 | end
24 |
25 |
26 | execute "sleepy2" do
27 | command "sleep 5"
28 | end
29 |
30 |
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-87/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-87
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | remote_file "/tmp/.dotfile" do
21 | source ".dotfile"
22 | end
23 |
24 | execute "cat /tmp/.dotfile"
25 |
26 | file "/tmp/.dotfile" do
27 | action :delete
28 | end
--------------------------------------------------------------------------------
/features/data/config/server.rb:
--------------------------------------------------------------------------------
1 | supportdir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
2 | tmpdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "tmp"))
3 |
4 | log_level :debug
5 | log_location STDOUT
6 | file_cache_path File.join(tmpdir, "cache")
7 | ssl_verify_mode :verify_none
8 | registration_url "http://127.0.0.1:4000"
9 | openid_url "http://127.0.0.1:4001"
10 | template_url "http://127.0.0.1:4000"
11 | remotefile_url "http://127.0.0.1:4000"
12 | search_url "http://127.0.0.1:4000"
13 | cookbook_path File.join(supportdir, "cookbooks")
14 | openid_store_path File.join(tmpdir, "openid", "store")
15 | openid_cstore_path File.join(tmpdir, "openid", "cstore")
16 | search_index_path File.join(tmpdir, "search_index")
17 | validation_token 'ceelo'
18 | couchdb_database 'chef_integration'
19 |
20 | Chef::Log::Formatter.show_time = true
21 |
--------------------------------------------------------------------------------
/chef-server/tasks/merb.thor/app_script.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This was added by Merb's bundler
4 |
5 | require "rubygems"
6 | require File.join(File.dirname(__FILE__), "common")
7 |
8 | gems_dir = File.join(File.dirname(__FILE__), '..', 'gems')
9 |
10 | if File.directory?(gems_dir)
11 | $BUNDLE = true
12 | Gem.clear_paths
13 | Gem.path.replace([File.expand_path(gems_dir)])
14 | ENV["PATH"] = "#{File.dirname(__FILE__)}:#{ENV["PATH"]}"
15 |
16 | gem_file = File.join(gems_dir, "specifications", "<%= spec.name %>-*.gemspec")
17 |
18 | if local_gem = Dir[gem_file].last
19 | version = File.basename(local_gem)[/-([\.\d]+)\.gemspec$/, 1]
20 | end
21 | end
22 |
23 | version ||= "<%= Gem::Requirement.default %>"
24 |
25 | if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
26 | version = $1
27 | ARGV.shift
28 | end
29 |
30 | gem '<%= @spec.name %>', version
31 | load '<%= bin_file_name %>'
--------------------------------------------------------------------------------
/features/data/cookbooks/transfer_remote_files/recipes/transfer_a_file_from_a_cookbook.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: transfer_remote_files
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | remote_file "#{node[:tmpdir]}/transfer_a_file_from_a_cookbook.txt" do
21 | source "transfer_a_file_from_a_cookbook.txt"
22 | end
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-88/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-88
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | remote_file "/tmp/rabbitmq-server_1.4.0-1_all.deb" do
21 | source "http://www.rabbitmq.com/releases/rabbitmq-server/v1.4.0/rabbitmq-server_1.4.0-1_all.deb"
22 | mode 0644
23 | end
24 |
--------------------------------------------------------------------------------
/example-repository/cookbooks/prior_resource_test/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: prior_resource_test
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | file "/tmp/prior_resource_test" do
21 | backup 16
22 | action :create
23 | end
24 |
25 | file "/tmp/prior_resource_test" do
26 | action :delete
27 | end
28 |
--------------------------------------------------------------------------------
/example-repository/config/solo.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Chef Server Config File
3 | #
4 | # Dynamically generated by Chef - local modifications will be replaced
5 | #
6 |
7 |
8 | log_level :info
9 | log_location STDOUT
10 | file_store_path "/var/chef/file_store"
11 | file_cache_path "/var/chef/cache"
12 | ssl_verify_mode :verify_none
13 | registration_url "http://127.0.0.1:4000"
14 | openid_url "http://127.0.0.1:4001"
15 | template_url "http://127.0.0.1:4000"
16 | remotefile_url "http://127.0.0.1:4000"
17 | search_url "http://127.0.0.1:4000"
18 | cookbook_path [ "/var/chef/site-cookbooks", "/var/chef/cookbooks" ]
19 | node_path "/var/chef/nodes"
20 | openid_store_path "/var/chef/openid/store"
21 | openid_cstore_path "/var/chef/openid/cstore"
22 | merb_log_path "/var/log/chef-server.log"
23 | search_index_path "/var/chef/search_index"
24 |
25 | Chef::Log::Formatter.show_time = false
26 |
--------------------------------------------------------------------------------
/features/delayed_notifications.feature:
--------------------------------------------------------------------------------
1 | Feature: Delayed Notifications
2 | In order to not impact the system we are configuring unduly
3 | As a developer
4 | I want to be able to trigger an action on a resource only at the end of a run
5 |
6 | Scenario: Notify a resource from a single source
7 | Given a validated node
8 | And it includes the recipe 'delayed_notifications::notify_a_resource_from_a_single_source'
9 | When I run the chef-client
10 | Then the run should exit '0'
11 | And a file named 'notified_file.txt' should exist
12 |
13 | Scenario: Notify a resource from multiple sources
14 | Given a validated node
15 | And it includes the recipe 'delayed_notifications::notify_a_resource_from_multiple_sources'
16 | When I run the chef-client
17 | Then the run should exit '0'
18 | And a file named 'notified_file.txt' should contain 'bob dylan' only '1' time
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-72-define/definitions/define_remote_file.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-72-define
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | define :define_remote_file do
21 | remote_file "/tmp/chef-72-remote-#{params[:name]}.txt" do
22 | source "chef-72.txt"
23 | cookbook "CHEF-72-define"
24 | end
25 | end
--------------------------------------------------------------------------------
/example-repository/cookbooks/http_request/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: http_request
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | [ :get, :put, :post, :delete].each do |method|
21 | http_request "http_request.txt" do
22 | url "http://www.opscode.com/chef/http_request.txt"
23 | epic_fail true
24 | action method
25 | end
26 | end
--------------------------------------------------------------------------------
/example-repository/cookbooks/remote_file/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-89
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | remote_file "/tmp/seattle.txt" do
21 | source "seattle.txt"
22 | action :create
23 | end
24 |
25 | remote_file "/tmp/chef-wiki-homepage.txt" do
26 | source "http://wiki.opscode.com/display/chef/Home"
27 | action :create
28 | end
29 |
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-72-define/definitions/define_template.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-72-define
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | define :define_template, :sing => 'ahh' do
21 | template "/tmp/chef-72-#{params[:name]}.txt" do
22 | source "chef-72.txt.erb"
23 | variables({:sing => params[:sing]})
24 | cookbook "CHEF-72-define"
25 | end
26 | end
--------------------------------------------------------------------------------
/chef/spec/unit/chef_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
20 |
21 | describe Chef do
22 | it "should have a version defined" do
23 | Chef::VERSION.should match(/(\d+)\.(\d+)\.(\d+)/)
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/chef-server-slice/app/views/openid_server/decide.html.haml:
--------------------------------------------------------------------------------
1 | %form{:method => "post", :action => url(:openid_server_decision)}
2 | %table
3 | %tr
4 | %td Site:
5 | %td= @oidreq.trust_root
6 | - if @oidreq.id_select
7 | %tr
8 | %td{:colspan => "2"}
9 | You entered the server identifier at the relying party.
10 | You will need to send an identifier of your choosing.
11 | Enter a username and password below.
12 | %tr
13 | %td Identity to send:
14 | %td
15 | %input{:type => "text", :name => "id_to_send", :size => "25"}
16 | - else
17 | %tr
18 | %td Identity:
19 | %td= @oidreq.identity
20 | %tr
21 | %td
22 | %label{:for => "password"} Password:
23 | %td
24 | %input{:type => "password", :name => "password"}
25 | %input{:type => "submit", :name => "submit", :value => "Authenticate"}
26 | %input{:type => "submit", :name => "cancel", :value => "Cancel"}
27 |
28 |
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-94/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-94
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | gnome "mygnome" do
21 | underpants :one, :two, :three, :four
22 | end
23 |
24 | gnome "mygnome" do
25 | underpants [ :one, :two ]
26 | end
27 |
28 | puts node[:gnome][:underpants].inspect
29 |
30 | gnome "mygnome" do
31 | underpants node[:gnome][:underpants]
32 | end
--------------------------------------------------------------------------------
/chef-server-slice/app/controllers/status.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Joe Williams (joe@joetify.com)
3 | # Copyright:: Copyright (c) 2009 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef' / 'node'
20 |
21 | class ChefServerSlice::Status < ChefServerSlice::Application
22 |
23 | provides :html, :json
24 |
25 | def index
26 | @node_list = Chef::Node.list
27 | display @node_list
28 | end
29 |
30 | end
31 |
--------------------------------------------------------------------------------
/chef-server-slice/app/helpers/openid_server_helpers.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | module Merb
20 | module ChefServerSlice
21 | module OpenidServerHelper
22 |
23 | def url_for_user
24 | url(:openid_node, :username => session[:username])
25 | end
26 |
27 | end
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/chef-server/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require "rubygems"
2 |
3 | # Add the local gems dir if found within the app root; any dependencies loaded
4 | # hereafter will try to load from the local gems before loading system gems.
5 | if (local_gem_dir = File.join(File.dirname(__FILE__), '..', 'gems')) && $BUNDLE.nil?
6 | $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir)
7 | end
8 |
9 | require "merb-core"
10 | require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
11 |
12 | # this loads all plugins required in your init file so don't add them
13 | # here again, Merb will do it for you
14 | Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test')
15 |
16 | Spec::Runner.configure do |config|
17 | config.include(Merb::Test::ViewHelper)
18 | config.include(Merb::Test::RouteHelper)
19 | config.include(Merb::Test::ControllerHelper)
20 |
21 | config.before(:all) do
22 | DataMapper.auto_migrate! if Merb.orm == :datamapper
23 | end
24 |
25 | end
26 |
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-90/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-90
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | results = search(:node, '*', [ 'ipaddress', 'hostname' ])
21 | Chef::Log.info(results.inspect)
22 |
23 | search(:node, '*', [ 'ipaddress', 'hostname' ]) do |n|
24 | Chef::Log.info("#{n['ipaddress']} #{n['hostname']}")
25 | end
26 |
27 | Chef::Log.info(search(:node, '*').inspect)
28 |
--------------------------------------------------------------------------------
/features/data/cookbooks/delayed_notifications/recipes/notify_a_resource_from_a_single_source.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: delayed_notifications
3 | # Recipe:: notify_a_resource_from_a_single_source
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | file "#{node[:tmpdir]}/notified_file.txt" do
21 | action :nothing
22 | end
23 |
24 | execute "echo foo" do
25 | notifies :create, resources("file[#{node[:tmpdir]}/notified_file.txt]"), :delayed
26 | end
--------------------------------------------------------------------------------
/example-repository/cookbooks/template_caching_test/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: template_caching_test
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | [ "one", "two", "three", "four" ].each do |value|
21 | template "/tmp/test_render.txt" do
22 | source "test_render.erb"
23 | variables({
24 | :number => value
25 | })
26 | action :create
27 | end
28 |
29 | file "/tmp/test_render.txt" do
30 | action :delete
31 | end
32 | end
--------------------------------------------------------------------------------
/chef-server-slice/app/views/cookbooks/show.html.haml:
--------------------------------------------------------------------------------
1 | - throw_content(:header, "Cookbook #{h @cookbook.name}")
2 | .cookbook
3 | - if @cookbook.lib_files.length > 0
4 | %h2 Library Files
5 | - @cookbook.lib_files.each do |f|
6 | = partial(:syntax_highlight, :name => File.basename(f), :contents => f)
7 |
8 | - if @cookbook.attribute_files.length > 0
9 | %h2 Attribute Files
10 | - @cookbook.attribute_files.each do |f|
11 | = partial(:syntax_highlight, :name => File.basename(f), :contents => f)
12 |
13 | - if @cookbook.definition_files.length > 0
14 | %h2 Definition Files
15 | - @cookbook.definition_files.each do |f|
16 | = partial(:syntax_highlight, :name => File.basename(f), :contents => f)
17 |
18 | - if @cookbook.recipe_files.length > 0
19 | %h2 Recipe Files
20 | - @cookbook.recipe_files.each do |f|
21 | = partial(:syntax_highlight, :name => File.basename(f), :contents => f)
22 |
23 | - if @cookbook.template_files.length > 0
24 | %h2 Template Files
25 | - @cookbook.template_files.each do |f|
26 | %h3= File.basename(f)
27 | %div= syntax_highlight(f)
28 |
29 |
--------------------------------------------------------------------------------
/chef-server-slice/app/views/openid_register/index.html.haml:
--------------------------------------------------------------------------------
1 | - throw_content(:header, "Registered OpenID Nodes List")
2 | %table
3 | - @registered_nodes.each do |node|
4 | %tr
5 | %td
6 | %a{ :href => slice_url(:registration, { :id => node.name }) }
7 | = h node.name
8 | %td
9 | - if session[:level] == :admin
10 | %form{ :method => "post", :action => slice_url(:validate_registration, { :id => node.name })}
11 | - submit_name = node.validated ? "Invalidate" : "Validate"
12 | %input{ :type => "submit", :name => submit_name, :value => submit_name }
13 | %form{ :method => "post", :action => slice_url(:admin_registration, { :id => node.name })}
14 | - submit_name = node.admin ? "Remove Admin Rights" : "Admin"
15 | %input{ :type => "submit", :name => submit_name, :value => submit_name }
16 | %form{ :method => "post", :action => slice_url(:registration, { :id => node.name })}
17 | %input{ :type => "hidden", :name => "_method", :value => "delete" }
18 | %input{ :type => "submit", :name => "Delete", :value => "Delete" }
19 |
--------------------------------------------------------------------------------
/chef/lib/chef/resource/bash.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/script'
20 |
21 | class Chef
22 | class Resource
23 | class Bash < Chef::Resource::Script
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :bash
28 | @interpreter = "bash"
29 | end
30 |
31 | end
32 | end
33 | end
--------------------------------------------------------------------------------
/chef/lib/chef/resource/csh.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/script'
20 |
21 | class Chef
22 | class Resource
23 | class Csh < Chef::Resource::Script
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :csh
28 | @interpreter = "csh"
29 | end
30 |
31 | end
32 | end
33 | end
--------------------------------------------------------------------------------
/chef/lib/chef/resource/perl.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/script'
20 |
21 | class Chef
22 | class Resource
23 | class Perl < Chef::Resource::Script
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :perl
28 | @interpreter = "perl"
29 | end
30 |
31 | end
32 | end
33 | end
--------------------------------------------------------------------------------
/chef/lib/chef/resource/ruby.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/script'
20 |
21 | class Chef
22 | class Resource
23 | class Ruby < Chef::Resource::Script
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :ruby
28 | @interpreter = "ruby"
29 | end
30 |
31 | end
32 | end
33 | end
--------------------------------------------------------------------------------
/chef/lib/chef/resource/python.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/script'
20 |
21 | class Chef
22 | class Resource
23 | class Python < Chef::Resource::Script
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :python
28 | @interpreter = "python"
29 | end
30 |
31 | end
32 | end
33 | end
--------------------------------------------------------------------------------
/chef/lib/chef/mixin/checksum.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'digest/sha2'
20 |
21 | class Chef
22 | module Mixin
23 | module Checksum
24 |
25 | def checksum(file)
26 | digest = Digest::SHA256.new
27 | fh = ::File.open(file)
28 | fh.each do |line|
29 | digest.update(line)
30 | end
31 | digest.hexdigest
32 | end
33 |
34 | end
35 | end
36 | end
--------------------------------------------------------------------------------
/chef-server-slice/app/views/openid_consumer/index.html.haml:
--------------------------------------------------------------------------------
1 | - throw_content(:header, "OpenID Relaying Party")
2 | -if session[:alert]
3 | .alert= h session[:alert]
4 | -if session[:error]
5 | .error= h session[:error]
6 | -if session[:success]
7 | .success= h session[:success]
8 | #verify-form
9 | %form{ :method => "get", "accept-charset" => "UTF-8", :action => slice_url(:openid_consumer_login) }
10 | Identifier:
11 | %input.openid{ :type => "text", :name => "openid_identifier" }/
12 | %input{ :type => "submit", :value => "Verify"}/
13 | %br
14 | %input#immediate{ :name => "immediate", :type => "checkbox" }/
15 | %label{:for => "immediate"} Use immediate mode
16 | %br
17 | %input#immediate{ :name => "use_sreg", :type => "checkbox" }/
18 | %label{:for => "use_sreg"} Request registration data
19 | %br
20 | %input#immediate{ :name => "use_pape", :type => "checkbox" }/
21 | %label{:for => "use_pape"} Request phishing-resistent auth policy
22 | %br
23 | %input#immediate{ :name => "force_post", :type => "checkbox" }/
24 | %label{:for => "force_post"} Force the transaction to POST
25 | %br
26 |
--------------------------------------------------------------------------------
/chef/lib/chef/mixin/check_helper.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 |
18 | class Chef
19 | module Mixin
20 | module CheckHelper
21 | def set_if_args(thing, arguments)
22 | raise ArgumentError, "Must call set_if_args with a block!" unless Kernel.block_given?
23 | if arguments != nil
24 | yield(arguments)
25 | else
26 | thing
27 | end
28 | end
29 | end
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-97/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-97
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | # Should not execute
21 | execute "echo onlyif" do
22 | only_if "test -d /tmp/CHEF-97"
23 | end
24 |
25 | directory "/tmp/CHEF-97"
26 |
27 | # Should execute
28 | execute "echo onlyif"
29 |
30 | # Should not execute
31 | execute "echo notif" do
32 | not_if "test -d /tmp/CHEF-97"
33 | end
34 |
35 | directory "/tmp/CHEF-97" do
36 | action :delete
37 | end
38 |
39 | # Should execute
40 | execute "echo notif"
41 |
42 |
--------------------------------------------------------------------------------
/features/data/cookbooks/delayed_notifications/recipes/notify_a_resource_from_multiple_sources.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: delayed_notifications
3 | # Recipe:: notify_a_resource_from_multiple_sources
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | execute "bob dylan" do
21 | command "echo 'bob dylan' >> #{node[:tmpdir]}/notified_file.txt"
22 | action :nothing
23 | end
24 |
25 | execute "echo foo" do
26 | notifies :run, resources("execute[bob dylan]"), :delayed
27 | end
28 |
29 | execute "echo bar" do
30 | notifies :run, resources("execute[bob dylan]"), :delayed
31 | end
32 |
--------------------------------------------------------------------------------
/features/steps/couchdb.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | Before do
20 | system("mkdir -p #{tmpdir}")
21 | cdb = Chef::CouchDB.new(Chef::Config[:couchdb_url])
22 | cdb.create_db
23 | Chef::Node.create_design_document
24 | Chef::OpenIDRegistration.create_design_document
25 | end
26 |
27 | After do
28 | r = Chef::REST.new(Chef::Config[:couchdb_url])
29 | r.delete_rest("#{Chef::Config[:couchdb_database]}/")
30 | system("rm -rf #{tmpdir}")
31 | end
--------------------------------------------------------------------------------
/chef-server-slice/app/helpers/cookbooks_helper.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | module Merb
20 | module ChefServerSlice
21 | module CookbooksHelper
22 | def syntax_highlight(code)
23 | converter = Syntax::Convertors::HTML.for_syntax "ruby"
24 | if File.exists?(code)
25 | converter.convert(File.read(code))
26 | else
27 | converter.convert(code)
28 | end
29 | end
30 | end
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/chef/lib/chef/resource/gem_package.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/package'
20 |
21 | class Chef
22 | class Resource
23 | class GemPackage < Chef::Resource::Package
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :gem_package
28 | @provider = Chef::Provider::Package::Rubygems
29 | end
30 |
31 | end
32 | end
33 | end
--------------------------------------------------------------------------------
/features/steps/recipe.rb:
--------------------------------------------------------------------------------
1 | Given /^the cookbook has a '(.+)' named '(.+)' in the '(.+)' specific directory$/ do |file_type, filename, specificity|
2 | cookbook_name, recipe_name = @recipe.split('::')
3 | type_dir = file_type == 'file' ? 'files' : 'templates'
4 | specific_dir = nil
5 | case specificity
6 | when "host"
7 | specific_dir = "host-#{@client.node[:fqdn]}"
8 | when "platform-version"
9 | specific_dir = "#{@client.node[:platform]}-#{@client.node[:platform_version]}"
10 | when "platform"
11 | specific_dir = @client.node[:platform]
12 | when "default"
13 | specific_dir = "default"
14 | end
15 | new_file_dir = File.expand_path(
16 | File.join(
17 | File.dirname(__FILE__),
18 | "..",
19 | "data",
20 | "cookbooks",
21 | cookbook_name,
22 | type_dir,
23 | specific_dir
24 | )
25 | )
26 | @cleanup_dirs << new_file_dir unless new_file_dir =~ /default$/
27 | system("mkdir -p #{new_file_dir}")
28 | new_file_name = File.join(new_file_dir, filename)
29 | @cleanup_files << new_file_name
30 | new_file = File.open(new_file_name, "w")
31 | new_file.puts(specificity)
32 | new_file.close
33 | end
34 |
--------------------------------------------------------------------------------
/chef/lib/chef/resource/portage_package.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/package'
20 |
21 | class Chef
22 | class Resource
23 | class PortagePackage < Chef::Resource::Package
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :portage_package
28 | @provider = Chef::Provider::Package::Portage
29 | end
30 |
31 | end
32 | end
33 | end
--------------------------------------------------------------------------------
/chef/lib/chef/resource/apt_package.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/package'
20 | require 'chef/provider/package/apt'
21 |
22 | class Chef
23 | class Resource
24 | class AptPackage < Chef::Resource::Package
25 |
26 | def initialize(name, collection=nil, node=nil)
27 | super(name, collection, node)
28 | @resource_name = :apt_package
29 | @provider = Chef::Provider::Package::Apt
30 | end
31 |
32 | end
33 | end
34 | end
--------------------------------------------------------------------------------
/chef-server-slice/app/views/layout/chef_server_slice.html.haml:
--------------------------------------------------------------------------------
1 | !!! XML
2 | !!!
3 | %html
4 | %head
5 | %title Chef Server
6 | %meta{"http-equiv" => "content-type", :content => "text/html; charset=utf-8" }
7 | %link{:rel => "stylesheet", :href => "/stylesheets/master-highlight.css", :type => "text/css", :media => "screen", :charset => "utf-8" }
8 | = js_include_tag "jquery-1.3.1.min", "jquery.jeditable.mini", "jquery.livequery"
9 | = js_include_tag "chef"
10 | %body
11 | .header
12 | %a{:href => slice_url(:searches) } Search
13 | |
14 | %a{:href => slice_url(:nodes) } Nodes
15 | |
16 | %a{:href => slice_url(:status) } Status
17 | |
18 | %a{:href => slice_url(:cookbooks) } Cookbooks
19 | |
20 | %a{:href => slice_url(:registrations)} Registrations
21 | - if session[:openid]
22 | |
23 | %a{:href => slice_url(:openid_consumer_logout)}= "Logout #{h session[:openid]}"
24 | = "(#{session[:level].to_s})"
25 | - else
26 | |
27 | %a{:href => slice_url(:openid_consumer)} Login
28 | %h3= catch_content :header
29 | - unless message.empty?
30 | = message[:error]
31 | = message[:notice]
32 | = catch_content :for_layout
33 |
--------------------------------------------------------------------------------
/chef/spec/lib/chef/provider/easy.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: GNU General Public License version 2 or later
5 | #
6 | # This program and entire repository is free software; you can
7 | # redistribute it and/or modify it under the terms of the GNU
8 | # General Public License as published by the Free Software
9 | # Foundation; either version 2 of the License, or any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program; if not, write to the Free Software
18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 | #
20 |
21 | class Chef
22 | class Provider
23 | class Easy < Chef::Provider
24 | def load_current_resource
25 | true
26 | end
27 |
28 | def action_sell
29 | true
30 | end
31 |
32 | def action_buy
33 | true
34 | end
35 | end
36 | end
37 | end
--------------------------------------------------------------------------------
/chef/spec/lib/chef/provider/snakeoil.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: GNU General Public License version 2 or later
5 | #
6 | # This program and entire repository is free software; you can
7 | # redistribute it and/or modify it under the terms of the GNU
8 | # General Public License as published by the Free Software
9 | # Foundation; either version 2 of the License, or any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program; if not, write to the Free Software
18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 | #
20 |
21 | class Chef
22 | class Provider
23 | class SnakeOil < Chef::Provider
24 | def load_current_resource
25 | true
26 | end
27 |
28 | def action_sell
29 | true
30 | end
31 |
32 | def action_buy
33 | true
34 | end
35 | end
36 | end
37 | end
--------------------------------------------------------------------------------
/chef-server-slice/app/controllers/exceptions.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Author:: Christopher Brown ()
4 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
5 | # License:: Apache License, Version 2.0
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | class ChefServerSlice::Exceptions < ChefServerSlice::Application
21 |
22 | provides :html, :json
23 |
24 | # handle NotFound exceptions (404)
25 | def not_found
26 | display params
27 | end
28 |
29 | # handle NotAcceptable exceptions (406)
30 | def not_acceptable
31 | display params
32 | end
33 |
34 | # handle BadRequest exceptions (400)
35 | def bad_request
36 | display params
37 | end
38 |
39 | end
40 |
--------------------------------------------------------------------------------
/chef-server-slice/app/helpers/global_helpers.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | module Merb
20 | module ChefServerSlice
21 |
22 | module GlobalHelpers
23 | # helpers defined here available to all views.
24 | def resource_collection(collection)
25 | html = "
"
26 | collection.each do |resource|
27 | html << "
#{resource.class}
"
28 | end
29 | html << "
"
30 | html
31 | end
32 |
33 | def node_escape(node)
34 | node.gsub(/\./, '_')
35 | end
36 | end
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/features/steps/nodes.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ###
20 | # Given
21 | ###
22 | Given /^a validated node$/ do
23 | @client.validation_token = Chef::Config[:validation_token] = 'ceelo'
24 | @client.build_node
25 | @client.node.recipes = "integration_setup"
26 | @client.register
27 | @client.authenticate
28 | end
29 |
30 | Given /^it includes the recipe '(.+)'$/ do |recipe|
31 | @recipe = recipe
32 | @client.node.recipes << recipe
33 | @client.save_node
34 | end
35 |
36 | ###
37 | # When
38 | ###
39 | When /^the node is converged$/ do
40 | @client.run
41 | end
42 |
43 |
--------------------------------------------------------------------------------
/chef-server-slice/app/helpers/nodes_helper.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | module Merb
20 | module ChefServerSlice
21 | module NodesHelper
22 | def recipe_list(node)
23 | response = ""
24 | node.recipes.each do |recipe|
25 | response << "
"
34 | end
35 | response
36 | end
37 | end
38 |
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/chef/lib/chef/exceptions.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 |
18 | class Chef
19 | class Exceptions
20 | class Cron < RuntimeError; end
21 | class Exec < RuntimeError; end
22 | class FileNotFound < RuntimeError; end
23 | class Package < RuntimeError; end
24 | class Service < RuntimeError; end
25 | class Route < RuntimeError; end
26 | class SearchIndex < RuntimeError; end
27 | class Override < RuntimeError; end
28 | class UnsupportedAction < RuntimeError; end
29 | class MissingLibrary < RuntimeError; end
30 | class User < RuntimeError; end
31 | class Group < RuntimeError; end
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/chef/lib/chef/provider.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | class Chef
20 | class Provider
21 |
22 | attr_accessor :node, :new_resource, :current_resource
23 |
24 | def initialize(node, new_resource)
25 | @node = node
26 | @new_resource = new_resource
27 | @current_resource = nil
28 | end
29 |
30 | def load_current_resource
31 | raise Chef::Exceptions::Override, "You must override load_current_resource in #{self.to_s}"
32 | end
33 |
34 | def action_nothing
35 | Chef::Log.debug("Doing nothing for #{@new_resource.to_s}")
36 | true
37 | end
38 |
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/example-repository/cookbooks/CHEF-72/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: CHEF-72
3 | # Recipe:: default
4 | #
5 | # Copyright 2009, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | template "/tmp/chef-72.txt" do
21 | source "chef-72.txt.erb"
22 | variables({:sing => "what"})
23 | end
24 |
25 | define_template "jail" do
26 | sing "scarecrow"
27 | end
28 |
29 | remote_file "/tmp/chef-72-remote.txt" do
30 | source "chef-72.txt"
31 | end
32 |
33 | define_remote_file "jail" do
34 | source "chef-72.txt"
35 | end
36 |
37 | %w{/tmp/chef-72.txt /tmp/chef-72-jail.txt /tmp/chef-72-remote.txt /tmp/chef-72-remote-jail.txt}.each do |filename|
38 | execute "cat #{filename}" do
39 | command "cat #{filename}"
40 | end
41 |
42 | file filename do
43 | action :delete
44 | end
45 | end
--------------------------------------------------------------------------------
/chef/lib/chef/mixin/from_file.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | class Chef
20 | module Mixin
21 | module FromFile
22 |
23 | # Loads a given ruby file, and runs instance_eval against it in the context of the current
24 | # object.
25 | #
26 | # Raises an IOError if the file cannot be found, or is not readable.
27 | def from_file(filename)
28 | if File.exists?(filename) && File.readable?(filename)
29 | self.instance_eval(IO.read(filename), filename, 1)
30 | else
31 | raise IOError, "Cannot open or read #{filename}!"
32 | end
33 | end
34 | end
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/chef/lib/chef/provider/script.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'tempfile'
20 | require 'chef/provider/execute'
21 |
22 | class Chef
23 | class Provider
24 | class Script < Chef::Provider::Execute
25 |
26 | def action_run
27 | tf = Tempfile.new("chef-script")
28 | tf.puts(@new_resource.code)
29 | tf.close
30 |
31 | fr = Chef::Resource::File.new(tf.path, nil, @node)
32 | fr.owner(@new_resource.user)
33 | fr.group(@new_resource.group)
34 | fr.run_action(:create)
35 |
36 | @new_resource.command("#{@new_resource.interpreter} #{tf.path}")
37 | super
38 | end
39 |
40 | end
41 | end
42 | end
--------------------------------------------------------------------------------
/chef/spec/lib/chef/resource/one_two_three_four.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: John Hampton ()
3 | # Copyright:: Copyright (c) 2009 CleanOffer, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | class Chef
20 | class Resource
21 | class OneTwoThreeFour < Chef::Resource
22 | attr_reader :i_can_count
23 |
24 | def initialize(name, collection=nil, node=nil)
25 | @resource_name = :one_two_three_four
26 | super(name, collection, node)
27 | end
28 |
29 | def i_can_count(tf)
30 | @i_can_count = tf
31 | end
32 |
33 | def something(arg=nil)
34 | set_if_args(@something, arg) do
35 | case arg
36 | when true, false
37 | @something = arg
38 | end
39 | end
40 | end
41 | end
42 | end
43 | end
--------------------------------------------------------------------------------
/chef/spec/unit/resource/csh_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::Csh do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::Csh.new("fakey_fakerton")
25 | end
26 |
27 | it "should create a new Chef::Resource::Csh" do
28 | @resource.should be_a_kind_of(Chef::Resource)
29 | @resource.should be_a_kind_of(Chef::Resource::Csh)
30 | end
31 |
32 | it "should have a resource name of :csh" do
33 | @resource.resource_name.should eql(:csh)
34 | end
35 |
36 | it "should have an interpreter of csh" do
37 | @resource.interpreter.should eql("csh")
38 | end
39 |
40 | end
--------------------------------------------------------------------------------
/chef/spec/unit/resource/bash_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::Bash do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::Bash.new("fakey_fakerton")
25 | end
26 |
27 | it "should create a new Chef::Resource::Bash" do
28 | @resource.should be_a_kind_of(Chef::Resource)
29 | @resource.should be_a_kind_of(Chef::Resource::Bash)
30 | end
31 |
32 | it "should have a resource name of :bash" do
33 | @resource.resource_name.should eql(:bash)
34 | end
35 |
36 | it "should have an interpreter of bash" do
37 | @resource.interpreter.should eql("bash")
38 | end
39 |
40 | end
--------------------------------------------------------------------------------
/chef/spec/unit/resource/perl_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::Perl do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::Perl.new("fakey_fakerton")
25 | end
26 |
27 | it "should create a new Chef::Resource::Perl" do
28 | @resource.should be_a_kind_of(Chef::Resource)
29 | @resource.should be_a_kind_of(Chef::Resource::Perl)
30 | end
31 |
32 | it "should have a resource name of :perl" do
33 | @resource.resource_name.should eql(:perl)
34 | end
35 |
36 | it "should have an interpreter of perl" do
37 | @resource.interpreter.should eql("perl")
38 | end
39 |
40 | end
--------------------------------------------------------------------------------
/chef/spec/unit/resource/ruby_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::Ruby do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::Ruby.new("fakey_fakerton")
25 | end
26 |
27 | it "should create a new Chef::Resource::Ruby" do
28 | @resource.should be_a_kind_of(Chef::Resource)
29 | @resource.should be_a_kind_of(Chef::Resource::Ruby)
30 | end
31 |
32 | it "should have a resource name of :ruby" do
33 | @resource.resource_name.should eql(:ruby)
34 | end
35 |
36 | it "should have an interpreter of ruby" do
37 | @resource.interpreter.should eql("ruby")
38 | end
39 |
40 | end
--------------------------------------------------------------------------------
/chef/spec/unit/resource/python_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::Python do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::Python.new("fakey_fakerton")
25 | end
26 |
27 | it "should create a new Chef::Resource::Python" do
28 | @resource.should be_a_kind_of(Chef::Resource)
29 | @resource.should be_a_kind_of(Chef::Resource::Python)
30 | end
31 |
32 | it "should have a resource name of :python" do
33 | @resource.resource_name.should eql(:python)
34 | end
35 |
36 | it "should have an interpreter of python" do
37 | @resource.interpreter.should eql("python")
38 | end
39 |
40 | end
--------------------------------------------------------------------------------
/chef/spec/unit/resource/apt_package_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::AptPackage, "initialize" do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::AptPackage.new("foo")
25 | end
26 |
27 | it "should return a Chef::Resource::AptPackage" do
28 | @resource.should be_a_kind_of(Chef::Resource::AptPackage)
29 | end
30 |
31 | it "should set the resource_name to :apt_package" do
32 | @resource.resource_name.should eql(:apt_package)
33 | end
34 |
35 | it "should set the provider to Chef::Provider::Package::Apt" do
36 | @resource.provider.should eql(Chef::Provider::Package::Apt)
37 | end
38 | end
--------------------------------------------------------------------------------
/example-repository/cookbooks/global-onlyif/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook Name:: global-onlyif
3 | # Recipe:: default
4 | #
5 | # Copyright 2008, Opscode
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | file "/tmp/neverhappen" do
21 | only_if do false; end
22 | end
23 |
24 | file "/tmp/stillnothappening" do
25 | not_if do true; end
26 | end
27 |
28 | file "/tmp/seriouslynothappening" do
29 | only_if "false"
30 | end
31 |
32 | file "/tmp/yepstillnot" do
33 | not_if "true"
34 | end
35 |
36 | file "/tmp/shouldhappen" do
37 | only_if do true; end
38 | action [:create, :delete]
39 | end
40 |
41 | file "/tmp/shouldhappen" do
42 | only_if "true"
43 | action [:create, :delete]
44 | end
45 |
46 | file "/tmp/shouldhappen" do
47 | not_if do false; end
48 | action [:create, :delete]
49 | end
50 |
51 | file "/tmp/shouldhappen" do
52 | not_if "false"
53 | action [:create, :delete]
54 | end
55 |
56 |
--------------------------------------------------------------------------------
/chef/spec/unit/resource/gem_package_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::GemPackage, "initialize" do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::GemPackage.new("foo")
25 | end
26 |
27 | it "should return a Chef::Resource::GemPackage" do
28 | @resource.should be_a_kind_of(Chef::Resource::GemPackage)
29 | end
30 |
31 | it "should set the resource_name to :gem_package" do
32 | @resource.resource_name.should eql(:gem_package)
33 | end
34 |
35 | it "should set the provider to Chef::Provider::Package::Rubygems" do
36 | @resource.provider.should eql(Chef::Provider::Package::Rubygems)
37 | end
38 | end
--------------------------------------------------------------------------------
/chef-server/lib/tasks/package.rake:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake/gempackagetask'
3 |
4 | spec = Gem::Specification.new do |s|
5 | s.name = GEM
6 | s.version = CHEF_SERVER_VERSION
7 | s.platform = Gem::Platform::RUBY
8 | s.has_rdoc = true
9 | s.extra_rdoc_files = ["README.rdoc", "LICENSE" ]
10 | s.summary = SUMMARY
11 | s.description = s.summary
12 | s.author = AUTHOR
13 | s.email = EMAIL
14 | s.homepage = HOMEPAGE
15 |
16 | s.add_dependency "stomp"
17 | s.add_dependency "stompserver"
18 | s.add_dependency "ferret"
19 | s.add_dependency "merb-core"
20 | s.add_dependency "merb-haml"
21 | s.add_dependency "merb-assets"
22 | s.add_dependency "merb-helpers"
23 | s.add_dependency "mongrel"
24 | s.add_dependency "haml"
25 | s.add_dependency "ruby-openid"
26 | s.add_dependency "json"
27 | s.add_dependency "syntax"
28 |
29 | s.bindir = "bin"
30 | s.executables = %w( chef-server chef-indexer )
31 | s.files = %w(LICENSE README.rdoc Rakefile) +
32 | [ "README.txt",
33 | "LICENSE",
34 | "NOTICE",
35 | "{app}/**/*",
36 | "{config}/**/*",
37 | "{doc}/**/*",
38 | "{lib}/**/*",
39 | "{log}/**/*",
40 | "{merb}/**/*",
41 | "{public}/**/*",
42 | "{slices}/**/*",
43 | "{spec}/**/*",
44 | "{tasks}/**/*",].inject([]) { |m,dir| m << Dir.glob(dir) }.flatten
45 | end
46 |
47 | Rake::GemPackageTask.new(spec) do |pkg|
48 | pkg.gem_spec = spec
49 | end
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/chef/spec/unit/resource/portage_package_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::PortagePackage, "initialize" do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::PortagePackage.new("foo")
25 | end
26 |
27 | it "should return a Chef::Resource::PortagePackage" do
28 | @resource.should be_a_kind_of(Chef::Resource::PortagePackage)
29 | end
30 |
31 | it "should set the resource_name to :portage_package" do
32 | @resource.resource_name.should eql(:portage_package)
33 | end
34 |
35 | it "should set the provider to Chef::Provider::Package::Portage" do
36 | @resource.provider.should eql(Chef::Provider::Package::Portage)
37 | end
38 | end
--------------------------------------------------------------------------------
/chef/spec/lib/chef/resource/cat.rb:
--------------------------------------------------------------------------------
1 | # Author:: Adam Jacob ()
2 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
3 | # License:: GNU General Public License version 2 or later
4 | #
5 | # This program and entire repository is free software; you can
6 | # redistribute it and/or modify it under the terms of the GNU
7 | # General Public License as published by the Free Software
8 | # Foundation; either version 2 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | #
19 |
20 | class Chef
21 | class Resource
22 | class Cat < Chef::Resource
23 |
24 | attr_accessor :action
25 |
26 | def initialize(name, collection=nil, node=nil)
27 | @resource_name = :cat
28 | super(name, collection, node)
29 | @action = "sell"
30 | end
31 |
32 | def pretty_kitty(arg=nil)
33 | set_if_args(@pretty_kitty, arg) do
34 | case arg
35 | when true, false
36 | @pretty_kitty = arg
37 | end
38 | end
39 | end
40 | end
41 | end
42 | end
--------------------------------------------------------------------------------
/chef/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # Author:: Adam Jacob ()
2 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
3 | # License:: GNU General Public License version 2 or later
4 | #
5 | # This program and entire repository is free software; you can
6 | # redistribute it and/or modify it under the terms of the GNU
7 | # General Public License as published by the Free Software
8 | # Foundation; either version 2 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | #
19 |
20 | $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
21 |
22 | require 'chef'
23 |
24 | chef_lib_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
25 | Dir[
26 | File.expand_path(
27 | File.join(
28 | chef_lib_path, 'chef', '**', '*.rb'
29 | )
30 | )
31 | ].sort.each do |lib|
32 | lib_short_path = lib.match("^#{chef_lib_path}#{File::SEPARATOR}(.+)$")[1]
33 | require lib_short_path
34 | end
35 | Dir[File.join(File.dirname(__FILE__), 'lib', '**', '*.rb')].sort.each { |lib| require lib }
36 |
37 | Chef::Config.log_level(:fatal)
38 |
--------------------------------------------------------------------------------
/chef/lib/chef/resource/script.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/execute'
20 |
21 | class Chef
22 | class Resource
23 | class Script < Chef::Resource::Execute
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :script
28 | @command = name
29 | @code = nil
30 | @interpreter = nil
31 | end
32 |
33 | def code(arg=nil)
34 | set_or_return(
35 | :code,
36 | arg,
37 | :kind_of => [ String ]
38 | )
39 | end
40 |
41 | def interpreter(arg=nil)
42 | set_or_return(
43 | :interpreter,
44 | arg,
45 | :kind_of => [ String ]
46 | )
47 | end
48 |
49 | end
50 | end
51 | end
--------------------------------------------------------------------------------
/chef/tasks/rspec.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake'
3 | require 'spec/rake/spectask'
4 |
5 | CHEF_ROOT = File.join(File.dirname(__FILE__), "..")
6 |
7 | task :default => :spec
8 |
9 | desc "Run all specs in spec directory"
10 | Spec::Rake::SpecTask.new(:spec) do |t|
11 | t.spec_opts = ['--options', "\"#{CHEF_ROOT}/spec/spec.opts\""]
12 | t.spec_files = FileList['spec/**/*_spec.rb']
13 | end
14 |
15 | namespace :spec do
16 | desc "Run all specs in spec directory with RCov"
17 | Spec::Rake::SpecTask.new(:rcov) do |t|
18 | t.spec_opts = ['--options', "\"#{CHEF_ROOT}/spec/spec.opts\""]
19 | t.spec_files = FileList['spec/**/*_spec.rb']
20 | t.rcov = true
21 | t.rcov_opts = lambda do
22 | IO.readlines("#{CHEF_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
23 | end
24 | end
25 |
26 | desc "Print Specdoc for all specs"
27 | Spec::Rake::SpecTask.new(:doc) do |t|
28 | t.spec_opts = ["--format", "specdoc", "--dry-run"]
29 | t.spec_files = FileList['spec/**/*_spec.rb']
30 | end
31 |
32 | [:unit].each do |sub|
33 | desc "Run the specs under spec/#{sub}"
34 | Spec::Rake::SpecTask.new(sub) do |t|
35 | t.spec_opts = ['--options', "\"#{CHEF_ROOT}/spec/spec.opts\""]
36 | t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
37 | end
38 | end
39 |
40 | desc "Translate/upgrade specs using the built-in translator"
41 | task :translate do
42 | translator = ::Spec::Translator.new
43 | dir = CHEF_ROOT + '/spec'
44 | translator.translate(dir, dir)
45 | end
46 | end
47 |
--------------------------------------------------------------------------------
/chef/lib/chef/resource/remote_file.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/file'
20 |
21 | class Chef
22 | class Resource
23 | class RemoteFile < Chef::Resource::File
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :remote_file
28 | @action = "create"
29 | @source = nil
30 | @cookbook = nil
31 | end
32 |
33 | def source(args=nil)
34 | set_or_return(
35 | :source,
36 | args,
37 | :kind_of => String
38 | )
39 | end
40 |
41 | def cookbook(args=nil)
42 | set_or_return(
43 | :cookbook,
44 | args,
45 | :kind_of => String
46 | )
47 | end
48 |
49 | end
50 | end
51 | end
52 |
--------------------------------------------------------------------------------
/chef-server-slice/bin/chef-server:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | #
3 | # ./chef-server - Serving up piping hot infrastructure!
4 | #
5 | # Author:: Adam Jacob ()
6 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
7 | # License:: Apache License, Version 2.0
8 | #
9 | # Licensed under the Apache License, Version 2.0 (the "License");
10 | # you may not use this file except in compliance with the License.
11 | # You may obtain a copy of the License at
12 | #
13 | # http://www.apache.org/licenses/LICENSE-2.0
14 | #
15 | # Unless required by applicable law or agreed to in writing, software
16 | # distributed under the License is distributed on an "AS IS" BASIS,
17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | # See the License for the specific language governing permissions and
19 | # limitations under the License.
20 |
21 | # Based on the 'merb' command, by Ezra
22 |
23 | require "rubygems"
24 | require "merb-core"
25 | require "chef"
26 |
27 | if ARGV[0] && ARGV[0] =~ /^[^-]/
28 | ARGV.push "-H"
29 | end
30 | unless %w[-a --adapter -i --irb-console -r --script-runner].any? { |o| ARGV.index(o) }
31 | ARGV.push *%w[-a mongrel]
32 | end
33 | ARGV.push *[ "-I", File.join(File.dirname(__FILE__), "..", "lib", "init.rb") ]
34 |
35 | if index = ARGV.index("-C")
36 | config = ARGV[index+1]
37 | ARGV.delete("-C")
38 | ARGV.delete(config)
39 | Chef::Config.from_file(File.expand_path(config))
40 | else
41 | Chef::Config.from_file(
42 | File.join("/etc", "chef", "server.rb")
43 | )
44 | end
45 |
46 | Merb.start
47 |
--------------------------------------------------------------------------------
/chef/spec/lib/chef/resource/zen_master.rb:
--------------------------------------------------------------------------------
1 | # Author:: Adam Jacob ()
2 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
3 | # License:: GNU General Public License version 2 or later
4 | #
5 | # This program and entire repository is free software; you can
6 | # redistribute it and/or modify it under the terms of the GNU
7 | # General Public License as published by the Free Software
8 | # Foundation; either version 2 of the License, or any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | #
19 |
20 | class Chef
21 | class Resource
22 | class ZenMaster < Chef::Resource
23 | attr_reader :peace
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | @resource_name = :zen_master
27 | super(name, collection, node)
28 | end
29 |
30 | def peace(tf)
31 | @peace = tf
32 | end
33 |
34 | def something(arg=nil)
35 | set_if_args(@something, arg) do
36 | case arg
37 | when true, false
38 | @something = arg
39 | end
40 | end
41 | end
42 | end
43 | end
44 | end
--------------------------------------------------------------------------------
/chef-server/merb/merb-auth/setup.rb:
--------------------------------------------------------------------------------
1 | # This file is specifically setup for use with the merb-auth plugin.
2 | # This file should be used to setup and configure your authentication stack.
3 | # It is not required and may safely be deleted.
4 | #
5 | # To change the parameter names for the password or login field you may set either of these two options
6 | #
7 | # Merb::Plugins.config[:"merb-auth"][:login_param] = :email
8 | # Merb::Plugins.config[:"merb-auth"][:password_param] = :my_password_field_name
9 |
10 | begin
11 | # Sets the default class ofr authentication. This is primarily used for
12 | # Plugins and the default strategies
13 | Merb::Authentication.user_class = User
14 |
15 |
16 | # Mixin the salted user mixin
17 | require 'merb-auth-more/mixins/salted_user'
18 | Merb::Authentication.user_class.class_eval{ include Merb::Authentication::Mixins::SaltedUser }
19 |
20 | # Setup the session serialization
21 | class Merb::Authentication
22 |
23 | def fetch_user(session_user_id)
24 | Merb::Authentication.user_class.get(session_user_id)
25 | end
26 |
27 | def store_user(user)
28 | user.nil? ? user : user.id
29 | end
30 | end
31 |
32 | rescue
33 | Merb.logger.error <<-TEXT
34 |
35 | You need to setup some kind of user class with merb-auth.
36 | Merb::Authentication.user_class = User
37 |
38 | If you want to fully customize your authentication you should use merb-core directly.
39 |
40 | See merb/merb-auth/setup.rb and strategies.rb to customize your setup
41 |
42 | TEXT
43 | end
44 |
45 |
--------------------------------------------------------------------------------
/chef/lib/chef/resource/http_request.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource'
20 |
21 | class Chef
22 | class Resource
23 | class HttpRequest < Chef::Resource
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :http_request
28 | @message = name
29 | @url = nil
30 | @action = :get
31 | @allowed_actions.push(:get, :put, :post, :delete, :head, :options)
32 | end
33 |
34 | def url(args=nil)
35 | set_or_return(
36 | :url,
37 | args,
38 | :kind_of => String
39 | )
40 | end
41 |
42 | def message(args=nil)
43 | set_or_return(
44 | :message,
45 | args,
46 | :kind_of => Object
47 | )
48 | end
49 |
50 | end
51 | end
52 | end
--------------------------------------------------------------------------------
/chef-server/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake/rdoctask'
3 |
4 | require 'merb-core'
5 | require 'merb-core/tasks/merb'
6 | require 'spec'
7 | require 'spec/rake/spectask'
8 | require 'chef'
9 |
10 | include FileUtils
11 |
12 | GEM = "chef-server"
13 | CHEF_SERVER_VERSION = "0.5.7"
14 | AUTHOR = "Opscode"
15 | EMAIL = "chef@opscode.com"
16 | HOMEPAGE = "http://wiki.opscode.com/display/chef"
17 | SUMMARY = "A systems integration framework, built to bring the benefits of configuration management to your entire infrastructure."
18 |
19 | # Load the basic runtime dependencies; this will include
20 | # any plugins and therefore plugin rake tasks.
21 | init_env = ENV['MERB_ENV'] || 'rake'
22 | Merb.load_dependencies(:environment => init_env)
23 |
24 | # Get Merb plugins and dependencies
25 | Merb::Plugins.rakefiles.each { |r| require r }
26 |
27 | # Load any app level custom rakefile extensions from lib/tasks
28 | tasks_path = File.join(File.dirname(__FILE__), "lib", "tasks")
29 | rake_files = Dir["#{tasks_path}/*.rake"]
30 | rake_files.each{|rake_file| load rake_file }
31 |
32 | desc "Start runner environment"
33 | task :merb_env do
34 | Merb.start_environment(:environment => init_env, :adapter => 'runner')
35 | end
36 |
37 | require 'spec/rake/spectask'
38 | require 'merb-core/test/tasks/spectasks'
39 | desc 'Default: run spec examples'
40 | task :default => 'spec'
41 |
42 | ##############################################################################
43 | # ADD YOUR CUSTOM TASKS IN /lib/tasks
44 | # NAME YOUR RAKE FILES file_name.rake
45 | ##############################################################################
46 |
--------------------------------------------------------------------------------
/chef-server/bin/chef-server:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | #
3 | # ./chef-server - Serving up piping hot infrastructure!
4 | #
5 | # Author:: Adam Jacob ()
6 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
7 | # License:: Apache License, Version 2.0
8 | #
9 | # Licensed under the Apache License, Version 2.0 (the "License");
10 | # you may not use this file except in compliance with the License.
11 | # You may obtain a copy of the License at
12 | #
13 | # http://www.apache.org/licenses/LICENSE-2.0
14 | #
15 | # Unless required by applicable law or agreed to in writing, software
16 | # distributed under the License is distributed on an "AS IS" BASIS,
17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | # See the License for the specific language governing permissions and
19 | # limitations under the License.
20 |
21 | # Based on the 'merb' command, by Ezra
22 |
23 | require "rubygems"
24 | require "merb-core"
25 | require "chef"
26 |
27 | Dir.chdir File.join(File.dirname(__FILE__),"..")
28 | __DIR__ = Dir.getwd
29 |
30 | if ARGV[0] && ARGV[0] =~ /^[^-]/
31 | ARGV.push "-H"
32 | end
33 | unless %w[-a --adapter -i --irb-console -r --script-runner].any? { |o| ARGV.index(o) }
34 | ARGV.push *%w[-a mongrel]
35 | end
36 | ARGV.push *[ "-I", File.join(__DIR__, "config", "init.rb") ]
37 | ARGV.push *[ "-m", __DIR__]
38 |
39 | if index = ARGV.index("-C")
40 | config = ARGV[index+1]
41 | ARGV.delete("-C")
42 | ARGV.delete(config)
43 | Chef::Config.from_file(File.expand_path(config))
44 | else
45 | Chef::Config.from_file(
46 | File.join("/etc", "chef", "server.rb")
47 | )
48 | end
49 |
50 | Merb.start
51 |
--------------------------------------------------------------------------------
/chef/lib/chef/mixin/generate_url.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/platform'
20 |
21 | class Chef
22 | module Mixin
23 | module GenerateURL
24 |
25 | def generate_cookbook_url(url, cookbook, type, node, args=nil)
26 | new_url = nil
27 | if url =~ /^(http|https):\/\//
28 | new_url = url
29 | else
30 | new_url = "cookbooks/#{cookbook}/#{type}?"
31 | new_url += "id=#{url}"
32 | platform, version = Chef::Platform.find_platform_and_version(node)
33 | if type == "files" || type == "templates"
34 | new_url += "&platform=#{platform}&version=#{version}&fqdn=#{node[:fqdn]}"
35 | end
36 | if args
37 | args.each do |key, value|
38 | new_url += "{key}=#{value}"
39 | end
40 | end
41 | end
42 |
43 | return new_url
44 | end
45 |
46 | end
47 | end
48 | end
49 |
--------------------------------------------------------------------------------
/chef/spec/unit/resource/http_request_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::HttpRequest do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::HttpRequest.new("fakey_fakerton")
25 | end
26 |
27 | it "should create a new Chef::Resource::HttpRequest" do
28 | @resource.should be_a_kind_of(Chef::Resource)
29 | @resource.should be_a_kind_of(Chef::Resource::HttpRequest)
30 | end
31 |
32 | it "should set url to a string" do
33 | @resource.url "http://slashdot.org"
34 | @resource.url.should eql("http://slashdot.org")
35 | end
36 |
37 | it "should set the message to the name by default" do
38 | @resource.message.should eql("fakey_fakerton")
39 | end
40 |
41 | it "should set message to a string" do
42 | @resource.message "monkeybars"
43 | @resource.message.should eql("monkeybars")
44 | end
45 |
46 | end
--------------------------------------------------------------------------------
/example-repository/config/rake.rb:
--------------------------------------------------------------------------------
1 | ###
2 | # Company and SSL Details
3 | ###
4 |
5 | # The company name - used for SSL certificates, and in various other places
6 | COMPANY_NAME = "Opscode"
7 |
8 | # The Country Name to use for SSL Certificates
9 | SSL_COUNTRY_NAME = "US"
10 |
11 | # The State Name to use for SSL Certificates
12 | SSL_STATE_NAME = "Washington"
13 |
14 | # The Locality Name for SSL - typically, the city
15 | SSL_LOCALITY_NAME = "Seattle"
16 |
17 | # What department?
18 | SSL_ORGANIZATIONAL_UNIT_NAME = "Operations"
19 |
20 | # The SSL contact email address
21 | SSL_EMAIL_ADDRESS = "ops@example.com"
22 |
23 | # License for new Cookbooks
24 | # Can be :apachev2 or :none
25 | NEW_COOKBOOK_LICENSE = :apachev2
26 |
27 | ##########################
28 | # Chef Repository Layout #
29 | ##########################
30 |
31 | # Where to find upstream cookbooks
32 | COOKBOOK_PATH = "/var/chef/cookbooks"
33 |
34 | # Where to find site-local modifications to upstream cookbooks
35 | SITE_COOKBOOK_PATH = "/var/chef/site-cookbooks"
36 |
37 | # Chef Config Path
38 | CHEF_CONFIG_PATH = "/etc/chef"
39 |
40 | # The location of the Chef Server Config file (on the server)
41 | CHEF_SERVER_CONFIG = File.join(CHEF_CONFIG_PATH, "server.rb")
42 |
43 | # The location of the Chef Client Config file (on the client)
44 | CHEF_CLIENT_CONFIG = File.join(CHEF_CONFIG_PATH, "client.rb")
45 |
46 | ###
47 | # Useful Extras (which you probably don't need to change)
48 | ###
49 |
50 | # The top of the repository checkout
51 | TOPDIR = File.expand_path(File.join(File.dirname(__FILE__), ".."))
52 |
53 | # Where to store certificates generated with ssl_cert
54 | CADIR = File.expand_path(File.join(TOPDIR, "certificates"))
55 |
--------------------------------------------------------------------------------
/features/support/env.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | %w{chef chef-server}.each do |inc_dir|
20 | $: << File.join(File.dirname(__FILE__), '..', '..', inc_dir, 'lib')
21 | end
22 |
23 | require 'spec/expectations'
24 | require 'chef'
25 | require 'chef/config'
26 | require 'chef/client'
27 | require 'tmpdir'
28 |
29 | Chef::Config.from_file(File.join(File.dirname(__FILE__), '..', 'data', 'config', 'client.rb'))
30 | Ohai::Config[:log_level] = :error
31 |
32 | class ChefWorld
33 | attr_accessor :client, :tmpdir
34 |
35 | def initialize
36 | @client = Chef::Client.new
37 | @tmpdir = File.join(Dir.tmpdir, "chef_integration")
38 | @cleanup_files = Array.new
39 | @cleanup_dirs = Array.new
40 | @recipe = nil
41 | end
42 | end
43 |
44 | World do
45 | ChefWorld.new
46 | end
47 |
48 | After do
49 | @cleanup_files.each do |file|
50 | system("rm #{file}")
51 | end
52 | @cleanup_dirs.each do |dir|
53 | system("rm -rf #{dir}")
54 | end
55 | end
56 |
57 |
--------------------------------------------------------------------------------
/chef/lib/chef.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | $:.unshift(File.dirname(__FILE__)) unless
20 | $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
21 |
22 | require 'rubygems'
23 | require 'extlib'
24 | require 'chef/exceptions'
25 | require 'chef/log'
26 | require 'chef/config'
27 | Dir[File.join(File.dirname(__FILE__), 'chef/mixin/**/*.rb')].sort.each { |lib| require lib }
28 |
29 | class Chef
30 | VERSION = '0.5.7'
31 |
32 | class << self
33 | def fatal!(msg, err = -1)
34 | Chef::Log.fatal(msg)
35 | exit err
36 | end
37 | end
38 | end
39 |
40 | # Adds a Dir.glob to Ruby 1.8.5, for compat
41 | if RUBY_VERSION < "1.8.6"
42 | class Dir
43 | class << self
44 | alias_method :glob_, :glob
45 | def glob(*args)
46 | raise ArgumentError if args.empty?
47 | args.inject([]) { |r, p| r + glob_(p) }
48 | end
49 | alias_method :[], :glob
50 | end
51 | end
52 | end
53 |
--------------------------------------------------------------------------------
/chef/spec/unit/provider_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
20 |
21 | describe Chef::Provider do
22 | before(:each) do
23 | @resource = Chef::Resource.new("funk")
24 | @node = Chef::Node.new
25 | @node.name "latte"
26 | @provider = Chef::Provider.new(@node, @resource)
27 | end
28 |
29 | it "should return a Chef::Provider" do
30 | @provider.should be_a_kind_of(Chef::Provider)
31 | end
32 |
33 | it "should store the resource passed to new as new_resource" do
34 | @provider.new_resource.should eql(@resource)
35 | end
36 |
37 | it "should store the node passed to new as node" do
38 | @provider.node.should eql(@node)
39 | end
40 |
41 | it "should have nil for current_resource by default" do
42 | @provider.current_resource.should eql(nil)
43 | end
44 |
45 | it "should return true for action_nothing" do
46 | @provider.action_nothing.should eql(true)
47 | end
48 | end
--------------------------------------------------------------------------------
/chef-server-slice/app/helpers/status_helper.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Joe Williams (joe@joetify.com)
3 | # Copyright:: Copyright (c) 2009 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | require 'chef' / 'node'
19 |
20 | module Merb
21 | module ChefServerSlice
22 | module StatusHelper
23 | def recipe_list(node)
24 | data = Chef::Node.load(node)
25 | response = ""
26 | data.recipes.each do |recipe|
27 | response << " #{recipe}"
28 | end
29 | response
30 | end
31 |
32 | def get_info(node)
33 | data = Chef::Node.load(node)
34 | response = ""
35 | response << "FQDN: #{data[:fqdn]} "
36 | response << "IP Address: #{data[:ipaddress]} "
37 | ohai_time = Time.at(data[:ohai_time])
38 | response << "Last Check-in: #{ohai_time} "
39 | response << "Uptime: #{data[:uptime]} "
40 | response << "Platform: #{data[:platform]} #{data[:platform_version]}"
41 | response
42 | end
43 | end
44 |
45 | end
46 | end
47 |
--------------------------------------------------------------------------------
/features/steps/run_client.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ###
20 | # When
21 | ###
22 | When /^I run the chef\-client$/ do
23 | log_level = ENV["LOG_LEVEL"] ? ENV["LOG_LEVEL"] : "error"
24 | status = Chef::Mixin::Command.popen4(
25 | "chef-client -l #{log_level} -c #{File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'config', 'client.rb'))}", :waitlast => true) do |p, i, o, e|
26 | i.close
27 | @stdout = o.gets(nil)
28 | @stderr = e.gets(nil)
29 | end
30 | @status = status
31 | end
32 |
33 | ###
34 | # Then
35 | ###
36 | Then /^the run should exit '(.+)'$/ do |exit_code|
37 | begin
38 | @status.exitstatus.should eql(exit_code.to_i)
39 | rescue
40 | print_output
41 | raise
42 | end
43 | print_output if ENV["LOG_LEVEL"] == "debug"
44 | end
45 |
46 | def print_output
47 | puts "--- run stdout:"
48 | puts @stdout
49 | puts "--- run stderr"
50 | puts @stderr
51 | end
52 |
53 | Then /^stdout should have '(.+)'$/ do |to_match|
54 | @stdout.should match(/#{to_match}/m)
55 | end
56 |
--------------------------------------------------------------------------------
/chef/lib/chef/resource/template.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource/file'
20 |
21 | class Chef
22 | class Resource
23 | class Template < Chef::Resource::File
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :template
28 | @action = "create"
29 | @source = nil
30 | @cookbook = nil
31 | @variables = Hash.new
32 | end
33 |
34 | def source(file=nil)
35 | set_or_return(
36 | :source,
37 | file,
38 | :kind_of => [ String ]
39 | )
40 | end
41 |
42 | def variables(args=nil)
43 | set_or_return(
44 | :variables,
45 | args,
46 | :kind_of => [ Hash ]
47 | )
48 | end
49 |
50 | def cookbook(args=nil)
51 | set_or_return(
52 | :cookbook,
53 | args,
54 | :kind_of => [ String ]
55 | )
56 | end
57 |
58 | end
59 | end
60 | end
--------------------------------------------------------------------------------
/chef-server-slice/app/controllers/cookbooks.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Author:: Christopher Brown ()
4 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
5 | # License:: Apache License, Version 2.0
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | require 'chef' / 'cookbook_loader'
21 |
22 | class ChefServerSlice::Cookbooks < ChefServerSlice::Application
23 |
24 | provides :html, :json
25 |
26 | def index
27 | @cl = Chef::CookbookLoader.new
28 | display @cl
29 | end
30 |
31 | def show
32 | @cl = Chef::CookbookLoader.new
33 | @cookbook = @cl[params[:id]]
34 | raise NotFound unless @cookbook
35 | display @cookbook
36 | end
37 |
38 | def recipe_files
39 | @recipe_files = load_all_files(:recipes)
40 | display @recipe_files
41 | end
42 |
43 | def attribute_files
44 | @attribute_files = load_all_files(:attributes)
45 | display @attribute_files
46 | end
47 |
48 | def definition_files
49 | @definition_files = load_all_files(:definitions)
50 | display @definition_files
51 | end
52 |
53 | def library_files
54 | @lib_files = load_all_files(:libraries)
55 | display @lib_files
56 | end
57 |
58 | end
59 |
--------------------------------------------------------------------------------
/features/manage_files.feature:
--------------------------------------------------------------------------------
1 | Feature: Manage Files
2 | In order to save time
3 | As a Developer
4 | I want to manage files declaratively
5 |
6 | Scenario: Create a file
7 | Given a validated node
8 | And it includes the recipe 'manage_files::create_a_file'
9 | When I run the chef-client
10 | Then the run should exit '0'
11 | And a file named 'create_a_file.txt' should exist
12 |
13 | Scenario: Set the owner of a created file
14 | Given a validated node
15 | And it includes the recipe 'manage_files::set_the_owner_of_a_created_file'
16 | When I run the chef-client
17 | Then the run should exit '0'
18 | And the file named 'create_a_file.txt' should be owned by 'nobody'
19 |
20 | Scenario: Delete a file
21 | Given a validated node
22 | And it includes the recipe 'manage_files::delete_a_file'
23 | When I run the chef-client
24 | Then the run should exit '0'
25 | And a file named 'create_a_file.txt' should not exist
26 |
27 | Scenario: Delete a file that already does not exist
28 | Given a validated node
29 | And it includes the recipe 'manage_files::delete_a_file_that_does_not_already_exist'
30 | When I run the chef-client
31 | Then the run should exit '1'
32 | And stdout should have 'Cannot delete file'
33 |
34 | Scenario: Touch a file
35 | Given a validated node
36 | And it includes the recipe 'manage_files::touch_a_file'
37 | And we have an empty file named 'touch_test.txt'
38 | And we have the atime/mtime of 'touch_test.txt'
39 | When I run the chef-client
40 | Then the run should exit '0'
41 | And the atime of 'touch_test.txt' should be different
42 | And the mtime of 'touch_test.txt' should be different
43 |
--------------------------------------------------------------------------------
/chef/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake/gempackagetask'
3 | require 'rake/rdoctask'
4 | require './tasks/rspec.rb'
5 |
6 | GEM = "chef"
7 | CHEF_VERSION = "0.5.7"
8 | AUTHOR = "Adam Jacob"
9 | EMAIL = "adam@opscode.com"
10 | HOMEPAGE = "http://wiki.opscode.com/display/chef"
11 | SUMMARY = "A systems integration framework, built to bring the benefits of configuration management to your entire infrastructure."
12 |
13 | spec = Gem::Specification.new do |s|
14 | s.name = GEM
15 | s.version = CHEF_VERSION
16 | s.platform = Gem::Platform::RUBY
17 | s.has_rdoc = true
18 | s.extra_rdoc_files = ["README.txt", "LICENSE" ]
19 | s.summary = SUMMARY
20 | s.description = s.summary
21 | s.author = AUTHOR
22 | s.email = EMAIL
23 | s.homepage = HOMEPAGE
24 |
25 | # Uncomment this to add a dependency
26 | s.add_dependency "ruby-openid"
27 | s.add_dependency "json"
28 | s.add_dependency "erubis"
29 | s.add_dependency "extlib"
30 | s.add_dependency "stomp"
31 | s.add_dependency "ohai"
32 |
33 | s.bindir = "bin"
34 | s.executables = %w( chef-client chef-solo )
35 |
36 | s.require_path = 'lib'
37 | s.files = %w(LICENSE README.txt Rakefile) + Dir.glob("{lib,specs,config,examples}/**/*")
38 | end
39 |
40 | Rake::GemPackageTask.new(spec) do |pkg|
41 | pkg.gem_spec = spec
42 | end
43 |
44 | Rake::RDocTask.new do |rd|
45 | rd.rdoc_files.include("lib/**/*.rb")
46 | end
47 |
48 | task :install => :package do
49 | sh %{sudo gem install pkg/#{GEM}-#{CHEF_VERSION} --no-rdoc --no-ri}
50 | end
51 |
52 | task :uninstall do
53 | sh %{sudo gem uninstall #{GEM} -x -v #{CHEF_VERSION} }
54 | end
55 |
56 | desc "create a gemspec file"
57 | task :make_spec do
58 | File.open("#{GEM}.gemspec", "w") do |file|
59 | file.puts spec.to_ruby
60 | end
61 | end
62 |
63 |
--------------------------------------------------------------------------------
/chef/spec/unit/resource/script_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::Script do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::Script.new("fakey_fakerton")
25 | end
26 |
27 | it "should create a new Chef::Resource::Script" do
28 | @resource.should be_a_kind_of(Chef::Resource)
29 | @resource.should be_a_kind_of(Chef::Resource::Script)
30 | end
31 |
32 | it "should have a resource name of :script" do
33 | @resource.resource_name.should eql(:script)
34 | end
35 |
36 | it "should set command to the argument provided to new" do
37 | @resource.command.should eql("fakey_fakerton")
38 | end
39 |
40 | it "should accept a string for the code" do
41 | @resource.code "hey jude"
42 | @resource.code.should eql("hey jude")
43 | end
44 |
45 | it "should accept a string for the interpreter" do
46 | @resource.interpreter "naaaaNaNaNaaNaaNaaNaa"
47 | @resource.interpreter.should eql("naaaaNaNaNaaNaaNaaNaa")
48 | end
49 |
50 | end
--------------------------------------------------------------------------------
/chef/lib/chef/resource/group.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 OpsCode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | class Chef
20 | class Resource
21 | class Group < Chef::Resource
22 |
23 | def initialize(name, collection=nil, node=nil)
24 | super(name, collection, node)
25 | @resource_name = :group
26 | @group_name = name
27 | @gid = nil
28 | @members = []
29 | @action = :create
30 | @allowed_actions.push(:create, :remove, :modify, :manage)
31 | end
32 |
33 | def group_name(arg=nil)
34 | set_or_return(
35 | :group_name,
36 | arg,
37 | :kind_of => [ String ]
38 | )
39 | end
40 |
41 | def gid(arg=nil)
42 | set_or_return(
43 | :gid,
44 | arg,
45 | :kind_of => [ Integer ]
46 | )
47 | end
48 |
49 | def members(arg=nil)
50 | converted_members = arg.is_a?(String) ? [].push(arg) : arg
51 | set_or_return(
52 | :members,
53 | converted_members,
54 | :kind_of => [ Array ]
55 | )
56 | end
57 |
58 | end
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/chef-server-slice/app/controllers/search.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Author:: Christopher Brown ()
4 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
5 | # License:: Apache License, Version 2.0
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 | #
19 |
20 | require 'chef' / 'search'
21 | require 'chef' / 'queue'
22 |
23 | class ChefServerSlice::Search < ChefServerSlice::Application
24 |
25 | provides :html, :json
26 |
27 | def index
28 | @s = Chef::Search.new
29 | @search_indexes = @s.list_indexes
30 | display @search_indexes
31 | end
32 |
33 | def show
34 | @s = Chef::Search.new
35 |
36 | query = params[:q].nil? ? "*" : (params[:q].empty? ? "*" : params[:q])
37 | attributes = params[:a].nil? ? [] : params[:a].split(",").collect { |a| a.to_sym }
38 | @results = @s.search(params[:id], query, attributes)
39 |
40 | display @results
41 | end
42 |
43 | def destroy
44 | @s = Chef::Search.new
45 | @entries = @s.search(params[:id], "*")
46 | @entries.each do |entry|
47 | Chef::Queue.send_msg(:queue, :remove, entry)
48 | end
49 | @status = 202
50 | if content_type == :html
51 | redirect url(:search)
52 | else
53 | display @entries
54 | end
55 | end
56 |
57 | end
58 |
--------------------------------------------------------------------------------
/chef/examples/sample_recipe.rb:
--------------------------------------------------------------------------------
1 | include_recipe "openldap"
2 | include_recipe "openldap::client"
3 | include_recipe "openldap::server"
4 | include_recipe "resolver"
5 | include_recipe "base"
6 |
7 | exec "restart-apache" do
8 | path "/usr/bin:/usr/local/bin"
9 | command "/etc/init.d/apache2 restart"
10 | action :nothing
11 | end
12 |
13 | service "apache2" do
14 | insure "running"
15 | has_restart true
16 | end
17 |
18 | file "/etc/nsswitch.conf" do
19 | owner "root"
20 | group "root"
21 | mode 0644
22 | notifies :restart, resources("service[openldap]"), :immediately
23 | end
24 |
25 | service "apache2" do
26 | action "enabled"
27 | subscribes :restart, resources("/etc/nsswitch.conf"), :immediately
28 | end
29 |
30 | file "/etc/ldap.conf" do
31 | owner "root"
32 | group "root"
33 | mode 0644
34 | end
35 |
36 | file "/srv/monkey" do
37 | insure "present"
38 | owner "root"
39 | group "root"
40 | mode 0644
41 | end
42 |
43 | file "/srv/owl" do
44 | insure "present"
45 | owner "root"
46 | group "root"
47 | mode 0644
48 | end
49 |
50 | file "/srv/zen" do
51 | insure "absent"
52 | end
53 |
54 | #
55 | # file "/srv/monkey" do |f|
56 | # f.insure = "present"
57 | # f.owner = "adam"
58 | # f.group = "adam"
59 | # f.mode = 0644
60 | # f.before = resources(:file => "/etc/nsswitch.conf")
61 | # end
62 | #
63 | # file "/etc/ldap-nss.conf" do |f|
64 | # f.insure = "present"
65 | # f.owner = "root"
66 | # f.group = "root"
67 | # f.mode = 0644
68 | # f.notifies = :refresh, resources(:file => "/etc/ldap.conf")
69 | # end
70 | #
71 | # file "/etc/coffee.conf" do |f|
72 | # f.insure = "present"
73 | # f.owner = "root"
74 | # f.group = "root"
75 | # f.mode = 0644
76 | # f.subscribes = :polio, resources(:file => "/etc/nsswitch.conf")
77 | # end
--------------------------------------------------------------------------------
/chef/lib/chef/resource/link.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require 'chef/resource'
20 |
21 | class Chef
22 | class Resource
23 | class Link < Chef::Resource
24 |
25 | def initialize(name, collection=nil, node=nil)
26 | super(name, collection, node)
27 | @resource_name = :link
28 | @to = nil
29 | @action = :create
30 | @link_type = :symbolic
31 | @target_file = name
32 | @allowed_actions.push(:create, :delete)
33 | end
34 |
35 | def to(arg=nil)
36 | set_or_return(
37 | :source_file,
38 | arg,
39 | :kind_of => String
40 | )
41 | end
42 |
43 | def target_file(arg=nil)
44 | set_or_return(
45 | :target_file,
46 | arg,
47 | :kind_of => String
48 | )
49 | end
50 |
51 | def link_type(arg=nil)
52 | real_arg = arg.kind_of?(String) ? arg.to_sym : arg
53 | set_or_return(
54 | :link_type,
55 | real_arg,
56 | :equal_to => [ :symbolic, :hard ]
57 | )
58 | end
59 |
60 | end
61 | end
62 | end
--------------------------------------------------------------------------------
/chef/spec/unit/resource/remote_file_spec.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Author:: Adam Jacob ()
3 | # Copyright:: Copyright (c) 2008 Opscode, Inc.
4 | # License:: Apache License, Version 2.0
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
20 |
21 | describe Chef::Resource::RemoteFile do
22 |
23 | before(:each) do
24 | @resource = Chef::Resource::RemoteFile.new("fakey_fakerton")
25 | end
26 |
27 | describe "initialize" do
28 | it "should create a new Chef::Resource::RemoteFile" do
29 | @resource.should be_a_kind_of(Chef::Resource)
30 | @resource.should be_a_kind_of(Chef::Resource::File)
31 | @resource.should be_a_kind_of(Chef::Resource::RemoteFile)
32 | end
33 | end
34 |
35 | describe "source" do
36 | it "should accept a string for the remote file source" do
37 | @resource.source "something"
38 | @resource.source.should eql("something")
39 | end
40 | end
41 |
42 | describe "cookbook" do
43 | it "should accept a string for the cookbook name" do
44 | @resource.cookbook "something"
45 | @resource.cookbook.should eql("something")
46 | end
47 |
48 | it "should default to nil" do
49 | @resource.cookbook.should == nil
50 | end
51 | end
52 |
53 | end
--------------------------------------------------------------------------------
/chef-server/config/router.rb:
--------------------------------------------------------------------------------
1 | # Merb::Router is the request routing mapper for the merb framework.
2 | #
3 | # You can route a specific URL to a controller / action pair:
4 | #
5 | # match("/contact").
6 | # to(:controller => "info", :action => "contact")
7 | #
8 | # You can define placeholder parts of the url with the :symbol notation. These
9 | # placeholders will be available in the params hash of your controllers. For example:
10 | #
11 | # match("/books/:book_id/:action").
12 | # to(:controller => "books")
13 | #
14 | # Or, use placeholders in the "to" results for more complicated routing, e.g.:
15 | #
16 | # match("/admin/:module/:controller/:action/:id").
17 | # to(:controller => ":module/:controller")
18 | #
19 | # You can specify conditions on the placeholder by passing a hash as the second
20 | # argument of "match"
21 | #
22 | # match("/registration/:course_name", :course_name => /^[a-z]{3,5}-\d{5}$/).
23 | # to(:controller => "registration")
24 | #
25 | # You can also use regular expressions, deferred routes, and many other options.
26 | # See merb/specs/merb/router.rb for a fairly complete usage sample.
27 |
28 | Merb.logger.info("Compiling routes...")
29 | Merb::Router.prepare do
30 | # RESTful routes
31 | # resources :posts
32 |
33 | # Adds the required routes for merb-auth using the password slice
34 | # slice(:merb_auth_slice_password, :name_prefix => nil, :path_prefix => "")
35 | slice(:chef_server_slice)
36 | # This is the default route for /:controller/:action/:id
37 | # This is fine for most cases. If you're heavily using resource-based
38 | # routes, you may want to comment/remove this line to prevent
39 | # clients from calling your create or destroy actions with a GET
40 | default_routes
41 |
42 | # Change this for your home page to be available at /
43 | # match('/').to(:controller => 'whatever', :action =>'index')
44 | end
45 |
--------------------------------------------------------------------------------