Skip to content

Commit

Permalink
Merge pull request #283 from chef/lcg/remove-hashrockets
Browse files Browse the repository at this point in the history
remove hashrocket syntax
  • Loading branch information
lamont-granquist authored Jul 3, 2018
2 parents f279509 + 388576b commit efaae3c
Show file tree
Hide file tree
Showing 31 changed files with 111 additions and 109 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Style/HashSyntax:
Enabled: true
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ gemspec
# gem 'rest-client', :git => 'https://github.com/chef/rest-client.git'

group :pedant do
gem "oc-chef-pedant", :git => "https://github.com/chef/chef-server.git"
gem "oc-chef-pedant", git: "https://github.com/chef/chef-server.git"
end

group :development, :test do
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Environment:
e.g. LOG_LEVEL=debug
END

task :default => :pedant
task default: :pedant

desc "Run specs"
task :spec do
system("rspec spec/*_spec.rb")
end

desc "Run oc-chef-pedant\n\n#{ENV_DOCS}"
task :pedant => :oc_pedant
task pedant: :oc_pedant

desc "Run oc-chef-pedant with CHEF_FS set\n\n#{ENV_DOCS}"
task :cheffs do
Expand Down
8 changes: 4 additions & 4 deletions lib/chef_zero/chef_data/cookbook_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def load_files(directory, recursive = true, part = nil)
def load_file(value, name, part = nil)
specific_name = part ? "#{part}/#{name}" : name
[{
:name => specific_name,
:path => name,
:checksum => Digest::MD5.hexdigest(value),
:specificity => "default",
name: specific_name,
path: name,
checksum: Digest::MD5.hexdigest(value),
specificity: "default",
}]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/data_store/default_facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get(path, request = nil)
rescue DataNotFoundError
result = default_creator.get(path)
if result
FFI_Yajl::Encoder.encode(result, :pretty => true)
FFI_Yajl::Encoder.encode(result, pretty: true)
else
raise
end
Expand Down
4 changes: 2 additions & 2 deletions lib/chef_zero/data_store/raw_file_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def create(path, name, data, *options)
FileUtils.mkdir_p(path_to(path))
end
begin
File.open(path_to(path, name), File::WRONLY | File::CREAT | File::EXCL | File::BINARY, :internal_encoding => nil) do |file|
File.open(path_to(path, name), File::WRONLY | File::CREAT | File::EXCL | File::BINARY, internal_encoding: nil) do |file|
file.write data
end
rescue Errno::ENOENT
Expand All @@ -94,7 +94,7 @@ def set(path, data, *options)
if options.include?(:create)
mode |= File::CREAT
end
File.open(path_to(path), mode, :internal_encoding => nil) do |file|
File.open(path_to(path), mode, internal_encoding: nil) do |file|
file.write data
end
rescue Errno::ENOENT
Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/endpoints/acl_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def put(request)
path, perm = validate_request(request)
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))
set_data(request, path, FFI_Yajl::Encoder.encode(acls, pretty: true))
json_response(200, { "uri" => "#{build_uri(request.base_uri, request.rest_path)}" })
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/endpoints/container_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(server)
def populate_defaults(request, response_json)
container = FFI_Yajl::Parser.parse(response_json)
container = ChefData::DataNormalizer.normalize_container(container, request.rest_path[3])
FFI_Yajl::Encoder.encode(container, :pretty => true)
FFI_Yajl::Encoder.encode(container, pretty: true)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/chef_zero/endpoints/cookbook_version_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def put(request)
request_body = FFI_Yajl::Parser.parse(request.body)
if !request_body["frozen?"]
request_body["frozen?"] = true
request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true)
request.body = FFI_Yajl::Encoder.encode(request_body, pretty: true)
end
end
end
Expand Down Expand Up @@ -122,7 +122,7 @@ def populate_defaults(request, response_json, normalize: true)
cookbook["chef_type"] ||= "cookbook_version"
cookbook["json_class"] ||= "Chef::CookbookVersion"
cookbook = ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, request.rest_path[3], request.rest_path[4], request.base_uri, request.method, false, api_version: request.api_version) if normalize
FFI_Yajl::Encoder.encode(cookbook, :pretty => true)
FFI_Yajl::Encoder.encode(cookbook, pretty: true)
end

