chef-zero 3.1.3 → 3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef_zero/chef_data/cookbook_data.rb +1 -1
  3. data/lib/chef_zero/chef_data/default_creator.rb +5 -5
  4. data/lib/chef_zero/data_store/default_facade.rb +1 -1
  5. data/lib/chef_zero/endpoints/acl_endpoint.rb +4 -4
  6. data/lib/chef_zero/endpoints/acls_endpoint.rb +2 -2
  7. data/lib/chef_zero/endpoints/actor_endpoint.rb +6 -6
  8. data/lib/chef_zero/endpoints/actors_endpoint.rb +10 -10
  9. data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +3 -3
  10. data/lib/chef_zero/endpoints/container_endpoint.rb +3 -3
  11. data/lib/chef_zero/endpoints/containers_endpoint.rb +1 -1
  12. data/lib/chef_zero/endpoints/cookbook_endpoint.rb +1 -1
  13. data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +7 -7
  14. data/lib/chef_zero/endpoints/cookbooks_base.rb +1 -1
  15. data/lib/chef_zero/endpoints/data_bag_endpoint.rb +3 -3
  16. data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +3 -3
  17. data/lib/chef_zero/endpoints/data_bags_endpoint.rb +2 -2
  18. data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +2 -2
  19. data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +5 -5
  20. data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +2 -2
  21. data/lib/chef_zero/endpoints/environment_endpoint.rb +3 -3
  22. data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +2 -2
  23. data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +3 -3
  24. data/lib/chef_zero/endpoints/environment_role_endpoint.rb +2 -2
  25. data/lib/chef_zero/endpoints/group_endpoint.rb +3 -3
  26. data/lib/chef_zero/endpoints/groups_endpoint.rb +1 -1
  27. data/lib/chef_zero/endpoints/license_endpoint.rb +1 -1
  28. data/lib/chef_zero/endpoints/node_endpoint.rb +3 -3
  29. data/lib/chef_zero/endpoints/not_found_endpoint.rb +2 -2
  30. data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +2 -2
  31. data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +2 -2
  32. data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +3 -3
  33. data/lib/chef_zero/endpoints/organization_endpoint.rb +6 -6
  34. data/lib/chef_zero/endpoints/organization_user_endpoint.rb +5 -5
  35. data/lib/chef_zero/endpoints/organization_users_endpoint.rb +1 -1
  36. data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +3 -3
  37. data/lib/chef_zero/endpoints/organizations_endpoint.rb +5 -5
  38. data/lib/chef_zero/endpoints/principal_endpoint.rb +2 -2
  39. data/lib/chef_zero/endpoints/rest_list_endpoint.rb +2 -2
  40. data/lib/chef_zero/endpoints/rest_object_endpoint.rb +5 -5
  41. data/lib/chef_zero/endpoints/role_endpoint.rb +3 -3
  42. data/lib/chef_zero/endpoints/role_environments_endpoint.rb +2 -2
  43. data/lib/chef_zero/endpoints/sandbox_endpoint.rb +2 -2
  44. data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +4 -4
  45. data/lib/chef_zero/endpoints/search_endpoint.rb +3 -3
  46. data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +3 -3
  47. data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +4 -4
  48. data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +1 -1
  49. data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +1 -1
  50. data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +2 -2
  51. data/lib/chef_zero/rest_base.rb +1 -1
  52. data/lib/chef_zero/rspec.rb +1 -1
  53. data/lib/chef_zero/server.rb +2 -2
  54. data/lib/chef_zero/version.rb +1 -1
  55. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ba30ee9950ff65e5d772c7e2092063f4916067a
4
- data.tar.gz: 2361f6ad62e82e24969f4a70fbf475b9be6ae873
3
+ metadata.gz: 4603478fc3f5f399df18a28c953d038cf823cb22
4
+ data.tar.gz: 7056fd875014833bb81c4eb82b5877475faa750c
5
5
  SHA512:
6
- metadata.gz: 68d6b4736a6eeb9ba697baf1296eb5cf9f456f0ed292bb7b6cc21e23288ea9f99a40d9548091f1a96a892f998dcdb351b3910c150dd5adbf71d58a8f0bf80e09
7
- data.tar.gz: 72e592a0a6b2f4eda33b02f5b8d08080ec536c9d80aac5992d826804614390d6d498399b05d4a55381becde2124c3ef9e12dd1f043c4458ab33c378b2bbe5f60
6
+ metadata.gz: a4ad51e269c42ee9ffa70dc36a2e1390e4d6258a8d47bd0dcff34577a8644490b7db96b4beee58530cdc579c5fd634384e8beb3c70a888713a58deb290f85fd4
7
+ data.tar.gz: 9ee1343e5f781047c367149572684ad731c29b5b131542eda55d1a41d997429fbb211cf03186a7dcdd1819bdbf7f4fe35624f68e6946e4c987fbc3e484efdeb9
@@ -75,7 +75,7 @@ module ChefZero
75
75
  end
76
76
 
77
77
  def from_json(json)
78
- self.merge!(JSON.parse(json))
78
+ self.merge!(FFI_Yajl::Parser.parse(json))
79
79
  end
80
80
 
81
81
  private
@@ -237,11 +237,11 @@ module ChefZero
237
237
 
238
238
  when "groups/admins"
239
239
  admins = data.list(path[0..1] + [ 'users' ]).select do |name|
240
- user = JSON.parse(data.get(path[0..1] + [ 'users', name ]), :create_additions => false)
240
+ user = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ 'users', name ]), :create_additions => false)
241
241
  user['admin']
242
242
  end
243
243
  admins += data.list(path[0..1] + [ 'clients' ]).select do |name|
