summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef_zero/endpoints')
-rw-r--r--lib/chef_zero/endpoints/actor_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/actors_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb42
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/cookbook_version_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/cookbooks_base.rb2
-rw-r--r--lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/not_found_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/organization_association_request_endpoint.rb1
-rw-r--r--lib/chef_zero/endpoints/policies_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/policy_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/policy_group_policy_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/policy_revision_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/policy_revisions_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/rest_object_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/search_endpoint.rb8
17 files changed, 43 insertions, 48 deletions
diff --git a/lib/chef_zero/endpoints/actor_endpoint.rb b/lib/chef_zero/endpoints/actor_endpoint.rb
index 8d90c13..4cba31a 100644
--- a/lib/chef_zero/endpoints/actor_endpoint.rb
+++ b/lib/chef_zero/endpoints/actor_endpoint.rb
@@ -156,7 +156,7 @@ module ChefZero
def client?(request, rest_path = nil)
rest_path ||= request.rest_path
- request.rest_path[2] == "clients"
+ rest_path[2] == "clients"
end
# Return the data store keys path for the request client or user, e.g.
diff --git a/lib/chef_zero/endpoints/actors_endpoint.rb b/lib/chef_zero/endpoints/actors_endpoint.rb
index 4a6d8c9..f4a2160 100644
--- a/lib/chef_zero/endpoints/actors_endpoint.rb
+++ b/lib/chef_zero/endpoints/actors_endpoint.rb
@@ -10,9 +10,9 @@ module ChefZero
# apply query filters: if one applies, stop processing rest
# (precendence matches chef-server: https://github.com/chef/chef-server/blob/268a0c9/src/oc_erchef/apps/chef_objects/src/chef_user.erl#L554-L559)
- if value = request.query_params["external_authentication_uid"]
+ if (value = request.query_params["external_authentication_uid"])
response[2] = filter("external_authentication_uid", value, request, response[2])
- elsif value = request.query_params["email"]
+ elsif (value = request.query_params["email"])
response[2] = filter("email", value, request, response[2], insensitive: true)
end
@@ -97,7 +97,7 @@ module ChefZero
end
def is_equal(a, b, ignore_case)
- ignore_case ? a.casecmp(b).zero? : a == b
+ ignore_case ? a.casecmp(b) == 0 : a == b
end
end
end
diff --git a/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb b/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb
index baf80d3..d0cf822 100644
--- a/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb
@@ -17,7 +17,7 @@ module ChefZero
response_data[cookbook_name] = { url: cookbook_url, versions: versions }
- return json_response(200, response_data)
+ json_response(200, response_data)
end
end
end
diff --git a/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb b/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb
index e586e94..9f7b973 100644
--- a/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb
@@ -10,7 +10,7 @@ module ChefZero
# GET /organizations/ORG/cookbook_artifacts/NAME/IDENTIFIER
def get(request)
cookbook_data = normalize(request, get_data(request))
- return json_response(200, cookbook_data)
+ json_response(200, cookbook_data)
end
# PUT /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
@@ -22,34 +22,32 @@ module ChefZero
cb_data = normalize(request, request.body)
set_data(request, nil, to_json(cb_data), :create_dir, :create)
- return already_json_response(201, request.body)
+ already_json_response(201, request.body)
end
# DELETE /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
def delete(request)
- begin
- doomed_cookbook_json = get_data(request)
- identified_cookbook_data = normalize(request, doomed_cookbook_json)
- delete_data(request)
+ doomed_cookbook_json = get_data(request)
+ identified_cookbook_data = normalize(request, doomed_cookbook_json)
+ delete_data(request)
- # go through the recipes and delete stuff in the file store.
- hoover_unused_checksums(get_checksums(doomed_cookbook_json), request)
+ # go through the recipes and delete stuff in the file store.
+ hoover_unused_checksums(get_checksums(doomed_cookbook_json), request)
- # if this was the last revision, delete the directory so future requests will 404, instead of
- # returning 200 with an empty list.
- # Last one out turns out the lights: delete /organizations/ORG/cookbooks/COOKBOOK if it no longer has versions
- cookbook_path = request.rest_path[0..3]
- if exists_data_dir?(request, cookbook_path) && list_data(request, cookbook_path).size == 0
- delete_data_dir(request, cookbook_path)
- end
+ # if this was the last revision, delete the directory so future requests will 404, instead of
+ # returning 200 with an empty list.
+ # Last one out turns out the lights: delete /organizations/ORG/cookbooks/COOKBOOK if it no longer has versions
+ cookbook_path = request.rest_path[0..3]
+ if exists_data_dir?(request, cookbook_path) && list_data(request, cookbook_path).size == 0
+ delete_data_dir(request, cookbook_path)
+ end
- json_response(200, identified_cookbook_data)
- rescue RestErrorResponse => ex
- if ex.response_code == 404
- error(404, "not_found")
- else
- raise
- end
+ json_response(200, identified_cookbook_data)
+ rescue RestErrorResponse => ex
+ if ex.response_code == 404
+ error(404, "not_found")
+ else
+ raise
end
end
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb b/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
index a105664..bfe2ff5 100644
--- a/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
@@ -27,7 +27,7 @@ module ChefZero
data[cookbook_artifact] = { url: cookbook_url, versions: versions }
end
- return json_response(200, data)
+ json_response(200, data)
end
end
end
diff --git a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
index 8afde32..615b03e 100644
--- a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
@@ -99,7 +99,7 @@ module ChefZero
begin
data_store.list(request.rest_path[0..1] + [cookbook_type, cookbook_name]).each do |version|
cookbook = data_store.get(request.rest_path[0..1] + [cookbook_type, cookbook_name, version], request)
- deleted_checksums = deleted_checksums - get_checksums(cookbook)
+ deleted_checksums -= get_checksums(cookbook)
end
rescue ChefZero::DataStore::DataNotFoundError
end
diff --git a/lib/chef_zero/endpoints/cookbooks_base.rb b/lib/chef_zero/endpoints/cookbooks_base.rb
index 55b79ca..d8af80a 100644
--- a/lib/chef_zero/endpoints/cookbooks_base.rb
+++ b/lib/chef_zero/endpoints/cookbooks_base.rb
@@ -65,7 +65,7 @@ module ChefZero
def recipe_names(cookbook_name, cookbook)
cookbook["all_files"].inject([]) do |acc, file|
part, name = file["name"].split("/")
- next unless part == "recipes" || File.extname(name) != ".rb"
+ next acc unless part == "recipes" || File.extname(name) != ".rb"
if name == "default.rb"
acc << cookbook_name
else
diff --git a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
index 669be9a..ddd44d3 100644
--- a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
@@ -82,7 +82,7 @@ module ChefZero
# If the dep is not already in the list, add it to the list to solve
# and bring in all environment-allowed cookbook versions to desired_versions
if !new_desired_versions.has_key?(dep_name)
- new_unsolved = new_unsolved + [dep_name]
+ new_unsolved += [dep_name]
# If the dep is missing, we will try other versions of the cookbook that might not have the bad dep.
if !exists_data_dir?(request, request.rest_path[0..1] + ["cookbooks", dep_name])
@last_missing_dep = dep_name.to_s
@@ -101,7 +101,7 @@ module ChefZero
result = depsolve(request, new_unsolved, new_desired_versions, environment_constraints)
return result if result
end
- return nil
+ nil
end
def sort_versions(versions)
diff --git a/lib/chef_zero/endpoints/not_found_endpoint.rb b/lib/chef_zero/endpoints/not_found_endpoint.rb
index 4c23800..582272b 100644
--- a/lib/chef_zero/endpoints/not_found_endpoint.rb
+++ b/lib/chef_zero/endpoints/not_found_endpoint.rb
@@ -4,7 +4,7 @@ module ChefZero
module Endpoints
class NotFoundEndpoint
def call(request)
- return [404, { "Content-Type" => "application/json" }, FFI_Yajl::Encoder.encode({ "error" => ["Object not found: #{request.env['REQUEST_PATH']}"] }, :pretty => true)]
+ [404, { "Content-Type" => "application/json" }, FFI_Yajl::Encoder.encode({ "error" => ["Object not found: #{request.env['REQUEST_PATH']}"] }, :pretty => true)]
end
end
end
diff --git a/lib/chef_zero/endpoints/organization_association_request_endpoint.rb b/lib/chef_zero/endpoints/organization_association_request_endpoint.rb
index 0402893..c73d816 100644
--- a/lib/chef_zero/endpoints/organization_association_request_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_association_request_endpoint.rb
@@ -13,7 +13,6 @@ module ChefZero
end
username = $1
path = request.rest_path[0..-2] + [username]
- data = FFI_Yajl::Parser.parse(get_data(request, path))
delete_data(request, path)
json_response(200, { "id" => id, "username" => username })
end
diff --git a/lib/chef_zero/endpoints/policies_endpoint.rb b/lib/chef_zero/endpoints/policies_endpoint.rb
index f830c5c..3a8deea 100644
--- a/lib/chef_zero/endpoints/policies_endpoint.rb
+++ b/lib/chef_zero/endpoints/policies_endpoint.rb
@@ -19,7 +19,7 @@ module ChefZero
}
end
- return json_response(200, response_data)
+ json_response(200, response_data)
end
end
end
diff --git a/lib/chef_zero/endpoints/policy_endpoint.rb b/lib/chef_zero/endpoints/policy_endpoint.rb
index 5c77a7c..1e80278 100644
--- a/lib/chef_zero/endpoints/policy_endpoint.rb
+++ b/lib/chef_zero/endpoints/policy_endpoint.rb
@@ -8,7 +8,7 @@ module ChefZero
def get(request)
revisions = list_data(request, request.rest_path + ["revisions"])
data = { revisions: hashify_list(revisions) }
- return json_response(200, data)
+ json_response(200, data)
end
# DELETE /organizations/ORG/policies/NAME
@@ -17,7 +17,7 @@ module ChefZero
data = { revisions: hashify_list(revisions) }
delete_data_dir(request, nil, :recursive)
- return json_response(200, data)
+ json_response(200, data)
end
end
end
diff --git a/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb b/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb
index 2643dd3..a34da32 100644
--- a/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb
+++ b/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb
@@ -76,7 +76,7 @@ module ChefZero
full_policy_doc = parse_json(get_data(request, policy_path))
full_policy_doc = ChefData::DataNormalizer.normalize_policy(full_policy_doc, policy_name, current_revision_id)
- return json_response(200, full_policy_doc)
+ json_response(200, full_policy_doc)
end
end
end
diff --git a/lib/chef_zero/endpoints/policy_revision_endpoint.rb b/lib/chef_zero/endpoints/policy_revision_endpoint.rb
index 64e2dca..c825510 100644
--- a/lib/chef_zero/endpoints/policy_revision_endpoint.rb
+++ b/lib/chef_zero/endpoints/policy_revision_endpoint.rb
@@ -8,7 +8,7 @@ module ChefZero
def get(request)
data = parse_json(get_data(request))
data = ChefData::DataNormalizer.normalize_policy(data, request.rest_path[3], request.rest_path[5])
- return json_response(200, data)
+ json_response(200, data)
end
# DELETE /organizations/ORG/policies/NAME/revisions/REVISION
@@ -16,7 +16,7 @@ module ChefZero
policyfile_data = parse_json(get_data(request))
policyfile_data = ChefData::DataNormalizer.normalize_policy(policyfile_data, request.rest_path[3], request.rest_path[5])
delete_data(request)
- return json_response(200, policyfile_data)
+ json_response(200, policyfile_data)
end
end
end
diff --git a/lib/chef_zero/endpoints/policy_revisions_endpoint.rb b/lib/chef_zero/endpoints/policy_revisions_endpoint.rb
index 27e019e..d755f81 100644
--- a/lib/chef_zero/endpoints/policy_revisions_endpoint.rb
+++ b/lib/chef_zero/endpoints/policy_revisions_endpoint.rb
@@ -8,7 +8,7 @@ module ChefZero
def post(request)
policyfile_data = parse_json(request.body)
create_data(request, request.rest_path, policyfile_data["revision_id"], request.body, :create_dir)
- return already_json_response(201, request.body)
+ already_json_response(201, request.body)
end
end
end
diff --git a/lib/chef_zero/endpoints/rest_object_endpoint.rb b/lib/chef_zero/endpoints/rest_object_endpoint.rb
index c35133f..887905e 100644
--- a/lib/chef_zero/endpoints/rest_object_endpoint.rb
+++ b/lib/chef_zero/endpoints/rest_object_endpoint.rb
@@ -20,7 +20,7 @@ module ChefZero
def put(request)
# We grab the old body to trigger a 404 if it doesn't exist
- old_body = get_data(request)
+ get_data(request)
# If it's a rename, check for conflict and delete the old value
if is_rename?(request)
@@ -69,7 +69,7 @@ module ChefZero
# Does this request change the value of the identity key?
def is_rename?(request)
- return false unless key = identity_key_value(request)
+ return false unless (key = identity_key_value(request))
key != request.rest_path[-1]
end
end
diff --git a/lib/chef_zero/endpoints/search_endpoint.rb b/lib/chef_zero/endpoints/search_endpoint.rb
index b808ce9..e2f30ce 100644
--- a/lib/chef_zero/endpoints/search_endpoint.rb
+++ b/lib/chef_zero/endpoints/search_endpoint.rb
@@ -96,8 +96,8 @@ module ChefZero
end
end
end
- value.each_pair do |key, value|
- result[key] = value unless %w{default normal override automatic}.include?(key)
+ value.each_pair do |key, val|
+ result[key] = val unless %w{default normal override automatic}.include?(key)
end
result
@@ -155,8 +155,6 @@ module ChefZero
}
end
- private
-
# Deep Merge core documentation.
# deep_merge! method permits merging of arbitrary child elements. The two top level
# elements must be hashes. These hashes can contain unlimited (to stack limit) levels
@@ -194,7 +192,7 @@ module ChefZero
end
when Array
if dest.kind_of?(Array)
- dest = dest | source
+ dest |= source
else
dest = source
end