chef-zero 4.8.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -4
  3. data/Rakefile +20 -10
  4. data/bin/chef-zero +12 -12
  5. data/chef-zero.gemspec +24 -24
  6. data/lib/chef_zero.rb +1 -1
  7. data/lib/chef_zero/chef_data/acl_path.rb +16 -16
  8. data/lib/chef_zero/chef_data/cookbook_data.rb +24 -24
  9. data/lib/chef_zero/chef_data/data_normalizer.rb +120 -120
  10. data/lib/chef_zero/chef_data/default_creator.rb +145 -145
  11. data/lib/chef_zero/data_store/data_already_exists_error.rb +1 -1
  12. data/lib/chef_zero/data_store/data_not_found_error.rb +2 -2
  13. data/lib/chef_zero/data_store/default_facade.rb +5 -5
  14. data/lib/chef_zero/data_store/interface_v1.rb +1 -1
  15. data/lib/chef_zero/data_store/interface_v2.rb +1 -1
  16. data/lib/chef_zero/data_store/memory_store.rb +4 -4
  17. data/lib/chef_zero/data_store/memory_store_v2.rb +8 -8
  18. data/lib/chef_zero/data_store/raw_file_store.rb +10 -10
  19. data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +9 -9
  20. data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +5 -5
  21. data/lib/chef_zero/endpoints/acl_endpoint.rb +6 -6
  22. data/lib/chef_zero/endpoints/acls_endpoint.rb +5 -5
  23. data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +1 -1
  24. data/lib/chef_zero/endpoints/actor_endpoint.rb +20 -20
  25. data/lib/chef_zero/endpoints/actor_key_endpoint.rb +1 -1
  26. data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +5 -6
  27. data/lib/chef_zero/endpoints/actors_endpoint.rb +12 -12
  28. data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +10 -10
  29. data/lib/chef_zero/endpoints/container_endpoint.rb +4 -4
  30. data/lib/chef_zero/endpoints/containers_endpoint.rb +3 -3
  31. data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +1 -1
  32. data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +1 -1
  33. data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +1 -1
  34. data/lib/chef_zero/endpoints/cookbook_endpoint.rb +5 -5
  35. data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +20 -16
  36. data/lib/chef_zero/endpoints/cookbooks_base.rb +13 -13
  37. data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +4 -4
  38. data/lib/chef_zero/endpoints/data_bag_endpoint.rb +12 -12
  39. data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +6 -6
  40. data/lib/chef_zero/endpoints/data_bags_endpoint.rb +5 -5
  41. data/lib/chef_zero/endpoints/dummy_endpoint.rb +0 -2
  42. data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +6 -6
  43. data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +16 -16
  44. data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +6 -6
  45. data/lib/chef_zero/endpoints/environment_endpoint.rb +3 -3
  46. data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +6 -6
  47. data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +4 -4
  48. data/lib/chef_zero/endpoints/environment_role_endpoint.rb +8 -8
  49. data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +2 -2
  50. data/lib/chef_zero/endpoints/group_endpoint.rb +4 -4
  51. data/lib/chef_zero/endpoints/groups_endpoint.rb +3 -3
  52. data/lib/chef_zero/endpoints/license_endpoint.rb +5 -5
  53. data/lib/chef_zero/endpoints/node_endpoint.rb +3 -4
  54. data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +7 -7
  55. data/lib/chef_zero/endpoints/nodes_endpoint.rb +3 -4
  56. data/lib/chef_zero/endpoints/not_found_endpoint.rb +2 -2
  57. data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +2 -2
  58. data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +6 -6
  59. data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +8 -8
  60. data/lib/chef_zero/endpoints/organization_endpoint.rb +10 -10
  61. data/lib/chef_zero/endpoints/organization_user_base.rb +2 -2
  62. data/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb +1 -1
  63. data/lib/chef_zero/endpoints/organization_user_endpoint.rb +5 -5
  64. data/lib/chef_zero/endpoints/organization_user_key_endpoint.rb +2 -2
  65. data/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb +1 -1
  66. data/lib/chef_zero/endpoints/organization_users_endpoint.rb +12 -12
  67. data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +6 -6
  68. data/lib/chef_zero/endpoints/organizations_endpoint.rb +12 -13
  69. data/lib/chef_zero/endpoints/policies_endpoint.rb +2 -2
  70. data/lib/chef_zero/endpoints/policy_endpoint.rb +1 -1
  71. data/lib/chef_zero/endpoints/policy_group_endpoint.rb +6 -6
  72. data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +3 -4
  73. data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +4 -4
  74. data/lib/chef_zero/endpoints/policy_revision_endpoint.rb +1 -1
  75. data/lib/chef_zero/endpoints/policy_revisions_endpoint.rb +1 -1
  76. data/lib/chef_zero/endpoints/principal_endpoint.rb +15 -15
  77. data/lib/chef_zero/endpoints/rest_list_endpoint.rb +4 -4
  78. data/lib/chef_zero/endpoints/rest_object_endpoint.rb +4 -4
  79. data/lib/chef_zero/endpoints/role_endpoint.rb +3 -3
  80. data/lib/chef_zero/endpoints/role_environments_endpoint.rb +3 -3
  81. data/lib/chef_zero/endpoints/sandbox_endpoint.rb +8 -8
  82. data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +9 -9
  83. data/lib/chef_zero/endpoints/search_endpoint.rb +51 -49
  84. data/lib/chef_zero/endpoints/searches_endpoint.rb +2 -2
  85. data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +2 -2
  86. data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +8 -8
  87. data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +12 -12
  88. data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +4 -4
  89. data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +4 -4
  90. data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +5 -5
  91. data/lib/chef_zero/endpoints/version_endpoint.rb +1 -1
  92. data/lib/chef_zero/log.rb +1 -1
  93. data/lib/chef_zero/rest_base.rb +25 -25
  94. data/lib/chef_zero/rest_request.rb +11 -11
  95. data/lib/chef_zero/rest_router.rb +30 -30
  96. data/lib/chef_zero/rspec.rb +33 -33
  97. data/lib/chef_zero/server.rb +188 -189
  98. data/lib/chef_zero/socketless_server_map.rb +2 -3
  99. data/lib/chef_zero/solr/query/binary_operator.rb +8 -8
  100. data/lib/chef_zero/solr/query/phrase.rb +1 -1
  101. data/lib/chef_zero/solr/query/range_query.rb +2 -2
  102. data/lib/chef_zero/solr/query/regexpable_query.rb +1 -0
  103. data/lib/chef_zero/solr/query/term.rb +5 -5
  104. data/lib/chef_zero/solr/query/unary_operator.rb +4 -4
  105. data/lib/chef_zero/solr/solr_doc.rb +4 -4
  106. data/lib/chef_zero/solr/solr_parser.rb +34 -33
  107. data/lib/chef_zero/version.rb +1 -1
  108. data/spec/run_oc_pedant.rb +61 -60
  109. data/spec/search_spec.rb +11 -11
  110. data/spec/server_spec.rb +35 -35
  111. data/spec/socketless_server_map_spec.rb +1 -3
  112. data/spec/support/oc_pedant.rb +20 -21
  113. metadata +2 -2