244
- client = JSON.parse(data.get(path[0..1] + [ 'clients', name ]), :create_additions => false)
244
+ client = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ 'clients', name ]), :create_additions => false)
245
245
  client['admin']
246
246
  end
247
247
  admins += @creators[path[0..1]] if @creators[path[0..1]]
@@ -351,7 +351,7 @@ module ChefZero
351
351
  # Non-validator clients own themselves.
352
352
  if path.size == 4 && path[0] == 'organizations' && path[2] == 'clients'
353
353
  begin
354
- client = JSON.parse(data.get(path), :create_additions => false)
354
+ client = FFI_Yajl::Parser.parse(data.get(path), :create_additions => false)
355
355
  if !client['validator']
356
356
  owners |= [ path[3] ]
357
357
  end
@@ -363,7 +363,7 @@ module ChefZero
363
363
  if @creators[path]
364
364
  @creators[path].each do |creator|
365
365
  begin
366
- client = JSON.parse(data.get(path[0..2] + [ creator ]), :create_additions => false)
366
+ client = FFI_Yajl::Parser.parse(data.get(path[0..2] + [ creator ]), :create_additions => false)
367
367
  next if client['validator']
368
368
  rescue
369
369
  end
@@ -409,7 +409,7 @@ module ChefZero
409
409
  def get_container_acl(acl_path)
410
410
  parent_path = AclPath.parent_acl_data_path(acl_path)
411
411
  if parent_path
412
- JSON.parse(data.get(parent_path), :create_additions => false)
412
+ FFI_Yajl::Parser.parse(data.get(parent_path), :create_additions => false)
413
413
  else
414
414
  nil
415
415
  end
@@ -71,7 +71,7 @@ module ChefZero
71
71
  rescue DataNotFoundError
72
72
  result = default_creator.get(path)
73
73
  if result
74
- JSON.pretty_generate(result)
74
+ FFI_Yajl::Encoder.encode(result, :pretty => true)
75
75
  else
76
76
  raise
77
77
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
  require 'chef_zero/chef_data/acl_path'
4
4
 
@@ -28,9 +28,9 @@ module ChefZero
28
28
 
29
29
  def put(request)
30
30
  path, perm = validate_request(request)
31
- acls = JSON.parse(get_data(request, path), :create_additions => false)
32
- acls[perm] = JSON.parse(request.body, :create_additions => false)[perm]
33
- set_data(request, path, JSON.pretty_generate(acls))
31
+ acls = FFI_Yajl::Parser.parse(get_data(request, path), :create_additions => false)
32
+ acls[perm] = FFI_Yajl::Parser.parse(request.body, :create_additions => false)[perm]
33
+ set_data(request, path, FFI_Yajl::Encoder.encode(acls, :pretty => true))
34
34
  json_response(200, {'uri' => "#{build_uri(request.base_uri, request.rest_path)}"})
35
35
  end
36
36
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
  require 'chef_zero/chef_data/data_normalizer'
4
4
  require 'chef_zero/chef_data/acl_path'
@@ -20,7 +20,7 @@ module ChefZero
20
20
  if !acl_path
21
21
  raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
22
22
  end
23
- acls = JSON.parse(get_data(request, acl_path), :create_additions => false)
23
+ acls = FFI_Yajl::Parser.parse(get_data(request, acl_path), :create_additions => false)
24
24
  acls = ChefData::DataNormalizer.normalize_acls(acls)
25
25
  json_response(200, acls)
26
26
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_object_endpoint'
3
3
  require 'chef_zero/chef_data/data_normalizer'
4
4
 
@@ -23,7 +23,7 @@ module ChefZero
23
23
 
24
24
  def put(request)
25
25
  # Find out if we're updating the public key.
26
- request_body = JSON.parse(request.body, :create_additions => false)
26
+ request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
27
27
  if request_body['public_key'].nil?
28
28
  # If public_key is null, then don't overwrite it. Weird patchiness.
29
29
  body_modified = true
@@ -44,7 +44,7 @@ module ChefZero
44
44
  end
45
45
 
46
46
  # Save request
47
- request.body = JSON.pretty_generate(request_body) if body_modified
47
+ request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true) if body_modified
48
48
 
49
49
  # PUT /clients is patchy
50
50
  request.body = patch_request_body(request)
@@ -63,7 +63,7 @@ module ChefZero
63
63
  'uri' => build_uri(request.base_uri, [ 'users', key ])
64
64
  }
65
65
  else
66
- response = JSON.parse(result[2], :create_additions => false)
66
+ response = FFI_Yajl::Parser.parse(result[2], :create_additions => false)
67
67
  end
68
68
  response['private_key'] = private_key if private_key
69
69
  response.delete('public_key') if !updating_public_key && request.rest_path[2] == 'users'
@@ -75,13 +75,13 @@ module ChefZero
75
75
  end
76
76
 
77
77
  def populate_defaults(request, response_json)
78
- response = JSON.parse(response_json, :create_additions => false)
78
+ response = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
79
79
  if request.rest_path[2] == 'clients'
80
80
  response = ChefData::DataNormalizer.normalize_client(response, request.rest_path[3])
81
81
  else
82
82
  response = ChefData::DataNormalizer.normalize_user(response, request.rest_path[3], identity_keys, server.options[:osc_compat], request.method)
83
83
  end
84
- JSON.pretty_generate(response)
84
+ FFI_Yajl::Encoder.encode(response, :pretty => true)
85
85
  end
86
86
  end
87
87
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_list_endpoint'
3
3
 
4
4
  module ChefZero
@@ -9,29 +9,29 @@ module ChefZero
9
9
  response = super(request)
