chef-zero 15.0.17 → 15.0.21

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 (122) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +36 -31
  3. data/LICENSE +201 -201
  4. data/Rakefile +73 -68
  5. data/bin/chef-zero +111 -111
  6. data/chef-zero.gemspec +34 -33
  7. data/lib/chef_zero/chef_data/acl_path.rb +140 -140
  8. data/lib/chef_zero/chef_data/cookbook_data.rb +237 -237
  9. data/lib/chef_zero/chef_data/data_normalizer.rb +276 -276
  10. data/lib/chef_zero/chef_data/default_creator.rb +476 -476
  11. data/lib/chef_zero/data_store/data_already_exists_error.rb +29 -29
  12. data/lib/chef_zero/data_store/data_error.rb +32 -32
  13. data/lib/chef_zero/data_store/data_not_found_error.rb +29 -29
  14. data/lib/chef_zero/data_store/default_facade.rb +143 -147
  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 +159 -159
  19. data/lib/chef_zero/data_store/raw_file_store.rb +143 -143
  20. data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +150 -150
  21. data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +105 -105
  22. data/lib/chef_zero/dist.rb +9 -9
  23. data/lib/chef_zero/endpoints/acl_endpoint.rb +39 -39
  24. data/lib/chef_zero/endpoints/acls_endpoint.rb +41 -41
  25. data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +78 -78
  26. data/lib/chef_zero/endpoints/actor_endpoint.rb +184 -184
  27. data/lib/chef_zero/endpoints/actor_key_endpoint.rb +62 -62
  28. data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +129 -129
  29. data/lib/chef_zero/endpoints/actors_endpoint.rb +104 -104
  30. data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +32 -32
  31. data/lib/chef_zero/endpoints/container_endpoint.rb +22 -22
  32. data/lib/chef_zero/endpoints/containers_endpoint.rb +25 -25
  33. data/lib/chef_zero/endpoints/controls_endpoint.rb +16 -16
  34. data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +24 -24
  35. data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +68 -68
  36. data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +34 -34
  37. data/lib/chef_zero/endpoints/cookbook_endpoint.rb +39 -39
  38. data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +136 -136
  39. data/lib/chef_zero/endpoints/cookbooks_base.rb +80 -80
  40. data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +19 -19
  41. data/lib/chef_zero/endpoints/data_bag_endpoint.rb +45 -45
  42. data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +25 -25
  43. data/lib/chef_zero/endpoints/data_bags_endpoint.rb +23 -23
  44. data/lib/chef_zero/endpoints/dummy_endpoint.rb +29 -29
  45. data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +24 -24
  46. data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +126 -126
  47. data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +22 -22
  48. data/lib/chef_zero/endpoints/environment_endpoint.rb +33 -33
  49. data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +23 -23
  50. data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +22 -22
  51. data/lib/chef_zero/endpoints/environment_role_endpoint.rb +36 -36
  52. data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +22 -22
  53. data/lib/chef_zero/endpoints/group_endpoint.rb +20 -20
  54. data/lib/chef_zero/endpoints/groups_endpoint.rb +13 -13
  55. data/lib/chef_zero/endpoints/license_endpoint.rb +25 -25
  56. data/lib/chef_zero/endpoints/node_endpoint.rb +34 -34
  57. data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +22 -22
  58. data/lib/chef_zero/endpoints/nodes_endpoint.rb +34 -34
  59. data/lib/chef_zero/endpoints/not_found_endpoint.rb +11 -11
  60. data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +22 -22
  61. data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +30 -30
  62. data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +26 -26
  63. data/lib/chef_zero/endpoints/organization_endpoint.rb +47 -47
  64. data/lib/chef_zero/endpoints/organization_user_base.rb +15 -15
  65. data/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb +16 -16
  66. data/lib/chef_zero/endpoints/organization_user_endpoint.rb +26 -26
  67. data/lib/chef_zero/endpoints/organization_user_key_endpoint.rb +17 -17
  68. data/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb +17 -17
  69. data/lib/chef_zero/endpoints/organization_users_endpoint.rb +43 -43
  70. data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +20 -20
  71. data/lib/chef_zero/endpoints/organizations_endpoint.rb +61 -61
  72. data/lib/chef_zero/endpoints/policies_endpoint.rb +26 -26
  73. data/lib/chef_zero/endpoints/policy_endpoint.rb +24 -24
  74. data/lib/chef_zero/endpoints/policy_group_endpoint.rb +46 -46
  75. data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +83 -83
  76. data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +38 -38
  77. data/lib/chef_zero/endpoints/policy_revision_endpoint.rb +66 -66
  78. data/lib/chef_zero/endpoints/policy_revisions_endpoint.rb +15 -15
  79. data/lib/chef_zero/endpoints/principal_endpoint.rb +55 -55
  80. data/lib/chef_zero/endpoints/rest_list_endpoint.rb +42 -42
  81. data/lib/chef_zero/endpoints/rest_object_endpoint.rb +78 -78
  82. data/lib/chef_zero/endpoints/role_endpoint.rb +16 -16
  83. data/lib/chef_zero/endpoints/role_environments_endpoint.rb +14 -14
  84. data/lib/chef_zero/endpoints/sandbox_endpoint.rb +27 -27
  85. data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +51 -51
  86. data/lib/chef_zero/endpoints/search_endpoint.rb +208 -208
  87. data/lib/chef_zero/endpoints/searches_endpoint.rb +18 -18
  88. data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +14 -14
  89. data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +30 -30
  90. data/lib/chef_zero/endpoints/universe_endpoint.rb +15 -15
  91. data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +41 -41
  92. data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +19 -19
  93. data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +19 -19
  94. data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +22 -22
  95. data/lib/chef_zero/endpoints/version_endpoint.rb +13 -13
  96. data/lib/chef_zero/log.rb +7 -7
  97. data/lib/chef_zero/rest_base.rb +332 -332
  98. data/lib/chef_zero/rest_error_response.rb +11 -11
  99. data/lib/chef_zero/rest_request.rb +84 -88
  100. data/lib/chef_zero/rest_router.rb +72 -72
  101. data/lib/chef_zero/rspec.rb +355 -355
  102. data/lib/chef_zero/server.rb +730 -730
  103. data/lib/chef_zero/socketless_server_map.rb +92 -93
  104. data/lib/chef_zero/solr/query/binary_operator.rb +52 -52
  105. data/lib/chef_zero/solr/query/phrase.rb +23 -23
  106. data/lib/chef_zero/solr/query/range_query.rb +46 -46
  107. data/lib/chef_zero/solr/query/regexpable_query.rb +30 -30
  108. data/lib/chef_zero/solr/query/subquery.rb +37 -37
  109. data/lib/chef_zero/solr/query/term.rb +45 -45
  110. data/lib/chef_zero/solr/query/unary_operator.rb +41 -41
  111. data/lib/chef_zero/solr/solr_doc.rb +53 -53
  112. data/lib/chef_zero/solr/solr_parser.rb +208 -208
  113. data/lib/chef_zero/version.rb +3 -3
  114. data/lib/chef_zero.rb +10 -10
  115. data/spec/run_oc_pedant.rb +226 -226
  116. data/spec/search_spec.rb +36 -36
  117. data/spec/server_spec.rb +96 -96
  118. data/spec/socketless_server_map_spec.rb +74 -74
  119. data/spec/support/oc_pedant.rb +149 -149
  120. data/spec/support/secrets.json +6 -6
  121. data/spec/support/stickywicket.pem +27 -27
  122. metadata +35 -18