def latest_version(versions)
Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/endpoints/data_bag_item_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def populate_defaults(request, response_json)
def self.populate_defaults(request, response_json, data_bag, data_bag_item)
response = FFI_Yajl::Parser.parse(response_json)
response = ChefData::DataNormalizer.normalize_data_bag_item(response, data_bag, data_bag_item, request.method)
FFI_Yajl::Encoder.encode(response, :pretty => true)
FFI_Yajl::Encoder.encode(response, pretty: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/endpoints/environment_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def put(request)
def populate_defaults(request, response_json)
response = FFI_Yajl::Parser.parse(response_json)
response = ChefData::DataNormalizer.normalize_environment(response, request.rest_path[3])
FFI_Yajl::Encoder.encode(response, :pretty => true)
FFI_Yajl::Encoder.encode(response, pretty: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/endpoints/file_store_file_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get(request)
end

def put(request)
data_store.set(request.rest_path, request.body, :create, :create_dir, :requestor => request.requestor)
data_store.set(request.rest_path, request.body, :create, :create_dir, requestor: request.requestor)
json_response(200, {})
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/endpoints/group_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(server)
def populate_defaults(request, response_json)
group = FFI_Yajl::Parser.parse(response_json)
group = ChefData::DataNormalizer.normalize_group(group, request.rest_path[3], request.rest_path[1])
FFI_Yajl::Encoder.encode(group, :pretty => true)
FFI_Yajl::Encoder.encode(group, pretty: true)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/chef_zero/endpoints/node_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def put(request)
data = parse_json(request.body)

if data.has_key?("policy_name") && policy_name_invalid?(data["policy_name"])
return error(400, "Field 'policy_name' invalid", :pretty => false)
return error(400, "Field 'policy_name' invalid", pretty: false)
end

if data.has_key?("policy_group") && policy_name_invalid?(data["policy_group"])
return error(400, "Field 'policy_group' invalid", :pretty => false)
return error(400, "Field 'policy_group' invalid", pretty: false)
end

super(request)
Expand All @@ -27,7 +27,7 @@ def head(request)
def populate_defaults(request, response_json)
node = FFI_Yajl::Parser.parse(response_json)
node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3])
FFI_Yajl::Encoder.encode(node, :pretty => true)
FFI_Yajl::Encoder.encode(node, pretty: true)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/chef_zero/endpoints/node_identifiers_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class NodeIdentifiersEndpoint < RestBase
def get(request)
if get_data(request, request.rest_path[0..3])
result = {
:id => UUIDTools::UUID.parse_raw(request.rest_path[0..4].to_s).to_s.delete("-"),
:authz_id => "0" * 32,
:org_id => UUIDTools::UUID.parse_raw(request.rest_path[0..1].to_s).to_s.delete("-") }
id: UUIDTools::UUID.parse_raw(request.rest_path[0..4].to_s).to_s.delete("-"),
authz_id: "0" * 32,
org_id: UUIDTools::UUID.parse_raw(request.rest_path[0..1].to_s).to_s.delete("-") }
json_response(200, result)
else
raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
Expand Down
6 changes: 3 additions & 3 deletions lib/chef_zero/endpoints/nodes_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def post(request)
data = parse_json(request.body)

if data.has_key?("policy_name") && policy_name_invalid?(data["policy_name"])
return error(400, "Field 'policy_name' invalid", :pretty => false)
return error(400, "Field 'policy_name' invalid", pretty: false)
end

if data.has_key?("policy_group") && policy_name_invalid?(data["policy_group"])
return error(400, "Field 'policy_group' invalid", :pretty => false)
return error(400, "Field 'policy_group' invalid", pretty: false)
end
end