@@ -1,4 +1,4 @@
1
- require 'chef_zero/rest_base'
1
+ require "chef_zero/rest_base"
2
2
 
3
3
  module ChefZero
4
4
  module Endpoints
@@ -1,4 +1,4 @@
1
- require 'chef_zero/rest_base'
1
+ require "chef_zero/rest_base"
2
2
 
3
3
  module ChefZero
4
4
  module Endpoints
@@ -8,7 +8,7 @@ module ChefZero
8
8
  DEFAULT_PUBLIC_KEY_NAME = "default"
9
9
  DATE_FORMAT = "%FT%TZ" # e.g. 2015-12-24T21:00:00Z
10
10
 
11
- def get(request, alt_uri_root=nil)
11
+ def get(request, alt_uri_root = nil)
12
12
  path = data_path(request)
13
13
 
14
14
  # Get actor or 404 if it doesn't exist
@@ -35,7 +35,7 @@ module ChefZero
35
35
  if generate_keys
36
36
  private_key, public_key = server.gen_key_pair
37
37
  else
38
- public_key = request_body['public_key']
38
+ public_key = request_body["public_key"]
39
39
  end
40
40
 
41
41
  key_name = request_body["name"]
@@ -74,7 +74,6 @@ module ChefZero
74
74
 
75
75
  actor_data["public_key"] = public_key