@@ -1,83 +1,83 @@
1
- require "ffi_yajl" unless defined?(FFI_Yajl)
2
- require_relative "../rest_base"
3
- require_relative "../chef_data/data_normalizer"
4
-
5
- module ChefZero
6
- module Endpoints
7
- # /organizations/ORG/policy_groups/GROUP/policies/NAME
8
- #
9
- # in the data store, this REST path actually stores the revision ID of ${policy_name} that's currently
10
- # associated with ${policy_group}.
11
- class PolicyGroupPolicyEndpoint < RestBase
12
-
13
- # GET /organizations/ORG/policy_groups/GROUP/policies/NAME
14
- def get(request)
15
- policy_name = request.rest_path[5]
16
-
17
- # fetch /organizations/{organization}/policies/{policy_name}/revisions/{revision_id}
18
- revision_id = parse_json(get_data(request))
19
- result = get_data(request, request.rest_path[0..1] +
20
- ["policies", policy_name, "revisions", revision_id])
21
- result = ChefData::DataNormalizer.normalize_policy(parse_json(result), policy_name, revision_id)
22
- json_response(200, result)
23
- end
24
-
25
- # Create or update the policy document for the given policy group and policy name. If no policy group
26
- # with the given name exists, it will be created. If no policy with the given revision_id exists, it
27
- # will be created from the document in the request body. If a policy with that revision_id exists, the
28
- # Chef Server simply associates that revision id with the given policy group. When successful, the
29
- # document that was created or updated is returned.
30
-
31
- ## MANDATORY FIELDS AND FORMATS
32
- # * `revision_id`: String; Must be < 255 chars, matches /^[\-[:alnum:]_\.\:]+$/
33
- # * `name`: String; Must match name in URI; Must be <= 255 chars, matches /^[\-[:alnum:]_\.\:]+$/
34
- # * `run_list`: Array
35
- # * `run_list[i]`: Fully Qualified Recipe Run List Item
36
- # * `cookbook_locks`: JSON Object
37
- # * `cookbook_locks(key)`: CookbookName
38
- # * `cookbook_locks[item]`: JSON Object, mandatory keys: "identifier", "dotted_decimal_identifier"
39
- # * `cookbook_locks[item]["identifier"]`: varchar(255) ?
40
- # * `cookbook_locks[item]["dotted_decimal_identifier"]` ChefCompatibleVersionNumber
41
-
42
- # PUT /organizations/ORG/policy_groups/GROUP/policies/NAME
43
- def put(request)
44
- policyfile_data = parse_json(request.body)
45
- policy_name = request.rest_path[5]
46
- revision_id = policyfile_data["revision_id"]
47
-
48
- # If the policy revision being submitted does not exist, create it.
49
- # Storage: /organizations/ORG/policies/POLICY/revisions/REVISION
50
- policyfile_path = request.rest_path[0..1] + ["policies", policy_name, "revisions", revision_id]
51
- unless exists_data?(request, policyfile_path)
52
- create_data(request, policyfile_path[0..-2], revision_id, request.body, :create_dir)
53
- end
54
-
55
- # if named policy exists and the given revision ID exists, associate the revision ID with the policy
56
- # group.
57
- # Storage: /organizations/ORG/policies/POLICY/revisions/REVISION
58
- response_code = exists_data?(request) ? 200 : 201
59
- set_data(request, nil, to_json(revision_id), :create, :create_dir)
60
-
61
- already_json_response(response_code, request.body)
62
- end
63
-
64
- # DELETE /organizations/ORG/policy_groups/GROUP/policies/NAME
65
- def delete(request)
66
- # Save the existing association.
67
- current_revision_id = parse_json(get_data(request))
68
-
69
- # delete the association.
70
- delete_data(request)
71
-
72
- # return the full policy document at the no-longer-associated revision.
73
- policy_name = request.rest_path[5]
74
- policy_path = request.rest_path[0..1] + ["policies", policy_name,
75
- "revisions", current_revision_id]
76
-
77
- full_policy_doc = parse_json(get_data(request, policy_path))
78
- full_policy_doc = ChefData::DataNormalizer.normalize_policy(full_policy_doc, policy_name, current_revision_id)
79
- json_response(200, full_policy_doc)
80
- end
81
- end
82
- end
83
- end
1
+ require "ffi_yajl" unless defined?(FFI_Yajl)
2
+ require_relative "../rest_base"
3
+ require_relative "../chef_data/data_normalizer"
4
+
5
+ module ChefZero
6
+ module Endpoints
7
+ # /organizations/ORG/policy_groups/GROUP/policies/NAME
8
+ #
9
+ # in the data store, this REST path actually stores the revision ID of ${policy_name} that's currently
10
+ # associated with ${policy_group}.
11
+ class PolicyGroupPolicyEndpoint < RestBase
12
+
13
+ # GET /organizations/ORG/policy_groups/GROUP/policies/NAME
14
+ def get(request)
15
+ policy_name = request.rest_path[5]
16
+
17
+ # fetch /organizations/{organization}/policies/{policy_name}/revisions/{revision_id}
18
+ revision_id = parse_json(get_data(request))
19
+ result = get_data(request, request.rest_path[0..1] +
20
+ ["policies", policy_name, "revisions", revision_id])
21
+ result = ChefData::DataNormalizer.normalize_policy(parse_json(result), policy_name, revision_id)
22
+ json_response(200, result)
23
+ end
24
+
25
+ # Create or update the policy document for the given policy group and policy name. If no policy group
26
+ # with the given name exists, it will be created. If no policy with the given revision_id exists, it
27
+ # will be created from the document in the request body. If a policy with that revision_id exists, the
28
+ # Chef Server simply associates that revision id with the given policy group. When successful, the
29
+ # document that was created or updated is returned.
30
+
31
+ ## MANDATORY FIELDS AND FORMATS
32
+ # * `revision_id`: String; Must be < 255 chars, matches /^[\-[:alnum:]_\.\:]+$/
33
+ # * `name`: String; Must match name in URI; Must be <= 255 chars, matches /^[\-[:alnum:]_\.\:]+$/
34
+ # * `run_list`: Array
35
+ # * `run_list[i]`: Fully Qualified Recipe Run List Item
36
+ # * `cookbook_locks`: JSON Object
37
+ # * `cookbook_locks(key)`: CookbookName
38
+ # * `cookbook_locks[item]`: JSON Object, mandatory keys: "identifier", "dotted_decimal_identifier"
39
+ # * `cookbook_locks[item]["identifier"]`: varchar(255) ?
40
+ # * `cookbook_locks[item]["dotted_decimal_identifier"]` ChefCompatibleVersionNumber
41
+
42
+ # PUT /organizations/ORG/policy_groups/GROUP/policies/NAME
43
+ def put(request)
44
+ policyfile_data = parse_json(request.body)
45
+ policy_name = request.rest_path[5]
46
+ revision_id = policyfile_data["revision_id"]
47
+
48
+ # If the policy revision being submitted does not exist, create it.
49
+ # Storage: /organizations/ORG/policies/POLICY/revisions/REVISION
50
+ policyfile_path = request.rest_path[0..1] + ["policies", policy_name, "revisions", revision_id]
51
+ unless exists_data?(request, policyfile_path)
52
+ create_data(request, policyfile_path[0..-2], revision_id, request.body, :create_dir)
53
+ end
54
+
55
+ # if named policy exists and the given revision ID exists, associate the revision ID with the policy
56
+ # group.
57
+ # Storage: /organizations/ORG/policies/POLICY/revisions/REVISION
58
+ response_code = exists_data?(request) ? 200 : 201
59
+ set_data(request, nil, to_json(revision_id), :create, :create_dir)
60
+
61
+ already_json_response(response_code, request.body)
62
+ end
63
+
64
+ # DELETE /organizations/ORG/policy_groups/GROUP/policies/NAME
65
+ def delete(request)
66
+ # Save the existing association.
67
+ current_revision_id = parse_json(get_data(request))
68
+
69
+ # delete the association.
70
+ delete_data(request)
71
+
72
+ # return the full policy document at the no-longer-associated revision.
73
+ policy_name = request.rest_path[5]
74
+ policy_path = request.rest_path[0..1] + ["policies", policy_name,
75
+ "revisions", current_revision_id]
76
+
77
+ full_policy_doc = parse_json(get_data(request, policy_path))
78
+ full_policy_doc = ChefData::DataNormalizer.normalize_policy(full_policy_doc, policy_name, current_revision_id)
79
+ json_response(200, full_policy_doc)
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,38 +1,38 @@
1
- require "ffi_yajl" unless defined?(FFI_Yajl)
2
- require_relative "../rest_base"
3
- require_relative "../chef_data/data_normalizer"
4
-
5
- module ChefZero
6
- module Endpoints
7
- # /organizations/ORG/policy_groups
8
- #
9
- # in the data store, this REST path actually stores the revision ID of ${policy_name} that's currently
10
- # associated with ${policy_group}.
11
- class PolicyGroupsEndpoint < RestBase
12
- # GET /organizations/ORG/policy_groups
13
- def get(request)
14
- # each policy group has policies and associated revisions under
15
- # /policy_groups/{group name}/policies/{policy name}.
16
- response_data = {}
17
- list_data(request).each do |group_name|
18
- group_path = request.rest_path + [group_name]
19
- policy_list = list_data(request, group_path + ["policies"])
20
-
21
- # build the list of policies with their revision ID associated with this policy group.
22
- policies = {}
23
- policy_list.each do |policy_name|
24
- revision_id = parse_json(get_data(request, group_path + ["policies", policy_name]))
25
- policies[policy_name] = { revision_id: revision_id }
26
- end
27
-
28
- response_data[group_name] = {
29
- uri: build_uri(request.base_uri, group_path),
30
- }
31
- response_data[group_name][:policies] = policies unless policies.empty?
32
- end
33
-
34
- json_response(200, response_data)
35
- end
36
- end
37
- end
38
- end
1
+ require "ffi_yajl" unless defined?(FFI_Yajl)
2
+ require_relative "../rest_base"
3
+ require_relative "../chef_data/data_normalizer"
4
+
5
+ module ChefZero
6
+ module Endpoints
7
+ # /organizations/ORG/policy_groups
8
+ #
9
+ # in the data store, this REST path actually stores the revision ID of ${policy_name} that's currently
10
+ # associated with ${policy_group}.
11
+ class PolicyGroupsEndpoint < RestBase
12
+ # GET /organizations/ORG/policy_groups
13
+ def get(request)
14
+ # each policy group has policies and associated revisions under
15
+ # /policy_groups/{group name}/policies/{policy name}.
16
+ response_data = {}
17
+ list_data(request).each do |group_name|
18
+ group_path = request.rest_path + [group_name]
19
+ policy_list = list_data(request, group_path + ["policies"])
20
+
21
+ # build the list of policies with their revision ID associated with this policy group.
22
+ policies = {}
23
+ policy_list.each do |policy_name|
24
+ revision_id = parse_json(get_data(request, group_path + ["policies", policy_name]))
25
+ policies[policy_name] = { revision_id: revision_id }
26
+ end
27
+
28
+ response_data[group_name] = {
29
+ uri: build_uri(request.base_uri, group_path),
30
+ }
31
+ response_data[group_name][:policies] = policies unless policies.empty?
32
+ end
33
+
34
+ json_response(200, response_data)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,66 +1,66 @@
1
- require_relative "../chef_data/data_normalizer"
2
-
3
- module ChefZero
4
- module Endpoints
5
- # /organizations/ORG/policies/NAME/revisions/REVISION
6
- class PolicyRevisionEndpoint < RestBase
7
- # GET /organizations/ORG/policies/NAME/revisions/REVISION
8
- def get(request)
9
- data = parse_json(get_data(request))
10
-
11
- # need to add another field in the response called 'policy_group_list'
12
- # example response
13
- # {
14
- # "revision_id": "909c26701e291510eacdc6c06d626b9fa5350d25",
15
- # "name": "some_policy_name",
16
- # "run_list": [
17
- # "recipe[policyfile_demo::default]"
18
- # ],
19
- # "cookbook_locks": {
20
- # "policyfile_demo": {
21
- # "identifier": "f04cc40faf628253fe7d9566d66a1733fb1afbe9",
22
- # "version": "1.2.3"
23
- # }
24
- # },
25
- # "policy_group_list": ["some_policy_group"]
26
- # }
27
- data[:policy_group_list] = Array.new
28
-
29
- # extracting policy name and revision
30
- request_policy_name = request.rest_path[3]
31
- request_policy_revision = request.rest_path[5]
32
-
33
- # updating the request to fetch the policy group list
34
- request.rest_path[2] = "policy_groups"
35
- request.rest_path = request.rest_path.slice(0,3)
36
-
37
- list_data(request).each do |group_name|
38
- group_path = request.rest_path + [group_name]
39
-
40
- # fetching all the policies associated with each group
41
- policy_list = list_data(request, group_path + ["policies"])
42
- policy_list.each do |policy_name|
43
- revision_id = parse_json(get_data(request, group_path + ["policies", policy_name]))
44
-
45
- # if the name and revision matchs, we add the group to the response
46
- if (policy_name == request_policy_name) && (revision_id == request_policy_revision)
47
- policy_group_list = data[:policy_group_list]
48
- data[:policy_group_list] = [group_name] + policy_group_list
49
- end
50
- end
51
- end
52
-
53
- data = ChefData::DataNormalizer.normalize_policy(data, request_policy_name, request_policy_revision)
54
- json_response(200, data)
55
- end
56
-
57
- # DELETE /organizations/ORG/policies/NAME/revisions/REVISION
58
- def delete(request)
59
- policyfile_data = parse_json(get_data(request))
60
- policyfile_data = ChefData::DataNormalizer.normalize_policy(policyfile_data, request.rest_path[3], request.rest_path[5])
61
- delete_data(request)
62
- json_response(200, policyfile_data)
63
- end
64
- end
65
- end
66
- end
1
+ require_relative "../chef_data/data_normalizer"
2
+
3
+ module ChefZero
4
+ module Endpoints
5
+ # /organizations/ORG/policies/NAME/revisions/REVISION
6
+ class PolicyRevisionEndpoint < RestBase
7
+ # GET /organizations/ORG/policies/NAME/revisions/REVISION
8
+ def get(request)
9
+ data = parse_json(get_data(request))
10
+
11
+ # need to add another field in the response called 'policy_group_list'
12
+ # example response
13
+ # {
14
+ # "revision_id": "909c26701e291510eacdc6c06d626b9fa5350d25",
15
+ # "name": "some_policy_name",
16
+ # "run_list": [
17
+ # "recipe[policyfile_demo::default]"
18
+ # ],
19
+ # "cookbook_locks": {
20
+ # "policyfile_demo": {
21
+ # "identifier": "f04cc40faf628253fe7d9566d66a1733fb1afbe9",
22
+ # "version": "1.2.3"
23
+ # }
24
+ # },
25
+ # "policy_group_list": ["some_policy_group"]
26
+ # }
27
+ data[:policy_group_list] = []
28
+
29
+ # extracting policy name and revision
30
+ request_policy_name = request.rest_path[3]
31
+ request_policy_revision = request.rest_path[5]
32
+
33
+ # updating the request to fetch the policy group list
34
+ request.rest_path[2] = "policy_groups"
35
+ request.rest_path = request.rest_path.slice(0, 3)
36
+
37
+ list_data(request).each do |group_name|
38
+ group_path = request.rest_path + [group_name]
39
+
40
+ # fetching all the policies associated with each group
41
+ policy_list = list_data(request, group_path + ["policies"])
42
+ policy_list.each do |policy_name|
43
+ revision_id = parse_json(get_data(request, group_path + ["policies", policy_name]))
44
+
45
+ # if the name and revision matchs, we add the group to the response
46
+ if (policy_name == request_policy_name) && (revision_id == request_policy_revision)
47
+ policy_group_list = data[:policy_group_list]
48
+ data[:policy_group_list] = [group_name] + policy_group_list
49
+ end
50
+ end
51
+ end
52
+
53
+ data = ChefData::DataNormalizer.normalize_policy(data, request_policy_name, request_policy_revision)
54
+ json_response(200, data)
55
+ end
56
+
57
+ # DELETE /organizations/ORG/policies/NAME/revisions/REVISION
58
+ def delete(request)
59
+ policyfile_data = parse_json(get_data(request))
60
+ policyfile_data = ChefData::DataNormalizer.normalize_policy(policyfile_data, request.rest_path[3], request.rest_path[5])
61
+ delete_data(request)
62
+ json_response(200, policyfile_data)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,15 +1,15 @@
1
- require_relative "../chef_data/data_normalizer"
2
-
3
- module ChefZero
4
- module Endpoints
5
- # /organizations/ORG/policies/NAME/revisions
6
- class PolicyRevisionsEndpoint < RestBase
7
- # POST /organizations/ORG/policies/NAME/revisions
8
- def post(request)
9
- policyfile_data = parse_json(request.body)
10
- create_data(request, request.rest_path, policyfile_data["revision_id"], request.body, :create_dir)
11
- already_json_response(201, request.body)
12
- end
13
- end
14
- end
15
- end
1
+ require_relative "../chef_data/data_normalizer"
2
+
3
+ module ChefZero
4
+ module Endpoints
5
+ # /organizations/ORG/policies/NAME/revisions
6
+ class PolicyRevisionsEndpoint < RestBase
7
+ # POST /organizations/ORG/policies/NAME/revisions
8
+ def post(request)
9
+ policyfile_data = parse_json(request.body)
10
+ create_data(request, request.rest_path, policyfile_data["revision_id"], request.body, :create_dir)
11
+ already_json_response(201, request.body)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,55 +1,55 @@
1
- require "ffi_yajl" unless defined?(FFI_Yajl)
2
- require_relative "../../chef_zero"
3
- require_relative "../rest_base"
4
-
5
- module ChefZero
6
- module Endpoints
7
- # /principals/NAME
8
- class PrincipalEndpoint < RestBase
9
- def get(request)
10
- name = request.rest_path[-1]
11
- # If /organizations/ORG/users/NAME exists, use this user (only org members have precedence over clients). hey are an org member.
12
- json = get_data(request, request.rest_path[0..1] + [ "users", name ], :nil)
13
- if json
14
- type = "user"
15
- org_member = true
16
- else
17
- # If /organizations/ORG/clients/NAME exists, use the client.
18
- json = get_data(request, request.rest_path[0..1] + [ "clients", name ], :nil)
19
- if json
20
- type = "client"
21
- org_member = true
22
- else
23
- # If there is no client with that name, check for a user (/users/NAME) and return that with
24
- # org_member = false.
25
- json = get_data(request, [ "users", name ], :nil)
26
- if json
27
- type = "user"
28
- org_member = false
29
- end
30
- end
31
- end
32
- if json
33
- principal_data = {
34
- "name" => name,
35
- "type" => type,
36
- "public_key" => FFI_Yajl::Parser.parse(json)["public_key"] || PUBLIC_KEY,
37
- "authz_id" => "0" * 32,
38
- "org_member" => org_member,
39
- }
40
-
41
- response_data =
42
- if request.api_v0?
43
- principal_data
44
- else
45
- { "principals" => [ principal_data ] }
46
- end
47
-
48
- json_response(200, response_data)
49
- else
50
- error(404, "Principal not found")
51
- end
52
- end
53
- end
54
- end
55
- end
1
+ require "ffi_yajl" unless defined?(FFI_Yajl)
2
+ require_relative "../../chef_zero"
3
+ require_relative "../rest_base"
4
+
5
+ module ChefZero
6
+ module Endpoints
7
+ # /principals/NAME
8
+ class PrincipalEndpoint < RestBase
9
+ def get(request)
10
+ name = request.rest_path[-1]
11
+ # If /organizations/ORG/users/NAME exists, use this user (only org members have precedence over clients). hey are an org member.
12
+ json = get_data(request, request.rest_path[0..1] + [ "users", name ], :nil)
13
+ if json
14
+ type = "user"
15
+ org_member = true
16
+ else
17
+ # If /organizations/ORG/clients/NAME exists, use the client.
18
+ json = get_data(request, request.rest_path[0..1] + [ "clients", name ], :nil)
19
+ if json
20
+ type = "client"
21
+ org_member = true
22
+ else
23
+ # If there is no client with that name, check for a user (/users/NAME) and return that with
24
+ # org_member = false.
25
+ json = get_data(request, [ "users", name ], :nil)
26
+ if json
27
+ type = "user"
28
+ org_member = false
29
+ end
30
+ end
31
+ end
32
+ if json
33
+ principal_data = {
34
+ "name" => name,
35
+ "type" => type,
36
+ "public_key" => FFI_Yajl::Parser.parse(json)["public_key"] || PUBLIC_KEY,
37
+ "authz_id" => "0" * 32,
38
+ "org_member" => org_member,
39
+ }
40
+
41
+ response_data =
42
+ if request.api_v0?
43
+ principal_data
44
+ else
45
+ { "principals" => [ principal_data ] }
46
+ end
47
+
48
+ json_response(200, response_data)
49
+ else
50
+ error(404, "Principal not found")
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,42 +1,42 @@
1
- require "ffi_yajl" unless defined?(FFI_Yajl)
2
- require_relative "../rest_base"
3
-
4
- module ChefZero
5
- module Endpoints
6
- # Typical REST list endpoint (/roles or /data/BAG)
7
- class RestListEndpoint < RestBase
8
- def initialize(server, identity_keys = [ "name" ])
9
- super(server)
10
- identity_keys = [ identity_keys ] if identity_keys.is_a?(String)
11
- @identity_keys = identity_keys
12
- end
13
-
14
- attr_reader :identity_keys
15
-
16
- def get(request)
17
- # Get the result
18
- result_hash = {}
19
- list_data(request).sort.each do |name|
20
- result_hash[name] = (build_uri(request.base_uri, request.rest_path + [name])).to_s
21
- end
22
- json_response(200, result_hash)
23
- end
24
-
25
- def post(request)
26
- contents = request.body
27
- key = get_key(contents)
28
- if key.nil?
29
- error(400, "Must specify #{identity_keys.map(&:inspect).join(" or ")} in JSON")
30
- else
31
- create_data(request, request.rest_path, key, contents)
32
- json_response(201, { "uri" => (build_uri(request.base_uri, request.rest_path + [key])).to_s })
33
- end
34
- end
35
-
36
- def get_key(contents)
37
- json = FFI_Yajl::Parser.parse(contents)
38
- identity_keys.map { |k| json[k] }.select { |v| v }.first
39
- end
40
- end
41
- end
42
- end
1
+ require "ffi_yajl" unless defined?(FFI_Yajl)
2
+ require_relative "../rest_base"
3
+
4
+ module ChefZero
5
+ module Endpoints
6
+ # Typical REST list endpoint (/roles or /data/BAG)
7
+ class RestListEndpoint < RestBase
8
+ def initialize(server, identity_keys = [ "name" ])
9
+ super(server)
10
+ identity_keys = [ identity_keys ] if identity_keys.is_a?(String)
11
+ @identity_keys = identity_keys
12
+ end
13
+
14
+ attr_reader :identity_keys
15
+
16
+ def get(request)
17
+ # Get the result
18
+ result_hash = {}
19
+ list_data(request).sort.each do |name|
20
+ result_hash[name] = (build_uri(request.base_uri, request.rest_path + [name])).to_s
21
+ end
22
+ json_response(200, result_hash)
23
+ end
24
+
25
+ def post(request)
26
+ contents = request.body
27
+ key = get_key(contents)
28
+ if key.nil?
29
+ error(400, "Must specify #{identity_keys.map(&:inspect).join(" or ")} in JSON")
30
+ else
31
+ create_data(request, request.rest_path, key, contents)
32
+ json_response(201, { "uri" => (build_uri(request.base_uri, request.rest_path + [key])).to_s })
33
+ end
34
+ end
35
+
36
+ def get_key(contents)
37
+ json = FFI_Yajl::Parser.parse(contents)
38
+ identity_keys.map { |k| json[k] }.select { |v| v }.first
39
+ end
40
+ end
41
+ end
42
+ end