Class: ChefZero::Endpoints::PoliciesEndpoint

Inherits:
RestObjectEndpoint show all
Defined in:
lib/chef_zero/endpoints/policies_endpoint.rb

Overview

/policies/:group/:name

Instance Attribute Summary

Attributes inherited from RestObjectEndpoint

#identity_keys

Attributes inherited from RestBase

#server

Instance Method Summary collapse

Methods inherited from RestObjectEndpoint

#patch_request_body

Methods inherited from RestBase

#accepts?, #already_json_response, build_uri, #build_uri, #call, #create_data, #create_data_dir, #data_store, #delete_data, #delete_data_dir, #error, #exists_data?, #exists_data_dir?, #get_data, #json_only, #json_response, #list_data, #populate_defaults, #set_data, #text_response

Constructor Details

#initialize(server) ⇒ PoliciesEndpoint

Returns a new instance of PoliciesEndpoint


13
14
15
# File 'lib/chef_zero/endpoints/policies_endpoint.rb', line 13

def initialize(server)
  super(server, 'id')
end

Instance Method Details

#delete(request) ⇒ Object


38
39
40
41
42
# File 'lib/chef_zero/endpoints/policies_endpoint.rb', line 38

def delete(request)
  result = get_data(request, request.rest_path)
  delete_data(request, request.rest_path, :data_store_exceptions)
  already_json_response(200, result)
end

#get(request) ⇒ Object


17
18
19
# File 'lib/chef_zero/endpoints/policies_endpoint.rb', line 17

def get(request)
  already_json_response(200, get_data(request))
end

#put(request) ⇒ Object

Right now we're allowing PUT to create.


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chef_zero/endpoints/policies_endpoint.rb', line 22

def put(request)
  error = validate(request)
  return error if error

  code =
    if data_store.exists?(request.rest_path)
      set_data(request, request.rest_path, request.body, :data_store_exceptions)
      200
    else
      name = request.rest_path[4]
      data_store.create(request.rest_path[0..3], name, request.body, :create_dir)
      201
    end
  already_json_response(code, request.body)
end