10
10
 
11
11
  if request.query_params['email']
12
- results = JSON.parse(response[2], :create_additions => false)
12
+ results = FFI_Yajl::Parser.parse(response[2], :create_additions => false)
13
13
  new_results = {}
14
14
  results.each do |name, url|
15
15
  record = get_data(request, request.rest_path + [ name ], :nil)
16
16
  if record
17
- record = JSON.parse(record, :create_additions => false)
17
+ record = FFI_Yajl::Parser.parse(record, :create_additions => false)
18
18
  new_results[name] = url if record['email'] == request.query_params['email']
19
19
  end
20
20
  end
21
- response[2] = JSON.pretty_generate(new_results)
21
+ response[2] = FFI_Yajl::Encoder.encode(new_results, :pretty => true)
22
22
  end
23
23
 
24
24
  if request.query_params['verbose']
25
- results = JSON.parse(response[2], :create_additions => false)
25
+ results = FFI_Yajl::Parser.parse(response[2], :create_additions => false)
26
26
  results.each do |name, url|
27
27
  record = get_data(request, request.rest_path + [ name ], :nil)
28
28
  if record
29
- record = JSON.parse(record, :create_additions => false)
29
+ record = FFI_Yajl::Parser.parse(record, :create_additions => false)
30
30
  record = ChefData::DataNormalizer.normalize_user(record, name, identity_keys, server.options[:osc_compat])
31
31
  results[name] = record
32
32
  end
33
33
  end
34
- response[2] = JSON.pretty_generate(results)
34
+ response[2] = FFI_Yajl::Encoder.encode(results, :pretty => true)
35
35
  end
36
36
  response
37
37
  end
@@ -39,19 +39,19 @@ module ChefZero
39
39
  def post(request)
40
40
  # First, find out if the user actually posted a public key. If not, make
41
41
  # one.
42
- request_body = JSON.parse(request.body, :create_additions => false)
42
+ request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
43
43
  public_key = request_body['public_key']
44
44
  if !public_key
45
45
  private_key, public_key = server.gen_key_pair
46
46
  request_body['public_key'] = public_key
47
- request.body = JSON.pretty_generate(request_body)
47
+ request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true)
48
48
  end
49
49
 
50
50
  result = super(request)
51
51
 
52
52
  if result[0] == 201
53
53
  # If we generated a key, stuff it in the response.
54
- response = JSON.parse(result[2], :create_additions => false)
54
+ response = FFI_Yajl::Parser.parse(result[2], :create_additions => false)
55
55
  response['private_key'] = private_key if private_key
56
56
  response['public_key'] = public_key unless request.rest_path[0] == 'users'
57
57
  json_response(201, response)
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -6,7 +6,7 @@ module ChefZero
6
6
  # /authenticate_user
7
7
  class AuthenticateUserEndpoint < RestBase
8
8
  def post(request)
9
- request_json = JSON.parse(request.body, :create_additions => false)
9
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
10
10
  name = request_json['username']
11
11
  password = request_json['password']
12
12
  begin
@@ -14,7 +14,7 @@ module ChefZero
14
14
  rescue ChefZero::DataStore::DataNotFoundError
15
15
  raise RestErrorResponse.new(401, "Bad username or password")
16
16
  end
17
- user = JSON.parse(user, :create_additions => false)
17
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
18
18
  user = ChefData::DataNormalizer.normalize_user(user, name, [ 'username' ], server.options[:osc_compat])
19
19
  if user['password'] != password
20
20
  raise RestErrorResponse.new(401, "Bad username or password")
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_object_endpoint'
3
3
  require 'chef_zero/chef_data/data_normalizer'
4
4
 
@@ -13,9 +13,9 @@ module ChefZero
13
13
  undef_method(:put)
14
14
 
15
15
  def populate_defaults(request, response_json)
16
- container = JSON.parse(response_json, :create_additions => false)
16
+ container = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
17
17
  container = ChefData::DataNormalizer.normalize_container(container, request.rest_path[3])
18
- JSON.pretty_generate(container)
18
+ FFI_Yajl::Encoder.encode(container, :pretty => true)
19
19
  end
20
20
  end
21
21
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_list_endpoint'
3
3
 
4
4
  module ChefZero
@@ -19,7 +19,7 @@ module ChefZero
19
19
  result = []
20
20
  filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
21
21
  if versions.size > 0
22
- cookbook = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
22
+ cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
23
23
  result += recipe_names(name, cookbook)
24
24
  end
25
25
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_object_endpoint'
3
3
  require 'chef_zero/rest_error_response'
4
4
  require 'chef_zero/chef_data/data_normalizer'
@@ -22,16 +22,16 @@ module ChefZero
22
22
 
23
23
  # Honor frozen
24
24
  if existing_cookbook
25
- existing_cookbook_json = JSON.parse(existing_cookbook, :create_additions => false)
25
+ existing_cookbook_json = FFI_Yajl::Parser.parse(existing_cookbook, :create_additions => false)
26
26
  if existing_cookbook_json['frozen?']
27
27
  if request.query_params['force'] != "true"
28
28
  raise RestErrorResponse.new(409, "The cookbook #{name} at version #{version} is frozen. Use the 'force' option to override.")
29
29
  end
30
30
  # For some reason, you are forever unable to modify "frozen?" on a frozen cookbook.
31
- request_body = JSON.parse(request.body, :create_additions => false)
31
+ request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
32
32
  if !request_body['frozen?']
33
33
  request_body['frozen?'] = true
34
- request.body = JSON.pretty_generate(request_body)
34
+ request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true)
35
35
  end
36
36
  end
37
37
  end
