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,11 +1,11 @@
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
6
6
  # Typical REST list endpoint (/roles or /data/BAG)
7
7
  class RestListEndpoint < RestBase
8
- def initialize(server, identity_keys = [ 'name' ])
8
+ def initialize(server, identity_keys = [ "name" ])
9
9
  super(server)
10
10
  identity_keys = [ identity_keys ] if identity_keys.is_a?(String)
11
11
  @identity_keys = identity_keys
@@ -29,7 +29,7 @@ module ChefZero
29
29
  error(400, "Must specify #{identity_keys.map { |k| k.inspect }.join(' or ')} in JSON")
30
30
  else
31
31
  create_data(request, request.rest_path, key, contents)
32
- json_response(201, {'uri' => "#{build_uri(request.base_uri, request.rest_path + [key])}"})
32
+ json_response(201, { "uri" => "#{build_uri(request.base_uri, request.rest_path + [key])}" })
33
33
  end
34
34
  end
35
35
 
@@ -1,12 +1,12 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/rest_base'
3
- require 'chef_zero/rest_error_response'
1
+ require "ffi_yajl"
2
+ require "chef_zero/rest_base"
3
+ require "chef_zero/rest_error_response"
4
4
 
5
5
  module ChefZero
6
6
  module Endpoints
7
7
  # Typical REST leaf endpoint (/roles/NAME or /data/BAG/NAME)
8
8
  class RestObjectEndpoint < RestBase
9
- def initialize(server, identity_keys = [ 'name' ])
9
+ def initialize(server, identity_keys = [ "name" ])
10
10
  super(server)
11
11
  identity_keys = [ identity_keys ] if identity_keys.is_a?(String)
12
12
  @identity_keys = identity_keys
@@ -1,6 +1,6 @@
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
@@ -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,7 +7,7 @@ module ChefZero
7
7
  class RoleEnvironmentsEndpoint < RestBase
8
8
  def get(request)
9
9
  role = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
10
- json_response(200, [ '_default' ] + (role['env_run_lists'].keys || []))
10
+ json_response(200, [ "_default" ] + (role["env_run_lists"].keys || []))
11
11
  end
12
12
  end
13
13
  end
@@ -1,6 +1,6 @@
1
- require 'chef_zero/rest_base'
2
- require 'chef_zero/rest_error_response'
3
- require 'ffi_yajl'
1
+ require "chef_zero/rest_base"
2
+ require "chef_zero/rest_error_response"
3
+ require "ffi_yajl"
4
4
 
5
5
  module ChefZero
6
6
  module Endpoints
@@ -8,8 +8,8 @@ module ChefZero
8
8
  class SandboxEndpoint < RestBase
9
9
  def put(request)
10
10
  existing_sandbox = FFI_Yajl::Parser.parse(get_data(request), :create_additions => false)
11
- existing_sandbox['checksums'].each do |checksum|
12
- if !exists_data?(request, request.rest_path[0..1] + ['file_store', 'checksums', checksum])
11
+ existing_sandbox["checksums"].each do |checksum|
12
+ if !exists_data?(request, request.rest_path[0..1] + ["file_store", "checksums", checksum])
13
13
  raise RestErrorResponse.new(503, "Checksum not uploaded: #{checksum}")
14
14
  end
15
15
  end
@@ -17,9 +17,9 @@ module ChefZero
17
17
  json_response(200, {
18
18
  :guid => request.rest_path[3],
19
19
  :name => request.rest_path[3],
20
- :checksums => existing_sandbox['checksums'],
21
- :create_time => existing_sandbox['create_time'],
22
- :is_completed => true
20
+ :checksums => existing_sandbox["checksums"],
21
+ :create_time => existing_sandbox["create_time"],
22
+ :is_completed => true,
23
23
  })
24
24
  end
25
25
  end
@@ -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
@@ -13,15 +13,15 @@ module ChefZero
13
13
  def post(request)
14
14
  sandbox_checksums = []
15
15
 
16
- needed_checksums = FFI_Yajl::Parser.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
- if list_data(request, request.rest_path[0..1] + ['file_store', 'checksums']).include?(needed_checksum)
19
+ if list_data(request, request.rest_path[0..1] + %w{file_store checksums}).include?(needed_checksum)
20
20
  result_checksums[needed_checksum] = { :needs_upload => false }
21
21
  else
