summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2014-09-26 16:18:48 -0700
committertyler-ball <tyleraball@gmail.com>2014-09-26 16:18:48 -0700
commite3f2e8471cd97340c28b7541ffb0fa7143a33ca4 (patch)
tree0b6451871dc704ab7988c19ed5f53e5318a7bd5f
parent15f4a3e533eefa59412e81c0252af3166541ede0 (diff)
downloadchef-zero-tball/chef-zero-yajl-replace-json.tar.gz
Removing 'json' gem dependency, replacing with 'ffi-yajl'tball/chef-zero-yajl-replace-json
-rw-r--r--CHANGELOG.md4
-rw-r--r--chef-zero.gemspec2
-rw-r--r--lib/chef_zero/chef_data/cookbook_data.rb2
-rw-r--r--lib/chef_zero/chef_data/default_creator.rb10
-rw-r--r--lib/chef_zero/data_store/default_facade.rb2
-rw-r--r--lib/chef_zero/endpoints/acl_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/acls_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/actor_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/actors_endpoint.rb20
-rw-r--r--lib/chef_zero/endpoints/authenticate_user_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/container_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/containers_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/cookbook_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/cookbook_version_endpoint.rb14
-rw-r--r--lib/chef_zero/endpoints/cookbooks_base.rb2
-rw-r--r--lib/chef_zero/endpoints/data_bag_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/data_bag_item_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/data_bags_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/environment_cookbook_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb10
-rw-r--r--lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/environment_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/environment_nodes_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/environment_recipes_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/environment_role_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/group_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/groups_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/license_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/node_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/not_found_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/organization_association_request_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/organization_association_requests_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/organization_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/organization_user_endpoint.rb10
-rw-r--r--lib/chef_zero/endpoints/organization_users_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/organization_validator_key_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/organizations_endpoint.rb10
-rw-r--r--lib/chef_zero/endpoints/principal_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/rest_list_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/rest_object_endpoint.rb10
-rw-r--r--lib/chef_zero/endpoints/role_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/role_environments_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/sandbox_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/sandboxes_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/search_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/system_recovery_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/user_association_request_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/user_association_requests_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/user_organizations_endpoint.rb4
-rw-r--r--lib/chef_zero/rest_base.rb2
-rw-r--r--lib/chef_zero/rspec.rb2
-rw-r--r--lib/chef_zero/server.rb4
-rw-r--r--lib/chef_zero/version.rb2
55 files changed, 153 insertions, 149 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 208f61a..d751646 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,10 @@
Chef Zero CHANGELOG
===================
+# 3.1.3 (9/26/2014)
+
+- removed 'json' gem dependency, replaced it with 'ffi-yajl'
+
# 3.1.3 (9/3/2014)
- fixes for running Chef local mode in multi-org mode
diff --git a/chef-zero.gemspec b/chef-zero.gemspec
index 4708385..c6bc909 100644
--- a/chef-zero.gemspec
+++ b/chef-zero.gemspec
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
s.add_dependency 'mixlib-log', '~> 1.3'
s.add_dependency 'hashie', '~> 2.0'
s.add_dependency 'uuidtools', '~> 2.1'
- s.add_dependency 'json'
+ s.add_dependency 'ffi-yajl', '~> 1.1'
s.add_dependency 'rack'
s.add_development_dependency 'rake'
diff --git a/lib/chef_zero/chef_data/cookbook_data.rb b/lib/chef_zero/chef_data/cookbook_data.rb
index 6f0dd83..aed625b 100644
--- a/lib/chef_zero/chef_data/cookbook_data.rb
+++ b/lib/chef_zero/chef_data/cookbook_data.rb
@@ -75,7 +75,7 @@ module ChefZero
end
def from_json(json)
- self.merge!(JSON.parse(json))
+ self.merge!(FFI_Yajl::Parser.parse(json))
end
private
diff --git a/lib/chef_zero/chef_data/default_creator.rb b/lib/chef_zero/chef_data/default_creator.rb
index 078ba8b..60b495a 100644
--- a/lib/chef_zero/chef_data/default_creator.rb
+++ b/lib/chef_zero/chef_data/default_creator.rb
@@ -237,11 +237,11 @@ module ChefZero
when "groups/admins"
admins = data.list(path[0..1] + [ 'users' ]).select do |name|
- user = JSON.parse(data.get(path[0..1] + [ 'users', name ]), :create_additions => false)
+ user = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ 'users', name ]), :create_additions => false)
user['admin']
end
admins += data.list(path[0..1] + [ 'clients' ]).select do |name|
- client = JSON.parse(data.get(path[0..1] + [ 'clients', name ]), :create_additions => false)
+ client = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ 'clients', name ]), :create_additions => false)
client['admin']
end
admins += @creators[path[0..1]] if @creators[path[0..1]]
@@ -351,7 +351,7 @@ module ChefZero
# Non-validator clients own themselves.
if path.size == 4 && path[0] == 'organizations' && path[2] == 'clients'
begin
- client = JSON.parse(data.get(path), :create_additions => false)
+ client = FFI_Yajl::Parser.parse(data.get(path), :create_additions => false)
if !client['validator']
owners |= [ path[3] ]
end
@@ -363,7 +363,7 @@ module ChefZero
if @creators[path]
@creators[path].each do |creator|
begin
- client = JSON.parse(data.get(path[0..2] + [ creator ]), :create_additions => false)
+ client = FFI_Yajl::Parser.parse(data.get(path[0..2] + [ creator ]), :create_additions => false)
next if client['validator']
rescue
end
@@ -409,7 +409,7 @@ module ChefZero
def get_container_acl(acl_path)
parent_path = AclPath.parent_acl_data_path(acl_path)
if parent_path
- JSON.parse(data.get(parent_path), :create_additions => false)
+ FFI_Yajl::Parser.parse(data.get(parent_path), :create_additions => false)
else
nil
end
diff --git a/lib/chef_zero/data_store/default_facade.rb b/lib/chef_zero/data_store/default_facade.rb
index c0e33b9..0d4cf34 100644
--- a/lib/chef_zero/data_store/default_facade.rb
+++ b/lib/chef_zero/data_store/default_facade.rb
@@ -71,7 +71,7 @@ module ChefZero
rescue DataNotFoundError
result = default_creator.get(path)
if result
- JSON.pretty_generate(result)
+ FFI_Yajl::Encoder.encode(result, :pretty => true)
else
raise
end
diff --git a/lib/chef_zero/endpoints/acl_endpoint.rb b/lib/chef_zero/endpoints/acl_endpoint.rb
index f1c0013..cca8392 100644
--- a/lib/chef_zero/endpoints/acl_endpoint.rb
+++ b/lib/chef_zero/endpoints/acl_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
require 'chef_zero/chef_data/acl_path'
@@ -28,9 +28,9 @@ module ChefZero
def put(request)
path, perm = validate_request(request)
- acls = JSON.parse(get_data(request, path), :create_additions => false)
- acls[perm] = JSON.parse(request.body, :create_additions => false)[perm]
- set_data(request, path, JSON.pretty_generate(acls))
+ acls = FFI_Yajl::Parser.parse(get_data(request, path), :create_additions => false)
+ acls[perm] = FFI_Yajl::Parser.parse(request.body, :create_additions => false)[perm]
+ set_data(request, path, FFI_Yajl::Encoder.encode(acls, :pretty => true))
json_response(200, {'uri' => "#{build_uri(request.base_uri, request.rest_path)}"})
end
end
diff --git a/lib/chef_zero/endpoints/acls_endpoint.rb b/lib/chef_zero/endpoints/acls_endpoint.rb
index d05abe5..ad9bb31 100644
--- a/lib/chef_zero/endpoints/acls_endpoint.rb
+++ b/lib/chef_zero/endpoints/acls_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
require 'chef_zero/chef_data/data_normalizer'
require 'chef_zero/chef_data/acl_path'
@@ -20,7 +20,7 @@ module ChefZero
if !acl_path
raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
end
- acls = JSON.parse(get_data(request, acl_path), :create_additions => false)
+ acls = FFI_Yajl::Parser.parse(get_data(request, acl_path), :create_additions => false)
acls = ChefData::DataNormalizer.normalize_acls(acls)
json_response(200, acls)
end
diff --git a/lib/chef_zero/endpoints/actor_endpoint.rb b/lib/chef_zero/endpoints/actor_endpoint.rb
index 7b098ff..342619c 100644
--- a/lib/chef_zero/endpoints/actor_endpoint.rb
+++ b/lib/chef_zero/endpoints/actor_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_object_endpoint'
require 'chef_zero/chef_data/data_normalizer'
@@ -23,7 +23,7 @@ module ChefZero
def put(request)
# Find out if we're updating the public key.
- request_body = JSON.parse(request.body, :create_additions => false)
+ request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
if request_body['public_key'].nil?
# If public_key is null, then don't overwrite it. Weird patchiness.
body_modified = true
@@ -44,7 +44,7 @@ module ChefZero
end
# Save request
- request.body = JSON.pretty_generate(request_body) if body_modified
+ request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true) if body_modified
# PUT /clients is patchy
request.body = patch_request_body(request)
@@ -63,7 +63,7 @@ module ChefZero
'uri' => build_uri(request.base_uri, [ 'users', key ])
}
else
- response = JSON.parse(result[2], :create_additions => false)
+ response = FFI_Yajl::Parser.parse(result[2], :create_additions => false)
end
response['private_key'] = private_key if private_key
response.delete('public_key') if !updating_public_key && request.rest_path[2] == 'users'
@@ -75,13 +75,13 @@ module ChefZero
end
def populate_defaults(request, response_json)
- response = JSON.parse(response_json, :create_additions => false)
+ 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])
else
response = ChefData::DataNormalizer.normalize_user(response, request.rest_path[3], identity_keys, server.options[:osc_compat], request.method)
end
- JSON.pretty_generate(response)
+ FFI_Yajl::Encoder.encode(response, :pretty => true)
end
end
end
diff --git a/lib/chef_zero/endpoints/actors_endpoint.rb b/lib/chef_zero/endpoints/actors_endpoint.rb
index 90a53d8..c6c676f 100644
--- a/lib/chef_zero/endpoints/actors_endpoint.rb
+++ b/lib/chef_zero/endpoints/actors_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_list_endpoint'
module ChefZero
@@ -9,29 +9,29 @@ module ChefZero
response = super(request)
if request.query_params['email']
- results = JSON.parse(response[2], :create_additions => false)
+ results = FFI_Yajl::Parser.parse(response[2], :create_additions => false)
new_results = {}
results.each do |name, url|
record = get_data(request, request.rest_path + [ name ], :nil)
if record
- record = JSON.parse(record, :create_additions => false)
+ record = FFI_Yajl::Parser.parse(record, :create_additions => false)
new_results[name] = url if record['email'] == request.query_params['email']
end
end
- response[2] = JSON.pretty_generate(new_results)
+ response[2] = FFI_Yajl::Encoder.encode(new_results, :pretty => true)
end
if request.query_params['verbose']
- results = JSON.parse(response[2], :create_additions => false)
+ results = FFI_Yajl::Parser.parse(response[2], :create_additions => false)
results.each do |name, url|
record = get_data(request, request.rest_path + [ name ], :nil)
if record
- record = JSON.parse(record, :create_additions => false)
+ record = FFI_Yajl::Parser.parse(record, :create_additions => false)
record = ChefData::DataNormalizer.normalize_user(record, name, identity_keys, server.options[:osc_compat])
results[name] = record
end
end
- response[2] = JSON.pretty_generate(results)
+ response[2] = FFI_Yajl::Encoder.encode(results, :pretty => true)
end
response
end
@@ -39,19 +39,19 @@ module ChefZero
def post(request)
# First, find out if the user actually posted a public key. If not, make
# one.
- request_body = JSON.parse(request.body, :create_additions => false)
+ request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
public_key = request_body['public_key']
if !public_key
private_key, public_key = server.gen_key_pair
request_body['public_key'] = public_key
- request.body = JSON.pretty_generate(request_body)
+ request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true)
end
result = super(request)
if result[0] == 201
# If we generated a key, stuff it in the response.
- response = JSON.parse(result[2], :create_additions => false)
+ response = FFI_Yajl::Parser.parse(result[2], :create_additions => false)
response['private_key'] = private_key if private_key
response['public_key'] = public_key unless request.rest_path[0] == 'users'
json_response(201, response)
diff --git a/lib/chef_zero/endpoints/authenticate_user_endpoint.rb b/lib/chef_zero/endpoints/authenticate_user_endpoint.rb
index 76751d8..5d5bb3b 100644
--- a/lib/chef_zero/endpoints/authenticate_user_endpoint.rb
+++ b/lib/chef_zero/endpoints/authenticate_user_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -6,7 +6,7 @@ module ChefZero
# /authenticate_user
class AuthenticateUserEndpoint < RestBase
def post(request)
- request_json = JSON.parse(request.body, :create_additions => false)
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
name = request_json['username']
password = request_json['password']
begin
@@ -14,7 +14,7 @@ module ChefZero
rescue ChefZero::DataStore::DataNotFoundError
raise RestErrorResponse.new(401, "Bad username or password")
end
- user = JSON.parse(user, :create_additions => false)
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
user = ChefData::DataNormalizer.normalize_user(user, name, [ 'username' ], server.options[:osc_compat])
if user['password'] != password
raise RestErrorResponse.new(401, "Bad username or password")
diff --git a/lib/chef_zero/endpoints/container_endpoint.rb b/lib/chef_zero/endpoints/container_endpoint.rb
index e2bb000..bf0a184 100644
--- a/lib/chef_zero/endpoints/container_endpoint.rb
+++ b/lib/chef_zero/endpoints/container_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_object_endpoint'
require 'chef_zero/chef_data/data_normalizer'
@@ -13,9 +13,9 @@ module ChefZero
undef_method(:put)
def populate_defaults(request, response_json)
- container = JSON.parse(response_json, :create_additions => false)
+ container = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
container = ChefData::DataNormalizer.normalize_container(container, request.rest_path[3])
- JSON.pretty_generate(container)
+ FFI_Yajl::Encoder.encode(container, :pretty => true)
end
end
end
diff --git a/lib/chef_zero/endpoints/containers_endpoint.rb b/lib/chef_zero/endpoints/containers_endpoint.rb
index 82ffbfc..3f7af87 100644
--- a/lib/chef_zero/endpoints/containers_endpoint.rb
+++ b/lib/chef_zero/endpoints/containers_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_list_endpoint'
module ChefZero
diff --git a/lib/chef_zero/endpoints/cookbook_endpoint.rb b/lib/chef_zero/endpoints/cookbook_endpoint.rb
index 939ef5c..35919ad 100644
--- a/lib/chef_zero/endpoints/cookbook_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_endpoint.rb
@@ -19,7 +19,7 @@ module ChefZero
result = []
filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
if versions.size > 0
- cookbook = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
+ cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
result += recipe_names(name, cookbook)
end
end
diff --git a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
index f1cc22f..8dad508 100644
--- a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_object_endpoint'
require 'chef_zero/rest_error_response'
require 'chef_zero/chef_data/data_normalizer'
@@ -22,16 +22,16 @@ module ChefZero
# Honor frozen
if existing_cookbook
- existing_cookbook_json = JSON.parse(existing_cookbook, :create_additions => false)
+ existing_cookbook_json = FFI_Yajl::Parser.parse(existing_cookbook, :create_additions => false)
if existing_cookbook_json['frozen?']
if request.query_params['force'] != "true"
raise RestErrorResponse.new(409, "The cookbook #{name} at version #{version} is frozen. Use the 'force' option to override.")
end
# For some reason, you are forever unable to modify "frozen?" on a frozen cookbook.
- request_body = JSON.parse(request.body, :create_additions => false)
+ request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
if !request_body['frozen?']
request_body['frozen?'] = true
- request.body = JSON.pretty_generate(request_body)
+ request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true)
end
end
end
@@ -71,7 +71,7 @@ module ChefZero
def get_checksums(cookbook)
result = []
- JSON.parse(cookbook, :create_additions => false).each_pair do |key, value|
+ FFI_Yajl::Parser.parse(cookbook, :create_additions => false).each_pair do |key, value|
if value.is_a?(Array)
value.each do |file|
if file.is_a?(Hash) && file.has_key?('checksum')
@@ -105,9 +105,9 @@ module ChefZero
def populate_defaults(request, response_json)
# Inject URIs into each cookbook file
- cookbook = JSON.parse(response_json, :create_additions => false)
+ cookbook = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
cookbook = ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, request.rest_path[3], request.rest_path[4], request.base_uri, request.method)
- JSON.pretty_generate(cookbook)
+ FFI_Yajl::Encoder.encode(cookbook, :pretty => true)
end
def latest_version(versions)
diff --git a/lib/chef_zero/endpoints/cookbooks_base.rb b/lib/chef_zero/endpoints/cookbooks_base.rb
index 76a4914..d138af9 100644
--- a/lib/chef_zero/endpoints/cookbooks_base.rb
+++ b/lib/chef_zero/endpoints/cookbooks_base.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
require 'chef_zero/chef_data/data_normalizer'
diff --git a/lib/chef_zero/endpoints/data_bag_endpoint.rb b/lib/chef_zero/endpoints/data_bag_endpoint.rb
index 41e87ae..f7a6142 100644
--- a/lib/chef_zero/endpoints/data_bag_endpoint.rb
+++ b/lib/chef_zero/endpoints/data_bag_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_list_endpoint'
require 'chef_zero/endpoints/data_bag_item_endpoint'
require 'chef_zero/rest_error_response'
@@ -12,7 +12,7 @@ module ChefZero
end
def post(request)
- json = JSON.parse(request.body, :create_additions => false)
+ json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
key = identity_keys.map { |k| json[k] }.select { |v| v }.first
response = super(request)
if response[0] == 201
@@ -23,7 +23,7 @@ module ChefZero
end
def get_key(contents)
- data_bag_item = JSON.parse(contents, :create_additions => false)
+ data_bag_item = FFI_Yajl::Parser.parse(contents, :create_additions => false)
if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
data_bag_item['raw_data']['id']
else
diff --git a/lib/chef_zero/endpoints/data_bag_item_endpoint.rb b/lib/chef_zero/endpoints/data_bag_item_endpoint.rb
index 1ab8793..a1dd71c 100644
--- a/lib/chef_zero/endpoints/data_bag_item_endpoint.rb
+++ b/lib/chef_zero/endpoints/data_bag_item_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_object_endpoint'
require 'chef_zero/endpoints/data_bag_item_endpoint'
require 'chef_zero/chef_data/data_normalizer'
@@ -16,9 +16,9 @@ module ChefZero
end
def self.populate_defaults(request, response_json, data_bag, data_bag_item)
- response = JSON.parse(response_json, :create_additions => false)
+ response = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
response = ChefData::DataNormalizer.normalize_data_bag_item(response, data_bag, data_bag_item, request.method)
- JSON.pretty_generate(response)
+ FFI_Yajl::Encoder.encode(response, :pretty => true)
end
end
end
diff --git a/lib/chef_zero/endpoints/data_bags_endpoint.rb b/lib/chef_zero/endpoints/data_bags_endpoint.rb
index 732c1a5..3694602 100644
--- a/lib/chef_zero/endpoints/data_bags_endpoint.rb
+++ b/lib/chef_zero/endpoints/data_bags_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_list_endpoint'
module ChefZero
@@ -7,7 +7,7 @@ module ChefZero
class DataBagsEndpoint < RestListEndpoint
def post(request)
contents = request.body
- json = JSON.parse(contents, :create_additions => false)
+ json = FFI_Yajl::Parser.parse(contents, :create_additions => false)
name = identity_keys.map { |k| json[k] }.select { |v| v }.first
if name.nil?
error(400, "Must specify #{identity_keys.map { |k| k.inspect }.join(' or ')} in JSON")
diff --git a/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb
index efba859..2554c98 100644
--- a/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/cookbooks_base'
module ChefZero
@@ -7,7 +7,7 @@ module ChefZero
class EnvironmentCookbookEndpoint < CookbooksBase
def get(request)
cookbook_name = request.rest_path[5]
- environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
+ environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
constraints = environment['cookbook_versions'] || {}
cookbook_versions = list_data(request, request.rest_path[0..1] + request.rest_path[4..5])
if request.query_params['num_versions'] == 'all'
diff --git a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
index ae4a85a..b11687b 100644
--- a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
require 'chef_zero/rest_error_response'
@@ -12,7 +12,7 @@ module ChefZero
# Get the list of cookbooks and versions desired by the runlist
desired_versions = {}
- run_list = JSON.parse(request.body, :create_additions => false)['run_list']
+ run_list = FFI_Yajl::Parser.parse(request.body, :create_additions => false)['run_list']
run_list.each do |run_list_entry|
if run_list_entry =~ /(.+)::.+\@(.+)/ || run_list_entry =~ /(.+)\@(.+)/
raise RestErrorResponse.new(412, "No such cookbook: #{$1}") if !cookbook_names.include?($1)
@@ -26,7 +26,7 @@ module ChefZero
end
# Filter by environment constraints
- environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
+ environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
environment_constraints = environment['cookbook_versions'] || {}
desired_versions.each_key do |name|
@@ -48,7 +48,7 @@ module ChefZero
result = {}
solved.each_pair do |name, versions|
- cookbook = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
+ cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
result[name] = ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, name, versions[0], request.base_uri, 'MIN')
end
json_response(200, result)
@@ -74,7 +74,7 @@ module ChefZero
new_unsolved = unsolved[1..-1]
# Pick this cookbook, and add dependencies
- cookbook_obj = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', solve_for, desired_version]), :create_additions => false)
+ cookbook_obj = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', solve_for, desired_version]), :create_additions => false)
cookbook_metadata = cookbook_obj['metadata'] || {}
cookbook_dependencies = cookbook_metadata['dependencies'] || {}
dep_not_found = false
diff --git a/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb
index c8f129b..166caa3 100644
--- a/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/cookbooks_base'
module ChefZero
@@ -6,7 +6,7 @@ module ChefZero
# /environments/NAME/cookbooks
class EnvironmentCookbooksEndpoint < CookbooksBase
def get(request)
- environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
+ environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
constraints = environment['cookbook_versions'] || {}
if request.query_params['num_versions'] == 'all'
num_versions = nil
diff --git a/lib/chef_zero/endpoints/environment_endpoint.rb b/lib/chef_zero/endpoints/environment_endpoint.rb
index 74a175b..9d89f44 100644
--- a/lib/chef_zero/endpoints/environment_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_object_endpoint'
require 'chef_zero/chef_data/data_normalizer'
@@ -24,9 +24,9 @@ module ChefZero
end
def populate_defaults(request, response_json)
- response = JSON.parse(response_json, :create_additions => false)
+ response = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
response = ChefData::DataNormalizer.normalize_environment(response, request.rest_path[3])
- JSON.pretty_generate(response)
+ FFI_Yajl::Encoder.encode(response, :pretty => true)
end
end
end
diff --git a/lib/chef_zero/endpoints/environment_nodes_endpoint.rb b/lib/chef_zero/endpoints/environment_nodes_endpoint.rb
index 6e221fd..e8eaca2 100644
--- a/lib/chef_zero/endpoints/environment_nodes_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_nodes_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -11,7 +11,7 @@ module ChefZero
result = {}
list_data(request, request.rest_path[0..1] + ['nodes']).each do |name|
- node = JSON.parse(get_data(request, request.rest_path[0..1] + ['nodes', name]), :create_additions => false)
+ node = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['nodes', name]), :create_additions => false)
if node['chef_environment'] == request.rest_path[3]
result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ['nodes', name])
end
diff --git a/lib/chef_zero/endpoints/environment_recipes_endpoint.rb b/lib/chef_zero/endpoints/environment_recipes_endpoint.rb
index 23c612b..4ecd7e0 100644
--- a/lib/chef_zero/endpoints/environment_recipes_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_recipes_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/cookbooks_base'
module ChefZero
@@ -6,12 +6,12 @@ module ChefZero
# /environment/NAME/recipes
class EnvironmentRecipesEndpoint < CookbooksBase
def get(request)
- environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
+ environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
constraints = environment['cookbook_versions'] || {}
result = []
filter_cookbooks(all_cookbooks_list(request), constraints, 1) do |name, versions|
if versions.size > 0
- cookbook = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
+ cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
result += recipe_names(name, cookbook)
end
end
diff --git a/lib/chef_zero/endpoints/environment_role_endpoint.rb b/lib/chef_zero/endpoints/environment_role_endpoint.rb
index 93c7578..2a87bb4 100644
--- a/lib/chef_zero/endpoints/environment_role_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_role_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/cookbooks_base'
module ChefZero
@@ -18,7 +18,7 @@ module ChefZero
# Verify that the environment exists
get_data(request, environment_path)
- role = JSON.parse(get_data(request, role_path), :create_additions => false)
+ role = FFI_Yajl::Parser.parse(get_data(request, role_path), :create_additions => false)
environment_name = environment_path[3]
if environment_name == '_default'
run_list = role['run_list']
diff --git a/lib/chef_zero/endpoints/group_endpoint.rb b/lib/chef_zero/endpoints/group_endpoint.rb
index 48f05cd..7404d4d 100644
--- a/lib/chef_zero/endpoints/group_endpoint.rb
+++ b/lib/chef_zero/endpoints/group_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_object_endpoint'
require 'chef_zero/chef_data/data_normalizer'
@@ -11,9 +11,9 @@ module ChefZero
end
def populate_defaults(request, response_json)
- group = JSON.parse(response_json, :create_additions => false)
+ group = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
group = ChefData::DataNormalizer.normalize_group(group, request.rest_path[3], request.rest_path[1])
- JSON.pretty_generate(group)
+ FFI_Yajl::Encoder.encode(group, :pretty => true)
end
end
end
diff --git a/lib/chef_zero/endpoints/groups_endpoint.rb b/lib/chef_zero/endpoints/groups_endpoint.rb
index 9683824..3e75293 100644
--- a/lib/chef_zero/endpoints/groups_endpoint.rb
+++ b/lib/chef_zero/endpoints/groups_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_list_endpoint'
module ChefZero
diff --git a/lib/chef_zero/endpoints/license_endpoint.rb b/lib/chef_zero/endpoints/license_endpoint.rb
index 06bbce8..8638875 100644
--- a/lib/chef_zero/endpoints/license_endpoint.rb
+++ b/lib/chef_zero/endpoints/license_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
diff --git a/lib/chef_zero/endpoints/node_endpoint.rb b/lib/chef_zero/endpoints/node_endpoint.rb
index c87e658..223ec9f 100644
--- a/lib/chef_zero/endpoints/node_endpoint.rb
+++ b/lib/chef_zero/endpoints/node_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_object_endpoint'
require 'chef_zero/chef_data/data_normalizer'
@@ -7,9 +7,9 @@ module ChefZero
# /nodes/ID
class NodeEndpoint < RestObjectEndpoint
def populate_defaults(request, response_json)
- node = JSON.parse(response_json, :create_additions => false)
+ node = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3])
- JSON.pretty_generate(node)
+ FFI_Yajl::Encoder.encode(node, :pretty => true)
end
end
end
diff --git a/lib/chef_zero/endpoints/not_found_endpoint.rb b/lib/chef_zero/endpoints/not_found_endpoint.rb
index edbf239..ddf1246 100644
--- a/lib/chef_zero/endpoints/not_found_endpoint.rb
+++ b/lib/chef_zero/endpoints/not_found_endpoint.rb
@@ -1,10 +1,10 @@
-require 'json'
+require 'ffi_yajl'
module ChefZero
module Endpoints
class NotFoundEndpoint
def call(request)
- return [404, {"Content-Type" => "application/json"}, JSON.pretty_generate({"error" => ["Object not found: #{request.env['REQUEST_PATH']}"]})]
+ return [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 08f64fb..974d2c3 100644
--- a/lib/chef_zero/endpoints/organization_association_request_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_association_request_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -13,7 +13,7 @@ module ChefZero
end
username = $1
path = request.rest_path[0..-2] + [username]
- data = JSON.parse(get_data(request, path), :create_additions => false)
+ data = FFI_Yajl::Parser.parse(get_data(request, path), :create_additions => false)
delete_data(request, path)
json_response(200, { "id" => id, "username" => username })
end
diff --git a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
index ed1c9ea..608d548 100644
--- a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -6,7 +6,7 @@ module ChefZero
# /organizations/ORG/association_requests
class OrganizationAssociationRequestsEndpoint < RestBase
def post(request)
- json = JSON.parse(request.body, :create_additions => false)
+ json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
username = json['user']
orgname = request.rest_path[1]
id = "#{username}-#{orgname}"
diff --git a/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb b/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb
index ea3edae..cc39a00 100644
--- a/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -6,12 +6,12 @@ module ChefZero
# /organizations/NAME/authenticate_user
class OrganizationAuthenticateUserEndpoint < RestBase
def post(request)
- request_json = JSON.parse(request.body, :create_additions => false)
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
name = request_json['name']
password = request_json['password']
begin
user = data_store.get(request.rest_path[0..-2] + ['users', name])
- user = JSON.parse(user, :create_additions => false)
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
verified = user['password'] == password
rescue DataStore::DataNotFoundError
verified = false
diff --git a/lib/chef_zero/endpoints/organization_endpoint.rb b/lib/chef_zero/endpoints/organization_endpoint.rb
index 4a0bcad..bc5c3f0 100644
--- a/lib/chef_zero/endpoints/organization_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -11,12 +11,12 @@ module ChefZero
end
def put(request)
- org = JSON.parse(get_data(request, request.rest_path + [ 'org' ]), :create_additions => false)
- new_org = JSON.parse(request.body, :create_additions => false)
+ 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 = JSON.pretty_generate(org)
+ 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")
@@ -32,9 +32,9 @@ module ChefZero
end
def populate_defaults(request, response_json)
- org = JSON.parse(response_json, :create_additions => false)
+ org = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
org = ChefData::DataNormalizer.normalize_organization(org, request.rest_path[1])
- JSON.pretty_generate(org)
+ FFI_Yajl::Encoder.encode(org, :pretty => true)
end
end
end
diff --git a/lib/chef_zero/endpoints/organization_user_endpoint.rb b/lib/chef_zero/endpoints/organization_user_endpoint.rb
index 8b3f20b..ef922d4 100644
--- a/lib/chef_zero/endpoints/organization_user_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_user_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -9,14 +9,14 @@ module ChefZero
username = request.rest_path[3]
get_data(request) # 404 if user is not in org
user = get_data(request, [ 'users', username ])
- user = JSON.parse(user, :create_additions => false)
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
json_response(200, ChefData::DataNormalizer.normalize_user(user, username, ['username'], server.options[:osc_compat], request.method))
end
def delete(request)
user = get_data(request)
delete_data(request)
- user = JSON.parse(user, :create_additions => false)
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
json_response(200, ChefData::DataNormalizer.normalize_user(user, request.rest_path[3], ['username'], server.options[:osc_compat]))
end
@@ -25,7 +25,7 @@ module ChefZero
username = request.rest_path[3]
users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
- users = JSON.parse(users, :create_additions => false)
+ users = FFI_Yajl::Parser.parse(users, :create_additions => false)
create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
@@ -39,7 +39,7 @@ module ChefZero
if !users['users'] || !users['users'].include?(username)
users['users'] ||= []
users['users'] |= [ username ]
- set_data(request, [ 'organizations', orgname, 'groups', 'users' ], JSON.pretty_generate(users))
+ set_data(request, [ 'organizations', orgname, 'groups', 'users' ], FFI_Yajl::Encoder.encode(users, :pretty => true))
end
json_response(200, {})
end
diff --git a/lib/chef_zero/endpoints/organization_users_endpoint.rb b/lib/chef_zero/endpoints/organization_users_endpoint.rb
index 810fbad..ed70cf6 100644
--- a/lib/chef_zero/endpoints/organization_users_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_users_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
diff --git a/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb b/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb
index 81419a6..a840515 100644
--- a/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
require 'uuidtools'
@@ -9,10 +9,10 @@ module ChefZero
def post(request)
org_name = request.rest_path[-2]
validator_path = [ 'organizations', org_name, 'clients', "#{org_name}-validator"]
- validator = JSON.parse(get_data(request, validator_path), :create_additions => false)
+ validator = FFI_Yajl::Parser.parse(get_data(request, validator_path), :create_additions => false)
private_key, public_key = server.gen_key_pair
validator['public_key'] = public_key
- set_data(request, validator_path, JSON.pretty_generate(validator))
+ set_data(request, validator_path, FFI_Yajl::Encoder.encode(validator, :pretty => true))
json_response(200, { 'private_key' => private_key })
end
end
diff --git a/lib/chef_zero/endpoints/organizations_endpoint.rb b/lib/chef_zero/endpoints/organizations_endpoint.rb
index 3a34fe4..88816e8 100644
--- a/lib/chef_zero/endpoints/organizations_endpoint.rb
+++ b/lib/chef_zero/endpoints/organizations_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
require 'uuidtools'
@@ -15,7 +15,7 @@ module ChefZero
end
def post(request)
- contents = JSON.parse(request.body, :create_additions => false)
+ contents = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
name = contents['name']
if name.nil?
error(400, "Must specify 'name' in JSON")
@@ -29,17 +29,17 @@ module ChefZero
"assigned_at" => Time.now.to_s
}.merge(contents)
org_path = request.rest_path + [ name ]
- set_data(request, org_path + [ 'org' ], JSON.pretty_generate(org))
+ set_data(request, org_path + [ 'org' ], FFI_Yajl::Encoder.encode(org, :pretty => true))
if server.generate_real_keys?
# Create the validator client
validator_name = "#{name}-validator"
validator_path = org_path + [ 'clients', validator_name ]
private_key, public_key = server.gen_key_pair
- validator = JSON.pretty_generate({
+ validator = FFI_Yajl::Encoder.encode({
'validator' => true,
'public_key' => public_key
- })
+ }, :pretty => true)
set_data(request, validator_path, validator)
end
diff --git a/lib/chef_zero/endpoints/principal_endpoint.rb b/lib/chef_zero/endpoints/principal_endpoint.rb
index f4c2f30..8cad07c 100644
--- a/lib/chef_zero/endpoints/principal_endpoint.rb
+++ b/lib/chef_zero/endpoints/principal_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero'
require 'chef_zero/rest_base'
@@ -29,7 +29,7 @@ module ChefZero
json_response(200, {
'name' => name,
'type' => type,
- 'public_key' => JSON.parse(json)['public_key'] || PUBLIC_KEY,
+ 'public_key' => FFI_Yajl::Parser.parse(json)['public_key'] || PUBLIC_KEY,
'authz_id' => '0'*32,
'org_member' => org_member
})
diff --git a/lib/chef_zero/endpoints/rest_list_endpoint.rb b/lib/chef_zero/endpoints/rest_list_endpoint.rb
index 9a0ab7d..d6556cf 100644
--- a/lib/chef_zero/endpoints/rest_list_endpoint.rb
+++ b/lib/chef_zero/endpoints/rest_list_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -34,7 +34,7 @@ module ChefZero
end
def get_key(contents)
- json = JSON.parse(contents, :create_additions => false)
+ json = FFI_Yajl::Parser.parse(contents, :create_additions => false)
identity_keys.map { |k| json[k] }.select { |v| v }.first
end
end
diff --git a/lib/chef_zero/endpoints/rest_object_endpoint.rb b/lib/chef_zero/endpoints/rest_object_endpoint.rb
index 4fb42e3..9e978b4 100644
--- a/lib/chef_zero/endpoints/rest_object_endpoint.rb
+++ b/lib/chef_zero/endpoints/rest_object_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
require 'chef_zero/rest_error_response'
@@ -21,7 +21,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)
- request_json = JSON.parse(request.body, :create_additions => false)
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
key = identity_keys.map { |k| request_json[k] }.select { |v| v }.first
key ||= request.rest_path[-1]
# If it's a rename, check for conflict and delete the old value
@@ -49,11 +49,11 @@ module ChefZero
def patch_request_body(request)
existing_value = get_data(request, nil, :nil)
if existing_value
- request_json = JSON.parse(request.body, :create_additions => false)
- existing_json = JSON.parse(existing_value, :create_additions => false)
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
+ existing_json = FFI_Yajl::Parser.parse(existing_value, :create_additions => false)
merged_json = existing_json.merge(request_json)
if merged_json.size > request_json.size
- return JSON.pretty_generate(merged_json)
+ return FFI_Yajl::Encoder.encode(merged_json, :pretty => true)
end
end
request.body
diff --git a/lib/chef_zero/endpoints/role_endpoint.rb b/lib/chef_zero/endpoints/role_endpoint.rb
index 6cf91c8..0325169 100644
--- a/lib/chef_zero/endpoints/role_endpoint.rb
+++ b/lib/chef_zero/endpoints/role_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_object_endpoint'
require 'chef_zero/chef_data/data_normalizer'
@@ -7,9 +7,9 @@ module ChefZero
# /roles/NAME
class RoleEndpoint < RestObjectEndpoint
def populate_defaults(request, response_json)
- role = JSON.parse(response_json, :create_additions => false)
+ role = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
role = ChefData::DataNormalizer.normalize_role(role, request.rest_path[3])
- JSON.pretty_generate(role)
+ FFI_Yajl::Encoder.encode(role, :pretty => true)
end
end
end
diff --git a/lib/chef_zero/endpoints/role_environments_endpoint.rb b/lib/chef_zero/endpoints/role_environments_endpoint.rb
index caac47c..d56930a 100644
--- a/lib/chef_zero/endpoints/role_environments_endpoint.rb
+++ b/lib/chef_zero/endpoints/role_environments_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -6,7 +6,7 @@ module ChefZero
# /roles/NAME/environments
class RoleEnvironmentsEndpoint < RestBase
def get(request)
- role = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
+ role = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
json_response(200, [ '_default' ] + (role['env_run_lists'].keys || []))
end
end
diff --git a/lib/chef_zero/endpoints/sandbox_endpoint.rb b/lib/chef_zero/endpoints/sandbox_endpoint.rb
index 3a8e139..c6a3508 100644
--- a/lib/chef_zero/endpoints/sandbox_endpoint.rb
+++ b/lib/chef_zero/endpoints/sandbox_endpoint.rb
@@ -1,13 +1,13 @@
require 'chef_zero/rest_base'
require 'chef_zero/rest_error_response'
-require 'json'
+require 'ffi_yajl'
module ChefZero
module Endpoints
# /sandboxes/ID
class SandboxEndpoint < RestBase
def put(request)
- existing_sandbox = JSON.parse(get_data(request), :create_additions => false)
+ existing_sandbox = FFI_Yajl::Parser.parse(get_data(request), :create_additions => false)
existing_sandbox['checksums'].each do |checksum|
if !exists_data?(request, request.rest_path[0..1] + ['file_store', 'checksums', checksum])
raise RestErrorResponse.new(503, "Checksum not uploaded: #{checksum}")
diff --git a/lib/chef_zero/endpoints/sandboxes_endpoint.rb b/lib/chef_zero/endpoints/sandboxes_endpoint.rb
index 09d2175..88314f7 100644
--- a/lib/chef_zero/endpoints/sandboxes_endpoint.rb
+++ b/lib/chef_zero/endpoints/sandboxes_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -13,7 +13,7 @@ module ChefZero
def post(request)
sandbox_checksums = []
- needed_checksums = JSON.parse(request.body, :create_additions => false)['checksums']
+ needed_checksums = FFI_Yajl::Parser.parse(request.body, :create_additions => false)['checksums']
result_checksums = {}
needed_checksums.keys.each do |needed_checksum|
if list_data(request, request.rest_path[0..1] + ['file_store', 'checksums']).include?(needed_checksum)
@@ -34,10 +34,10 @@ module ChefZero
time_str = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S%z')
time_str = "#{time_str[0..21]}:#{time_str[22..23]}"
- create_data(request, request.rest_path, id, JSON.pretty_generate({
+ create_data(request, request.rest_path, id, FFI_Yajl::Encoder.encode({
:create_time => time_str,
:checksums => sandbox_checksums
- }))
+ }, :pretty => true))
json_response(201, {
:uri => build_uri(request.base_uri, request.rest_path + [id]),
diff --git a/lib/chef_zero/endpoints/search_endpoint.rb b/lib/chef_zero/endpoints/search_endpoint.rb
index db29f7c..3a093be 100644
--- a/lib/chef_zero/endpoints/search_endpoint.rb
+++ b/lib/chef_zero/endpoints/search_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/endpoints/rest_object_endpoint'
require 'chef_zero/chef_data/data_normalizer'
require 'chef_zero/rest_error_response'
@@ -17,7 +17,7 @@ module ChefZero
def post(request)
full_results = search(request)
- keys = JSON.parse(request.body, :create_additions => false)
+ keys = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
partial_results = full_results['rows'].map do |name, uri, doc, search_value|
data = {}
keys.each_pair do |key, path|
@@ -110,7 +110,7 @@ module ChefZero
result = []
list_data(request, container).each do |name|
value = get_data(request, container + [name])
- expanded = expander.call(JSON.parse(value, :create_additions => false), name)
+ expanded = expander.call(FFI_Yajl::Parser.parse(value, :create_additions => false), name)
result << [ name, build_uri(request.base_uri, container + [name]), expanded, expand_for_indexing(expanded, index, name) ]
end
result = result.select do |name, uri, value, search_value|
diff --git a/lib/chef_zero/endpoints/system_recovery_endpoint.rb b/lib/chef_zero/endpoints/system_recovery_endpoint.rb
index a3c62fa..be438f8 100644
--- a/lib/chef_zero/endpoints/system_recovery_endpoint.rb
+++ b/lib/chef_zero/endpoints/system_recovery_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -6,7 +6,7 @@ module ChefZero
# /system_recovery
class SystemRecoveryEndpoint < RestBase
def post(request)
- request_json = JSON.parse(request.body, :create_additions => false)
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
name = request_json['username']
password = request_json['password']
user = get_data(request, request.rest_path[0..-2] + ['users', name], :nil)
@@ -14,7 +14,7 @@ module ChefZero
raise RestErrorResponse.new(403, "Nonexistent user")
end
- user = JSON.parse(user, :create_additions => false)
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
user = ChefData::DataNormalizer.normalize_user(user, name, [ 'username' ], server.options[:osc_compat])
if !user['recovery_authentication_enabled']
raise RestErrorResponse.new(403, "Only users with recovery_authentication_enabled=true may use /system_recovery to log in")
diff --git a/lib/chef_zero/endpoints/user_association_request_endpoint.rb b/lib/chef_zero/endpoints/user_association_request_endpoint.rb
index ead081b..a83849f 100644
--- a/lib/chef_zero/endpoints/user_association_request_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_association_request_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -13,11 +13,11 @@ module ChefZero
end
orgname = $1
- json = JSON.parse(request.body, :create_additions => false)
+ json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
association_request_path = [ 'organizations', orgname, 'association_requests', username ]
if json['response'] == 'accept'
users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
- users = JSON.parse(users, :create_additions => false)
+ users = FFI_Yajl::Parser.parse(users, :create_additions => false)
delete_data(request, association_request_path)
create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
@@ -26,7 +26,7 @@ module ChefZero
if !users['users'] || !users['users'].include?(username)
users['users'] ||= []
users['users'] |= [ username ]
- set_data(request, [ 'organizations', orgname, 'groups', 'users' ], JSON.pretty_generate(users))
+ set_data(request, [ 'organizations', orgname, 'groups', 'users' ], FFI_Yajl::Encoder.encode(users, :pretty => true))
end
elsif json['response'] == 'reject'
delete_data(request, association_request_path)
diff --git a/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb b/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb
index 168b315..ae8ba9b 100644
--- a/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
diff --git a/lib/chef_zero/endpoints/user_association_requests_endpoint.rb b/lib/chef_zero/endpoints/user_association_requests_endpoint.rb
index cdff2fd..d8dc6eb 100644
--- a/lib/chef_zero/endpoints/user_association_requests_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_association_requests_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
diff --git a/lib/chef_zero/endpoints/user_organizations_endpoint.rb b/lib/chef_zero/endpoints/user_organizations_endpoint.rb
index 98824d6..b6decb9 100644
--- a/lib/chef_zero/endpoints/user_organizations_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_organizations_endpoint.rb
@@ -1,4 +1,4 @@
-require 'json'
+require 'ffi_yajl'
require 'chef_zero/rest_base'
module ChefZero
@@ -12,7 +12,7 @@ module ChefZero
end
result = result.map do |orgname|
org = get_data(request, [ 'organizations', orgname, 'org' ])
- org = JSON.parse(org, :create_additions => false)
+ org = FFI_Yajl::Parser.parse(org, :create_additions => false)
ChefData::DataNormalizer.normalize_organization(org, orgname)
end
json_response(200, result)
diff --git a/lib/chef_zero/rest_base.rb b/lib/chef_zero/rest_base.rb
index d85f489..3fa017a 100644
--- a/lib/chef_zero/rest_base.rb
+++ b/lib/chef_zero/rest_base.rb
@@ -178,7 +178,7 @@ module ChefZero
end
def json_response(response_code, json)
- already_json_response(response_code, JSON.pretty_generate(json))
+ already_json_response(response_code, FFI_Yajl::Encoder.encode(json, :pretty => true))
end
def already_json_response(response_code, json_text)
diff --git a/lib/chef_zero/rspec.rb b/lib/chef_zero/rspec.rb
index 5d702d6..3c4b502 100644
--- a/lib/chef_zero/rspec.rb
+++ b/lib/chef_zero/rspec.rb
@@ -265,7 +265,7 @@ module ChefZero
if data.is_a?(String)
data
else
- JSON.pretty_generate(data)
+ FFI_Yajl::Encoder.encode(data, :pretty => true)
end
end
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index dc6e6a3..db3f2a5 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -423,7 +423,7 @@ module ChefZero
end
raise "No version specified" if !cookbook_data[:version]
data_store.create_dir(['organizations', org_name, 'cookbooks'], cookbook_data[:cookbook_name], :recursive)
- data_store.set(['organizations', org_name, 'cookbooks', cookbook_data[:cookbook_name], cookbook_data[:version]], JSON.pretty_generate(cookbook_data), :create)
+ data_store.set(['organizations', org_name, 'cookbooks', cookbook_data[:cookbook_name], cookbook_data[:version]], FFI_Yajl::Encoder.encode(cookbook_data, :pretty => true), :create)
cookbook_data.values.each do |files|
next unless files.is_a? Array
files.each do |file|
@@ -583,7 +583,7 @@ module ChefZero
end
def dejsonize(value)
- value.is_a?(Hash) ? JSON.pretty_generate(value) : value
+ value.is_a?(Hash) ? FFI_Yajl::Encoder.encode(value, :pretty => true) : value
end
def get_file(directory, path)
diff --git a/lib/chef_zero/version.rb b/lib/chef_zero/version.rb
index c569cb7..f00de42 100644
--- a/lib/chef_zero/version.rb
+++ b/lib/chef_zero/version.rb
@@ -1,3 +1,3 @@
module ChefZero
- VERSION = '3.1.3'
+ VERSION = '3.1.4'
end