76
76
  set_data(request, actor_path(request), to_json(actor_data))
77
-
78
77
  end
79
78
 
80
79
  # Returns the keys data store path, which is the same as
@@ -90,7 +89,7 @@ module ChefZero
90
89
  end
91
90
  end
92
91
 
93
- def list_key(request, data_path, alt_uri_root=nil)
92
+ def list_key(request, data_path, alt_uri_root = nil)
94
93
  key_name, expiration_date =
95
94
  if data_path[-1] == DEFAULT_PUBLIC_KEY_NAME
96
95
  [ DEFAULT_PUBLIC_KEY_NAME, "infinity" ]
@@ -111,7 +110,7 @@ module ChefZero
111
110
  request.rest_path[2] == "clients"
112
111
  end
113
112
 
114
- def key_uri(request, key_name, alt_uri_root=nil)
113
+ def key_uri(request, key_name, alt_uri_root = nil)
115
114
  uri_root = alt_uri_root.nil? ? request.rest_path : alt_uri_root
116
115
  build_uri(request.base_uri, [ *uri_root, key_name ])
117
116
  end
@@ -1,5 +1,5 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/endpoints/rest_list_endpoint'
1
+ require "ffi_yajl"
2
+ require "chef_zero/endpoints/rest_list_endpoint"
3
3
 
4
4
  module ChefZero
5
5
  module Endpoints
@@ -10,13 +10,13 @@ module ChefZero
10
10
 
11
11
  # apply query filters: if one applies, stop processing rest
12
12
  # (precendence matches chef-server: https://github.com/chef/chef-server/blob/268a0c9/src/oc_erchef/apps/chef_objects/src/chef_user.erl#L554-L559)
13
- if value = request.query_params['external_authentication_uid']
14
- response[2] = filter('external_authentication_uid', value, request, response[2])
15
- elsif value = request.query_params['email']
16
- response[2] = filter('email', value, request, response[2])
13
+ if value = request.query_params["external_authentication_uid"]
14
+ response[2] = filter("external_authentication_uid", value, request, response[2])
15
+ elsif value = request.query_params["email"]
16
+ response[2] = filter("email", value, request, response[2])
17
17
  end
18
18
 
19
- if request.query_params['verbose']
19
+ if request.query_params["verbose"]
20
20
  results = parse_json(response[2])
21
21
  results.each do |name, url|
22
22
  record = get_data(request, request.rest_path + [ name ], :nil)
@@ -35,16 +35,16 @@ module ChefZero
35
35
  # First, find out if the user actually posted a public key. If not, make
36
36
  # one.
37
37
  request_body = parse_json(request.body)
38
- public_key = request_body['public_key']
38
+ public_key = request_body["public_key"]
39
39
 
40
40
  skip_key_create = !request.api_v0? && !request_body["create_key"]
41
41
 
42
42
  if !public_key && !skip_key_create
43
43
  private_key, public_key = server.gen_key_pair
44
- request_body['public_key'] = public_key
44
+ request_body["public_key"] = public_key
45
45
  request.body = to_json(request_body)
46
46
  elsif skip_key_create