22
22
  result_checksums[needed_checksum] = {
23
23
  :needs_upload => true,
24
- :url => build_uri(request.base_uri, request.rest_path[0..1] + ['file_store', 'checksums', needed_checksum])
24
+ :url => build_uri(request.base_uri, request.rest_path[0..1] + ["file_store", "checksums", needed_checksum]),
25
25
  }
26
26
  sandbox_checksums << needed_checksum
27
27
  end
@@ -29,20 +29,20 @@ module ChefZero
29
29
 
30
30
  # There is an obvious race condition here.
31
31
  id = @next_id.to_s
32
- @next_id+=1
32
+ @next_id += 1
33
33
 
34
- time_str = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S%z')
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
37
  create_data(request, request.rest_path, id, FFI_Yajl::Encoder.encode({
38
38
  :create_time => time_str,
39
- :checksums => sandbox_checksums
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]),
44
44
  :checksums => result_checksums,
45
- :sandbox_id => id
45
+ :sandbox_id => id,
46
46
  })
47
47
  end
48
48
  end
@@ -1,9 +1,9 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/endpoints/rest_object_endpoint'
3
- require 'chef_zero/chef_data/data_normalizer'
4
- require 'chef_zero/rest_error_response'
5
- require 'chef_zero/solr/solr_parser'
6
- require 'chef_zero/solr/solr_doc'
1
+ require "ffi_yajl"
2
+ require "chef_zero/endpoints/rest_object_endpoint"
3
+ require "chef_zero/chef_data/data_normalizer"
4
+ require "chef_zero/rest_error_response"
5
+ require "chef_zero/solr/solr_parser"
6
+ require "chef_zero/solr/solr_doc"
7
7
 
8
8
  module ChefZero
9
9
  module Endpoints
@@ -12,7 +12,7 @@ module ChefZero
12
12
  def get(request)
13
13
  orgname = request.rest_path[1]
14
14
  results = search(request, orgname)
15
- results['rows'] = results['rows'].map { |name,uri,value,search_value| value }
15
+ results["rows"] = results["rows"].map { |name, uri, value, search_value| value }
16
16
  json_response(200, results)
17
17
  rescue ChefZero::Solr::ParseError
18
18
  bad_search_request(request)
@@ -22,7 +22,7 @@ module ChefZero
22
22
  orgname = request.rest_path[1]
23
23
  full_results = search(request, orgname)
24
24
  keys = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
25
- partial_results = full_results['rows'].map do |name, uri, doc, search_value|
25
+ partial_results = full_results["rows"].map do |name, uri, doc, search_value|
26
26
  data = {}
27
27
  keys.each_pair do |key, path|
28
28
  if path.size > 0
@@ -36,14 +36,14 @@ module ChefZero
36
36
  end
37
37
  end
38
38
  {
39
- 'url' => uri,
40
- 'data' => data
39
+ "url" => uri,
40
+ "data" => data,
41
41
  }
42
42
  end
43
43
  json_response(200, {
44
- 'rows' => partial_results,
45
- 'start' => full_results['start'],
46
- 'total' => full_results['total']
44
+ "rows" => partial_results,
45
+ "start" => full_results["start"],
46
+ "total" => full_results["total"],
47
47
  })
48
48
  rescue ChefZero::Solr::ParseError
49
49
  bad_search_request(request)
@@ -52,53 +52,55 @@ module ChefZero
52
52
  private
53
53
 
54
54
  def bad_search_request(request)
55
- query_string = request.query_params['q']
56
- resp = {"error" => ["invalid search query: '#{query_string}'"]}
55
+ query_string = request.query_params["q"]
56
+ resp = { "error" => ["invalid search query: '#{query_string}'"] }
57
57
  json_response(400, resp)
58
58
  end
59
59
 
60
60
  def search_container(request, index, orgname)
