Class: DataBags
Instance Method Summary
collapse
Methods inherited from Application
#access_denied, #admin_or_requesting_node, #authenticate_every, #display, #get_available_recipes, #is_admin, #is_admin_or_validator, #redirect_back_or_default, #store_location
Instance Method Details
#create ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/data_bags.rb', line 44
def create
@data_bag = nil
if params.has_key?("inflated_object")
@data_bag = params["inflated_object"]
else
@data_bag = Chef::DataBag.new
@data_bag.name(params["name"])
end
exists = true
begin
Chef::DataBag.cdb_load(@data_bag.name)
rescue Chef::Exceptions::CouchDBNotFound
exists = false
end
raise Conflict, "Data bag already exists" if exists
self.status = 201
@data_bag.cdb_save
display({ :uri => absolute_url(:datum, :id => @data_bag.name) })
end
|
#destroy ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/data_bags.rb', line 64
def destroy
begin
@data_bag = Chef::DataBag.cdb_load(params[:id])
rescue Chef::Exceptions::CouchDBNotFound => e
raise NotFound, "Cannot load data bag #{params[:id]}"
end
@data_bag.cdb_destroy
@data_bag.couchdb_rev = nil
display @data_bag
end
|
#index ⇒ Object
29
30
31
32
33
|
# File 'app/controllers/data_bags.rb', line 29
def index
@bag_list = Chef::DataBag.cdb_list(false)
display(@bag_list.inject({}) { |r,b| r[b] = absolute_url(:datum, :id => b); r })
end
|
#show ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'app/controllers/data_bags.rb', line 35
def show
begin
@data_bag = Chef::DataBag.cdb_load(params[:id])
rescue Chef::Exceptions::CouchDBNotFound => e
raise NotFound, "Cannot load data bag #{params[:id]}"
end
display(@data_bag.list.inject({}) { |res, i| res[i] = absolute_url(:data_bag_item, :data_bag_id => @data_bag.name, :id => i); res })
end
|