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,22 +1,22 @@
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/containers/NAME
8
- class ContainerEndpoint < RestObjectEndpoint
9
- def initialize(server)
10
- super(server, %w{id containername})
11
- end
12
-
13
- undef_method(:put)
14
-
15
- def populate_defaults(request, response_json)
16
- container = FFI_Yajl::Parser.parse(response_json)
17
- container = ChefData::DataNormalizer.normalize_container(container, request.rest_path[3])
18
- FFI_Yajl::Encoder.encode(container, pretty: true)
19
- end
20
- end
21
- end
22
- 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/containers/NAME
8
+ class ContainerEndpoint < RestObjectEndpoint
9
+ def initialize(server)
10
+ super(server, %w{id containername})
11
+ end
12
+
13
+ undef_method(:put)
14
+
15
+ def populate_defaults(request, response_json)
16
+ container = FFI_Yajl::Parser.parse(response_json)
17
+ container = ChefData::DataNormalizer.normalize_container(container, request.rest_path[3])
18
+ FFI_Yajl::Encoder.encode(container, pretty: true)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,25 +1,25 @@
1
- require "ffi_yajl" unless defined?(FFI_Yajl)
2
- require_relative "rest_list_endpoint"
3
-
4
- module ChefZero
5
- module Endpoints
6
- # /organizations/ORG/containers
7
- class ContainersEndpoint < RestListEndpoint
8
- def initialize(server)
9
- super(server, %w{id containername})
10
- end
11
-
12
- # create a container.
13
- # input: {"containername"=>"new-container", "containerpath"=>"/"}
14
- def post(request)
15
- data = parse_json(request.body)
16
- # if they don't match, id wins.
17
- container_name = data["id"] || data["containername"]
18
- container_path_suffix = data["containerpath"].split("/").reject(&:empty?)
19
- create_data(request, request.rest_path, container_name, to_json({}), :create_dir)
20
-
21
- json_response(201, { uri: build_uri(request.base_uri, request.rest_path + container_path_suffix + [container_name]) })
22
- end
23
- end
24
- end
25
- 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/containers
7
+ class ContainersEndpoint < RestListEndpoint
8
+ def initialize(server)
9
+ super(server, %w{id containername})
10
+ end
11
+
12
+ # create a container.
13
+ # input: {"containername"=>"new-container", "containerpath"=>"/"}
14
+ def post(request)
15
+ data = parse_json(request.body)
16
+ # if they don't match, id wins.
17
+ container_name = data["id"] || data["containername"]
18
+ container_path_suffix = data["containerpath"].split("/").reject(&:empty?)
19
+ create_data(request, request.rest_path, container_name, to_json({}), :create_dir)
20
+
21
+ json_response(201, { uri: build_uri(request.base_uri, request.rest_path + container_path_suffix + [container_name]) })
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,16 +1,16 @@
1
- require_relative "../dist"
2
- module ChefZero
3
- module Endpoints
4
- # /organizations/ORG/controls
5
- class ControlsEndpoint < RestBase
6
- # ours is not to wonder why; ours is but to make the pedant specs pass.
7
- def get(request)
8
- error(410, "Server says 410, #{ChefZero::Dist::CLIENT} says 410.")
9
- end
10
-
11
- def post(request)
12
- error(410, "Server says 410, #{ChefZero::Dist::CLIENT} says 410.")
13
- end
14
- end
15
- end
16
- end
1
+ require_relative "../dist"
2
+ module ChefZero
3
+ module Endpoints
4
+ # /organizations/ORG/controls
5
+ class ControlsEndpoint < RestBase
6
+ # ours is not to wonder why; ours is but to make the pedant specs pass.
7
+ def get(request)
8
+ error(410, "Server says 410, #{ChefZero::Dist::CLIENT} says 410.")
9
+ end
10
+
11
+ def post(request)
12
+ error(410, "Server says 410, #{ChefZero::Dist::CLIENT} says 410.")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,24 +1,24 @@
1
- require_relative "../chef_data/data_normalizer"
2
-
3
- module ChefZero
4
- module Endpoints
5
- class CookbookArtifactEndpoint < RestBase
6
- # GET /organizations/ORG/cookbook_artifacts/COOKBOOK
7
- def get(request)
8
- cookbook_name = request.rest_path.last
9
- cookbook_url = build_uri(request.base_uri, request.rest_path)
10
- response_data = {}
11
- versions = []
12
-
13
- list_data(request).each do |identifier|
14
- artifact_url = build_uri(request.base_uri, request.rest_path + [cookbook_name, identifier])
15
- versions << { url: artifact_url, identifier: identifier }
16
- end
17
-
18
- response_data[cookbook_name] = { url: cookbook_url, versions: versions }
19
-
20
- json_response(200, response_data)
21
- end
22
- end
23
- end
24
- end
1
+ require_relative "../chef_data/data_normalizer"
2
+
3
+ module ChefZero
4
+ module Endpoints
5
+ class CookbookArtifactEndpoint < RestBase
6
+ # GET /organizations/ORG/cookbook_artifacts/COOKBOOK
7
+ def get(request)
8
+ cookbook_name = request.rest_path.last
9
+ cookbook_url = build_uri(request.base_uri, request.rest_path)
10
+ response_data = {}
11
+ versions = []
12
+
13
+ list_data(request).each do |identifier|
14
+ artifact_url = build_uri(request.base_uri, request.rest_path + [cookbook_name, identifier])
15
+ versions << { url: artifact_url, identifier: identifier }
16
+ end
17
+
18
+ response_data[cookbook_name] = { url: cookbook_url, versions: versions }
19
+
20
+ json_response(200, response_data)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,68 +1,68 @@
1
- require_relative "../chef_data/data_normalizer"
2
-
3
- module ChefZero
4
- module Endpoints
5
- class CookbookArtifactIdentifierEndpoint < ChefZero::Endpoints::CookbookVersionEndpoint
6
- # these endpoints are almost, but not quite, not entirely unlike the corresponding /cookbooks endpoints.
7
- # it could all be refactored for maximum reuse, but they're short REST methods with well-defined
8
- # behavioral specs (pedant), so there's not a huge benefit.
9
-
10
- # GET /organizations/ORG/cookbook_artifacts/NAME/IDENTIFIER
11
- def get(request)
12
- cookbook_data = normalize(request, get_data(request))
13
- json_response(200, cookbook_data)
14
- end
15
-
16
- # PUT /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
17
- def put(request)
18
- if exists_data?(request)
19
- return error(409, "Cookbooks cannot be modified, and a cookbook with this identifier already exists.")
20
- end
21
-
22
- cb_data = normalize(request, request.body)
23
- set_data(request, nil, to_json(cb_data), :create_dir, :create)
24
-
25
- already_json_response(201, request.body)
26
- end
27
-
28
- # DELETE /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
29
- def delete(request)
30
- doomed_cookbook_json = get_data(request)
31
- identified_cookbook_data = normalize(request, doomed_cookbook_json)
32
- delete_data(request)
33
-
34
- # go through the recipes and delete stuff in the file store.
35
- hoover_unused_checksums(get_checksums(doomed_cookbook_json), request)
36
-
37
- # if this was the last revision, delete the directory so future requests will 404, instead of
38
- # returning 200 with an empty list.
39
- # Last one out turns out the lights: delete /organizations/ORG/cookbooks/COOKBOOK if it no longer has versions
40
- cookbook_path = request.rest_path[0..3]
41
- if exists_data_dir?(request, cookbook_path) && list_data(request, cookbook_path).size == 0
42
- delete_data_dir(request, cookbook_path)
43
- end
44
-
45
- json_response(200, identified_cookbook_data)
46
- rescue RestErrorResponse => ex
47
- if ex.response_code == 404
48
- error(404, "not_found")
49
- else
50
- raise
51
- end
52
- end
53
-
54
- private
55
-
56
- def make_file_store_path(rest_path, recipe)
57
- rest_path.first(2) + ["file_store", "checksums", recipe["checksum"]]
58
- end
59
-
60
- def normalize(request, cookbook_artifact_data)
61
- cookbook = parse_json(cookbook_artifact_data)
62
- ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1],
63
- cookbook, request.rest_path[3], request.rest_path[4],
64
- request.base_uri, request.method, true, api_version: request.api_version)
65
- end
66
- end
67
- end
68
- end
1
+ require_relative "../chef_data/data_normalizer"
2
+
3
+ module ChefZero
4
+ module Endpoints
5
+ class CookbookArtifactIdentifierEndpoint < ChefZero::Endpoints::CookbookVersionEndpoint
6
+ # these endpoints are almost, but not quite, not entirely unlike the corresponding /cookbooks endpoints.
7
+ # it could all be refactored for maximum reuse, but they're short REST methods with well-defined
8
+ # behavioral specs (pedant), so there's not a huge benefit.
9
+
10
+ # GET /organizations/ORG/cookbook_artifacts/NAME/IDENTIFIER
11
+ def get(request)
12
+ cookbook_data = normalize(request, get_data(request))
13
+ json_response(200, cookbook_data)
14
+ end
15
+
16
+ # PUT /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
17
+ def put(request)
18
+ if exists_data?(request)
19
+ return error(409, "Cookbooks cannot be modified, and a cookbook with this identifier already exists.")
20
+ end
21
+
22
+ cb_data = normalize(request, request.body)
23
+ set_data(request, nil, to_json(cb_data), :create_dir, :create)
24
+
25
+ already_json_response(201, request.body)
26
+ end
27
+
28
+ # DELETE /organizations/ORG/cookbook_artifacts/COOKBOOK/IDENTIFIER
29
+ def delete(request)
30
+ doomed_cookbook_json = get_data(request)
31
+ identified_cookbook_data = normalize(request, doomed_cookbook_json)
32
+ delete_data(request)
33
+
34
+ # go through the recipes and delete stuff in the file store.
35
+ hoover_unused_checksums(get_checksums(doomed_cookbook_json), request)
36
+
37
+ # if this was the last revision, delete the directory so future requests will 404, instead of
38
+ # returning 200 with an empty list.
39
+ # Last one out turns out the lights: delete /organizations/ORG/cookbooks/COOKBOOK if it no longer has versions
40
+ cookbook_path = request.rest_path[0..3]
41
+ if exists_data_dir?(request, cookbook_path) && list_data(request, cookbook_path).size == 0
42
+ delete_data_dir(request, cookbook_path)
43
+ end
44
+
45
+ json_response(200, identified_cookbook_data)
46
+ rescue RestErrorResponse => ex
47
+ if ex.response_code == 404
48
+ error(404, "not_found")
49
+ else
50
+ raise
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def make_file_store_path(rest_path, recipe)
57
+ rest_path.first(2) + ["file_store", "checksums", recipe["checksum"]]
58
+ end
59
+
60
+ def normalize(request, cookbook_artifact_data)
61
+ cookbook = parse_json(cookbook_artifact_data)
62
+ ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1],
63
+ cookbook, request.rest_path[3], request.rest_path[4],
64
+ request.base_uri, request.method, true, api_version: request.api_version)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,34 +1,34 @@
1
- require_relative "../chef_data/data_normalizer"
2
-
3
- module ChefZero
4
- module Endpoints
5
- class CookbookArtifactsEndpoint < RestBase
6
- # GET /organizations/ORG/cookbook_artifacts
7
- def get(request)
8
- data = {}
9
-
10
- artifacts = begin
11
- list_data(request)
12
- rescue Exception => e
13
- if e.response_code == 404
14
- return already_json_response(200, "{}")
15
- end
16
- end
17
-
18
- artifacts.each do |cookbook_artifact|
19
- cookbook_url = build_uri(request.base_uri, request.rest_path + [cookbook_artifact])
20
-
21
- versions = []
22
- list_data(request, request.rest_path + [cookbook_artifact]).each do |identifier|
23
- artifact_url = build_uri(request.base_uri, request.rest_path + [cookbook_artifact, identifier])
24
- versions << { url: artifact_url, identifier: identifier }
25
- end
26
-
27
- data[cookbook_artifact] = { url: cookbook_url, versions: versions }
28
- end
29
-
30
- json_response(200, data)
31
- end
32
- end
33
- end
34
- end
1
+ require_relative "../chef_data/data_normalizer"
2
+
3
+ module ChefZero
4
+ module Endpoints
5
+ class CookbookArtifactsEndpoint < RestBase
6
+ # GET /organizations/ORG/cookbook_artifacts
7
+ def get(request)
8
+ data = {}
9
+
10
+ artifacts = begin
11
+ list_data(request)
12
+ rescue Exception => e
13
+ if e.response_code == 404
14
+ return already_json_response(200, "{}")
15
+ end
16
+ end
17
+
18
+ artifacts.each do |cookbook_artifact|
19
+ cookbook_url = build_uri(request.base_uri, request.rest_path + [cookbook_artifact])
20
+
21
+ versions = []
22
+ list_data(request, request.rest_path + [cookbook_artifact]).each do |identifier|
23
+ artifact_url = build_uri(request.base_uri, request.rest_path + [cookbook_artifact, identifier])
24
+ versions << { url: artifact_url, identifier: identifier }
25
+ end
26
+
27
+ data[cookbook_artifact] = { url: cookbook_url, versions: versions }
28
+ end
29
+
30
+ json_response(200, data)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,39 +1,39 @@
1
- require_relative "cookbooks_base"
2
-
3
- module ChefZero
4
- module Endpoints
5
- # /cookbooks/NAME
6
- class CookbookEndpoint < CookbooksBase
7
- def get(request)
8
- filter = request.rest_path[3]
9
- case filter
10
- when "_latest"
11
- result = {}
12
- filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
13
- if versions.size > 0
14
- result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name, versions[0]])
15
- end
16
- end
17
- json_response(200, result)
18
- when "_recipes"
19
- result = []
20
- filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
21
- if versions.size > 0
22
- cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]]))
23
- result += recipe_names(name, cookbook)
24
- end
25
- end
26
- json_response(200, result.sort)
27
- else
28
- cookbook_list = { filter => list_data(request, request.rest_path) }
29
- json_response(200, format_cookbooks_list(request, cookbook_list))
30
- end
31
- end
32
-
33
- def latest_version(versions)
34
- sorted = versions.sort_by { |version| Gem::Version.new(version.dup) }
35
- sorted[-1]
36
- end
37
- end
38
- end
39
- end
1
+ require_relative "cookbooks_base"
2
+
3
+ module ChefZero
4
+ module Endpoints
5
+ # /cookbooks/NAME
6
+ class CookbookEndpoint < CookbooksBase
7
+ def get(request)
8
+ filter = request.rest_path[3]
9
+ case filter
10
+ when "_latest"
11
+ result = {}
12
+ filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
13
+ if versions.size > 0
14
+ result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name, versions[0]])
15
+ end
16
+ end
17
+ json_response(200, result)
18
+ when "_recipes"
19
+ result = []
20
+ filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
21
+ if versions.size > 0
22
+ cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]]))
23
+ result += recipe_names(name, cookbook)
24
+ end
25
+ end
26
+ json_response(200, result.sort)
27
+ else
28
+ cookbook_list = { filter => list_data(request, request.rest_path) }
29
+ json_response(200, format_cookbooks_list(request, cookbook_list))
30
+ end
31
+ end
32
+
33
+ def latest_version(versions)
34
+ sorted = versions.sort_by { |version| Gem::Version.new(version.dup) }
35
+ sorted[-1]
36
+ end
37
+ end
38
+ end
39
+ end