@@ -71,7 +71,7 @@ module ChefZero
71
71
 
72
72
  def get_checksums(cookbook)
73
73
  result = []
74
- JSON.parse(cookbook, :create_additions => false).each_pair do |key, value|
74
+ FFI_Yajl::Parser.parse(cookbook, :create_additions => false).each_pair do |key, value|
75
75
  if value.is_a?(Array)
76
76
  value.each do |file|
77
77
  if file.is_a?(Hash) && file.has_key?('checksum')
@@ -105,9 +105,9 @@ module ChefZero
105
105
 
106
106
  def populate_defaults(request, response_json)
107
107
  # Inject URIs into each cookbook file
108
- cookbook = JSON.parse(response_json, :create_additions => false)
108
+ cookbook = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
109
109
  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)
110
- JSON.pretty_generate(cookbook)
110
+ FFI_Yajl::Encoder.encode(cookbook, :pretty => true)
111
111
  end
112
112
 
113
113
  def latest_version(versions)
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
  require 'chef_zero/chef_data/data_normalizer'
4
4
 
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_list_endpoint'
3
3
  require 'chef_zero/endpoints/data_bag_item_endpoint'
4
4
  require 'chef_zero/rest_error_response'
@@ -12,7 +12,7 @@ module ChefZero
12
12
  end
13
13
 
14
14
  def post(request)
15
- json = JSON.parse(request.body, :create_additions => false)
15
+ json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
16
16
  key = identity_keys.map { |k| json[k] }.select { |v| v }.first
17
17
  response = super(request)
18
18
  if response[0] == 201
@@ -23,7 +23,7 @@ module ChefZero
23
23
  end
24
24
 
25
25
  def get_key(contents)
26
- data_bag_item = JSON.parse(contents, :create_additions => false)
26
+ data_bag_item = FFI_Yajl::Parser.parse(contents, :create_additions => false)
27
27
  if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
28
28
  data_bag_item['raw_data']['id']
29
29
  else
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_object_endpoint'
3
3
  require 'chef_zero/endpoints/data_bag_item_endpoint'
4
4
  require 'chef_zero/chef_data/data_normalizer'
@@ -16,9 +16,9 @@ module ChefZero
16
16
  end
17
17
 
18
18
  def self.populate_defaults(request, response_json, data_bag, data_bag_item)
19
- response = JSON.parse(response_json, :create_additions => false)
19
+ response = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
20
20
  response = ChefData::DataNormalizer.normalize_data_bag_item(response, data_bag, data_bag_item, request.method)
21
- JSON.pretty_generate(response)
21
+ FFI_Yajl::Encoder.encode(response, :pretty => true)
22
22
  end
23
23
  end
24
24
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_list_endpoint'
3
3
 
4
4
  module ChefZero
@@ -7,7 +7,7 @@ module ChefZero
7
7
  class DataBagsEndpoint < RestListEndpoint
8
8
  def post(request)
9
9
  contents = request.body
10
- json = JSON.parse(contents, :create_additions => false)
10
+ json = FFI_Yajl::Parser.parse(contents, :create_additions => false)
11
11
  name = identity_keys.map { |k| json[k] }.select { |v| v }.first
12
12
  if name.nil?
13
13
  error(400, "Must specify #{identity_keys.map { |k| k.inspect }.join(' or ')} in JSON")
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/cookbooks_base'
3
3
 
4
4
  module ChefZero
@@ -7,7 +7,7 @@ module ChefZero
7
7
  class EnvironmentCookbookEndpoint < CookbooksBase
8
8
  def get(request)
9
9
  cookbook_name = request.rest_path[5]
10
- environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
10
+ environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
11
11
  constraints = environment['cookbook_versions'] || {}
12
12
  cookbook_versions = list_data(request, request.rest_path[0..1] + request.rest_path[4..5])
13
13
  if request.query_params['num_versions'] == 'all'
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
  require 'chef_zero/rest_error_response'
4
4
 
@@ -12,7 +12,7 @@ module ChefZero
12
12
 
13
13
  # Get the list of cookbooks and versions desired by the runlist
14
14
  desired_versions = {}
15
- run_list = JSON.parse(request.body, :create_additions => false)['run_list']
15
+ run_list = FFI_Yajl::Parser.parse(request.body, :create_additions => false)['run_list']
16
16
  run_list.each do |run_list_entry|
17
17
  if run_list_entry =~ /(.+)::.+\@(.+)/ || run_list_entry =~ /(.+)\@(.+)/
18
18
  raise RestErrorResponse.new(412, "No such cookbook: #{$1}") if !cookbook_names.include?($1)
@@ -26,7 +26,7 @@ module ChefZero
26
26
  end
27
27
 
28
28
  # Filter by environment constraints
29
- environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
29
+ environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
30
30
  environment_constraints = environment['cookbook_versions'] || {}
31
31
 
32
32
  desired_versions.each_key do |name|
@@ -48,7 +48,7 @@ module ChefZero
48
48
 
49
49
  result = {}
50
50
  solved.each_pair do |name, versions|
51
- cookbook = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
51
+ cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
52
52
  result[name] = ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, name, versions[0], request.base_uri, 'MIN')
53
53
  end
54
54
  json_response(200, result)
@@ -74,7 +74,7 @@ module ChefZero
74
74
  new_unsolved = unsolved[1..-1]
75
75
 
76
76
  # Pick this cookbook, and add dependencies
77
- cookbook_obj = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', solve_for, desired_version]), :create_additions => false)
77
+ cookbook_obj = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', solve_for, desired_version]), :create_additions => false)
78
78
  cookbook_metadata = cookbook_obj['metadata'] || {}