61
- relative_parts, normalize_proc = case index
62
- when 'client'
63
- [ ['clients'], Proc.new { |client, name| ChefData::DataNormalizer.normalize_client(client, name, orgname) } ]
64
- when 'node'
65
- [ ['nodes'], Proc.new { |node, name| ChefData::DataNormalizer.normalize_node(node, name) } ]
66
- when 'environment'
67
- [ ['environments'], Proc.new { |environment, name| ChefData::DataNormalizer.normalize_environment(environment, name) } ]
68
- when 'role'
69
- [ ['roles'], Proc.new { |role, name| ChefData::DataNormalizer.normalize_role(role, name) } ]
70
- else
71
- [ ['data', index], Proc.new { |data_bag_item, id| ChefData::DataNormalizer.normalize_data_bag_item(data_bag_item, index, id, 'DELETE') } ]
72
- end
61
+ relative_parts, normalize_proc =
62
+ case index
63
+ when "client"
64
+ [ ["clients"], Proc.new { |client, name| ChefData::DataNormalizer.normalize_client(client, name, orgname) } ]
65
+ when "node"
66
+ [ ["nodes"], Proc.new { |node, name| ChefData::DataNormalizer.normalize_node(node, name) } ]
67
+ when "environment"
68
+ [ ["environments"], Proc.new { |environment, name| ChefData::DataNormalizer.normalize_environment(environment, name) } ]
69
+ when "role"
70
+ [ ["roles"], Proc.new { |role, name| ChefData::DataNormalizer.normalize_role(role, name) } ]
71
+ else
72
+ [ ["data", index], Proc.new { |data_bag_item, id| ChefData::DataNormalizer.normalize_data_bag_item(data_bag_item, index, id, "DELETE") } ]
73
+ end
74
+
73
75
  [
74
76
  request.rest_path[0..1] + relative_parts,
75
- normalize_proc
77
+ normalize_proc,
76
78
  ]
77
79
  end
78
80
 
79
81
  def expand_for_indexing(value, index, id)
80
- if index == 'node'
82
+ if index == "node"
81
83
  result = {}
82
- deep_merge!(value['default'] || {}, result)
83
- deep_merge!(value['normal'] || {}, result)
84
- deep_merge!(value['override'] || {}, result)
85
- deep_merge!(value['automatic'] || {}, result)
86
- result['recipe'] = []
87
- result['role'] = []
88
- if value['run_list']
89
- value['run_list'].each do |run_list_entry|
84
+ deep_merge!(value["default"] || {}, result)
85
+ deep_merge!(value["normal"] || {}, result)
86
+ deep_merge!(value["override"] || {}, result)
87
+ deep_merge!(value["automatic"] || {}, result)
88
+ result["recipe"] = []
89
+ result["role"] = []
90
+ if value["run_list"]
91
+ value["run_list"].each do |run_list_entry|
90
92
  if run_list_entry =~ /^(recipe|role)\[(.*)\]/
91
93
  result[$1] << $2
92
94
  end
93
95
  end
94
96
  end
95
97
  value.each_pair do |key, value|
96
- result[key] = value unless %w(default normal override automatic).include?(key)
98
+ result[key] = value unless %w{default normal override automatic}.include?(key)
97
99
  end
98
100
  result
99
101
 
100
- elsif !%w(client environment role).include?(index)
101
- ChefData::DataNormalizer.normalize_data_bag_item(value, index, id, 'GET')
102
+ elsif !%w{client environment role}.include?(index)
103
+ ChefData::DataNormalizer.normalize_data_bag_item(value, index, id, "GET")
102
104
  else
103
105
  value
104
106
  end
@@ -107,12 +109,12 @@ module ChefZero
107
109
  def search(request, orgname = nil)
108
110
  # Extract parameters
109
111
  index = request.rest_path[3]
110
- query_string = request.query_params['q'] || '*:*'
112
+ query_string = request.query_params["q"] || "*:*"
111
113
  solr_query = ChefZero::Solr::SolrParser.new(query_string).parse
112
- sort_string = request.query_params['sort']
113
- start = request.query_params['start']
114
+ sort_string = request.query_params["sort"]
115
+ start = request.query_params["start"]
114
116
  start = start.to_i if start
115
- rows = request.query_params['rows']
117
+ rows = request.query_params["rows"]
116
118
  rows = rows.to_i if rows
117
119
 
118
120
  # Get the search container
@@ -133,18 +135,18 @@ module ChefZero
133
135
  # Sort
134
136
  if sort_string
135
137
  sort_key, sort_order = sort_string.split(/\s+/, 2)
136
- result = result.sort_by { |name,uri,value,search_value| ChefZero::Solr::SolrDoc.new(search_value, name)[sort_key] }
138
+ result = result.sort_by { |name, uri, value, search_value| ChefZero::Solr::SolrDoc.new(search_value, name)[sort_key] }
137
139
  result = result.reverse if sort_order == "DESC"
138
140
  end
139
141
 
140
142
  # Paginate
141
143
  if start
142
- result = result[start..start+(rows||-1)]
144
+ result = result[start..start + (rows || -1)]
143
145
  end
144
146
  {
145
- 'rows' => result,
146
- 'start' => start || 0,
147
- 'total' => total
147
+ "rows" => result,
148
+ "start" => start || 0,
149
+ "total" => total,
148
150
  }
