/usr/share/chef-server-api/app/controllers/roles.rb is in chef-server-api 10.12.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | require 'chef/role'
class Roles < Application
provides :json
before :authenticate_every
before :is_admin, :only => [ :create, :update, :destroy ]
# GET /roles
def index
@role_list = Chef::Role.cdb_list(true)
display(@role_list.inject({}) { |r,role| r[role.name] = absolute_url(:role, role.name); r })
end
# GET /roles/:id
def show
begin
@role = Chef::Role.cdb_load(params[:id])
rescue Chef::Exceptions::CouchDBNotFound => e
raise NotFound, "Cannot load role #{params[:id]}"
end
@role.couchdb_rev = nil
display @role
end
# POST /roles
def create
@role = params["inflated_object"]
exists = true
begin
Chef::Role.cdb_load(@role.name)
rescue Chef::Exceptions::CouchDBNotFound
exists = false
end
raise Conflict, "Role already exists" if exists
@role.cdb_save
self.status = 201
display({ :uri => absolute_url(:role, :id => @role.name) })
end
# PUT /roles/:id
def update
begin
@role = Chef::Role.cdb_load(params[:id])
rescue Chef::Exceptions::CouchDBNotFound => e
raise NotFound, "Cannot load role #{params[:id]}"
end
@role.update_from!(params["inflated_object"])
@role.cdb_save
self.status = 200
@role.couchdb_rev = nil
display(@role)
end
# DELETE /roles/:id
def destroy
begin
@role = Chef::Role.cdb_load(params[:id])
rescue Chef::Exceptions::CouchDBNotFound => e
raise NotFound, "Cannot load role #{params[:id]}"
end
@role.cdb_destroy
display @role
end
# GET /roles/:id/environments/:env_id
def environment
begin
@role = Chef::Role.cdb_load(params[:role_id])
rescue Chef::Exceptions::CouchDBNotFound => e
raise NotFound, "Cannot load role #{params[:role_id]}"
end
display("run_list" => @role.env_run_lists[params[:env_id]])
end
# GET /roles/:id/environments
def environments
begin
@role = Chef::Role.cdb_load(params[:role_id])
rescue Chef::Exceptions::CouchDBNotFound => e
raise NotFound, "Cannot load role #{params[:role_id]}"
end
display(@role.env_run_lists.keys.sort)
end
end
|