79
79
  cookbook_dependencies = cookbook_metadata['dependencies'] || {}
80
80
  dep_not_found = false
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/cookbooks_base'
3
3
 
4
4
  module ChefZero
@@ -6,7 +6,7 @@ module ChefZero
6
6
  # /environments/NAME/cookbooks
7
7
  class EnvironmentCookbooksEndpoint < CookbooksBase
8
8
  def get(request)
9
- environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
9
+ environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
10
10
  constraints = environment['cookbook_versions'] || {}
11
11
  if request.query_params['num_versions'] == 'all'
12
12
  num_versions = nil
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_object_endpoint'
3
3
  require 'chef_zero/chef_data/data_normalizer'
4
4
 
@@ -24,9 +24,9 @@ module ChefZero
24
24
  end
25
25
 
26
26
  def populate_defaults(request, response_json)
27
- response = JSON.parse(response_json, :create_additions => false)
27
+ response = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
28
28
  response = ChefData::DataNormalizer.normalize_environment(response, request.rest_path[3])
29
- JSON.pretty_generate(response)
29
+ FFI_Yajl::Encoder.encode(response, :pretty => true)
30
30
  end
31
31
  end
32
32
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -11,7 +11,7 @@ module ChefZero
11
11
 
12
12
  result = {}
13
13
  list_data(request, request.rest_path[0..1] + ['nodes']).each do |name|
14
- node = JSON.parse(get_data(request, request.rest_path[0..1] + ['nodes', name]), :create_additions => false)
14
+ node = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['nodes', name]), :create_additions => false)
15
15
  if node['chef_environment'] == request.rest_path[3]
16
16
  result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ['nodes', name])
17
17
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/cookbooks_base'
3
3
 
4
4
  module ChefZero
@@ -6,12 +6,12 @@ module ChefZero
6
6
  # /environment/NAME/recipes
7
7
  class EnvironmentRecipesEndpoint < CookbooksBase
8
8
  def get(request)
9
- environment = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
9
+ environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
10
10
  constraints = environment['cookbook_versions'] || {}
11
11
  result = []
12
12
  filter_cookbooks(all_cookbooks_list(request), constraints, 1) do |name, versions|
13
13
  if versions.size > 0
14
- cookbook = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
14
+ cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
15
15
  result += recipe_names(name, cookbook)
16
16
  end
17
17
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/cookbooks_base'
3
3
 
4
4
  module ChefZero
@@ -18,7 +18,7 @@ module ChefZero
18
18
  # Verify that the environment exists
19
19
  get_data(request, environment_path)
20
20
 
21
- role = JSON.parse(get_data(request, role_path), :create_additions => false)
21
+ role = FFI_Yajl::Parser.parse(get_data(request, role_path), :create_additions => false)
22
22
  environment_name = environment_path[3]
23
23
  if environment_name == '_default'
24
24
  run_list = role['run_list']
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_object_endpoint'
3
3
  require 'chef_zero/chef_data/data_normalizer'
4
4
 
@@ -11,9 +11,9 @@ module ChefZero
11
11
  end
12
12
 
13
13
  def populate_defaults(request, response_json)
14
- group = JSON.parse(response_json, :create_additions => false)
14
+ group = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
15
15
  group = ChefData::DataNormalizer.normalize_group(group, request.rest_path[3], request.rest_path[1])
16
- JSON.pretty_generate(group)
16
+ FFI_Yajl::Encoder.encode(group, :pretty => true)
17
17
  end
18
18
  end
19
19
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_list_endpoint'
3
3
 
4
4
  module ChefZero
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_object_endpoint'
3
3
  require 'chef_zero/chef_data/data_normalizer'
4
4
 
@@ -7,9 +7,9 @@ module ChefZero
7
7
  # /nodes/ID
8
8
  class NodeEndpoint < RestObjectEndpoint
9
9
  def populate_defaults(request, response_json)
10
- node = JSON.parse(response_json, :create_additions => false)
10
+ node = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
11
11
  node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3])
12
- JSON.pretty_generate(node)
12
+ FFI_Yajl::Encoder.encode(node, :pretty => true)
13
13
  end
14
14
  end
15
15
  end
@@ -1,10 +1,10 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
 
3
3
  module ChefZero
4
4
  module Endpoints
5
5
  class NotFoundEndpoint
6
6
  def call(request)
7
- return [404, {"Content-Type" => "application/json"}, JSON.pretty_generate({"error" => ["Object not found: #{request.env['REQUEST_PATH']}"]})]
7
+ return [404, {"Content-Type" => "application/json"}, FFI_Yajl::Encoder.encode({"error" => ["Object not found: #{request.env['REQUEST_PATH']}"]}, :pretty => true)]
8
8
  end
9
9
  end
10
10
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -13,7 +13,7 @@ module ChefZero
13
13
  end
14
14
  username = $1
15
15
  path = request.rest_path[0..-2] + [username]
16
- data = JSON.parse(get_data(request, path), :create_additions => false)
16
+ data = FFI_Yajl::Parser.parse(get_data(request, path), :create_additions => false)
17
17
  delete_data(request, path)
18
18
  json_response(200, { "id" => id, "username" => username })
19
19
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -6,7 +6,7 @@ module ChefZero
6
6
  # /organizations/ORG/association_requests
7
7
  class OrganizationAssociationRequestsEndpoint < RestBase
8
8
  def post(request)
9
- json = JSON.parse(request.body, :create_additions => false)
9
+ json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
10
10
  username = json['user']
11
11
  orgname = request.rest_path[1]
12
12
  id = "#{username}-#{orgname}"
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -6,12 +6,12 @@ module ChefZero
6
6
  # /organizations/NAME/authenticate_user