47
- request_body['public_key'] = nil
47
+ request_body["public_key"] = nil
48
48
  request.body = to_json(request_body)
49
49
  end
50
50
 
@@ -55,8 +55,8 @@ module ChefZero
55
55
  user_data = parse_json(result[2])
56
56
 
57
57
  key_data = {}
58
- key_data['private_key'] = private_key if private_key
59
- key_data['public_key'] = public_key unless request.rest_path[0] == 'users'
58
+ key_data["private_key"] = private_key if private_key
59
+ key_data["public_key"] = public_key unless request.rest_path[0] == "users"
60
60
 
61
61
  response =
62
62
  if request.api_v0?
@@ -1,5 +1,5 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/rest_base'
1
+ require "ffi_yajl"
2
+ require "chef_zero/rest_base"
3
3
 
4
4
  module ChefZero
5
5
  module Endpoints
@@ -7,23 +7,23 @@ module ChefZero
7
7
  class AuthenticateUserEndpoint < RestBase
8
8
  def post(request)
9
9
  request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
10
- name = request_json['username']
11
- password = request_json['password']
10
+ name = request_json["username"]
11
+ password = request_json["password"]
12
12
  begin
13
- user = data_store.get(['users', name])
13
+ user = data_store.get(["users", name])
14
14
  rescue ChefZero::DataStore::DataNotFoundError
15
15
  raise RestErrorResponse.new(401, "Bad username or password")
16
16
  end
17
17
  user = FFI_Yajl::Parser.parse(user, :create_additions => false)
18
- user = ChefData::DataNormalizer.normalize_user(user, name, [ 'username' ], server.options[:osc_compat])
19
- if user['password'] != password
18
+ user = ChefData::DataNormalizer.normalize_user(user, name, [ "username" ], server.options[:osc_compat])
19
+ if user["password"] != password
20
20
  raise RestErrorResponse.new(401, "Bad username or password")
21
21
  end
22
22
  # Include only particular user data in the response
23
- user.keep_if { |key,value| %w(first_name last_name display_name email username).include?(key) }
23
+ user.keep_if { |key, value| %w{first_name last_name display_name email username}.include?(key) }
24
24
  json_response(200, {
25
- 'status' => 'linked',
26
- 'user' => user
25
+ "status" => "linked",
26
+ "user" => user,
27
27
  })
28
28
  end
29
29
  end
@@ -1,13 +1,13 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/endpoints/rest_object_endpoint'
3
- require 'chef_zero/chef_data/data_normalizer'
1
+ require "ffi_yajl"
2
+ require "chef_zero/endpoints/rest_object_endpoint"
3
+ require "chef_zero/chef_data/data_normalizer"
4
4
 
5
5
  module ChefZero
6
6
  module Endpoints
7
7
  # /organizations/ORG/containers/NAME
8
8
  class ContainerEndpoint < RestObjectEndpoint
9
9
  def initialize(server)
10
- super(server, %w(id containername))
10
+ super(server, %w{id containername})
11
11
  end
12
12
 
13
13
  undef_method(:put)
@@ -1,12 +1,12 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/endpoints/rest_list_endpoint'
1
+ require "ffi_yajl"
2
+ require "chef_zero/endpoints/rest_list_endpoint"
3
3
 
4
4
  module ChefZero
5
5
  module Endpoints
6
6
  # /organizations/ORG/containers
7
7
  class ContainersEndpoint < RestListEndpoint
8
8
  def initialize(server)
9
- super(server, %w(id containername))
9
+ super(server, %w{id containername})
10
10
  end
11
11
 
12
12
  # create a container.
@@ -1,4 +1,4 @@
1
- require 'chef_zero/chef_data/data_normalizer'
1
+ require "chef_zero/chef_data/data_normalizer"
2
2
 
3
3
  module ChefZero
4
4
  module Endpoints