149
151
  end
150
152
 
@@ -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
@@ -7,7 +7,7 @@ module ChefZero
7
7
  def get(request)
8
8
  # Get the result
9
9
  result_hash = {}
10
- indices = (%w(client environment node role) + data_store.list(request.rest_path[0..1] + ['data'])).sort
10
+ indices = (%w{client environment node role} + data_store.list(request.rest_path[0..1] + ["data"])).sort
11
11
  indices.each do |index|
12
12
  result_hash[index] = build_uri(request.base_uri, request.rest_path + [index])
13
13
  end
@@ -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
@@ -6,7 +6,7 @@ module ChefZero
6
6
  class ServerAPIVersionEndpoint < RestBase
7
7
  API_VERSION = 1
8
8
  def get(request)
9
- json_response(200, {"min_api_version"=>MIN_API_VERSION, "max_api_version"=>MAX_API_VERSION},
9
+ json_response(200, { "min_api_version" => MIN_API_VERSION, "max_api_version" => MAX_API_VERSION },
10
10
  request_version: request.api_version, response_version: API_VERSION)
11
11
  end
12
12
  end
@@ -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,19 +7,19 @@ module ChefZero
7
7
  class SystemRecoveryEndpoint < 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']
12
- user = get_data(request, request.rest_path[0..-2] + ['users', name], :nil)
10
+ name = request_json["username"]
11
+ password = request_json["password"]
12
+ user = get_data(request, request.rest_path[0..-2] + ["users", name], :nil)
13
13
  if !user
14
14
  raise RestErrorResponse.new(403, "Nonexistent user")
15
15
  end
16
16
 
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['recovery_authentication_enabled']
18
+ user = ChefData::DataNormalizer.normalize_user(user, name, [ "username" ], server.options[:osc_compat])
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")
21
21
  end
22
- if user['password'] != password
22
+ if user["password"] != password
23
23
  raise RestErrorResponse.new(401, "Incorrect password")
24
24
  end
25
25
 
@@ -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
@@ -14,26 +14,26 @@ module ChefZero
14
14
  orgname = $1
15
15
 
16
16
  json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
17
- association_request_path = [ 'organizations', orgname, 'association_requests', username ]
18
- if json['response'] == 'accept'
19
- users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
17
+ association_request_path = [ "organizations", orgname, "association_requests", username ]
18
+ if json["response"] == "accept"
19
+ users = get_data(request, [ "organizations", orgname, "groups", "users" ])
20
20
  users = FFI_Yajl::Parser.parse(users, :create_additions => false)
21
21
 
22
22
  delete_data(request, association_request_path)
23
- create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
23
+ create_data(request, [ "organizations", orgname, "users" ], username, "{}")
24
24
 
25
25
  # Add the user to the users group if it isn't already there
26
- if !users['users'] || !users['users'].include?(username)
27
- users['users'] ||= []
28
- users['users'] |= [ username ]
29
- set_data(request, [ 'organizations', orgname, 'groups', 'users' ], FFI_Yajl::Encoder.encode(users, :pretty => true))
26
+ if !users["users"] || !users["users"].include?(username)
27
+ users["users"] ||= []
28
+ users["users"] |= [ username ]
29
+ set_data(request, [ "organizations", orgname, "groups", "users" ], FFI_Yajl::Encoder.encode(users, :pretty => true))
30
30
  end
31
- elsif json['response'] == 'reject'
31
+ elsif json["response"] == "reject"
32
32
  delete_data(request, association_request_path)
33
33
  else
34
34
  raise RestErrorResponse.new(400, "response parameter was missing or set to the wrong value (must be accept or reject)")
35
35
  end
36
- json_response(200, { 'organization' => { 'name' => orgname } })
36
+ json_response(200, { "organization" => { "name" => orgname } })
37
37
  end
38
38
  end
39
39
  end
@@ -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
@@ -9,8 +9,8 @@ module ChefZero
9
9
  get_data(request, request.rest_path[0..-3])
10
10
 
11
11
  username = request.rest_path[1]
12
- result = list_data(request, [ 'organizations' ]).select do |org|
13
- exists_data?(request, [ 'organizations', org, 'association_requests', username ])
12
+ result = list_data(request, [ "organizations" ]).select do |org|
13
+ exists_data?(request, [ "organizations", org, "association_requests", username ])
14
14
  end
15
15
  json_response(200, { "value" => result.size })
16
16
  end