Expand All @@ -27,7 +27,7 @@ def post(request)
def populate_defaults(request, response_json)
node = FFI_Yajl::Parser.parse(response_json)
node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3])
FFI_Yajl::Encoder.encode(node, :pretty => true)
FFI_Yajl::Encoder.encode(node, pretty: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/endpoints/not_found_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ChefZero
module Endpoints
class NotFoundEndpoint
def call(request)
[404, { "Content-Type" => "application/json" }, FFI_Yajl::Encoder.encode({ "error" => ["Object not found: #{request.env['REQUEST_PATH']}"] }, :pretty => true)]
[404, { "Content-Type" => "application/json" }, FFI_Yajl::Encoder.encode({ "error" => ["Object not found: #{request.env['REQUEST_PATH']}"] }, pretty: true)]
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/chef_zero/endpoints/organization_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def put(request)
new_org.each do |key, value|
org[key] = value
end
save_org = FFI_Yajl::Encoder.encode(org, :pretty => true)
save_org = FFI_Yajl::Encoder.encode(org, pretty: true)
if new_org["name"] != request.rest_path[-1]
# This is a rename
return error(400, "Cannot rename org #{request.rest_path[-1]} to #{new_org['name']}: rename not supported for orgs")
Expand All @@ -39,7 +39,7 @@ def delete(request)
def populate_defaults(request, response_json)
org = FFI_Yajl::Parser.parse(response_json)
org = ChefData::DataNormalizer.normalize_organization(org, request.rest_path[1])
FFI_Yajl::Encoder.encode(org, :pretty => true)
FFI_Yajl::Encoder.encode(org, pretty: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/endpoints/organization_users_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def post(request)
if !users["users"] || !users["users"].include?(username)
users["users"] ||= []
users["users"] |= [ username ]
set_data(request, [ "organizations", orgname, "groups", "users" ], FFI_Yajl::Encoder.encode(users, :pretty => true))
set_data(request, [ "organizations", orgname, "groups", "users" ], FFI_Yajl::Encoder.encode(users, pretty: true))
end
json_response(201, { "uri" => build_uri(request.base_uri, request.rest_path + [ username ]) })
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def post(request)
validator = FFI_Yajl::Parser.parse(get_data(request, validator_path))
private_key, public_key = server.gen_key_pair
validator["public_key"] = public_key
set_data(request, validator_path, FFI_Yajl::Encoder.encode(validator, :pretty => true))
set_data(request, validator_path, FFI_Yajl::Encoder.encode(validator, pretty: true))
json_response(200, { "private_key" => private_key })
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/chef_zero/endpoints/organizations_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def post(request)
elsif exists_data_dir?(request, request.rest_path + [ name ])
error(409, "Organization already exists")
else
create_data_dir(request, request.rest_path, name, :requestor => request.requestor)
create_data_dir(request, request.rest_path, name, requestor: request.requestor)

org = {
"guid" => UUIDTools::UUID.random_create.to_s.delete("-"),
"assigned_at" => Time.now.to_s,
}.merge(contents)
org_path = request.rest_path + [ name ]
set_data(request, org_path + [ "org" ], FFI_Yajl::Encoder.encode(org, :pretty => true))
set_data(request, org_path + [ "org" ], FFI_Yajl::Encoder.encode(org, pretty: true))

if server.generate_real_keys?
# Create the validator client
Expand All @@ -42,7 +42,7 @@ def post(request)
validator = FFI_Yajl::Encoder.encode({
"validator" => true,
"public_key" => public_key,
}, :pretty => true)
}, pretty: true)
set_data(request, validator_path, validator)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/endpoints/rest_object_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def patch_request_body(request)
existing_json = FFI_Yajl::Parser.parse(existing_value)
merged_json = existing_json.merge(request_json)
if merged_json.size > request_json.size
return FFI_Yajl::Encoder.encode(merged_json, :pretty => true)
return FFI_Yajl::Encoder.encode(merged_json, pretty: true)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/endpoints/role_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RoleEndpoint < RestObjectEndpoint
def populate_defaults(request, response_json)
role = FFI_Yajl::Parser.parse(response_json)
role = ChefData::DataNormalizer.normalize_role(role, request.rest_path[3])
FFI_Yajl::Encoder.encode(role, :pretty => true)
FFI_Yajl::Encoder.encode(role, pretty: true)
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/chef_zero/endpoints/sandbox_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def put(request)
end
delete_data(request)
json_response(200, {
:guid => request.rest_path[3],
:name => request.rest_path[3],
:checksums => existing_sandbox["checksums"],
:create_time => existing_sandbox["create_time"],
:is_completed => true,
guid: request.rest_path[3],
name: request.rest_path[3],
checksums: existing_sandbox["checksums"],
create_time: existing_sandbox["create_time"],
is_completed: true,
})
end
end
Expand Down
18 changes: 9 additions & 9 deletions lib/chef_zero/endpoints/sandboxes_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def post(request)
result_checksums = {}
needed_checksums.keys.each do |needed_checksum|
if list_data(request, request.rest_path[0..1] + %w{file_store checksums}).include?(needed_checksum)
result_checksums[needed_checksum] = { :needs_upload => false }
result_checksums[needed_checksum] = { needs_upload: false }
else
result_checksums[needed_checksum] = {
:needs_upload => true,
:url => build_uri(request.base_uri, request.rest_path[0..1] + ["file_store", "checksums", needed_checksum]),
needs_upload: true,
url: build_uri(request.base_uri, request.rest_path[0..1] + ["file_store", "checksums", needed_checksum]),
}
sandbox_checksums << needed_checksum
end
Expand All @@ -35,14 +35,14 @@ def post(request)
time_str = "#{time_str[0..21]}:#{time_str[22..23]}"

