Skip to content

Commit 7ae2fd7

Browse files
committed
Merge branch 'master' into imbriaco/chef-248
2 parents ab90508 + e0319db commit 7ae2fd7

84 files changed

Lines changed: 1299 additions & 941 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

chef-server-slice/app/controllers/application.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
class ChefServerSlice::Application < Merb::Controller
2424

25+
include Chef::Mixin::Checksum
26+
2527
controller_for_slice
2628

2729
# Generate the absolute url for a slice - takes the slice's :path_prefix into account.
@@ -168,7 +170,8 @@ def load_all_files(segment)
168170
file_name = mo[1]
169171
files << {
170172
:cookbook => cookbook.name,
171-
:name => file_name
173+
:name => file_name,
174+
:checksum => checksum(sf)
172175
}
173176
end
174177
end

chef-server-slice/app/controllers/cookbook_files.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ def index
4545

4646
def show
4747
only_provides :json
48-
to_send = find_preferred_file(
49-
params[:cookbook_id],
50-
:remote_file,
51-
params[:id],
52-
params[:fqdn],
53-
params[:platform],
54-
params[:version]
55-
)
56-
raise NotFound, "Cannot find a suitable file!" unless to_send
48+
begin
49+
to_send = find_preferred_file(
50+
params[:cookbook_id],
51+
:remote_file,
52+
params[:id],
53+
params[:fqdn],
54+
params[:platform],
55+
params[:version]
56+
)
57+
rescue Chef::Exceptions::FileNotFound
58+
raise NotFound, "Cannot find a suitable file!"
59+
end
60+
5761
current_checksum = checksum(to_send)
5862
Chef::Log.debug("old sum: #{params[:checksum]}, new sum: #{current_checksum}")
5963
if current_checksum == params[:checksum]

chef-server-slice/app/controllers/openid_consumer.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,22 @@ class ChefServerSlice::OpenidConsumer < ChefServerSlice::Application
2828
def index
2929
if request.xhr?
3030
render :layout => false
31-
else
31+
else
3232
render
3333
end
3434
end
35-
35+
3636
def start
3737
oid = params[:openid_identifier]
3838
providers = Chef::Config[:openid_providers]
39-
raise(Unauthorized, "Sorry, #{openid} is not an authorized OpenID.") unless is_authorized_openid_identifier?(oid, providers)
40-
raise(Unauthorized, "Sorry, #{openid} is not an allowed OpenID Provider.") unless is_valid_openid_provider?(oid,providers)
41-
39+
raise(Unauthorized, "Sorry, #{oid} is not an allowed OpenID Provider.") unless is_valid_openid_provider?(oid,providers)
40+
4241
begin
4342
oidreq = consumer.begin(oid)
4443
rescue OpenID::OpenIDError => e
4544
raise BadRequest, "Discovery failed for #{params[:openid_identifier]}: #{e}"
4645
end
47-
46+
4847
return_to = absolute_slice_url(:openid_consumer_complete)
4948
realm = absolute_slice_url(:openid_consumer)
5049

@@ -57,9 +56,12 @@ def start
5756
end
5857

5958
def login
59+
oid = params[:openid_identifier]
60+
authorized_openids = Chef::Config[:authorized_openid_identifiers]
61+
raise(Unauthorized, "Sorry, #{oid} is not an authorized OpenID.") unless is_authorized_openid_identifier?(oid, authorized_openids)
6062
start
6163
end
62-
64+
6365
def complete
6466
# FIXME - url_for some action is not necessarily the current URL.
6567
current_url = absolute_slice_url(:openid_consumer_complete)
@@ -96,17 +98,17 @@ def logout
9698
end
9799