7
7
  class OrganizationAuthenticateUserEndpoint < RestBase
8
8
  def post(request)
9
- request_json = JSON.parse(request.body, :create_additions => false)
9
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
10
10
  name = request_json['name']
11
11
  password = request_json['password']
12
12
  begin
13
13
  user = data_store.get(request.rest_path[0..-2] + ['users', name])
14
- user = JSON.parse(user, :create_additions => false)
14
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
15
15
  verified = user['password'] == password
16
16
  rescue DataStore::DataNotFoundError
17
17
  verified = false
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -11,12 +11,12 @@ module ChefZero
11
11
  end
12
12
 
13
13
  def put(request)
14
- org = JSON.parse(get_data(request, request.rest_path + [ 'org' ]), :create_additions => false)
15
- new_org = JSON.parse(request.body, :create_additions => false)
14
+ org = FFI_Yajl::Parser.parse(get_data(request, request.rest_path + [ 'org' ]), :create_additions => false)
15
+ new_org = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
16
16
  new_org.each do |key, value|
17
17
  org[key] = value
18
18
  end
19
- org = JSON.pretty_generate(org)
19
+ org = FFI_Yajl::Encoder.encode(org, :pretty => true)
20
20
  if new_org['name'] != request.rest_path[-1]
21
21
  # This is a rename
22
22
  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
32
32
  end
33
33
 
34
34
  def populate_defaults(request, response_json)
35
- org = JSON.parse(response_json, :create_additions => false)
35
+ org = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
36
36
  org = ChefData::DataNormalizer.normalize_organization(org, request.rest_path[1])
37
- JSON.pretty_generate(org)
37
+ FFI_Yajl::Encoder.encode(org, :pretty => true)
38
38
  end
39
39
  end
40
40
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -9,14 +9,14 @@ module ChefZero
9
9
  username = request.rest_path[3]
10
10
  get_data(request) # 404 if user is not in org
11
11
  user = get_data(request, [ 'users', username ])
12
- user = JSON.parse(user, :create_additions => false)
12
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
13
13
  json_response(200, ChefData::DataNormalizer.normalize_user(user, username, ['username'], server.options[:osc_compat], request.method))
14
14
  end
15
15
 
16
16
  def delete(request)
17
17
  user = get_data(request)
18
18
  delete_data(request)
19
- user = JSON.parse(user, :create_additions => false)
19
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
20
20
  json_response(200, ChefData::DataNormalizer.normalize_user(user, request.rest_path[3], ['username'], server.options[:osc_compat]))
21
21
  end
22
22
 
@@ -25,7 +25,7 @@ module ChefZero
25
25
  username = request.rest_path[3]
26
26
 
27
27
  users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
28
- users = JSON.parse(users, :create_additions => false)
28
+ users = FFI_Yajl::Parser.parse(users, :create_additions => false)
29
29
 
30
30
  create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
31
31
 
@@ -39,7 +39,7 @@ module ChefZero
39
39
  if !users['users'] || !users['users'].include?(username)
40
40
  users['users'] ||= []
41
41
  users['users'] |= [ username ]
42
- set_data(request, [ 'organizations', orgname, 'groups', 'users' ], JSON.pretty_generate(users))
42
+ set_data(request, [ 'organizations', orgname, 'groups', 'users' ], FFI_Yajl::Encoder.encode(users, :pretty => true))
43
43
  end
44
44
  json_response(200, {})
45
45
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
  require 'uuidtools'
4
4
 
@@ -9,10 +9,10 @@ module ChefZero
9
9
  def post(request)
10
10
  org_name = request.rest_path[-2]
11
11
  validator_path = [ 'organizations', org_name, 'clients', "#{org_name}-validator"]
12
- validator = JSON.parse(get_data(request, validator_path), :create_additions => false)
12
+ validator = FFI_Yajl::Parser.parse(get_data(request, validator_path), :create_additions => false)
13
13
  private_key, public_key = server.gen_key_pair
14
14
  validator['public_key'] = public_key
15
- set_data(request, validator_path, JSON.pretty_generate(validator))
15
+ set_data(request, validator_path, FFI_Yajl::Encoder.encode(validator, :pretty => true))
16
16
  json_response(200, { 'private_key' => private_key })
17
17
  end
18
18
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
  require 'uuidtools'
4
4
 
@@ -15,7 +15,7 @@ module ChefZero
15
15
  end
16
16
 
17
17
  def post(request)
18
- contents = JSON.parse(request.body, :create_additions => false)
18
+ contents = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
19
19
  name = contents['name']
20
20
  if name.nil?
21
21
  error(400, "Must specify 'name' in JSON")
@@ -29,17 +29,17 @@ module ChefZero
29
29
  "assigned_at" => Time.now.to_s
30
30
  }.merge(contents)
31
31
  org_path = request.rest_path + [ name ]
32
- set_data(request, org_path + [ 'org' ], JSON.pretty_generate(org))
32
+ set_data(request, org_path + [ 'org' ], FFI_Yajl::Encoder.encode(org, :pretty => true))
33
33
 
34
34
  if server.generate_real_keys?
35
35
  # Create the validator client
36
36
  validator_name = "#{name}-validator"
37
37
  validator_path = org_path + [ 'clients', validator_name ]
38
38
  private_key, public_key = server.gen_key_pair
39
- validator = JSON.pretty_generate({
39
+ validator = FFI_Yajl::Encoder.encode({
40
40
  'validator' => true,
41
41
  'public_key' => public_key
42
- })
42
+ }, :pretty => true)
43
43
  set_data(request, validator_path, validator)
44
44
  end
