From b244346c1e8d500e82603d0dace7a84a8031c89c Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 3 Jul 2018 10:02:37 -0700 Subject: fixes for new chefstyle Signed-off-by: Lamont Granquist --- Rakefile | 16 ++++++++-------- lib/chef_zero.rb | 6 +++--- lib/chef_zero/chef_data/acl_path.rb | 4 ++-- lib/chef_zero/chef_data/cookbook_data.rb | 4 ++-- lib/chef_zero/chef_data/data_normalizer.rb | 8 ++++---- lib/chef_zero/chef_data/default_creator.rb | 8 ++++---- lib/chef_zero/data_store/memory_store_v2.rb | 10 +++++----- lib/chef_zero/endpoints/acl_endpoint.rb | 2 +- lib/chef_zero/endpoints/actor_keys_endpoint.rb | 4 ++-- lib/chef_zero/endpoints/cookbook_version_endpoint.rb | 2 +- lib/chef_zero/endpoints/data_bags_endpoint.rb | 2 +- .../endpoints/environment_cookbook_versions_endpoint.rb | 2 +- lib/chef_zero/endpoints/node_endpoint.rb | 4 ++-- lib/chef_zero/endpoints/nodes_endpoint.rb | 4 ++-- lib/chef_zero/endpoints/organization_endpoint.rb | 2 +- lib/chef_zero/endpoints/organizations_endpoint.rb | 2 +- lib/chef_zero/endpoints/rest_list_endpoint.rb | 4 ++-- lib/chef_zero/rspec.rb | 4 ++-- lib/chef_zero/server.rb | 4 ++-- lib/chef_zero/solr/query/range_query.rb | 2 +- lib/chef_zero/solr/query/regexpable_query.rb | 6 +++--- lib/chef_zero/solr/solr_parser.rb | 2 +- lib/chef_zero/version.rb | 2 +- spec/support/oc_pedant.rb | 2 +- 24 files changed, 53 insertions(+), 53 deletions(-) diff --git a/Rakefile b/Rakefile index 25d7db4..048e97a 100644 --- a/Rakefile +++ b/Rakefile @@ -8,14 +8,14 @@ def run_oc_pedant(env = {}) require File.expand_path("spec/run_oc_pedant") end -ENV_DOCS = < /acls/root diff --git a/lib/chef_zero/chef_data/cookbook_data.rb b/lib/chef_zero/chef_data/cookbook_data.rb index 74bc9e7..e4ec9b3 100644 --- a/lib/chef_zero/chef_data/cookbook_data.rb +++ b/lib/chef_zero/chef_data/cookbook_data.rb @@ -11,7 +11,7 @@ module ChefZero class << self def to_hash(cookbook, name, version = nil) frozen = false - if cookbook.has_key?(:frozen) + if cookbook.key?(:frozen) frozen = cookbook[:frozen] cookbook = cookbook.dup cookbook.delete(:frozen) @@ -72,7 +72,7 @@ module ChefZero def has_child(directory, name) if directory.is_a?(Hash) - directory.has_key?(name) + directory.key?(name) else directory.child(name).exists? end diff --git a/lib/chef_zero/chef_data/data_normalizer.rb b/lib/chef_zero/chef_data/data_normalizer.rb index 6e96f85..b69fcaf 100644 --- a/lib/chef_zero/chef_data/data_normalizer.rb +++ b/lib/chef_zero/chef_data/data_normalizer.rb @@ -6,13 +6,13 @@ module ChefZero module ChefData class DataNormalizer - COOKBOOK_SEGMENTS = %w{ resources providers recipes definitions libraries attributes files templates root_files } + COOKBOOK_SEGMENTS = %w{ resources providers recipes definitions libraries attributes files templates root_files }.freeze def self.normalize_acls(acls) ChefData::DefaultCreator::PERMISSIONS.each do |perm| acls[perm] ||= {} acls[perm]["groups"] ||= [] - if acls[perm].has_key? "users" + if acls[perm].key? "users" # When clients and users are split, their combined list # is the final list of actors that a subsequent GET will # provide. Each list is guaranteed to be unique, but the @@ -98,7 +98,7 @@ module ChefZero if method == "PUT" && api_version < 2 cookbook["all_files"] = cookbook.delete(["root_files"]) { [] } COOKBOOK_SEGMENTS.each do |segment| - next unless cookbook.has_key? segment + next unless cookbook.key? segment cookbook[segment].each do |file| file["name"] = "#{segment}/#{file['name']}" cookbook["all_files"] << file @@ -108,7 +108,7 @@ module ChefZero elsif method != "PUT" if cookbook.key? "all_files" cookbook["all_files"].each do |file| - if file.is_a?(Hash) && file.has_key?("checksum") + if file.is_a?(Hash) && file.key?("checksum") file["url"] ||= endpoint.build_uri(base_uri, org_prefix + ["file_store", "checksums", file["checksum"]]) end end diff --git a/lib/chef_zero/chef_data/default_creator.rb b/lib/chef_zero/chef_data/default_creator.rb index 1af04a1..0b155f2 100644 --- a/lib/chef_zero/chef_data/default_creator.rb +++ b/lib/chef_zero/chef_data/default_creator.rb @@ -24,8 +24,8 @@ module ChefZero attr_reader :creators attr_writer :deleted - PERMISSIONS = %w{create read update delete grant} - DEFAULT_SUPERUSERS = %w{pivotal} + PERMISSIONS = %w{create read update delete grant}.freeze + DEFAULT_SUPERUSERS = %w{pivotal}.freeze def clear @creators = { [] => @superusers } @@ -166,7 +166,7 @@ module ChefZero "containers" => %w{clients containers cookbook_artifacts cookbooks data environments groups nodes policies policy_groups roles sandboxes}, "groups" => %w{admins billing-admins clients users}, "association_requests" => {}, - } + }.freeze def list_org_default(path) if path.size >= 3 && path[2] == "acls" @@ -373,7 +373,7 @@ module ChefZero end owners = filter_owners(path, unknown_owners) - #ANGRY + # ANGRY # Non-default containers do not get superusers added to them, # because reasons. unless path.size == 4 && path[0] == "organizations" && path[2] == "containers" && !exists?(path) diff --git a/lib/chef_zero/data_store/memory_store_v2.rb b/lib/chef_zero/data_store/memory_store_v2.rb index 85f8b3d..8e041b5 100644 --- a/lib/chef_zero/data_store/memory_store_v2.rb +++ b/lib/chef_zero/data_store/memory_store_v2.rb @@ -36,7 +36,7 @@ module ChefZero def create_dir(path, name, *options) parent = _get(path, options.include?(:recursive)) - if parent.has_key?(name) + if parent.key?(name) if !options.include?(:recursive) raise DataAlreadyExistsError.new(path + [name]) end @@ -52,7 +52,7 @@ module ChefZero parent = _get(path, options.include?(:create_dir)) - if parent.has_key?(name) + if parent.key?(name) raise DataAlreadyExistsError.new(path + [name]) end parent[name] = data @@ -82,7 +82,7 @@ module ChefZero def delete(path) parent = _get(path[0, path.length - 1]) - if !parent.has_key?(path[-1]) + if !parent.key?(path[-1]) raise DataNotFoundError.new(path) end if !parent[path[-1]].is_a?(String) @@ -93,7 +93,7 @@ module ChefZero def delete_dir(path, *options) parent = _get(path[0, path.length - 1]) - if !parent.has_key?(path[-1]) + if !parent.key?(path[-1]) raise DataNotFoundError.new(path) end if !parent[path[-1]].is_a?(Hash) @@ -135,7 +135,7 @@ module ChefZero def _get(path, create_dir = false) value = @data path.each_with_index do |path_part, index| - if !value.has_key?(path_part) + if !value.key?(path_part) if create_dir value[path_part] = {} else diff --git a/lib/chef_zero/endpoints/acl_endpoint.rb b/lib/chef_zero/endpoints/acl_endpoint.rb index cfa3a97..e389f2d 100644 --- a/lib/chef_zero/endpoints/acl_endpoint.rb +++ b/lib/chef_zero/endpoints/acl_endpoint.rb @@ -31,7 +31,7 @@ module ChefZero acls = FFI_Yajl::Parser.parse(get_data(request, path)) acls[perm] = FFI_Yajl::Parser.parse(request.body)[perm] set_data(request, path, FFI_Yajl::Encoder.encode(acls, pretty: true)) - json_response(200, { "uri" => "#{build_uri(request.base_uri, request.rest_path)}" }) + json_response(200, { "uri" => (build_uri(request.base_uri, request.rest_path)).to_s }) end end end diff --git a/lib/chef_zero/endpoints/actor_keys_endpoint.rb b/lib/chef_zero/endpoints/actor_keys_endpoint.rb index 00c11d0..b3bab9a 100644 --- a/lib/chef_zero/endpoints/actor_keys_endpoint.rb +++ b/lib/chef_zero/endpoints/actor_keys_endpoint.rb @@ -5,8 +5,8 @@ module ChefZero # /users/USER/keys # /organizations/ORG/clients/CLIENT/keys class ActorKeysEndpoint < RestBase - DEFAULT_PUBLIC_KEY_NAME = "default" - DATE_FORMAT = "%FT%TZ" # e.g. 2015-12-24T21:00:00Z + DEFAULT_PUBLIC_KEY_NAME = "default".freeze + DATE_FORMAT = "%FT%TZ".freeze # e.g. 2015-12-24T21:00:00Z def get(request, alt_uri_root = nil) path = data_path(request) diff --git a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb index 97b0ce4..0ee5be7 100644 --- a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +++ b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb @@ -74,7 +74,7 @@ module ChefZero FFI_Yajl::Parser.parse(cookbook).each_pair do |key, value| if value.is_a?(Array) value.each do |file| - if file.is_a?(Hash) && file.has_key?("checksum") + if file.is_a?(Hash) && file.key?("checksum") result << file["checksum"] end end diff --git a/lib/chef_zero/endpoints/data_bags_endpoint.rb b/lib/chef_zero/endpoints/data_bags_endpoint.rb index 0ddb34e..5b9dd14 100644 --- a/lib/chef_zero/endpoints/data_bags_endpoint.rb +++ b/lib/chef_zero/endpoints/data_bags_endpoint.rb @@ -15,7 +15,7 @@ module ChefZero error(409, "Object already exists") else create_data_dir(request, request.rest_path[0..1] + ["data"], name, :recursive) - json_response(201, { "uri" => "#{build_uri(request.base_uri, request.rest_path + [name])}" }) + json_response(201, { "uri" => (build_uri(request.base_uri, request.rest_path + [name])).to_s }) end end end diff --git a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb index ddd44d3..43ef4ce 100644 --- a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +++ b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb @@ -81,7 +81,7 @@ module ChefZero cookbook_dependencies.each_pair do |dep_name, dep_constraint| # If the dep is not already in the list, add it to the list to solve # and bring in all environment-allowed cookbook versions to desired_versions - if !new_desired_versions.has_key?(dep_name) + if !new_desired_versions.key?(dep_name) new_unsolved += [dep_name] # If the dep is missing, we will try other versions of the cookbook that might not have the bad dep. if !exists_data_dir?(request, request.rest_path[0..1] + ["cookbooks", dep_name]) diff --git a/lib/chef_zero/endpoints/node_endpoint.rb b/lib/chef_zero/endpoints/node_endpoint.rb index ee07678..689b631 100644 --- a/lib/chef_zero/endpoints/node_endpoint.rb +++ b/lib/chef_zero/endpoints/node_endpoint.rb @@ -9,11 +9,11 @@ module ChefZero def put(request) data = parse_json(request.body) - if data.has_key?("policy_name") && policy_name_invalid?(data["policy_name"]) + if data.key?("policy_name") && policy_name_invalid?(data["policy_name"]) return error(400, "Field 'policy_name' invalid", pretty: false) end - if data.has_key?("policy_group") && policy_name_invalid?(data["policy_group"]) + if data.key?("policy_group") && policy_name_invalid?(data["policy_group"]) return error(400, "Field 'policy_group' invalid", pretty: false) end diff --git a/lib/chef_zero/endpoints/nodes_endpoint.rb b/lib/chef_zero/endpoints/nodes_endpoint.rb index 8b141f8..d828a11 100644 --- a/lib/chef_zero/endpoints/nodes_endpoint.rb +++ b/lib/chef_zero/endpoints/nodes_endpoint.rb @@ -12,11 +12,11 @@ module ChefZero if request.rest_path.last == "nodes" data = parse_json(request.body) - if data.has_key?("policy_name") && policy_name_invalid?(data["policy_name"]) + if data.key?("policy_name") && policy_name_invalid?(data["policy_name"]) return error(400, "Field 'policy_name' invalid", pretty: false) end - if data.has_key?("policy_group") && policy_name_invalid?(data["policy_group"]) + if data.key?("policy_group") && policy_name_invalid?(data["policy_group"]) return error(400, "Field 'policy_group' invalid", pretty: false) end end diff --git a/lib/chef_zero/endpoints/organization_endpoint.rb b/lib/chef_zero/endpoints/organization_endpoint.rb index 4cf9e12..3c14548 100644 --- a/lib/chef_zero/endpoints/organization_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_endpoint.rb @@ -23,7 +23,7 @@ module ChefZero end set_data(request, request.rest_path + [ "org" ], save_org) json_response(200, { - "uri" => "#{build_uri(request.base_uri, request.rest_path)}", + "uri" => (build_uri(request.base_uri, request.rest_path)).to_s, "name" => org["name"], "org_type" => org["org_type"], "full_name" => org["full_name"], diff --git a/lib/chef_zero/endpoints/organizations_endpoint.rb b/lib/chef_zero/endpoints/organizations_endpoint.rb index 9fe6573..6ad46fe 100644 --- a/lib/chef_zero/endpoints/organizations_endpoint.rb +++ b/lib/chef_zero/endpoints/organizations_endpoint.rb @@ -47,7 +47,7 @@ module ChefZero end json_response(201, { - "uri" => "#{build_uri(request.base_uri, org_path)}", + "uri" => (build_uri(request.base_uri, org_path)).to_s, "name" => name, "org_type" => org["org_type"], "full_name" => full_name, diff --git a/lib/chef_zero/endpoints/rest_list_endpoint.rb b/lib/chef_zero/endpoints/rest_list_endpoint.rb index b1e3d5c..135f0e9 100644 --- a/lib/chef_zero/endpoints/rest_list_endpoint.rb +++ b/lib/chef_zero/endpoints/rest_list_endpoint.rb @@ -17,7 +17,7 @@ module ChefZero # Get the result result_hash = {} list_data(request).sort.each do |name| - result_hash[name] = "#{build_uri(request.base_uri, request.rest_path + [name])}" + result_hash[name] = (build_uri(request.base_uri, request.rest_path + [name])).to_s end json_response(200, result_hash) end @@ -29,7 +29,7 @@ module ChefZero error(400, "Must specify #{identity_keys.map { |k| k.inspect }.join(' or ')} in JSON") else create_data(request, request.rest_path, key, contents) - json_response(201, { "uri" => "#{build_uri(request.base_uri, request.rest_path + [key])}" }) + json_response(201, { "uri" => (build_uri(request.base_uri, request.rest_path + [key])).to_s }) end end diff --git a/lib/chef_zero/rspec.rb b/lib/chef_zero/rspec.rb index b6d6dd1..e1fdfcc 100644 --- a/lib/chef_zero/rspec.rb +++ b/lib/chef_zero/rspec.rb @@ -219,7 +219,7 @@ module ChefZero with_object_path("cookbooks/#{name}") do # If you didn't specify metadata.rb, we generate it for you. If you # explicitly set it to nil, that means you don't want it at all. - if data.has_key?("metadata.rb") + if data.key?("metadata.rb") if data["metadata.rb"].nil? data.delete("metadata.rb") end @@ -235,7 +235,7 @@ module ChefZero with_object_path("cookbook_artifacts/#{name}") do # If you didn't specify metadata.rb, we generate it for you. If you # explicitly set it to nil, that means you don't want it at all. - if data.has_key?("metadata.rb") + if data.key?("metadata.rb") if data["metadata.rb"].nil? data.delete("metadata.rb") end diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index cadf8c3..9800913 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -124,11 +124,11 @@ module ChefZero "/license", "/version", "/server_api_version", - ] + ].freeze def initialize(options = {}) @options = DEFAULT_OPTIONS.merge(options) - if @options[:single_org] && !@options.has_key?(:osc_compat) + if @options[:single_org] && !@options.key?(:osc_compat) @options[:osc_compat] = true end @options.freeze diff --git a/lib/chef_zero/solr/query/range_query.rb b/lib/chef_zero/solr/query/range_query.rb index 76ec828..67ce1ce 100644 --- a/lib/chef_zero/solr/query/range_query.rb +++ b/lib/chef_zero/solr/query/range_query.rb @@ -39,7 +39,7 @@ module ChefZero matches_values?(doc[DEFAULT_FIELD]) end - DEFAULT_FIELD = "text" + DEFAULT_FIELD = "text".freeze end end end diff --git a/lib/chef_zero/solr/query/regexpable_query.rb b/lib/chef_zero/solr/query/regexpable_query.rb index 62d7fc7..4cf6748 100644 --- a/lib/chef_zero/solr/query/regexpable_query.rb +++ b/lib/chef_zero/solr/query/regexpable_query.rb @@ -21,9 +21,9 @@ module ChefZero values.any? { |value| !@regexp.match(value).nil? } end - DEFAULT_FIELD = "text" - WORD_CHARACTER = "[A-Za-z0-9@._':\-]" - NON_WORD_CHARACTER = "[^A-Za-z0-9@._':\-]" + DEFAULT_FIELD = "text".freeze + WORD_CHARACTER = "[A-Za-z0-9@._':\-]".freeze + NON_WORD_CHARACTER = "[^A-Za-z0-9@._':\-]".freeze end end end diff --git a/lib/chef_zero/solr/solr_parser.rb b/lib/chef_zero/solr/solr_parser.rb index cec1b34..86c232f 100644 --- a/lib/chef_zero/solr/solr_parser.rb +++ b/lib/chef_zero/solr/solr_parser.rb @@ -200,7 +200,7 @@ module ChefZero end end - DEFAULT_FIELD = "text" + DEFAULT_FIELD = "text".freeze end end end diff --git a/lib/chef_zero/version.rb b/lib/chef_zero/version.rb index 27f9632..cf5897f 100644 --- a/lib/chef_zero/version.rb +++ b/lib/chef_zero/version.rb @@ -1,3 +1,3 @@ module ChefZero - VERSION = "14.0.7" + VERSION = "14.0.7".freeze end diff --git a/spec/support/oc_pedant.rb b/spec/support/oc_pedant.rb index 9a59e4c..03c4db1 100644 --- a/spec/support/oc_pedant.rb +++ b/spec/support/oc_pedant.rb @@ -32,7 +32,7 @@ chef_server "http://127.0.0.1:8889" # testing location, you should not specify a value for this parameter. # The tests will still run, albeit slower, as they will now need to # poll for a period to ensure they are querying committed results. -#search_server "http://localhost:8983" +# search_server "http://localhost:8983" # Related to the 'search_server' parameter, this specifies the maximum # amout of time (in seconds) that search endpoint requests should be -- cgit v1.2.1