summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints
diff options
context:
space:
mode:
authorMarc Paradise <marc@getchef.com>2015-03-04 02:43:54 -0500
committertyler-ball <tyleraball@gmail.com>2015-07-10 10:16:57 -0700
commit27584250fd7b7d0ac76c32fdd93b70fdb3fb2fb9 (patch)
treec58a0cf150b490b17ca39e1b3841b79fe756d749 /lib/chef_zero/endpoints
parent28fe2928469885b0138de4d4270c6eccac8ab482 (diff)
downloadchef-zero-27584250fd7b7d0ac76c32fdd93b70fdb3fb2fb9.tar.gz
update chef-zero to be fully compatible with CS12
Diffstat (limited to 'lib/chef_zero/endpoints')
-rw-r--r--lib/chef_zero/endpoints/actor_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/organization_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/organization_user_endpoint.rb24
-rw-r--r--lib/chef_zero/endpoints/organizations_endpoint.rb7
-rw-r--r--lib/chef_zero/endpoints/search_endpoint.rb14
-rw-r--r--lib/chef_zero/endpoints/user_organizations_endpoint.rb2
6 files changed, 36 insertions, 35 deletions
diff --git a/lib/chef_zero/endpoints/actor_endpoint.rb b/lib/chef_zero/endpoints/actor_endpoint.rb
index 342619c..a34ad14 100644
--- a/lib/chef_zero/endpoints/actor_endpoint.rb
+++ b/lib/chef_zero/endpoints/actor_endpoint.rb
@@ -65,7 +65,15 @@ module ChefZero
else
response = FFI_Yajl::Parser.parse(result[2], :create_additions => false)
end
- response['private_key'] = private_key if private_key
+
+ # TODO some oc_erchef follow-up here. I still don't see that we're returning this
+ # as a flag in absence of an actual private key.
+ if request.rest_path[2] == 'clients'
+ response['private_key'] = private_key ? private_key : false
+ else
+ response['private_key'] = private_key if private_key
+ end
+
response.delete('public_key') if !updating_public_key && request.rest_path[2] == 'users'
response.delete('password')
json_response(result[0], response)
@@ -77,7 +85,7 @@ module ChefZero
def populate_defaults(request, response_json)
response = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
if request.rest_path[2] == 'clients'
- response = ChefData::DataNormalizer.normalize_client(response, request.rest_path[3])
+ response = ChefData::DataNormalizer.normalize_client(response,request.rest_path[3], request.rest_path[1])
else
response = ChefData::DataNormalizer.normalize_user(response, request.rest_path[3], identity_keys, server.options[:osc_compat], request.method)
end
diff --git a/lib/chef_zero/endpoints/organization_endpoint.rb b/lib/chef_zero/endpoints/organization_endpoint.rb
index bc5c3f0..fbc6610 100644
--- a/lib/chef_zero/endpoints/organization_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_endpoint.rb
@@ -16,13 +16,19 @@ module ChefZero
new_org.each do |key, value|
org[key] = value
end
- org = FFI_Yajl::Encoder.encode(org, :pretty => true)
+ save_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)}")
+ set_data(request, request.rest_path + [ 'org' ], save_org)
+ pp org
+ json_response(200, {
+ "uri" => "#{build_uri(request.base_uri, request.rest_path)}",
+ "name" => org['name'],
+ "org_type" => org['org_type'],
+ "full_name" => org['full_name']
+ })
end
def delete(request)
diff --git a/lib/chef_zero/endpoints/organization_user_endpoint.rb b/lib/chef_zero/endpoints/organization_user_endpoint.rb
index ef922d4..8fd97d4 100644
--- a/lib/chef_zero/endpoints/organization_user_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_user_endpoint.rb
@@ -20,29 +20,7 @@ module ChefZero
json_response(200, ChefData::DataNormalizer.normalize_user(user, request.rest_path[3], ['username'], server.options[:osc_compat]))
end
- def post(request)
- orgname = request.rest_path[1]
- username = request.rest_path[3]
-
- users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
- users = FFI_Yajl::Parser.parse(users, :create_additions => false)
-
- create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
-
- # /organizations/ORG/association_requests/USERNAME-ORG
- begin
- delete_data(request, [ 'organizations', orgname, 'association_requests', username], :data_store_exceptions)
- rescue DataStore::DataNotFoundError
- end
-
- # Add the user to the users group if it isn't already there
- if !users['users'] || !users['users'].include?(username)
- users['users'] ||= []
- users['users'] |= [ username ]
- set_data(request, [ 'organizations', orgname, 'groups', 'users' ], FFI_Yajl::Encoder.encode(users, :pretty => true))
- end
- json_response(200, {})
- end
+ # Note: post to a named org user is not permitted, alllow invalid method handling (405)
end
end
end
diff --git a/lib/chef_zero/endpoints/organizations_endpoint.rb b/lib/chef_zero/endpoints/organizations_endpoint.rb
index 88816e8..d774371 100644
--- a/lib/chef_zero/endpoints/organizations_endpoint.rb
+++ b/lib/chef_zero/endpoints/organizations_endpoint.rb
@@ -17,8 +17,11 @@ module ChefZero
def post(request)
contents = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
name = contents['name']
+ full_name = contents['full_name']
if name.nil?
error(400, "Must specify 'name' in JSON")
+ elsif full_name.nil?
+ error(400, "Must specify 'full_name' in JSON")
elsif exists_data_dir?(request, request.rest_path + [ name ])
error(409, "Organization already exists")
else
@@ -43,8 +46,12 @@ module ChefZero
set_data(request, validator_path, validator)
end
+
json_response(201, {
"uri" => "#{build_uri(request.base_uri, org_path)}",
+ "name" => name,
+ "org_type" => "Pleasure",
+ "full_name" => full_name,
"clientname" => validator_name,
"private_key" => private_key
})
diff --git a/lib/chef_zero/endpoints/search_endpoint.rb b/lib/chef_zero/endpoints/search_endpoint.rb
index 3a093be..a9ad2bf 100644
--- a/lib/chef_zero/endpoints/search_endpoint.rb
+++ b/lib/chef_zero/endpoints/search_endpoint.rb
@@ -10,13 +10,15 @@ module ChefZero
# /search/INDEX
class SearchEndpoint < RestBase
def get(request)
- results = search(request)
+ orgname = request.rest_path[1]
+ results = search(request, orgname)
results['rows'] = results['rows'].map { |name,uri,value,search_value| value }
json_response(200, results)
end
def post(request)
- full_results = search(request)
+ orgname = request.rest_path[1]
+ full_results = search(request, orgname)
keys = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
partial_results = full_results['rows'].map do |name, uri, doc, search_value|
data = {}
@@ -45,10 +47,10 @@ module ChefZero
private
- def search_container(request, index)
+ def search_container(request, index, orgname)
relative_parts, normalize_proc = case index
when 'client'
- [ ['clients'], Proc.new { |client, name| ChefData::DataNormalizer.normalize_client(client, name) } ]
+ [ ['clients'], Proc.new { |client, name| ChefData::DataNormalizer.normalize_client(client, name, orgname) } ]
when 'node'
[ ['nodes'], Proc.new { |node, name| ChefData::DataNormalizer.normalize_node(node, name) } ]
when 'environment'
@@ -92,7 +94,7 @@ module ChefZero
end
end
- def search(request)
+ def search(request, orgname = nil)
# Extract parameters
index = request.rest_path[3]
query_string = request.query_params['q'] || '*:*'
@@ -104,7 +106,7 @@ module ChefZero
rows = rows.to_i if rows
# Get the search container
- container, expander = search_container(request, index)
+ container, expander = search_container(request, index, orgname)
# Search!
result = []
diff --git a/lib/chef_zero/endpoints/user_organizations_endpoint.rb b/lib/chef_zero/endpoints/user_organizations_endpoint.rb
index b6decb9..3eb13c4 100644
--- a/lib/chef_zero/endpoints/user_organizations_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_organizations_endpoint.rb
@@ -13,7 +13,7 @@ module ChefZero
result = result.map do |orgname|
org = get_data(request, [ 'organizations', orgname, 'org' ])
org = FFI_Yajl::Parser.parse(org, :create_additions => false)
- ChefData::DataNormalizer.normalize_organization(org, orgname)
+ { "organization" => ChefData::DataNormalizer.normalize_organization(org, orgname) }
end
json_response(200, result)
end