Class: ChefZero::Endpoints::OrganizationEndpoint

Inherits:
RestBase
  • Object
show all
Defined in:
lib/chef_zero/endpoints/organization_endpoint.rb

Overview

/organizations/NAME

Instance Attribute Summary

Attributes inherited from RestBase

#server

Instance Method Summary collapse

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, #initialize, #json_only, #json_response, #list_data, #set_data, #text_response

Constructor Details

This class inherits a constructor from ChefZero::RestBase

Instance Method Details

#delete(request) ⇒ Object


28
29
30
31
32
# File 'lib/chef_zero/endpoints/organization_endpoint.rb', line 28

def delete(request)
  org = get_data(request, request.rest_path + [ 'org' ])
  delete_data_dir(request, request.rest_path)
  already_json_response(200, populate_defaults(request, org))
end

#get(request) ⇒ Object


8
9
10
11
# File 'lib/chef_zero/endpoints/organization_endpoint.rb', line 8

def get(request)
  org = get_data(request, request.rest_path + [ 'org' ])
  already_json_response(200, populate_defaults(request, org))
end

#populate_defaults(request, response_json) ⇒ Object


34
35
36
37
38
# File 'lib/chef_zero/endpoints/organization_endpoint.rb', line 34

def populate_defaults(request, response_json)
  org = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
  org = ChefData::DataNormalizer.normalize_organization(org, request.rest_path[1])
  FFI_Yajl::Encoder.encode(org, :pretty => true)
end

#put(request) ⇒ Object


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

def put(request)
  org = FFI_Yajl::Parser.parse(get_data(request, request.rest_path + [ 'org' ]), :create_additions => false)
  new_org = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
  new_org.each do |key, value|
    org[key] = value
  end
  org = FFI_Yajl::Encoder.encode(org, :pretty => true)
  if new_org['name'] != request.rest_path[-1]
    # This is a rename
    return error(400, "Cannot rename org #{request.rest_path[-1]} to #{new_org['name']}: rename not supported for orgs")
  end
  set_data(request, request.rest_path + [ 'org' ], org)
  json_response(200, "uri" => "#{build_uri(request.base_uri, request.rest_path)}")
end