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,16 +1,16 @@
|
|
1
|
-
require_relative "../rest_base"
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Endpoints
|
5
|
-
# GET /organizations/ORG/users/USER/keys/default
|
6
|
-
class OrganizationUserDefaultKeyEndpoint < RestBase
|
7
|
-
def get(request)
|
8
|
-
# 404 if it doesn't exist
|
9
|
-
get_data(request, request.rest_path[0..3])
|
10
|
-
# Just use the /users/USER/keys/default endpoint
|
11
|
-
request.rest_path = request.rest_path[2..-1]
|
12
|
-
ActorDefaultKeyEndpoint.new(server).get(request)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
require_relative "../rest_base"
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Endpoints
|
5
|
+
# GET /organizations/ORG/users/USER/keys/default
|
6
|
+
class OrganizationUserDefaultKeyEndpoint < RestBase
|
7
|
+
def get(request)
|
8
|
+
# 404 if it doesn't exist
|
9
|
+
get_data(request, request.rest_path[0..3])
|
10
|
+
# Just use the /users/USER/keys/default endpoint
|
11
|
+
request.rest_path = request.rest_path[2..-1]
|
12
|
+
ActorDefaultKeyEndpoint.new(server).get(request)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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/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)
|
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)
|
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
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "../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)
|
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)
|
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,17 +1,17 @@
|
|
1
|
-
require_relative "../rest_base"
|
2
|
-
require_relative "actor_keys_endpoint"
|
3
|
-
|
4
|
-
module ChefZero
|
5
|
-
module Endpoints
|
6
|
-
# GET /organizations/ORG/users/USER/keys/NAME
|
7
|
-
class OrganizationUserKeyEndpoint < RestBase
|
8
|
-
def get(request)
|
9
|
-
# 404 if not a member of the org
|
10
|
-
get_data(request, request.rest_path[0..3])
|
11
|
-
# Just use the /users/USER/keys endpoint
|
12
|
-
request.rest_path = request.rest_path[2..-1]
|
13
|
-
ActorKeyEndpoint.new(server).get(request)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require_relative "../rest_base"
|
2
|
+
require_relative "actor_keys_endpoint"
|
3
|
+
|
4
|
+
module ChefZero
|
5
|
+
module Endpoints
|
6
|
+
# GET /organizations/ORG/users/USER/keys/NAME
|
7
|
+
class OrganizationUserKeyEndpoint < RestBase
|
8
|
+
def get(request)
|
9
|
+
# 404 if not a member of the org
|
10
|
+
get_data(request, request.rest_path[0..3])
|
11
|
+
# Just use the /users/USER/keys endpoint
|
12
|
+
request.rest_path = request.rest_path[2..-1]
|
13
|
+
ActorKeyEndpoint.new(server).get(request)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require_relative "../rest_base"
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Endpoints
|
5
|
-
# GET /organizations/ORG/users/USER/keys
|
6
|
-
class OrganizationUserKeysEndpoint < RestBase
|
7
|
-
def get(request)
|
8
|
-
# 404 if it doesn't exist
|
9
|
-
get_data(request, request.rest_path[0..3])
|
10
|
-
# Just use the /users/USER/keys/key endpoint
|
11
|
-
original_path = request.rest_path
|
12
|
-
request.rest_path = request.rest_path[2..-1]
|
13
|
-
ActorKeysEndpoint.new(server).get(request, original_path)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
require_relative "../rest_base"
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Endpoints
|
5
|
+
# GET /organizations/ORG/users/USER/keys
|
6
|
+
class OrganizationUserKeysEndpoint < RestBase
|
7
|
+
def get(request)
|
8
|
+
# 404 if it doesn't exist
|
9
|
+
get_data(request, request.rest_path[0..3])
|
10
|
+
# Just use the /users/USER/keys/key endpoint
|
11
|
+
original_path = request.rest_path
|
12
|
+
request.rest_path = request.rest_path[2..-1]
|
13
|
+
ActorKeysEndpoint.new(server).get(request, original_path)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,43 +1,43 @@
|
|
1
|
-
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "../rest_base"
|
3
|
-
require_relative "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)
|
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)
|
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
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "../rest_base"
|
3
|
+
require_relative "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)
|
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)
|
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" unless defined?(FFI_Yajl)
|
2
|
-
require_relative "../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))
|
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" unless defined?(FFI_Yajl)
|
2
|
+
require_relative "../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))
|
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,61 +1,61 @@
|
|
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
|
8
|
-
class OrganizationsEndpoint < RestBase
|
9
|
-
def get(request)
|
10
|
-
result = {}
|
11
|
-
data_store.list(request.rest_path).each do |name|
|
12
|
-
result[name] = build_uri(request.base_uri, request.rest_path + [name])
|
13
|
-
end
|
14
|
-
json_response(200, result)
|
15
|
-
end
|
16
|
-
|
17
|
-
def post(request)
|
18
|
-
contents = FFI_Yajl::Parser.parse(request.body)
|
19
|
-
name = contents["name"]
|
20
|
-
full_name = contents["full_name"]
|
21
|
-
if name.nil?
|
22
|
-
error(400, "Must specify 'name' in JSON")
|
23
|
-
elsif full_name.nil?
|
24
|
-
error(400, "Must specify 'full_name' in JSON")
|
25
|
-
elsif exists_data_dir?(request, request.rest_path + [ name ])
|
26
|
-
error(409, "Organization already exists")
|
27
|
-
else
|
28
|
-
create_data_dir(request, request.rest_path, name, requestor: request.requestor)
|
29
|
-
|
30
|
-
org = {
|
31
|
-
"guid" => UUIDTools::UUID.random_create.to_s.delete("-"),
|
32
|
-
"assigned_at" => Time.now.to_s,
|
33
|
-
}.merge(contents)
|
34
|
-
org_path = request.rest_path + [ name ]
|
35
|
-
set_data(request, org_path + [ "org" ], FFI_Yajl::Encoder.encode(org, pretty: true))
|
36
|
-
|
37
|
-
if server.generate_real_keys?
|
38
|
-
# Create the validator client
|
39
|
-
validator_name = "#{name}-validator"
|
40
|
-
validator_path = org_path + [ "clients", validator_name ]
|
41
|
-
private_key, public_key = server.gen_key_pair
|
42
|
-
validator = FFI_Yajl::Encoder.encode({
|
43
|
-
"validator" => true,
|
44
|
-
"public_key" => public_key,
|
45
|
-
}, pretty: true)
|
46
|
-
set_data(request, validator_path, validator)
|
47
|
-
end
|
48
|
-
|
49
|
-
json_response(201, {
|
50
|
-
"uri" => (build_uri(request.base_uri, org_path)).to_s,
|
51
|
-
"name" => name,
|
52
|
-
"org_type" => org["org_type"],
|
53
|
-
"full_name" => full_name,
|
54
|
-
"clientname" => validator_name,
|
55
|
-
"private_key" => private_key,
|
56
|
-
})
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
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
|
8
|
+
class OrganizationsEndpoint < RestBase
|
9
|
+
def get(request)
|
10
|
+
result = {}
|
11
|
+
data_store.list(request.rest_path).each do |name|
|
12
|
+
result[name] = build_uri(request.base_uri, request.rest_path + [name])
|
13
|
+
end
|
14
|
+
json_response(200, result)
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(request)
|
18
|
+
contents = FFI_Yajl::Parser.parse(request.body)
|
19
|
+
name = contents["name"]
|
20
|
+
full_name = contents["full_name"]
|
21
|
+
if name.nil?
|
22
|
+
error(400, "Must specify 'name' in JSON")
|
23
|
+
elsif full_name.nil?
|
24
|
+
error(400, "Must specify 'full_name' in JSON")
|
25
|
+
elsif exists_data_dir?(request, request.rest_path + [ name ])
|
26
|
+
error(409, "Organization already exists")
|
27
|
+
else
|
28
|
+
create_data_dir(request, request.rest_path, name, requestor: request.requestor)
|
29
|
+
|
30
|
+
org = {
|
31
|
+
"guid" => UUIDTools::UUID.random_create.to_s.delete("-"),
|
32
|
+
"assigned_at" => Time.now.to_s,
|
33
|
+
}.merge(contents)
|
34
|
+
org_path = request.rest_path + [ name ]
|
35
|
+
set_data(request, org_path + [ "org" ], FFI_Yajl::Encoder.encode(org, pretty: true))
|
36
|
+
|
37
|
+
if server.generate_real_keys?
|
38
|
+
# Create the validator client
|
39
|
+
validator_name = "#{name}-validator"
|
40
|
+
validator_path = org_path + [ "clients", validator_name ]
|
41
|
+
private_key, public_key = server.gen_key_pair
|
42
|
+
validator = FFI_Yajl::Encoder.encode({
|
43
|
+
"validator" => true,
|
44
|
+
"public_key" => public_key,
|
45
|
+
}, pretty: true)
|
46
|
+
set_data(request, validator_path, validator)
|
47
|
+
end
|
48
|
+
|
49
|
+
json_response(201, {
|
50
|
+
"uri" => (build_uri(request.base_uri, org_path)).to_s,
|
51
|
+
"name" => name,
|
52
|
+
"org_type" => org["org_type"],
|
53
|
+
"full_name" => full_name,
|
54
|
+
"clientname" => validator_name,
|
55
|
+
"private_key" => private_key,
|
56
|
+
})
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
require_relative "../chef_data/data_normalizer"
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Endpoints
|
5
|
-
# /organizations/ORG/policies
|
6
|
-
class PoliciesEndpoint < RestBase
|
7
|
-
# GET /organizations/ORG/policies
|
8
|
-
def get(request)
|
9
|
-
response_data = {}
|
10
|
-
policy_names = list_data(request)
|
11
|
-
policy_names.each do |policy_name|
|
12
|
-
policy_path = request.rest_path + [policy_name]
|
13
|
-
policy_uri = build_uri(request.base_uri, policy_path)
|
14
|
-
revisions = list_data(request, policy_path + ["revisions"])
|
15
|
-
|
16
|
-
response_data[policy_name] = {
|
17
|
-
uri: policy_uri,
|
18
|
-
revisions: hashify_list(revisions),
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
json_response(200, response_data)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
1
|
+
require_relative "../chef_data/data_normalizer"
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Endpoints
|
5
|
+
# /organizations/ORG/policies
|
6
|
+
class PoliciesEndpoint < RestBase
|
7
|
+
# GET /organizations/ORG/policies
|
8
|
+
def get(request)
|
9
|
+
response_data = {}
|
10
|
+
policy_names = list_data(request)
|
11
|
+
policy_names.each do |policy_name|
|
12
|
+
policy_path = request.rest_path + [policy_name]
|
13
|
+
policy_uri = build_uri(request.base_uri, policy_path)
|
14
|
+
revisions = list_data(request, policy_path + ["revisions"])
|
15
|
+
|
16
|
+
response_data[policy_name] = {
|
17
|
+
uri: policy_uri,
|
18
|
+
revisions: hashify_list(revisions),
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
json_response(200, response_data)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
require_relative "../chef_data/data_normalizer"
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Endpoints
|
5
|
-
# /organizations/ORG/policies/NAME
|
6
|
-
class PolicyEndpoint < RestBase
|
7
|
-
# GET /organizations/ORG/policies/NAME
|
8
|
-
def get(request)
|
9
|
-
revisions = list_data(request, request.rest_path + ["revisions"])
|
10
|
-
data = { revisions: hashify_list(revisions) }
|
11
|
-
json_response(200, data)
|
12
|
-
end
|
13
|
-
|
14
|
-
# DELETE /organizations/ORG/policies/NAME
|
15
|
-
def delete(request)
|
16
|
-
revisions = list_data(request, request.rest_path + ["revisions"])
|
17
|
-
data = { revisions: hashify_list(revisions) }
|
18
|
-
|
19
|
-
delete_data_dir(request, nil, :recursive)
|
20
|
-
json_response(200, data)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
require_relative "../chef_data/data_normalizer"
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Endpoints
|
5
|
+
# /organizations/ORG/policies/NAME
|
6
|
+
class PolicyEndpoint < RestBase
|
7
|
+
# GET /organizations/ORG/policies/NAME
|
8
|
+
def get(request)
|
9
|
+
revisions = list_data(request, request.rest_path + ["revisions"])
|
10
|
+
data = { revisions: hashify_list(revisions) }
|
11
|
+
json_response(200, data)
|
12
|
+
end
|
13
|
+
|
14
|
+
# DELETE /organizations/ORG/policies/NAME
|
15
|
+
def delete(request)
|
16
|
+
revisions = list_data(request, request.rest_path + ["revisions"])
|
17
|
+
data = { revisions: hashify_list(revisions) }
|
18
|
+
|
19
|
+
delete_data_dir(request, nil, :recursive)
|
20
|
+
json_response(200, data)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,46 +1,46 @@
|
|
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/NAME
|
8
|
-
class PolicyGroupEndpoint < RestBase
|
9
|
-
|
10
|
-
# GET /organizations/ORG/policy_groups/NAME
|
11
|
-
def get(request)
|
12
|
-
data = {
|
13
|
-
uri: build_uri(request.base_uri, request.rest_path),
|
14
|
-
policies: get_policy_group_policies(request),
|
15
|
-
}
|
16
|
-
json_response(200, data)
|
17
|
-
end
|
18
|
-
|
19
|
-
# build a hash of {"some_policy_name"=>{"revision_id"=>"909c26701e291510eacdc6c06d626b9fa5350d25"}}
|
20
|
-
def get_policy_group_policies(request)
|
21
|
-
policies_revisions = {}
|
22
|
-
|
23
|
-
policies_path = request.rest_path + ["policies"]
|
24
|
-
policy_names = list_data(request, policies_path)
|
25
|
-
policy_names.each do |policy_name|
|
26
|
-
revision = parse_json(get_data(request, policies_path + [policy_name]))
|
27
|
-
policies_revisions[policy_name] = { revision_id: revision }
|
28
|
-
end
|
29
|
-
|
30
|
-
policies_revisions
|
31
|
-
end
|
32
|
-
|
33
|
-
# DELETE /organizations/ORG/policy_groups/NAME
|
34
|
-
def delete(request)
|
35
|
-
policy_group_policies = get_policy_group_policies(request)
|
36
|
-
delete_data_dir(request, nil, :recursive)
|
37
|
-
|
38
|
-
data = {
|
39
|
-
uri: build_uri(request.base_uri, request.rest_path),
|
40
|
-
policies: policy_group_policies,
|
41
|
-
}
|
42
|
-
json_response(200, data)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
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/NAME
|
8
|
+
class PolicyGroupEndpoint < RestBase
|
9
|
+
|
10
|
+
# GET /organizations/ORG/policy_groups/NAME
|
11
|
+
def get(request)
|
12
|
+
data = {
|
13
|
+
uri: build_uri(request.base_uri, request.rest_path),
|
14
|
+
policies: get_policy_group_policies(request),
|
15
|
+
}
|
16
|
+
json_response(200, data)
|
17
|
+
end
|
18
|
+
|
19
|
+
# build a hash of {"some_policy_name"=>{"revision_id"=>"909c26701e291510eacdc6c06d626b9fa5350d25"}}
|
20
|
+
def get_policy_group_policies(request)
|
21
|
+
policies_revisions = {}
|
22
|
+
|
23
|
+
policies_path = request.rest_path + ["policies"]
|
24
|
+
policy_names = list_data(request, policies_path)
|
25
|
+
policy_names.each do |policy_name|
|
26
|
+
revision = parse_json(get_data(request, policies_path + [policy_name]))
|
27
|
+
policies_revisions[policy_name] = { revision_id: revision }
|
28
|
+
end
|
29
|
+
|
30
|
+
policies_revisions
|
31
|
+
end
|
32
|
+
|
33
|
+
# DELETE /organizations/ORG/policy_groups/NAME
|
34
|
+
def delete(request)
|
35
|
+
policy_group_policies = get_policy_group_policies(request)
|
36
|
+
delete_data_dir(request, nil, :recursive)
|
37
|
+
|
38
|
+
data = {
|
39
|
+
uri: build_uri(request.base_uri, request.rest_path),
|
40
|
+
policies: policy_group_policies,
|
41
|
+
}
|
42
|
+
json_response(200, data)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|