@@ -1,4 +1,4 @@
1
- require 'chef_zero/chef_data/data_normalizer'
1
+ require "chef_zero/chef_data/data_normalizer"
2
2
 
3
3
  module ChefZero
4
4
  module Endpoints
@@ -1,4 +1,4 @@
1
- require 'chef_zero/chef_data/data_normalizer'
1
+ require "chef_zero/chef_data/data_normalizer"
2
2
 
3
3
  module ChefZero
4
4
  module Endpoints
@@ -1,4 +1,4 @@
1
- require 'chef_zero/endpoints/cookbooks_base'
1
+ require "chef_zero/endpoints/cookbooks_base"
2
2
 
3
3
  module ChefZero
4
4
  module Endpoints
@@ -7,19 +7,19 @@ module ChefZero
7
7
  def get(request)
8
8
  filter = request.rest_path[3]
9
9
  case filter
10
- when '_latest'
10
+ when "_latest"
11
11
  result = {}
12
12
  filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
13
13
  if versions.size > 0
14
- result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ['cookbooks', name, versions[0]])
14
+ result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name, versions[0]])
15
15
  end
16
16
  end
17
17
  json_response(200, result)
18
- when '_recipes'
18
+ when "_recipes"
19
19
  result = []
20
20
  filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
21
21
  if versions.size > 0
22
- cookbook = FFI_Yajl::Parser.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,8 +1,8 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/endpoints/rest_object_endpoint'
3
- require 'chef_zero/rest_error_response'
4
- require 'chef_zero/chef_data/data_normalizer'
5
- require 'chef_zero/data_store/data_not_found_error'
1
+ require "ffi_yajl"
2
+ require "chef_zero/endpoints/rest_object_endpoint"
3
+ require "chef_zero/rest_error_response"
4
+ require "chef_zero/chef_data/data_normalizer"
5
+ require "chef_zero/data_store/data_not_found_error"
6
6
 
7
7
  module ChefZero
8
8
  module Endpoints
@@ -23,14 +23,14 @@ module ChefZero
23
23
  # Honor frozen
24
24
  if existing_cookbook
25
25
  existing_cookbook_json = FFI_Yajl::Parser.parse(existing_cookbook, :create_additions => false)
26
- if existing_cookbook_json['frozen?']
27
- if request.query_params['force'] != "true"
26
+ if existing_cookbook_json["frozen?"]
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
31
  request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
32
- if !request_body['frozen?']
33
- request_body['frozen?'] = true
32
+ if !request_body["frozen?"]
33
+ request_body["frozen?"] = true
34
34
  request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true)
35
35
  end
36
36
  end
@@ -74,8 +74,8 @@ module ChefZero
74
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
- if file.is_a?(Hash) && file.has_key?('checksum')
78
- result << file['checksum']
77
+ if file.is_a?(Hash) && file.has_key?("checksum")
78
+ result << file["checksum"]
79
79
  end
80
80
  end
81
81
  end
@@ -86,7 +86,7 @@ module ChefZero
86
86
  private
87
87
 
88
88
  def hoover_unused_checksums(deleted_checksums, request)
89
- %w(cookbooks cookbook_artifacts).each do |cookbook_type|
89
+ %w{cookbooks cookbook_artifacts}.each do |cookbook_type|
90
90
  begin
91
91
  cookbooks = data_store.list(request.rest_path[0..1] + [cookbook_type])
92
92
  rescue ChefZero::DataStore::DataNotFoundError
@@ -95,9 +95,13 @@ module ChefZero
95
95
  cookbooks = []
96
96
  end
97
97
  cookbooks.each do |cookbook_name|