create_data(request, request.rest_path, id, FFI_Yajl::Encoder.encode({
:create_time => time_str,
:checksums => sandbox_checksums,
}, :pretty => true))
create_time: time_str,
checksums: sandbox_checksums,
}, pretty: true))

json_response(201, {
:uri => build_uri(request.base_uri, request.rest_path + [id]),
:checksums => result_checksums,
:sandbox_id => id,
uri: build_uri(request.base_uri, request.rest_path + [id]),
checksums: result_checksums,
sandbox_id: id,
})
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def put(request)
if !users["users"] || !users["users"].include?(username)
users["users"] ||= []
users["users"] |= [ username ]
set_data(request, [ "organizations", orgname, "groups", "users" ], FFI_Yajl::Encoder.encode(users, :pretty => true))
set_data(request, [ "organizations", orgname, "groups", "users" ], FFI_Yajl::Encoder.encode(users, pretty: true))
end
elsif json["response"] == "reject"
delete_data(request, association_request_path)
Expand Down
8 changes: 4 additions & 4 deletions lib/chef_zero/rest_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def delete_data_dir(request, rest_path, *options)
def set_data(request, rest_path, data, *options)
rest_path ||= request.rest_path
begin
data_store.set(rest_path, data, *options, :requestor => request.requestor)
data_store.set(rest_path, data, *options, requestor: request.requestor)
rescue DataStore::DataNotFoundError
if options.include?(:data_store_exceptions)
raise
Expand All @@ -158,7 +158,7 @@ def set_data(request, rest_path, data, *options)
def create_data_dir(request, rest_path, name, *options)
rest_path ||= request.rest_path
begin
data_store.create_dir(rest_path, name, *options, :requestor => request.requestor)
data_store.create_dir(rest_path, name, *options, requestor: request.requestor)
rescue DataStore::DataNotFoundError
if options.include?(:data_store_exceptions)
raise
Expand All @@ -177,7 +177,7 @@ def create_data_dir(request, rest_path, name, *options)
def create_data(request, rest_path, name, data, *options)
rest_path ||= request.rest_path
begin
data_store.create(rest_path, name, data, *options, :requestor => request.requestor)
data_store.create(rest_path, name, data, *options, requestor: request.requestor)
rescue DataStore::DataNotFoundError
if options.include?(:data_store_exceptions)
raise
Expand Down Expand Up @@ -296,7 +296,7 @@ def parse_json(json)
end

def to_json(data)
FFI_Yajl::Encoder.encode(data, :pretty => true)
FFI_Yajl::Encoder.encode(data, pretty: true)
end

def get_data_or_else(request, path, or_else_value)
Expand Down
2 changes: 1 addition & 1 deletion lib/chef_zero/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def dejsonize(data)
if data.is_a?(String)
data
else
FFI_Yajl::Encoder.encode(data, :pretty => true)
FFI_Yajl::Encoder.encode(data, pretty: true)
end
end

Expand Down
Loading

0 comments on commit efaae3c

Please sign in to comment.