45
45
 
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero'
3
3
  require 'chef_zero/rest_base'
4
4
 
@@ -29,7 +29,7 @@ module ChefZero
29
29
  json_response(200, {
30
30
  'name' => name,
31
31
  'type' => type,
32
- 'public_key' => JSON.parse(json)['public_key'] || PUBLIC_KEY,
32
+ 'public_key' => FFI_Yajl::Parser.parse(json)['public_key'] || PUBLIC_KEY,
33
33
  'authz_id' => '0'*32,
34
34
  'org_member' => org_member
35
35
  })
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -34,7 +34,7 @@ module ChefZero
34
34
  end
35
35
 
36
36
  def get_key(contents)
37
- json = JSON.parse(contents, :create_additions => false)
37
+ json = FFI_Yajl::Parser.parse(contents, :create_additions => false)
38
38
  identity_keys.map { |k| json[k] }.select { |v| v }.first
39
39
  end
40
40
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
  require 'chef_zero/rest_error_response'
4
4
 
@@ -21,7 +21,7 @@ module ChefZero
21
21
  def put(request)
22
22
  # We grab the old body to trigger a 404 if it doesn't exist
23
23
  old_body = get_data(request)
24
- request_json = JSON.parse(request.body, :create_additions => false)
24
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
25
25
  key = identity_keys.map { |k| request_json[k] }.select { |v| v }.first
26
26
  key ||= request.rest_path[-1]
27
27
  # If it's a rename, check for conflict and delete the old value
@@ -49,11 +49,11 @@ module ChefZero
49
49
  def patch_request_body(request)
50
50
  existing_value = get_data(request, nil, :nil)
51
51
  if existing_value
52
- request_json = JSON.parse(request.body, :create_additions => false)
53
- existing_json = JSON.parse(existing_value, :create_additions => false)
52
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
53
+ existing_json = FFI_Yajl::Parser.parse(existing_value, :create_additions => false)
54
54
  merged_json = existing_json.merge(request_json)
55
55
  if merged_json.size > request_json.size
56
- return JSON.pretty_generate(merged_json)
56
+ return FFI_Yajl::Encoder.encode(merged_json, :pretty => true)
57
57
  end
58
58
  end
59
59
  request.body
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_object_endpoint'
3
3
  require 'chef_zero/chef_data/data_normalizer'
4
4
 
@@ -7,9 +7,9 @@ module ChefZero
7
7
  # /roles/NAME
8
8
  class RoleEndpoint < RestObjectEndpoint
9
9
  def populate_defaults(request, response_json)
10
- role = JSON.parse(response_json, :create_additions => false)
10
+ role = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
11
11
  role = ChefData::DataNormalizer.normalize_role(role, request.rest_path[3])
12
- JSON.pretty_generate(role)
12
+ FFI_Yajl::Encoder.encode(role, :pretty => true)
13
13
  end
14
14
  end
15
15
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -6,7 +6,7 @@ module ChefZero
6
6
  # /roles/NAME/environments
7
7
  class RoleEnvironmentsEndpoint < RestBase
8
8
  def get(request)
9
- role = JSON.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
9
+ role = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
10
10
  json_response(200, [ '_default' ] + (role['env_run_lists'].keys || []))
11
11
  end
12
12
  end
@@ -1,13 +1,13 @@
1
1
  require 'chef_zero/rest_base'
2
2
  require 'chef_zero/rest_error_response'
3
- require 'json'
3
+ require 'ffi_yajl'
4
4
 
5
5
  module ChefZero
6
6
  module Endpoints
7
7
  # /sandboxes/ID
8
8
  class SandboxEndpoint < RestBase
9
9
  def put(request)
10
- existing_sandbox = JSON.parse(get_data(request), :create_additions => false)
10
+ existing_sandbox = FFI_Yajl::Parser.parse(get_data(request), :create_additions => false)
11
11
  existing_sandbox['checksums'].each do |checksum|
12
12
  if !exists_data?(request, request.rest_path[0..1] + ['file_store', 'checksums', checksum])
13
13
  raise RestErrorResponse.new(503, "Checksum not uploaded: #{checksum}")
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -13,7 +13,7 @@ module ChefZero
13
13
  def post(request)
14
14
  sandbox_checksums = []
15
15
 
16
- needed_checksums = JSON.parse(request.body, :create_additions => false)['checksums']
16
+ needed_checksums = FFI_Yajl::Parser.parse(request.body, :create_additions => false)['checksums']
17
17
  result_checksums = {}
18
18
  needed_checksums.keys.each do |needed_checksum|
19
19
  if list_data(request, request.rest_path[0..1] + ['file_store', 'checksums']).include?(needed_checksum)
@@ -34,10 +34,10 @@ module ChefZero
34
34
  time_str = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S%z')
35
35
  time_str = "#{time_str[0..21]}:#{time_str[22..23]}"
36
36
 
37
- create_data(request, request.rest_path, id, JSON.pretty_generate({
37
+ create_data(request, request.rest_path, id, FFI_Yajl::Encoder.encode({
38
38
  :create_time => time_str,
39
39
  :checksums => sandbox_checksums
40
- }))
40
+ }, :pretty => true))
41
41
 
