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,22 +1,22 @@
|
|
1
|
-
require_relative "../rest_base"
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Endpoints
|
5
|
-
# The minimum amount of S3 necessary to support cookbook upload/download
|
6
|
-
# /organizations/NAME/file_store/FILE
|
7
|
-
class FileStoreFileEndpoint < RestBase
|
8
|
-
def json_only
|
9
|
-
false
|
10
|
-
end
|
11
|
-
|
12
|
-
def get(request)
|
13
|
-
[200, { "Content-Type" => "application/x-binary" }, get_data(request) ]
|
14
|
-
end
|
15
|
-
|
16
|
-
def put(request)
|
17
|
-
data_store.set(request.rest_path, request.body, :create, :create_dir, requestor: request.requestor)
|
18
|
-
json_response(200, {})
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
1
|
+
require_relative "../rest_base"
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Endpoints
|
5
|
+
# The minimum amount of S3 necessary to support cookbook upload/download
|
6
|
+
# /organizations/NAME/file_store/FILE
|
7
|
+
class FileStoreFileEndpoint < RestBase
|
8
|
+
def json_only
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(request)
|
13
|
+
[200, { "Content-Type" => "application/x-binary" }, get_data(request) ]
|
14
|
+
end
|
15
|
+
|
16
|
+
def put(request)
|
17
|
+
data_store.set(request.rest_path, request.body, :create, :create_dir, requestor: request.requestor)
|
18
|
+
json_response(200, {})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "rest_object_endpoint"
|
3
|
-
require_relative "../chef_data/data_normalizer"
|
4
|
-
|
5
|
-
module ChefZero
|
6
|
-
module Endpoints
|
7
|
-
# /organizations/ORG/groups/NAME
|
8
|
-
class GroupEndpoint < RestObjectEndpoint
|
9
|
-
def initialize(server)
|
10
|
-
super(server, %w{id groupname})
|
11
|
-
end
|
12
|
-
|
13
|
-
def populate_defaults(request, response_json)
|
14
|
-
group = FFI_Yajl::Parser.parse(response_json)
|
15
|
-
group = ChefData::DataNormalizer.normalize_group(group, request.rest_path[3], request.rest_path[1])
|
16
|
-
FFI_Yajl::Encoder.encode(group, pretty: true)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "rest_object_endpoint"
|
3
|
+
require_relative "../chef_data/data_normalizer"
|
4
|
+
|
5
|
+
module ChefZero
|
6
|
+
module Endpoints
|
7
|
+
# /organizations/ORG/groups/NAME
|
8
|
+
class GroupEndpoint < RestObjectEndpoint
|
9
|
+
def initialize(server)
|
10
|
+
super(server, %w{id groupname})
|
11
|
+
end
|
12
|
+
|
13
|
+
def populate_defaults(request, response_json)
|
14
|
+
group = FFI_Yajl::Parser.parse(response_json)
|
15
|
+
group = ChefData::DataNormalizer.normalize_group(group, request.rest_path[3], request.rest_path[1])
|
16
|
+
FFI_Yajl::Encoder.encode(group, pretty: true)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "rest_list_endpoint"
|
3
|
-
|
4
|
-
module ChefZero
|
5
|
-
module Endpoints
|
6
|
-
# /organizations/ORG/groups/NAME
|
7
|
-
class GroupsEndpoint < RestListEndpoint
|
8
|
-
def initialize(server)
|
9
|
-
super(server, %w{id groupname})
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "rest_list_endpoint"
|
3
|
+
|
4
|
+
module ChefZero
|
5
|
+
module Endpoints
|
6
|
+
# /organizations/ORG/groups/NAME
|
7
|
+
class GroupsEndpoint < RestListEndpoint
|
8
|
+
def initialize(server)
|
9
|
+
super(server, %w{id groupname})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "../rest_base"
|
3
|
-
|
4
|
-
module ChefZero
|
5
|
-
module Endpoints
|
6
|
-
# /license
|
7
|
-
class LicenseEndpoint < RestBase
|
8
|
-
MAX_NODE_COUNT = 25
|
9
|
-
|
10
|
-
def get(request)
|
11
|
-
node_count = 0
|
12
|
-
list_data(request, [ "organizations" ]).each do |orgname|
|
13
|
-
node_count += list_data(request, [ "organizations", orgname, "nodes" ]).size
|
14
|
-
end
|
15
|
-
|
16
|
-
json_response(200, {
|
17
|
-
"limit_exceeded" => (node_count > MAX_NODE_COUNT) ? true : false,
|
18
|
-
"node_license" => MAX_NODE_COUNT,
|
19
|
-
"node_count" => node_count,
|
20
|
-
"upgrade_url" => "https://blah.com",
|
21
|
-
})
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "../rest_base"
|
3
|
+
|
4
|
+
module ChefZero
|
5
|
+
module Endpoints
|
6
|
+
# /license
|
7
|
+
class LicenseEndpoint < RestBase
|
8
|
+
MAX_NODE_COUNT = 25
|
9
|
+
|
10
|
+
def get(request)
|
11
|
+
node_count = 0
|
12
|
+
list_data(request, [ "organizations" ]).each do |orgname|
|
13
|
+
node_count += list_data(request, [ "organizations", orgname, "nodes" ]).size
|
14
|
+
end
|
15
|
+
|
16
|
+
json_response(200, {
|
17
|
+
"limit_exceeded" => (node_count > MAX_NODE_COUNT) ? true : false,
|
18
|
+
"node_license" => MAX_NODE_COUNT,
|
19
|
+
"node_count" => node_count,
|
20
|
+
"upgrade_url" => "https://blah.com",
|
21
|
+
})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "rest_object_endpoint"
|
3
|
-
require_relative "../chef_data/data_normalizer"
|
4
|
-
|
5
|
-
module ChefZero
|
6
|
-
module Endpoints
|
7
|
-
# /nodes/ID
|
8
|
-
class NodeEndpoint < RestObjectEndpoint
|
9
|
-
def put(request)
|
10
|
-
data = parse_json(request.body)
|
11
|
-
|
12
|
-
if data.key?("policy_name") && policy_name_invalid?(data["policy_name"])
|
13
|
-
return error(400, "Field 'policy_name' invalid", pretty: false)
|
14
|
-
end
|
15
|
-
|
16
|
-
if data.key?("policy_group") && policy_name_invalid?(data["policy_group"])
|
17
|
-
return error(400, "Field 'policy_group' invalid", pretty: false)
|
18
|
-
end
|
19
|
-
|
20
|
-
super(request)
|
21
|
-
end
|
22
|
-
|
23
|
-
def head(request)
|
24
|
-
head_request(request)
|
25
|
-
end
|
26
|
-
|
27
|
-
def populate_defaults(request, response_json)
|
28
|
-
node = FFI_Yajl::Parser.parse(response_json)
|
29
|
-
node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3])
|
30
|
-
FFI_Yajl::Encoder.encode(node, pretty: true)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "rest_object_endpoint"
|
3
|
+
require_relative "../chef_data/data_normalizer"
|
4
|
+
|
5
|
+
module ChefZero
|
6
|
+
module Endpoints
|
7
|
+
# /nodes/ID
|
8
|
+
class NodeEndpoint < RestObjectEndpoint
|
9
|
+
def put(request)
|
10
|
+
data = parse_json(request.body)
|
11
|
+
|
12
|
+
if data.key?("policy_name") && policy_name_invalid?(data["policy_name"])
|
13
|
+
return error(400, "Field 'policy_name' invalid", pretty: false)
|
14
|
+
end
|
15
|
+
|
16
|
+
if data.key?("policy_group") && policy_name_invalid?(data["policy_group"])
|
17
|
+
return error(400, "Field 'policy_group' invalid", pretty: false)
|
18
|
+
end
|
19
|
+
|
20
|
+
super(request)
|
21
|
+
end
|
22
|
+
|
23
|
+
def head(request)
|
24
|
+
head_request(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
def populate_defaults(request, response_json)
|
28
|
+
node = FFI_Yajl::Parser.parse(response_json)
|
29
|
+
node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3])
|
30
|
+
FFI_Yajl::Encoder.encode(node, pretty: true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "../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.delete("-"),
|
13
|
-
authz_id: "0" * 32,
|
14
|
-
org_id: UUIDTools::UUID.parse_raw(request.rest_path[0..1].to_s).to_s.delete("-") }
|
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
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "../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.delete("-"),
|
13
|
+
authz_id: "0" * 32,
|
14
|
+
org_id: UUIDTools::UUID.parse_raw(request.rest_path[0..1].to_s).to_s.delete("-") }
|
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,34 +1,34 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "rest_object_endpoint"
|
3
|
-
require_relative "../chef_data/data_normalizer"
|
4
|
-
|
5
|
-
module ChefZero
|
6
|
-
module Endpoints
|
7
|
-
# /nodes
|
8
|
-
class NodesEndpoint < RestListEndpoint
|
9
|
-
|
10
|
-
def post(request)
|
11
|
-
# /nodes validation
|
12
|
-
if request.rest_path.last == "nodes"
|
13
|
-
data = parse_json(request.body)
|
14
|
-
|
15
|
-
if data.key?("policy_name") && policy_name_invalid?(data["policy_name"])
|
16
|
-
return error(400, "Field 'policy_name' invalid", pretty: false)
|
17
|
-
end
|
18
|
-
|
19
|
-
if data.key?("policy_group") && policy_name_invalid?(data["policy_group"])
|
20
|
-
return error(400, "Field 'policy_group' invalid", pretty: false)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
super(request)
|
25
|
-
end
|
26
|
-
|
27
|
-
def populate_defaults(request, response_json)
|
28
|
-
node = FFI_Yajl::Parser.parse(response_json)
|
29
|
-
node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3])
|
30
|
-
FFI_Yajl::Encoder.encode(node, pretty: true)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "rest_object_endpoint"
|
3
|
+
require_relative "../chef_data/data_normalizer"
|
4
|
+
|
5
|
+
module ChefZero
|
6
|
+
module Endpoints
|
7
|
+
# /nodes
|
8
|
+
class NodesEndpoint < RestListEndpoint
|
9
|
+
|
10
|
+
def post(request)
|
11
|
+
# /nodes validation
|
12
|
+
if request.rest_path.last == "nodes"
|
13
|
+
data = parse_json(request.body)
|
14
|
+
|
15
|
+
if data.key?("policy_name") && policy_name_invalid?(data["policy_name"])
|
16
|
+
return error(400, "Field 'policy_name' invalid", pretty: false)
|
17
|
+
end
|
18
|
+
|
19
|
+
if data.key?("policy_group") && policy_name_invalid?(data["policy_group"])
|
20
|
+
return error(400, "Field 'policy_group' invalid", pretty: false)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
super(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
def populate_defaults(request, response_json)
|
28
|
+
node = FFI_Yajl::Parser.parse(response_json)
|
29
|
+
node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3])
|
30
|
+
FFI_Yajl::Encoder.encode(node, pretty: true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Endpoints
|
5
|
-
class NotFoundEndpoint
|
6
|
-
def call(request)
|
7
|
-
[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" unless defined?(FFI_Yajl)
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Endpoints
|
5
|
+
class NotFoundEndpoint
|
6
|
+
def call(request)
|
7
|
+
[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" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "../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
|
-
|
15
|
-
username = $1
|
16
|
-
path = request.rest_path[0..-2] + [username]
|
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" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "../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
|
+
|
15
|
+
username = $1
|
16
|
+
path = request.rest_path[0..-2] + [username]
|
17
|
+
delete_data(request, path)
|
18
|
+
json_response(200, { "id" => id, "username" => username })
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "../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)
|
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
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "../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)
|
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" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "../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)
|
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)
|
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" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "../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)
|
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)
|
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,47 +1,47 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "../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" ]))
|
15
|
-
new_org = FFI_Yajl::Parser.parse(request.body)
|
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
|
-
|
25
|
-
set_data(request, request.rest_path + [ "org" ], save_org)
|
26
|
-
json_response(200, {
|
27
|
-
"uri" => (build_uri(request.base_uri, request.rest_path)).to_s,
|
28
|
-
"name" => org["name"],
|
29
|
-
"org_type" => org["org_type"],
|
30
|
-
"full_name" => org["full_name"],
|
31
|
-
})
|
32
|
-
end
|
33
|
-
|
34
|
-
def delete(request)
|
35
|
-
org = get_data(request, request.rest_path + [ "org" ])
|
36
|
-
delete_data_dir(request, request.rest_path, :recursive)
|
37
|
-
already_json_response(200, populate_defaults(request, org))
|
38
|
-
end
|
39
|
-
|
40
|
-
def populate_defaults(request, response_json)
|
41
|
-
org = FFI_Yajl::Parser.parse(response_json)
|
42
|
-
org = ChefData::DataNormalizer.normalize_organization(org, request.rest_path[1])
|
43
|
-
FFI_Yajl::Encoder.encode(org, pretty: true)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
1
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "../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" ]))
|
15
|
+
new_org = FFI_Yajl::Parser.parse(request.body)
|
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
|
+
|
25
|
+
set_data(request, request.rest_path + [ "org" ], save_org)
|
26
|
+
json_response(200, {
|
27
|
+
"uri" => (build_uri(request.base_uri, request.rest_path)).to_s,
|
28
|
+
"name" => org["name"],
|
29
|
+
"org_type" => org["org_type"],
|
30
|
+
"full_name" => org["full_name"],
|
31
|
+
})
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete(request)
|
35
|
+
org = get_data(request, request.rest_path + [ "org" ])
|
36
|
+
delete_data_dir(request, request.rest_path, :recursive)
|
37
|
+
already_json_response(200, populate_defaults(request, org))
|
38
|
+
end
|
39
|
+
|
40
|
+
def populate_defaults(request, response_json)
|
41
|
+
org = FFI_Yajl::Parser.parse(response_json)
|
42
|
+
org = ChefData::DataNormalizer.normalize_organization(org, request.rest_path[1])
|
43
|
+
FFI_Yajl::Encoder.encode(org, pretty: true)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "../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
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "../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
|