98
- data_store.list(request.rest_path[0..1] + [cookbook_type, cookbook_name]).each do |version|
99
- cookbook = data_store.get(request.rest_path[0..1] + [cookbook_type, cookbook_name, version], request)
100
- deleted_checksums = deleted_checksums - get_checksums(cookbook)
98
+ # as below, this can be racy.
99
+ begin
100
+ data_store.list(request.rest_path[0..1] + [cookbook_type, cookbook_name]).each do |version|
101
+ cookbook = data_store.get(request.rest_path[0..1] + [cookbook_type, cookbook_name, version], request)
102
+ deleted_checksums = deleted_checksums - get_checksums(cookbook)
103
+ end
104
+ rescue ChefZero::DataStore::DataNotFoundError
101
105
  end
102
106
  end
103
107
  end
@@ -106,7 +110,7 @@ module ChefZero
106
110
  # This deals with an exception on delete, but things can still get deleted
107
111
  # that shouldn't be.
108
112
  begin
109
- delete_data(request, request.rest_path[0..1] + ['file_store', 'checksums', checksum], :data_store_exceptions)
113
+ delete_data(request, request.rest_path[0..1] + ["file_store", "checksums", checksum], :data_store_exceptions)
110
114
  rescue ChefZero::DataStore::DataNotFoundError
111
115
  end
112
116
  end
@@ -1,6 +1,6 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/rest_base'
3
- require 'chef_zero/chef_data/data_normalizer'
1
+ require "ffi_yajl"
2
+ require "chef_zero/rest_base"
3
+ require "chef_zero/chef_data/data_normalizer"
4
4
 
5
5
  module ChefZero
6
6
  module Endpoints
@@ -11,13 +11,13 @@ module ChefZero
11
11
  filter_cookbooks(cookbooks_list, constraints, num_versions) do |name, versions|
12
12
  versions_list = versions.map do |version|
13
13
  {
14
- 'url' => build_uri(request.base_uri, request.rest_path[0..1] + ['cookbooks', name, version]),
15
- 'version' => version
14
+ "url" => build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name, version]),
15
+ "version" => version,
16
16
  }
17
17
  end
18
18
  results[name] = {
19
- 'url' => build_uri(request.base_uri, request.rest_path[0..1] + ['cookbooks', name]),
20
- 'versions' => versions_list
19
+ "url" => build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name]),
20
+ "versions" => versions_list,
21
21
  }
22
22
  end
23
23
  results
@@ -26,8 +26,8 @@ module ChefZero
26
26
  def all_cookbooks_list(request)
27
27
  result = {}
28
28
  # Race conditions exist here (if someone deletes while listing). I don't care.
29
- data_store.list(request.rest_path[0..1] + ['cookbooks']).each do |name|
30
- result[name] = data_store.list(request.rest_path[0..1] + ['cookbooks', name])
29
+ data_store.list(request.rest_path[0..1] + ["cookbooks"]).each do |name|
30
+ result[name] = data_store.list(request.rest_path[0..1] + ["cookbooks", name])
31
31
  end
32
32
  result
33
33
  end
@@ -48,10 +48,10 @@ module ChefZero
48
48
 
49
49
  def recipe_names(cookbook_name, cookbook)
50
50
  result = []
51
- if cookbook['recipes']
52
- cookbook['recipes'].each do |recipe|
53
- if recipe['path'] == "recipes/#{recipe['name']}" && recipe['name'][-3..-1] == '.rb'
54
- if recipe['name'] == 'default.rb'
51
+ if cookbook["recipes"]
52
+ cookbook["recipes"].each do |recipe|
53
+ if recipe["path"] == "recipes/#{recipe['name']}" && recipe["name"][-3..-1] == ".rb"
54
+ if recipe["name"] == "default.rb"
55
55
  result << cookbook_name
56
56
  end
57
57
  result << "#{cookbook_name}::#{recipe['name'][0..-4]}"
@@ -1,14 +1,14 @@
1
- require 'chef_zero/endpoints/cookbooks_base'
1
+ require "chef_zero/endpoints/cookbooks_base"
2
2
 
3
3
  module ChefZero
4
4
  module Endpoints
5
5
  # /cookbooks
6
6
  class CookbooksEndpoint < CookbooksBase
7
7
  def get(request)
