chef-zero 4.2.3 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -201
  3. data/README.md +155 -150
  4. data/Rakefile +31 -31
  5. data/bin/chef-zero +100 -100
  6. data/lib/chef_zero.rb +10 -7
  7. data/lib/chef_zero/chef_data/acl_path.rb +139 -139
  8. data/lib/chef_zero/chef_data/cookbook_data.rb +240 -240
  9. data/lib/chef_zero/chef_data/data_normalizer.rb +207 -207
  10. data/lib/chef_zero/chef_data/default_creator.rb +446 -446
  11. data/lib/chef_zero/data_store/data_already_exists_error.rb +29 -29
  12. data/lib/chef_zero/data_store/data_error.rb +31 -31
  13. data/lib/chef_zero/data_store/data_not_found_error.rb +28 -28
  14. data/lib/chef_zero/data_store/default_facade.rb +149 -149
  15. data/lib/chef_zero/data_store/interface_v1.rb +67 -67
  16. data/lib/chef_zero/data_store/interface_v2.rb +18 -18
  17. data/lib/chef_zero/data_store/memory_store.rb +33 -33
  18. data/lib/chef_zero/data_store/memory_store_v2.rb +155 -155
  19. data/lib/chef_zero/data_store/raw_file_store.rb +147 -147
  20. data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +142 -142
  21. data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +107 -107
  22. data/lib/chef_zero/endpoints/acl_endpoint.rb +38 -38
  23. data/lib/chef_zero/endpoints/acls_endpoint.rb +29 -29
  24. data/lib/chef_zero/endpoints/actor_endpoint.rb +94 -88
  25. data/lib/chef_zero/endpoints/actors_endpoint.rb +64 -64
  26. data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +31 -31
  27. data/lib/chef_zero/endpoints/container_endpoint.rb +22 -22
  28. data/lib/chef_zero/endpoints/containers_endpoint.rb +13 -13
  29. data/lib/chef_zero/endpoints/cookbook_endpoint.rb +39 -39
  30. data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +119 -119
  31. data/lib/chef_zero/endpoints/cookbooks_base.rb +65 -65
  32. data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +19 -19
  33. data/lib/chef_zero/endpoints/data_bag_endpoint.rb +45 -45
  34. data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +25 -25
  35. data/lib/chef_zero/endpoints/data_bags_endpoint.rb +23 -23
  36. data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +24 -24
  37. data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +123 -123
  38. data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +22 -22
  39. data/lib/chef_zero/endpoints/environment_endpoint.rb +33 -33
  40. data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +23 -23
  41. data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +22 -22
  42. data/lib/chef_zero/endpoints/environment_role_endpoint.rb +36 -36
  43. data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +22 -22
  44. data/lib/chef_zero/endpoints/group_endpoint.rb +20 -20
  45. data/lib/chef_zero/endpoints/groups_endpoint.rb +13 -13
  46. data/lib/chef_zero/endpoints/license_endpoint.rb +25 -25
  47. data/lib/chef_zero/endpoints/node_endpoint.rb +17 -17
  48. data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +22 -0
  49. data/lib/chef_zero/endpoints/not_found_endpoint.rb +11 -11
  50. data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +22 -22
  51. data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +30 -29
  52. data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +26 -26
  53. data/lib/chef_zero/endpoints/organization_endpoint.rb +46 -41
  54. data/lib/chef_zero/endpoints/organization_user_base.rb +15 -0
  55. data/lib/chef_zero/endpoints/organization_user_endpoint.rb +26 -48
  56. data/lib/chef_zero/endpoints/organization_users_endpoint.rb +43 -14
  57. data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +20 -20
  58. data/lib/chef_zero/endpoints/organizations_endpoint.rb +62 -55
  59. data/lib/chef_zero/endpoints/policies_endpoint.rb +151 -154
  60. data/lib/chef_zero/endpoints/principal_endpoint.rb +42 -42
  61. data/lib/chef_zero/endpoints/rest_list_endpoint.rb +42 -42
  62. data/lib/chef_zero/endpoints/rest_object_endpoint.rb +63 -63
  63. data/lib/chef_zero/endpoints/role_endpoint.rb +16 -16
  64. data/lib/chef_zero/endpoints/role_environments_endpoint.rb +14 -14
  65. data/lib/chef_zero/endpoints/sandbox_endpoint.rb +27 -27
  66. data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +50 -50
  67. data/lib/chef_zero/endpoints/search_endpoint.rb +194 -192
  68. data/lib/chef_zero/endpoints/searches_endpoint.rb +18 -18
  69. data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +14 -0
  70. data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +30 -30
  71. data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +40 -40
  72. data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +19 -19
  73. data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +19 -19
  74. data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +22 -22
  75. data/lib/chef_zero/endpoints/version_endpoint.rb +12 -12
  76. data/lib/chef_zero/log.rb +7 -7
  77. data/lib/chef_zero/rest_base.rb +242 -214
  78. data/lib/chef_zero/rest_error_response.rb +11 -11
  79. data/lib/chef_zero/rest_request.rb +69 -65
  80. data/lib/chef_zero/rest_router.rb +45 -45
  81. data/lib/chef_zero/rspec.rb +308 -308
  82. data/lib/chef_zero/server.rb +642 -637
  83. data/lib/chef_zero/socketless_server_map.rb +92 -92
  84. data/lib/chef_zero/solr/query/binary_operator.rb +52 -52
  85. data/lib/chef_zero/solr/query/phrase.rb +23 -23
  86. data/lib/chef_zero/solr/query/range_query.rb +46 -46
  87. data/lib/chef_zero/solr/query/regexpable_query.rb +29 -29
  88. data/lib/chef_zero/solr/query/subquery.rb +37 -37
  89. data/lib/chef_zero/solr/query/term.rb +45 -45
  90. data/lib/chef_zero/solr/query/unary_operator.rb +43 -43
  91. data/lib/chef_zero/solr/solr_doc.rb +53 -53
  92. data/lib/chef_zero/solr/solr_parser.rb +203 -203
  93. data/lib/chef_zero/version.rb +3 -3
  94. data/spec/run_oc_pedant.rb +63 -56
  95. data/spec/search_spec.rb +32 -32
  96. data/spec/server_spec.rb +92 -91
  97. data/spec/socketless_server_map_spec.rb +76 -76
  98. data/spec/support/oc_pedant.rb +132 -134
  99. data/spec/support/stickywicket.pem +27 -27
  100. metadata +10 -15
  101. data/spec/run_pedant.rb +0 -103
  102. data/spec/support/pedant.rb +0 -129
