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.
- checksums.yaml +4 -4
- data/Gemfile +36 -31
- data/LICENSE +201 -201
- data/Rakefile +73 -68
- data/bin/chef-zero +111 -111
- data/chef-zero.gemspec +34 -33
- data/lib/chef_zero/chef_data/acl_path.rb +140 -140
- data/lib/chef_zero/chef_data/cookbook_data.rb +237 -237
- data/lib/chef_zero/chef_data/data_normalizer.rb +276 -276
- data/lib/chef_zero/chef_data/default_creator.rb +476 -476
- data/lib/chef_zero/data_store/data_already_exists_error.rb +29 -29
- data/lib/chef_zero/data_store/data_error.rb +32 -32
- data/lib/chef_zero/data_store/data_not_found_error.rb +29 -29
- data/lib/chef_zero/data_store/default_facade.rb +143 -147
- data/lib/chef_zero/data_store/interface_v1.rb +67 -67
- data/lib/chef_zero/data_store/interface_v2.rb +18 -18
- data/lib/chef_zero/data_store/memory_store.rb +33 -33
- data/lib/chef_zero/data_store/memory_store_v2.rb +159 -159
- data/lib/chef_zero/data_store/raw_file_store.rb +143 -143
- data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +150 -150
- data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +105 -105
- data/lib/chef_zero/dist.rb +9 -9
- data/lib/chef_zero/endpoints/acl_endpoint.rb +39 -39
- data/lib/chef_zero/endpoints/acls_endpoint.rb +41 -41
- data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +78 -78
- data/lib/chef_zero/endpoints/actor_endpoint.rb +184 -184
- data/lib/chef_zero/endpoints/actor_key_endpoint.rb +62 -62
- data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +129 -129
- data/lib/chef_zero/endpoints/actors_endpoint.rb +104 -104
- data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +32 -32
- data/lib/chef_zero/endpoints/container_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/containers_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/controls_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +68 -68
- data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +34 -34
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +39 -39
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +136 -136
- data/lib/chef_zero/endpoints/cookbooks_base.rb +80 -80
- data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/data_bag_endpoint.rb +45 -45
- data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/data_bags_endpoint.rb +23 -23
- data/lib/chef_zero/endpoints/dummy_endpoint.rb +29 -29
- data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +126 -126
- data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/environment_endpoint.rb +33 -33
- data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +23 -23
- data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/environment_role_endpoint.rb +36 -36
- data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/group_endpoint.rb +20 -20
- data/lib/chef_zero/endpoints/groups_endpoint.rb +13 -13
- data/lib/chef_zero/endpoints/license_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/node_endpoint.rb +34 -34
- data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/nodes_endpoint.rb +34 -34
- data/lib/chef_zero/endpoints/not_found_endpoint.rb +11 -11
- data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +30 -30
- data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/organization_endpoint.rb +47 -47
- data/lib/chef_zero/endpoints/organization_user_base.rb +15 -15
- data/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/organization_user_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/organization_user_key_endpoint.rb +17 -17
- data/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb +17 -17
- data/lib/chef_zero/endpoints/organization_users_endpoint.rb +43 -43
- data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +20 -20
- data/lib/chef_zero/endpoints/organizations_endpoint.rb +61 -61
- data/lib/chef_zero/endpoints/policies_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/policy_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/policy_group_endpoint.rb +46 -46
- data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +83 -83
- data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +38 -38
- data/lib/chef_zero/endpoints/policy_revision_endpoint.rb +66 -66
- data/lib/chef_zero/endpoints/policy_revisions_endpoint.rb +15 -15
- data/lib/chef_zero/endpoints/principal_endpoint.rb +55 -55
- data/lib/chef_zero/endpoints/rest_list_endpoint.rb +42 -42
- data/lib/chef_zero/endpoints/rest_object_endpoint.rb +78 -78
- data/lib/chef_zero/endpoints/role_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/role_environments_endpoint.rb +14 -14
- data/lib/chef_zero/endpoints/sandbox_endpoint.rb +27 -27
- data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +51 -51
- data/lib/chef_zero/endpoints/search_endpoint.rb +208 -208
- data/lib/chef_zero/endpoints/searches_endpoint.rb +18 -18
- data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +14 -14
- data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +30 -30
- data/lib/chef_zero/endpoints/universe_endpoint.rb +15 -15
- data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +41 -41
- data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/version_endpoint.rb +13 -13
- data/lib/chef_zero/log.rb +7 -7
- data/lib/chef_zero/rest_base.rb +332 -332
- data/lib/chef_zero/rest_error_response.rb +11 -11
- data/lib/chef_zero/rest_request.rb +84 -88
- data/lib/chef_zero/rest_router.rb +72 -72
- data/lib/chef_zero/rspec.rb +355 -355
- data/lib/chef_zero/server.rb +730 -730
- data/lib/chef_zero/socketless_server_map.rb +92 -93
- data/lib/chef_zero/solr/query/binary_operator.rb +52 -52
- data/lib/chef_zero/solr/query/phrase.rb +23 -23
- data/lib/chef_zero/solr/query/range_query.rb +46 -46
- data/lib/chef_zero/solr/query/regexpable_query.rb +30 -30
- data/lib/chef_zero/solr/query/subquery.rb +37 -37
- data/lib/chef_zero/solr/query/term.rb +45 -45
- data/lib/chef_zero/solr/query/unary_operator.rb +41 -41
- data/lib/chef_zero/solr/solr_doc.rb +53 -53
- data/lib/chef_zero/solr/solr_parser.rb +208 -208
- data/lib/chef_zero/version.rb +3 -3
- data/lib/chef_zero.rb +10 -10
- data/spec/run_oc_pedant.rb +226 -226
- data/spec/search_spec.rb +36 -36
- data/spec/server_spec.rb +96 -96
- data/spec/socketless_server_map_spec.rb +74 -74
- data/spec/support/oc_pedant.rb +149 -149
- data/spec/support/secrets.json +6 -6
- data/spec/support/stickywicket.pem +27 -27
- 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] =
|
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
|