8
- if request.query_params['num_versions'] == 'all'
8
+ if request.query_params["num_versions"] == "all"
9
9
  num_versions = nil
10
- elsif request.query_params['num_versions']
11
- num_versions = request.query_params['num_versions'].to_i
10
+ elsif request.query_params["num_versions"]
11
+ num_versions = request.query_params["num_versions"].to_i
12
12
  else
13
13
  num_versions = 1
14
14
  end
@@ -1,14 +1,14 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/endpoints/rest_list_endpoint'
3
- require 'chef_zero/endpoints/data_bag_item_endpoint'
4
- require 'chef_zero/rest_error_response'
1
+ require "ffi_yajl"
2
+ require "chef_zero/endpoints/rest_list_endpoint"
3
+ require "chef_zero/endpoints/data_bag_item_endpoint"
4
+ require "chef_zero/rest_error_response"
5
5
 
6
6
  module ChefZero
7
7
  module Endpoints
8
8
  # /data/NAME
9
9
  class DataBagEndpoint < RestListEndpoint
10
10
  def initialize(server)
11
- super(server, 'id')
11
+ super(server, "id")
12
12
  end
13
13
 
14
14
  def post(request)
@@ -16,7 +16,7 @@ module ChefZero
16
16
  key = identity_keys.map { |k| json[k] }.select { |v| v }.first
17
17
  response = super(request)
18
18
  if response[0] == 201
19
- already_json_response(201, DataBagItemEndpoint::populate_defaults(request, request.body, request.rest_path[3], key))
19
+ already_json_response(201, DataBagItemEndpoint.populate_defaults(request, request.body, request.rest_path[3], key))
20
20
  else
21
21
  response
22
22
  end
@@ -24,10 +24,10 @@ module ChefZero
24
24
 
25
25
  def get_key(contents)
26
26
  data_bag_item = FFI_Yajl::Parser.parse(contents, :create_additions => false)
27
- if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
28
- data_bag_item['raw_data']['id']
27
+ if data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"]
28
+ data_bag_item["raw_data"]["id"]
29
29
  else
30
- data_bag_item['id']
30
+ data_bag_item["id"]
31
31
  end
32
32
  end
33
33
 
@@ -35,9 +35,9 @@ module ChefZero
35
35
  key = request.rest_path[3]
36
36
  delete_data_dir(request, request.rest_path, :recursive)
37
37
  json_response(200, {
38
- 'chef_type' => 'data_bag',
39
- 'json_class' => 'Chef::DataBag',
40
- 'name' => key
38
+ "chef_type" => "data_bag",
39
+ "json_class" => "Chef::DataBag",
40
+ "name" => key,
41
41
  })
42
42
  end
43
43
  end
@@ -1,18 +1,18 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/endpoints/rest_object_endpoint'
3
- require 'chef_zero/endpoints/data_bag_item_endpoint'
4
- require 'chef_zero/chef_data/data_normalizer'
1
+ require "ffi_yajl"
2
+ require "chef_zero/endpoints/rest_object_endpoint"
3
+ require "chef_zero/endpoints/data_bag_item_endpoint"
4
+ require "chef_zero/chef_data/data_normalizer"
5
5
 
6
6
  module ChefZero
7
7
  module Endpoints
8
8
  # /data/NAME/NAME
9
9
  class DataBagItemEndpoint < RestObjectEndpoint
10
10
  def initialize(server)
11
- super(server, 'id')
11
+ super(server, "id")
12
12
  end
13
13
 
14
14
  def populate_defaults(request, response_json)
15
- DataBagItemEndpoint::populate_defaults(request, response_json, request.rest_path[3], request.rest_path[4])
15
+ DataBagItemEndpoint.populate_defaults(request, response_json, request.rest_path[3], request.rest_path[4])
16
16
  end
17
17
 
18
18
  def self.populate_defaults(request, response_json, data_bag, data_bag_item)