@@ -0,0 +1,22 @@
1
+ require 'ffi_yajl'
2
+ require 'chef_zero/rest_base'
3
+ require 'uuidtools'
4
+
5
+ module ChefZero
6
+ module Endpoints
7
+ # /organizations/NAME/nodes/NAME/_identifiers
8
+ class NodeIdentifiersEndpoint < RestBase
9
+ def get(request)
10
+ if get_data(request, request.rest_path[0..3])
11
+ result = {
12
+ :id => UUIDTools::UUID.parse_raw(request.rest_path[0..4].to_s).to_s.gsub('-',''),
13
+ :authz_id => '0'*32,
14
+ :org_id => UUIDTools::UUID.parse_raw(request.rest_path[0..1].to_s).to_s.gsub('-','') }
15
+ json_response(200, result)
16
+ else
17
+ raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,11 +1,11 @@
1
- require 'ffi_yajl'
2
-
3
- module ChefZero
4
- module Endpoints
5
- class NotFoundEndpoint
6
- def call(request)
7
- return [404, {"Content-Type" => "application/json"}, FFI_Yajl::Encoder.encode({"error" => ["Object not found: #{request.env['REQUEST_PATH']}"]}, :pretty => true)]
8
- end
9
- end
10
- end
11
- end
1
+ require 'ffi_yajl'
2
+
3
+ module ChefZero
4
+ module Endpoints
5
+ class NotFoundEndpoint
6
+ def call(request)
7
+ return [404, {"Content-Type" => "application/json"}, FFI_Yajl::Encoder.encode({"error" => ["Object not found: #{request.env['REQUEST_PATH']}"]}, :pretty => true)]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,22 +1,22 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/rest_base'
3
-
4
- module ChefZero
5
- module Endpoints
6
- # /organizations/ORG/association_requests/ID
7
- class OrganizationAssociationRequestEndpoint < RestBase
8
- def delete(request)
9
- orgname = request.rest_path[1]
10
- id = request.rest_path[3]
11
- if id !~ /(.+)-#{orgname}$/
12
- raise HttpErrorResponse.new(404, "Invalid ID #{id}. Must be of the form username-#{orgname}")
13
- end
14
- username = $1
15
- path = request.rest_path[0..-2] + [username]
16
- data = FFI_Yajl::Parser.parse(get_data(request, path), :create_additions => false)
17
- delete_data(request, path)
18
- json_response(200, { "id" => id, "username" => username })
19
- end
20
- end
21
- end
22
- end
1
+ require 'ffi_yajl'
2
+ require 'chef_zero/rest_base'
3
+
4
+ module ChefZero
5
+ module Endpoints
6
+ # /organizations/ORG/association_requests/ID
7
+ class OrganizationAssociationRequestEndpoint < RestBase
8
+ def delete(request)
9
+ orgname = request.rest_path[1]
10
+ id = request.rest_path[3]
11
+ if id !~ /(.+)-#{orgname}$/
12
+ raise HttpErrorResponse.new(404, "Invalid ID #{id}. Must be of the form username-#{orgname}")
13
+ end
14
+ username = $1
15
+ path = request.rest_path[0..-2] + [username]
16
+ data = FFI_Yajl::Parser.parse(get_data(request, path), :create_additions => false)
17
+ delete_data(request, path)
18
+ json_response(200, { "id" => id, "username" => username })
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,29 +1,30 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/rest_base'
3
-
4
- module ChefZero
5
- module Endpoints
6
- # /organizations/ORG/association_requests
7
- class OrganizationAssociationRequestsEndpoint < RestBase
8
- def post(request)
9
- json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
10
- username = json['user']
11
- orgname = request.rest_path[1]
12
- id = "#{username}-#{orgname}"
13
-
14
- if exists_data?(request, [ 'organizations', orgname, 'users', username ])
15
- raise RestErrorResponse.new(409, "User #{username} is already in organization #{orgname}")
16
- end
17
-
18
- create_data(request, request.rest_path, username, '{}')
19
- json_response(201, { "uri" => build_uri(request.base_uri, request.rest_path + [ id ]) })
20
- end
21
-
22
- def get(request)
23
- orgname = request.rest_path[1]
24
- result = list_data(request).map { |username| { "id" => "#{username}-#{orgname}", 'username' => username } }
25
- json_response(200, result)
26
- end
27
- end
28
- end
29
- end
1
+ require 'ffi_yajl'
2
+ require 'chef_zero/rest_base'
3
+
4
+ module ChefZero
5
+ module Endpoints
6
+ # /organizations/ORG/association_requests
7
+ class OrganizationAssociationRequestsEndpoint < RestBase
8
+ def post(request)
9
+ json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
10
+ username = json['user']
11
+ orgname = request.rest_path[1]
12
+ id = "#{username}-#{orgname}"
13
+
14
+ if exists_data?(request, [ 'organizations', orgname, 'users', username ])
15
+ raise RestErrorResponse.new(409, "User #{username} is already in organization #{orgname}")
16
+ end
17
+
18
+ create_data(request, request.rest_path, username, '{}')
19
+ json_response(201, { "uri" => build_uri(request.base_uri, request.rest_path + [ id ]) })
20
+ end
21
+
22
+ def get(request)
23
+ orgname = request.rest_path[1]
24
+ ChefZero::Endpoints::OrganizationUserBase.get(self, request) do |username|
25
+ { "id" => "#{username}-#{orgname}", 'username' => username }
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,26 +1,26 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/rest_base'
3
-
4
- module ChefZero
5
- module Endpoints
6
- # /organizations/NAME/authenticate_user
7
- class OrganizationAuthenticateUserEndpoint < RestBase
8
- def post(request)
9
- request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
10
- name = request_json['name']
11
- password = request_json['password']
12
- begin
13
- user = data_store.get(request.rest_path[0..-2] + ['users', name])
14
- user = FFI_Yajl::Parser.parse(user, :create_additions => false)
15
- verified = user['password'] == password
16
- rescue DataStore::DataNotFoundError
17
- verified = false
18
- end
19
- json_response(200, {
20
- 'name' => name,
21
- 'verified' => !!verified
22
- })
23
- end
24
- end
25
- end
26
- end
1
+ require 'ffi_yajl'
2
+ require 'chef_zero/rest_base'
3
+
4
+ module ChefZero
5
+ module Endpoints
6
+ # /organizations/NAME/authenticate_user
7
+ class OrganizationAuthenticateUserEndpoint < RestBase
8
+ def post(request)
9
+ request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
10
+ name = request_json['name']
11
+ password = request_json['password']
12
+ begin
13
+ user = data_store.get(request.rest_path[0..-2] + ['users', name])
14
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
15
+ verified = user['password'] == password
16
+ rescue DataStore::DataNotFoundError
17
+ verified = false
18
+ end
19
+ json_response(200, {
20
+ 'name' => name,
21
+ 'verified' => !!verified
22
+ })
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,41 +1,46 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/rest_base'
3
-
4
- module ChefZero
5
- module Endpoints
6
- # /organizations/NAME
7
- class OrganizationEndpoint < RestBase
8
- def get(request)
9
- org = get_data(request, request.rest_path + [ 'org' ])
10
- already_json_response(200, populate_defaults(request, org))
11
- end
12
-
13
- def put(request)
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
- new_org.each do |key, value|
17
- org[key] = value
18
- end
19
- org = FFI_Yajl::Encoder.encode(org, :pretty => true)
20
- if new_org['name'] != request.rest_path[-1]
21
- # This is a rename
22
- return error(400, "Cannot rename org #{request.rest_path[-1]} to #{new_org['name']}: rename not supported for orgs")
23
- end
24
- set_data(request, request.rest_path + [ 'org' ], org)
25
- json_response(200, "uri" => "#{build_uri(request.base_uri, request.rest_path)}")
26
- end
27
-
28
- def delete(request)
29
- org = get_data(request, request.rest_path + [ 'org' ])
30
- delete_data_dir(request, request.rest_path)
31
- already_json_response(200, populate_defaults(request, org))
32
- end
33
-
34
- def populate_defaults(request, response_json)
35
- org = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
36
- org = ChefData::DataNormalizer.normalize_organization(org, request.rest_path[1])
37
- FFI_Yajl::Encoder.encode(org, :pretty => true)
38
- end
39
- end
40
- end
41
- end
1
+ require 'ffi_yajl'
2
+ require 'chef_zero/rest_base'
3
+
4
+ module ChefZero
5
+ module Endpoints
6
+ # /organizations/NAME
7
+ class OrganizationEndpoint < RestBase
8
+ def get(request)
9
+ org = get_data(request, request.rest_path + [ 'org' ])
10
+ already_json_response(200, populate_defaults(request, org))
11
+ end
12
+
13
+ def put(request)
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
+ new_org.each do |key, value|
17
+ org[key] = value
18
+ end
19
+ save_org = FFI_Yajl::Encoder.encode(org, :pretty => true)
20
+ if new_org['name'] != request.rest_path[-1]
21
+ # This is a rename
22
+ return error(400, "Cannot rename org #{request.rest_path[-1]} to #{new_org['name']}: rename not supported for orgs")
23
+ end
24
+ set_data(request, request.rest_path + [ 'org' ], save_org)
25
+ json_response(200, {
26
+ "uri" => "#{build_uri(request.base_uri, request.rest_path)}",
27
+ "name" => org['name'],
28
+ "org_type" => org['org_type'],
29
+ "full_name" => org['full_name']
30
+ })
31
+ end
32
+
33
+ def delete(request)
34
+ org = get_data(request, request.rest_path + [ 'org' ])
35
+ delete_data_dir(request, request.rest_path, :recursive)
36
+ already_json_response(200, populate_defaults(request, org))
37
+ end
38
+
39
+ def populate_defaults(request, response_json)
40
+ org = FFI_Yajl::Parser.parse(response_json, :create_additions => false)
41
+ org = ChefData::DataNormalizer.normalize_organization(org, request.rest_path[1])
42
+ FFI_Yajl::Encoder.encode(org, :pretty => true)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,15 @@
1
+ require 'ffi_yajl'
2
+ require 'chef_zero/rest_base'
3
+
4
+ module ChefZero
5
+ module Endpoints
6
+ module OrganizationUserBase
7
+
8
+ def self.get(obj, request, &block)
9
+ result = obj.list_data(request).map(&block)
10
+ obj.json_response(200, result)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -1,48 +1,26 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/rest_base'
3
-
4
- module ChefZero
5
- module Endpoints
6
- # /organizations/ORG/users/NAME
7
- class OrganizationUserEndpoint < RestBase
8
- def get(request)
9
- username = request.rest_path[3]
10
- get_data(request) # 404 if user is not in org
11
- user = get_data(request, [ 'users', username ])
12
- user = FFI_Yajl::Parser.parse(user, :create_additions => false)
13
- json_response(200, ChefData::DataNormalizer.normalize_user(user, username, ['username'], server.options[:osc_compat], request.method))
14
- end
15
-
16
- def delete(request)
17
- user = get_data(request)
18
- delete_data(request)
19
- user = FFI_Yajl::Parser.parse(user, :create_additions => false)
20
- json_response(200, ChefData::DataNormalizer.normalize_user(user, request.rest_path[3], ['username'], server.options[:osc_compat]))
21
- end
22
-
23
- def post(request)
24
- orgname = request.rest_path[1]
25
- username = request.rest_path[3]
26
-
27
- users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
28
- users = FFI_Yajl::Parser.parse(users, :create_additions => false)
29
-
30
- create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
31
-
32
- # /organizations/ORG/association_requests/USERNAME-ORG
33
- begin
34
- delete_data(request, [ 'organizations', orgname, 'association_requests', username], :data_store_exceptions)
35
- rescue DataStore::DataNotFoundError
36
- end
37
-
38
- # Add the user to the users group if it isn't already there
39
- if !users['users'] || !users['users'].include?(username)
40
- users['users'] ||= []
41
- users['users'] |= [ username ]
42
- set_data(request, [ 'organizations', orgname, 'groups', 'users' ], FFI_Yajl::Encoder.encode(users, :pretty => true))
43
- end
44
- json_response(200, {})
45
- end
46
- end
47
- end
48
- end
1
+ require 'ffi_yajl'
2
+ require 'chef_zero/rest_base'
3
+
4
+ module ChefZero
5
+ module Endpoints
6
+ # /organizations/ORG/users/NAME
7
+ class OrganizationUserEndpoint < RestBase
8
+ def get(request)
9
+ username = request.rest_path[3]
10
+ get_data(request) # 404 if user is not in org
11
+ user = get_data(request, [ 'users', username ])
12
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
13
+ json_response(200, ChefData::DataNormalizer.normalize_user(user, username, ['username'], server.options[:osc_compat], request.method))
14
+ end
15
+
16
+ def delete(request)
17
+ user = get_data(request)
18
+ delete_data(request)
19
+ user = FFI_Yajl::Parser.parse(user, :create_additions => false)
20
+ json_response(200, ChefData::DataNormalizer.normalize_user(user, request.rest_path[3], ['username'], server.options[:osc_compat]))
21
+ end
22
+
23
+ # Note: post to a named org user is not permitted, alllow invalid method handling (405)
24
+ end
25
+ end
26
+ end
@@ -1,14 +1,43 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/rest_base'
3
-
4
- module ChefZero
5
- module Endpoints
6
- # /organizations/ORG/users
7
- class OrganizationUsersEndpoint < RestBase
8
- def get(request)
9
- result = list_data(request).map { |username| { "user" => { "username" => username } } }
10
- json_response(200, result)
11
- end
12
- end
13
- end
14
- end
1
+ require 'ffi_yajl'
2
+ require 'chef_zero/rest_base'
3
+ require 'chef_zero/endpoints/organization_user_base'
4
+
5
+ module ChefZero
6
+ module Endpoints
7
+ # /organizations/ORG/users
8
+ class OrganizationUsersEndpoint < RestBase
9
+ def post(request)
10
+ orgname = request.rest_path[1]
11
+ json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
12
+ username = json['username']
13
+
14
+ if exists_data?(request, [ 'organizations', orgname, 'users', username ])
15
+ raise RestErrorResponse.new(409, "User #{username} is already in organization #{orgname}")
16
+ end
17
+
18
+ users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
19
+ users = FFI_Yajl::Parser.parse(users, :create_additions => false)
20
+
21
+ create_data(request, request.rest_path, username, '{}')
22
+
23
+ # /organizations/ORG/association_requests/USERNAME-ORG
24
+ begin
25
+ delete_data(request, [ 'organizations', orgname, 'association_requests', username], :data_store_exceptions)
26
+ rescue DataStore::DataNotFoundError
27
+ end
28
+
29
+ # Add the user to the users group if it isn't already there
30
+ if !users['users'] || !users['users'].include?(username)
31
+ users['users'] ||= []
32
+ users['users'] |= [ username ]
33
+ set_data(request, [ 'organizations', orgname, 'groups', 'users' ], FFI_Yajl::Encoder.encode(users, :pretty => true))
34
+ end
35
+ json_response(201, { "uri" => build_uri(request.base_uri, request.rest_path + [ username ]) })
36
+ end
37
+
38
+ def get(request)
39
+ ChefZero::Endpoints::OrganizationUserBase.get(self, request) { |username| { "user" => { "username" => username } } }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,20 +1,20 @@
1
- require 'ffi_yajl'
2
- require 'chef_zero/rest_base'
3
- require 'uuidtools'
4
-
5
- module ChefZero
6
- module Endpoints
7
- # /organizations/NAME/_validator_key
8
- class OrganizationValidatorKeyEndpoint < RestBase
9
- def post(request)
10
- org_name = request.rest_path[-2]
11
- validator_path = [ 'organizations', org_name, 'clients', "#{org_name}-validator"]
12
- validator = FFI_Yajl::Parser.parse(get_data(request, validator_path), :create_additions => false)
13
- private_key, public_key = server.gen_key_pair
14
- validator['public_key'] = public_key
15
- set_data(request, validator_path, FFI_Yajl::Encoder.encode(validator, :pretty => true))
16
- json_response(200, { 'private_key' => private_key })
17
- end
18
- end
19
- end
20
- end
1
+ require 'ffi_yajl'
2
+ require 'chef_zero/rest_base'
3
+ require 'uuidtools'
4
+
5
+ module ChefZero
6
+ module Endpoints
7
+ # /organizations/NAME/_validator_key
8
+ class OrganizationValidatorKeyEndpoint < RestBase
9
+ def post(request)
10
+ org_name = request.rest_path[-2]
11
+ validator_path = [ 'organizations', org_name, 'clients', "#{org_name}-validator"]
12
+ validator = FFI_Yajl::Parser.parse(get_data(request, validator_path), :create_additions => false)
13
+ private_key, public_key = server.gen_key_pair
14
+ validator['public_key'] = public_key
15
+ set_data(request, validator_path, FFI_Yajl::Encoder.encode(validator, :pretty => true))
16
+ json_response(200, { 'private_key' => private_key })
17
+ end
18
+ end
19
+ end
20
+ end