42
42
  json_response(201, {
43
43
  :uri => build_uri(request.base_uri, request.rest_path + [id]),
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/endpoints/rest_object_endpoint'
3
3
  require 'chef_zero/chef_data/data_normalizer'
4
4
  require 'chef_zero/rest_error_response'
@@ -17,7 +17,7 @@ module ChefZero
17
17
 
18
18
  def post(request)
19
19
  full_results = search(request)
20
- keys = JSON.parse(request.body, :create_additions => false)
20
+ keys = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
21
21
  partial_results = full_results['rows'].map do |name, uri, doc, search_value|
22
22
  data = {}
23
23
  keys.each_pair do |key, path|
@@ -110,7 +110,7 @@ module ChefZero
110
110
  result = []
111
111
  list_data(request, container).each do |name|
112
112
  value = get_data(request, container + [name])
113
- expanded = expander.call(JSON.parse(value, :create_additions => false), name)
113
+ expanded = expander.call(FFI_Yajl::Parser.parse(value, :create_additions => false), name)
114
114
  result << [ name, build_uri(request.base_uri, container + [name]), expanded, expand_for_indexing(expanded, index, name) ]
115
115
  end
116
116
  result = result.select do |name, uri, value, search_value|
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -6,7 +6,7 @@ module ChefZero
6
6
  # /system_recovery
7
7
  class SystemRecoveryEndpoint < RestBase
8
8
  def post(request)
9
- request_json = JSON.parse(request.body, :create_additions => false)
9
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
10
10
  name = request_json['username']
11
11
  password = request_json['password']
12
12
  user = get_data(request, request.rest_path[0..-2] + ['users', name], :nil)
@@ -14,7 +14,7 @@ module ChefZero
14
14
  raise RestErrorResponse.new(403, "Nonexistent user")
15
15
  end
16
16
 
17
- user = JSON.parse(user, :create_additions => false)
17
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
18
18
  user = ChefData::DataNormalizer.normalize_user(user, name, [ 'username' ], server.options[:osc_compat])
19
19
  if !user['recovery_authentication_enabled']
20
20
  raise RestErrorResponse.new(403, "Only users with recovery_authentication_enabled=true may use /system_recovery to log in")
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -13,11 +13,11 @@ module ChefZero
13
13
  end
14
14
  orgname = $1
15
15
 
16
- json = JSON.parse(request.body, :create_additions => false)
16
+ json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
17
17
  association_request_path = [ 'organizations', orgname, 'association_requests', username ]
18
18
  if json['response'] == 'accept'
19
19
  users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
20
- users = JSON.parse(users, :create_additions => false)
20
+ users = FFI_Yajl::Parser.parse(users, :create_additions => false)
21
21
 
22
22
  delete_data(request, association_request_path)
23
23
  create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
@@ -26,7 +26,7 @@ module ChefZero
26
26
  if !users['users'] || !users['users'].include?(username)
27
27
  users['users'] ||= []
28
28
  users['users'] |= [ username ]
29
- set_data(request, [ 'organizations', orgname, 'groups', 'users' ], JSON.pretty_generate(users))
29
+ set_data(request, [ 'organizations', orgname, 'groups', 'users' ], FFI_Yajl::Encoder.encode(users, :pretty => true))
30
30
  end
31
31
  elsif json['response'] == 'reject'
32
32
  delete_data(request, association_request_path)
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'ffi_yajl'
2
2
  require 'chef_zero/rest_base'
3
3
 
4
4
  module ChefZero
@@ -12,7 +12,7 @@ module ChefZero
12
12
  end
13
13
  result = result.map do |orgname|
14
14
  org = get_data(request, [ 'organizations', orgname, 'org' ])
15
- org = JSON.parse(org, :create_additions => false)
15
+ org = FFI_Yajl::Parser.parse(org, :create_additions => false)
16
16
  ChefData::DataNormalizer.normalize_organization(org, orgname)
17
17
  end
18
18
  json_response(200, result)
@@ -178,7 +178,7 @@ module ChefZero
178
178
  end
179
179
 
180
180
  def json_response(response_code, json)
181
- already_json_response(response_code, JSON.pretty_generate(json))
181
+ already_json_response(response_code, FFI_Yajl::Encoder.encode(json, :pretty => true))
182
182
  end
183
183
 
184
184
  def already_json_response(response_code, json_text)
@@ -265,7 +265,7 @@ module ChefZero
265
265
  if data.is_a?(String)
266
266
  data
267
267
  else
268
- JSON.pretty_generate(data)
268
+ FFI_Yajl::Encoder.encode(data, :pretty => true)
269
269
  end
270
270
  end
271
271
 
@@ -423,7 +423,7 @@ module ChefZero
423
423
  end
424
424
  raise "No version specified" if !cookbook_data[:version]
425
425
  data_store.create_dir(['organizations', org_name, 'cookbooks'], cookbook_data[:cookbook_name], :recursive)
426
- data_store.set(['organizations', org_name, 'cookbooks', cookbook_data[:cookbook_name], cookbook_data[:version]], JSON.pretty_generate(cookbook_data), :create)
426
+ data_store.set(['organizations', org_name, 'cookbooks', cookbook_data[:cookbook_name], cookbook_data[:version]], FFI_Yajl::Encoder.encode(cookbook_data, :pretty => true), :create)
427
427
  cookbook_data.values.each do |files|
428
428
  next unless files.is_a? Array
429
429
  files.each do |file|
@@ -583,7 +583,7 @@ module ChefZero
583
583
  end
584
584
 
585
585
  def dejsonize(value)
586
- value.is_a?(Hash) ? JSON.pretty_generate(value) : value
586
+ value.is_a?(Hash) ? FFI_Yajl::Encoder.encode(value, :pretty => true) : value
587
587
  end
588
588
 
589
589
  def get_file(directory, path)
@@ -1,3 +1,3 @@
1
1
  module ChefZero
2
- VERSION = '3.1.3'
2
+ VERSION = '3.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: '3.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2014-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-log
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
- name: json
56
+ name: ffi-yajl
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.1'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack
71
71
  requirement: !ruby/object:Gem::Requirement