Class: ChefZero::Endpoints::NodesEndpoint

Inherits:
RestListEndpoint show all
Defined in:
lib/chef_zero/endpoints/nodes_endpoint.rb

Overview

/nodes

Constant Summary

Constants inherited from RestBase

RestBase::DEFAULT_REQUEST_VERSION, RestBase::DEFAULT_RESPONSE_VERSION

Instance Attribute Summary

Attributes inherited from RestListEndpoint

#identity_keys

Attributes inherited from RestBase

#server

Instance Method Summary collapse

Methods inherited from RestListEndpoint

#get, #get_key, #initialize

Methods inherited from RestBase

#accepts?, #already_json_response, #build_uri, build_uri, #call, #check_api_version, #create_data, #create_data_dir, #data_store, #delete_data, #delete_data_dir, #error, #exists_data?, #exists_data_dir?, #get_data, #get_data_or_else, #hashify_list, #head_request, #initialize, #json_only, #json_response, #list_data, #list_data_or_else, #parse_json, #policy_name_invalid?, rfc2396_parser, #set_data, #text_response, #to_json

Constructor Details

This class inherits a constructor from ChefZero::Endpoints::RestListEndpoint

Instance Method Details

#populate_defaults(request, response_json) ⇒ Object



27
28
29
30
31
# File 'lib/chef_zero/endpoints/nodes_endpoint.rb', line 27

def populate_defaults(request, response_json)
  node = FFI_Yajl::Parser.parse(response_json)
  node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3])
  FFI_Yajl::Encoder.encode(node, pretty: true)
end

#post(request) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chef_zero/endpoints/nodes_endpoint.rb', line 10

def post(request)
  # /nodes validation
  if request.rest_path.last == "nodes"
    data = parse_json(request.body)

    if data.key?("policy_name") && policy_name_invalid?(data["policy_name"])
      return error(400, "Field 'policy_name' invalid", pretty: false)
    end

    if data.key?("policy_group") && policy_name_invalid?(data["policy_group"])
      return error(400, "Field 'policy_group' invalid", pretty: false)
    end
  end

  super(request)
end