98100
private
99-
#
100-
#
101-
101+
#
102+
#
103+
102104
# Returns true if the openid is at a valid provider, based on whether :openid_providers is
103105
# defined. Raises an exception if it is not an allowed provider.
104106
def is_valid_openid_provider?(openid,providers)
105107
(providers && providers.detect {|p| openid =~ /^https?:\/\/#{p}/ or openid =~ /^#{p}/}) || true
106108
end
107109

108-
def is_authorized_openid_identifier?(openid,providers)
109-
(providers && providers.detect { |p| openid==p }) || true
110+
def is_authorized_openid_identifier?(openid,authorized_openids)
111+
(authorized_openids && authorized_openids.detect { |p| openid==p })
110112
end
111113

112114
def consumer
@@ -117,5 +119,5 @@ def consumer
117119
OpenID::Store::Filesystem.new(Chef::Config[:openid_cstore_path])
118120
end)
119121
end
120-
122+
121123
end

chef-server-slice/app/controllers/search_entries.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ChefServerSlice::SearchEntries < ChefServerSlice::Application
2626

2727
def index
2828
@s = Chef::Search.new
29-
@entries = @s.search(params[:search_id], "?*")
29+
@entries = @s.search(params[:search_id])
3030
display @entries
3131
end
3232

@@ -57,7 +57,7 @@ def update
5757

5858
def destroy
5959
@s = Chef::Search.new
60-
@entries = @s.search(params[:id], "?*")
60+
@entries = @s.search(params[:id])
6161
@entries.each do |entry|
6262
Chef::Queue.send_msg(:queue, :remove, entry)
6363
end

chef-server-slice/app/views/nodes/_node.html.haml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
- @node.recipes.each_with_index do |recipe, index|
1111
%tr{:class => "#{index % 2 == 1 ? 'odd' : 'even'}"}
1212
%td{:colspan => 2}= recipe
13+
%table.table
14+
%tr
15+
%th.first Tags
16+
%th.last &nbsp
17+
- if @node[:tags].empty?
18+
%tr
19+
%td{:colspan => 2} This node has no tags applied, double click to add one.
20+
- else
21+
%tr
22+
%td{:colspan => 2}= @node[:tags].join(", ")
1323
%table.table
1424
%tr
1525
%th.first Attributes
@@ -19,4 +29,5 @@
1929
%td{:colspan => 2} This node has no attributes, double click to add one.
2030
- else
2131
%tr
22-
%td{:colspan => 2}= build_tree(@node)
32+
%td{:colspan => 2}= build_tree(@node)
33+

chef-server-slice/app/views/openid_consumer/index.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.content
33
%h2.title Login
44
.inner
5-
%form.form{ :method => "get", "accept-charset" => "UTF-8", :action => slice_url(:openid_consumer_start) }
5+
%form.form{ :method => "get", "accept-charset" => "UTF-8", :action => slice_url(:openid_consumer_login) }
66
.group
77
.text_field= text_field :openid_identifier
88
.group

chef-server-slice/lib/chef-server-slice.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ def self.setup_router(scope)
9494
scope.match("/cookbooks/_definition_files").to(:controller => "cookbooks", :action => "definition_files")
9595
scope.match("/cookbooks/_library_files").to(:controller => "cookbooks", :action => "library_files")
9696

97-
scope.match("/cookbooks/:cookbook_id/templates").to(:controller => "cookbook_templates", :action => "index")
98-
scope.match("/cookbooks/:cookbook_id/libraries").to(:controller => "cookbook_libraries", :action => "index")
99-
scope.match("/cookbooks/:cookbook_id/definitions").to(:controller => "cookbook_definitions", :action => "index")
100-
scope.match("/cookbooks/:cookbook_id/recipes").to(:controller => "cookbook_recipes", :action => "index")
101-
scope.match("/cookbooks/:cookbook_id/attributes").to(:controller => "cookbook_attributes", :action => "index")
102-
scope.match("/cookbooks/:cookbook_id/files").to(:controller => "cookbook_files", :action => "index")
97+
scope.match("/cookbooks/:cookbook_id/templates", :cookbook_id => /[\w\.]+/).to(:controller => "cookbook_templates", :action => "index")
98+
scope.match("/cookbooks/:cookbook_id/libraries", :cookbook_id => /[\w\.]+/).to(:controller => "cookbook_libraries", :action => "index")
99+
scope.match("/cookbooks/:cookbook_id/definitions", :cookbook_id => /[\w\.]+/).to(:controller => "cookbook_definitions", :action => "index")
100+
scope.match("/cookbooks/:cookbook_id/recipes", :cookbook_id => /[\w\.]+/).to(:controller => "cookbook_recipes", :action => "index")
101+
scope.match("/cookbooks/:cookbook_id/attributes", :cookbook_id => /[\w\.]+/).to(:controller => "cookbook_attributes", :action => "index")
102+
scope.match("/cookbooks/:cookbook_id/files", :cookbook_id => /[\w\.]+/).to(:controller => "cookbook_files", :action => "index")
103103

104104
scope.resources :cookbooks
105105
scope.resources :registrations, :controller => "openid_register"

chef-server/bin/chef-indexer

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ config = {
3131
:config_file => "/etc/chef/server.rb",
3232
}
3333
opts = OptionParser.new do |opts|
34-
opts.banner = "Usage: #{$0} [-d DIR|-r FILE] (options)"
34+
opts.banner = "Usage: #{$0} (options)"
3535
opts.on("-c CONFIG", "--config CONFIG", "The Chef Config file to use") do |c|
3636
config[:config_file] = c
3737
end
@@ -64,6 +64,8 @@ end
6464
Chef::Config.from_file(config[:config_file])
6565
Chef::Config.configure { |c| c.merge!(config) }
6666

67+
Chef::Daemon.change_privilege
68+
6769
if Chef::Config[:daemonize]
6870
unless Chef::Config[:log_location].is_a? IO
6971
Chef::Log.init(Chef::Config[:log_location])
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Chef Server Config File
3+
#
4+
5+
log_level :info
6+
search_index_path "/var/lib/chef/search_index"
7+
8+
Chef::Log::Formatter.show_time = false
9+
10+
pid_file "/var/run/chef/chef-indexer.pid"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
# Startup script for chef-indexer
3+
#
4+
# chkconfig: - 75 25
5+
# description: Server component of the Chef systems integration framework.
6+
# processname: chef-indexer
7+
#
8+
# config: /etc/sysconfig/chef-indexer
9+
# pidfile: /var/run/chef/chef-indexer.pid
10+
11+
# Source function library
12+
. /etc/init.d/functions
13+
14+
[ -f /etc/sysconfig/chef-indexer ] && . /etc/sysconfig/chef-indexer
15+
16+
prog="chef-indexer"
17+
PIDFILE=/var/run/chef/chef-indexer.pid
18+
LOCKFILE=/var/lock/subsys/$prog
19+
CONFIG=/etc/chef/indexer.rb
20+
USER="chef"
21+
GROUP="chef"
22+
LOGFILE=/var/log/chef/chef-indexer.log
23+
OPTIONS=
24+
25+
start() {
26+
echo -n "Starting $prog:"
27+
daemon chef-indexer -d -c "$CONFIG" -u "$USER" -g "$GROUP" -L "$LOGFILE" "$OPTIONS" ">/dev/null"
28+
RETVAL=$?
29+
echo
30+
[ $RETVAL -eq 0 ] && touch ${LOCKFILE}
31+
return $RETVAL
32+
}
33+
34+
stop() {
35+
echo -n "Stopping $prog: "
36+
if [ -f $PIDFILE ]; then
37+
killproc chef-indexer
38+
RETVAL=$?
39+
if [ $RETVAL -ne 0 ]; then
40+
failure;
41+
fi;
42+
else
43+
RETVAL=1
44+
failure;
45+
fi
46+
rm -f $LOCKFILE
47+
echo
48+
return $RETVAL
49+
}
50+
51+
case "$1" in
52+
start)
53+
start
54+
;;
55+
stop)
56+
stop
57+
;;
58+
restart)
59+
stop
60+
start
61+
;;
62+
condrestart)
63+
if [ -f $LOCKFILE ]; then
64+
stop
65+
start
66+
fi
67+
;;
68+
status)
69+
status chef-indexer
70+
;;
71+
*)
72+
echo "Usage: $0 {start|stop|restart|condrestart|status}"
73+
exit 1
74+
esac
75+
76+
exit $RETVAL

0 commit comments

Comments
 (0)