summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-07-29 17:00:49 +0100
committerThom May <thom@may.lt>2016-07-29 17:00:49 +0100
commite257f450c044616fefbd15e9a180387aaaa572a1 (patch)
tree6a148967013485078af6601546bdb7b61c623f3c /lib
parent4c86d798010b73c76c916e601ff48c24ffb65dd6 (diff)
downloadchef-zero-e257f450c044616fefbd15e9a180387aaaa572a1.tar.gz
ChefStyletm/style
Signed-off-by: Thom May <thom@may.lt>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef_zero.rb2
-rw-r--r--lib/chef_zero/chef_data/acl_path.rb32
-rw-r--r--lib/chef_zero/chef_data/cookbook_data.rb48
-rw-r--r--lib/chef_zero/chef_data/data_normalizer.rb240
-rw-r--r--lib/chef_zero/chef_data/default_creator.rb290
-rw-r--r--lib/chef_zero/data_store/data_already_exists_error.rb2
-rw-r--r--lib/chef_zero/data_store/data_not_found_error.rb4
-rw-r--r--lib/chef_zero/data_store/default_facade.rb10
-rw-r--r--lib/chef_zero/data_store/interface_v1.rb2
-rw-r--r--lib/chef_zero/data_store/interface_v2.rb2
-rw-r--r--lib/chef_zero/data_store/memory_store.rb8
-rw-r--r--lib/chef_zero/data_store/memory_store_v2.rb16
-rw-r--r--lib/chef_zero/data_store/raw_file_store.rb20
-rw-r--r--lib/chef_zero/data_store/v1_to_v2_adapter.rb18
-rw-r--r--lib/chef_zero/data_store/v2_to_v1_adapter.rb10
-rw-r--r--lib/chef_zero/endpoints/acl_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/acls_endpoint.rb10
-rw-r--r--lib/chef_zero/endpoints/actor_default_key_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/actor_endpoint.rb40
-rw-r--r--lib/chef_zero/endpoints/actor_key_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/actor_keys_endpoint.rb11
-rw-r--r--lib/chef_zero/endpoints/actors_endpoint.rb24
-rw-r--r--lib/chef_zero/endpoints/authenticate_user_endpoint.rb20
-rw-r--r--lib/chef_zero/endpoints/container_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/containers_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/cookbook_endpoint.rb10
-rw-r--r--lib/chef_zero/endpoints/cookbook_version_endpoint.rb26
-rw-r--r--lib/chef_zero/endpoints/cookbooks_base.rb26
-rw-r--r--lib/chef_zero/endpoints/cookbooks_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/data_bag_endpoint.rb24
-rw-r--r--lib/chef_zero/endpoints/data_bag_item_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/data_bags_endpoint.rb10
-rw-r--r--lib/chef_zero/endpoints/dummy_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/environment_cookbook_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb32
-rw-r--r--lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/environment_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/environment_nodes_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/environment_recipes_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/environment_role_endpoint.rb16
-rw-r--r--lib/chef_zero/endpoints/file_store_file_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/group_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/groups_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/license_endpoint.rb10
-rw-r--r--lib/chef_zero/endpoints/node_endpoint.rb7
-rw-r--r--lib/chef_zero/endpoints/node_identifiers_endpoint.rb14
-rw-r--r--lib/chef_zero/endpoints/nodes_endpoint.rb7
-rw-r--r--lib/chef_zero/endpoints/not_found_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/organization_association_request_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/organization_association_requests_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb16
-rw-r--r--lib/chef_zero/endpoints/organization_endpoint.rb20
-rw-r--r--lib/chef_zero/endpoints/organization_user_base.rb4
-rw-r--r--lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/organization_user_endpoint.rb10
-rw-r--r--lib/chef_zero/endpoints/organization_user_key_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/organization_user_keys_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/organization_users_endpoint.rb24
-rw-r--r--lib/chef_zero/endpoints/organization_validator_key_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/organizations_endpoint.rb25
-rw-r--r--lib/chef_zero/endpoints/policies_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/policy_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/policy_group_endpoint.rb12
-rw-r--r--lib/chef_zero/endpoints/policy_group_policy_endpoint.rb7
-rw-r--r--lib/chef_zero/endpoints/policy_groups_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/policy_revision_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/policy_revisions_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/principal_endpoint.rb30
-rw-r--r--lib/chef_zero/endpoints/rest_list_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/rest_object_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/role_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/role_environments_endpoint.rb6
-rw-r--r--lib/chef_zero/endpoints/sandbox_endpoint.rb16
-rw-r--r--lib/chef_zero/endpoints/sandboxes_endpoint.rb18
-rw-r--r--lib/chef_zero/endpoints/search_endpoint.rb100
-rw-r--r--lib/chef_zero/endpoints/searches_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/server_api_version_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/system_recovery_endpoint.rb16
-rw-r--r--lib/chef_zero/endpoints/user_association_request_endpoint.rb24
-rw-r--r--lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/user_association_requests_endpoint.rb8
-rw-r--r--lib/chef_zero/endpoints/user_organizations_endpoint.rb10
-rw-r--r--lib/chef_zero/endpoints/version_endpoint.rb2
-rw-r--r--lib/chef_zero/log.rb2
-rw-r--r--lib/chef_zero/rest_base.rb50
-rw-r--r--lib/chef_zero/rest_request.rb22
-rw-r--r--lib/chef_zero/rest_router.rb60
-rw-r--r--lib/chef_zero/rspec.rb66
-rw-r--r--lib/chef_zero/server.rb377
-rw-r--r--lib/chef_zero/socketless_server_map.rb5
-rw-r--r--lib/chef_zero/solr/query/binary_operator.rb16
-rw-r--r--lib/chef_zero/solr/query/phrase.rb2
-rw-r--r--lib/chef_zero/solr/query/range_query.rb4
-rw-r--r--lib/chef_zero/solr/query/regexpable_query.rb1
-rw-r--r--lib/chef_zero/solr/query/term.rb10
-rw-r--r--lib/chef_zero/solr/query/unary_operator.rb8
-rw-r--r--lib/chef_zero/solr/solr_doc.rb8
-rw-r--r--lib/chef_zero/solr/solr_parser.rb67
-rw-r--r--lib/chef_zero/version.rb2
102 files changed, 1128 insertions, 1133 deletions
diff --git a/lib/chef_zero.rb b/lib/chef_zero.rb
index 94633d4..2db3392 100644
--- a/lib/chef_zero.rb
+++ b/lib/chef_zero.rb
@@ -1,5 +1,5 @@
module ChefZero
- require 'chef_zero/log'
+ require "chef_zero/log"
MIN_API_VERSION = 0
MAX_API_VERSION = 1
diff --git a/lib/chef_zero/chef_data/acl_path.rb b/lib/chef_zero/chef_data/acl_path.rb
index 52b43d4..dd162bd 100644
--- a/lib/chef_zero/chef_data/acl_path.rb
+++ b/lib/chef_zero/chef_data/acl_path.rb
@@ -13,9 +13,9 @@ module ChefZero
# specified on X, they are not inherited from X's parent
# - stop adding pivotal to acls (he already has access to what he needs)
module AclPath
- ORG_DATA_TYPES = %w(clients cookbook_artifacts cookbooks containers data environments groups
- nodes policies policy_groups roles sandboxes)
- TOP_DATA_TYPES = %w(containers organizations users)
+ ORG_DATA_TYPES = %w{clients cookbook_artifacts cookbooks containers data environments groups
+ nodes policies policy_groups roles sandboxes}
+ TOP_DATA_TYPES = %w{containers organizations users}
# ACL data paths for a partition are:
# / -> /acls/root
@@ -42,7 +42,7 @@ module ChefZero
# return nil, because it is the parent path (data/bag) that has an ACL.
def self.get_acl_data_path(path)
# Things under organizations have their own acls hierarchy
- if path[0] == 'organizations' && path.size >= 2
+ if path[0] == "organizations" && path.size >= 2
under_org = partition_acl_data_path(path[2..-1], ORG_DATA_TYPES)
if under_org
path[0..1] + under_org
@@ -63,14 +63,14 @@ module ChefZero
# /containers/nodes, not /nodes.
#
def self.get_object_path(acl_data_path)
- if acl_data_path[0] == 'acls'
- if acl_data_path[1] == 'root'
+ if acl_data_path[0] == "acls"
+ if acl_data_path[1] == "root"
[]
else
acl_data_path[1..-1]
end
- elsif acl_data_path[0] == 'organizations' && acl_data_path[2] == 'acls'
- if acl_data_path[3] == 'root'
+ elsif acl_data_path[0] == "organizations" && acl_data_path[2] == "acls"
+ if acl_data_path[3] == "root"
acl_data_path[0..1]
else
acl_data_path[0..1] + acl_data_path[3..-1]
@@ -91,13 +91,13 @@ module ChefZero
# /acls/root ->
# nil
def self.parent_acl_data_path(acl_data_path)
- if acl_data_path[0] == 'organizations'
+ if acl_data_path[0] == "organizations"
under_org = partition_parent_acl_data_path(acl_data_path[2..-1])
if under_org
acl_data_path[0..1] + under_org
else
# ACL data path is /organizations/X/acls/root; therefore parent is "/organizations"
- [ 'acls', 'containers', 'organizations' ]
+ %w{acls containers organizations}
end
else
partition_parent_acl_data_path(acl_data_path)
@@ -114,10 +114,10 @@ module ChefZero
# Returns nil if the path is /acls/root
def self.partition_parent_acl_data_path(acl_data_path)
if acl_data_path.size == 3
- if acl_data_path == %w(acls containers containers)
- [ 'acls', 'root' ]
+ if acl_data_path == %w{acls containers containers}
+ %w{acls root}
else
- [ 'acls', 'containers', acl_data_path[1]]
+ [ "acls", "containers", acl_data_path[1]]
end
else
nil
@@ -126,12 +126,12 @@ module ChefZero
def self.partition_acl_data_path(path, data_types)
if path.size == 0
- [ 'acls', 'root']
+ %w{acls root}
elsif data_types.include?(path[0])
if path.size == 0
- [ 'acls', 'containers', path[0] ]
+ [ "acls", "containers", path[0] ]
elsif path.size == 2
- [ 'acls', path[0], path[1] ]
+ [ "acls", path[0], path[1] ]
end
end
end
diff --git a/lib/chef_zero/chef_data/cookbook_data.rb b/lib/chef_zero/chef_data/cookbook_data.rb
index 83bdd46..1a0f473 100644
--- a/lib/chef_zero/chef_data/cookbook_data.rb
+++ b/lib/chef_zero/chef_data/cookbook_data.rb
@@ -1,10 +1,10 @@
-require 'digest/md5'
-require 'hashie/mash'
+require "digest/md5"
+require "hashie/mash"
module ChefZero
module ChefData
module CookbookData
- def self.to_hash(cookbook, name, version=nil)
+ def self.to_hash(cookbook, name, version = nil)
frozen = false
if cookbook.has_key?(:frozen)
frozen = cookbook[:frozen]
@@ -15,14 +15,14 @@ module ChefZero
result = files_from(cookbook)
recipe_names = result[:recipes].map do |recipe|
recipe_name = recipe[:name][0..-2]
- recipe_name == 'default' ? name : "#{name}::#{recipe_name}"
+ recipe_name == "default" ? name : "#{name}::#{recipe_name}"
end
result[:metadata] = metadata_from(cookbook, name, version, recipe_names)
result[:name] = "#{name}-#{result[:metadata][:version]}"
- result[:json_class] = 'Chef::CookbookVersion'
+ result[:json_class] = "Chef::CookbookVersion"
result[:cookbook_name] = name
result[:version] = result[:metadata][:version]
- result[:chef_type] = 'cookbook_version'
+ result[:chef_type] = "cookbook_version"
result[:frozen?] = true if frozen
result
end
@@ -32,18 +32,18 @@ module ChefZero
# If both .rb and .json exist, read .rb
# TODO if recipes has 3 recipes in it, and the Ruby/JSON has only one, should
# the resulting recipe list have 1, or 3-4 recipes in it?
- if has_child(directory, 'metadata.rb')
+ if has_child(directory, "metadata.rb")
begin
- file = filename(directory, 'metadata.rb') || "(#{name}/metadata.rb)"
- metadata.instance_eval(read_file(directory, 'metadata.rb'), file)
+ file = filename(directory, "metadata.rb") || "(#{name}/metadata.rb)"
+ metadata.instance_eval(read_file(directory, "metadata.rb"), file)
rescue
ChefZero::Log.error("Error loading cookbook #{name}: #{$!}\n #{$!.backtrace.join("\n ")}")
end
- elsif has_child(directory, 'metadata.json')
- metadata.from_json(read_file(directory, 'metadata.json'))
+ elsif has_child(directory, "metadata.json")
+ metadata.from_json(read_file(directory, "metadata.json"))
end
result = {}
- metadata.to_hash.each_pair do |key,value|
+ metadata.to_hash.each_pair do |key, value|
result[key.to_sym] = value
end
result[:version] = version if version
@@ -69,7 +69,7 @@ module ChefZero
def initialize(cookbook)
self.name(cookbook.name)
self.recipes(cookbook.fully_qualified_recipe_names)
- %w(attributes grouping dependencies supports recommendations suggestions conflicting providing replacing recipes).each do |hash_arg|
+ %w{attributes grouping dependencies supports recommendations suggestions conflicting providing replacing recipes}.each do |hash_arg|
self[hash_arg.to_sym] = Hashie::Mash.new
end
end
@@ -145,15 +145,15 @@ module ChefZero
def self.files_from(directory)
# TODO some support .rb only
result = {
- :attributes => load_child_files(directory, 'attributes', false),
- :definitions => load_child_files(directory, 'definitions', false),
- :recipes => load_child_files(directory, 'recipes', false),
- :libraries => load_child_files(directory, 'libraries', true),
- :templates => load_child_files(directory, 'templates', true),
- :files => load_child_files(directory, 'files', true),
- :resources => load_child_files(directory, 'resources', true),
- :providers => load_child_files(directory, 'providers', true),
- :root_files => load_files(directory, false)
+ :attributes => load_child_files(directory, "attributes", false),
+ :definitions => load_child_files(directory, "definitions", false),
+ :recipes => load_child_files(directory, "recipes", false),
+ :libraries => load_child_files(directory, "libraries", true),
+ :templates => load_child_files(directory, "templates", true),
+ :files => load_child_files(directory, "files", true),
+ :resources => load_child_files(directory, "resources", true),
+ :providers => load_child_files(directory, "providers", true),
+ :root_files => load_files(directory, false),
}
set_specificity(result[:templates])
set_specificity(result[:files])
@@ -231,13 +231,13 @@ module ChefZero
:name => name,
:path => name,
:checksum => Digest::MD5.hexdigest(value),
- :specificity => 'default'
+ :specificity => "default",
}]
end
def self.set_specificity(files)
files.each do |file|
- parts = file[:path].split('/')
+ parts = file[:path].split("/")
raise "Only directories are allowed directly under templates or files: #{file[:path]}" if parts.size == 2
file[:specificity] = parts[1]
end
diff --git a/lib/chef_zero/chef_data/data_normalizer.rb b/lib/chef_zero/chef_data/data_normalizer.rb
index e819f1d..a762581 100644
--- a/lib/chef_zero/chef_data/data_normalizer.rb
+++ b/lib/chef_zero/chef_data/data_normalizer.rb
@@ -1,6 +1,6 @@
-require 'chef_zero'
-require 'chef_zero/rest_base'
-require 'chef_zero/chef_data/default_creator'
+require "chef_zero"
+require "chef_zero/rest_base"
+require "chef_zero/chef_data/default_creator"
module ChefZero
module ChefData
@@ -8,210 +8,210 @@ module ChefZero
def self.normalize_acls(acls)
ChefData::DefaultCreator::PERMISSIONS.each do |perm|
acls[perm] ||= {}
- (acls[perm]['actors'] ||= []).uniq! # this gets doubled sometimes, for reasons.
- acls[perm]['groups'] ||= []
+ (acls[perm]["actors"] ||= []).uniq! # this gets doubled sometimes, for reasons.
+ acls[perm]["groups"] ||= []
end
acls
end
def self.normalize_client(client, name, orgname = nil)
- client['name'] ||= name
- client['clientname'] ||= name
- client['admin'] = !!client['admin'] if client.key?('admin')
- client['public_key'] = PUBLIC_KEY unless client.key?('public_key')
- client['orgname'] ||= orgname
- client['validator'] ||= false
- client['validator'] = !!client['validator']
- client['json_class'] ||= "Chef::ApiClient"
- client['chef_type'] ||= "client"
+ client["name"] ||= name
+ client["clientname"] ||= name
+ client["admin"] = !!client["admin"] if client.key?("admin")
+ client["public_key"] = PUBLIC_KEY unless client.key?("public_key")
+ client["orgname"] ||= orgname
+ client["validator"] ||= false
+ client["validator"] = !!client["validator"]
+ client["json_class"] ||= "Chef::ApiClient"
+ client["chef_type"] ||= "client"
client
end
def self.normalize_container(container, name)
- container.delete('id')
- container['containername'] = name
- container['containerpath'] = name
+ container.delete("id")
+ container["containername"] = name
+ container["containerpath"] = name
container
end
- def self.normalize_user(user, name, identity_keys, osc_compat, method=nil)
+ def self.normalize_user(user, name, identity_keys, osc_compat, method = nil)
user[identity_keys.first] ||= name
- user['public_key'] = PUBLIC_KEY unless user.key?('public_key')
- user['admin'] ||= false
- user['admin'] = !!user['admin']
- user['openid'] ||= nil
+ user["public_key"] = PUBLIC_KEY unless user.key?("public_key")
+ user["admin"] ||= false
+ user["admin"] = !!user["admin"]
+ user["openid"] ||= nil
if !osc_compat
- if method == 'GET'
- user.delete('admin')
- user.delete('password')
- user.delete('openid')
+ if method == "GET"
+ user.delete("admin")
+ user.delete("password")
+ user.delete("openid")
end
- user['email'] ||= nil
- user['first_name'] ||= nil
- user['last_name'] ||= nil
+ user["email"] ||= nil
+ user["first_name"] ||= nil
+ user["last_name"] ||= nil
end
user
end
def self.normalize_data_bag_item(data_bag_item, data_bag_name, id, method)
- if method == 'DELETE'
+ if method == "DELETE"
# TODO SERIOUSLY, WHO DOES THIS MANY EXCEPTIONS IN THEIR INTERFACE
- if !(data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data'])
- data_bag_item['id'] ||= id
- data_bag_item = { 'raw_data' => data_bag_item }
- data_bag_item['chef_type'] ||= 'data_bag_item'
- data_bag_item['json_class'] ||= 'Chef::DataBagItem'
- data_bag_item['data_bag'] ||= data_bag_name
- data_bag_item['name'] ||= "data_bag_item_#{data_bag_name}_#{id}"
+ if !(data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"])
+ data_bag_item["id"] ||= id
+ data_bag_item = { "raw_data" => data_bag_item }
+ data_bag_item["chef_type"] ||= "data_bag_item"
+ data_bag_item["json_class"] ||= "Chef::DataBagItem"
+ data_bag_item["data_bag"] ||= data_bag_name
+ data_bag_item["name"] ||= "data_bag_item_#{data_bag_name}_#{id}"
end
else
# If it's not already wrapped with raw_data, wrap it.
- if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
- data_bag_item = data_bag_item['raw_data']
+ if data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"]
+ data_bag_item = data_bag_item["raw_data"]
end
# Argh. We don't do this on GET, but we do on PUT and POST????
- if %w(PUT POST).include?(method)
- data_bag_item['chef_type'] ||= 'data_bag_item'
- data_bag_item['data_bag'] ||= data_bag_name
+ if %w{PUT POST}.include?(method)
+ data_bag_item["chef_type"] ||= "data_bag_item"
+ data_bag_item["data_bag"] ||= data_bag_name
end
- data_bag_item['id'] ||= id
+ data_bag_item["id"] ||= id
end
data_bag_item
end
def self.normalize_cookbook(endpoint, org_prefix, cookbook, name, version, base_uri, method,
- is_cookbook_artifact=false)
+ is_cookbook_artifact = false)
# TODO I feel dirty
- if method != 'PUT'
+ if method != "PUT"
cookbook.each_pair do |key, value|
if value.is_a?(Array)
value.each do |file|
- if file.is_a?(Hash) && file.has_key?('checksum')
- file['url'] ||= endpoint.build_uri(base_uri, org_prefix + ['file_store', 'checksums', file['checksum']])
+ if file.is_a?(Hash) && file.has_key?("checksum")
+ file["url"] ||= endpoint.build_uri(base_uri, org_prefix + ["file_store", "checksums", file["checksum"]])
end
end
end
end
- cookbook['name'] ||= "#{name}-#{version}"
+ cookbook["name"] ||= "#{name}-#{version}"
# TODO it feels wrong, but the real chef server doesn't expand 'version', so we don't either.
- cookbook['frozen?'] ||= false
- cookbook['metadata'] ||= {}
- cookbook['metadata']['version'] ||= version
+ cookbook["frozen?"] ||= false
+ cookbook["metadata"] ||= {}
+ cookbook["metadata"]["version"] ||= version
# defaults set by the client and not the Server:
# metadata[name, description, maintainer, maintainer_email, license]
- cookbook['metadata']['long_description'] ||= ""
- cookbook['metadata']['dependencies'] ||= {}
- cookbook['metadata']['attributes'] ||= {}
- cookbook['metadata']['recipes'] ||= {}
+ cookbook["metadata"]["long_description"] ||= ""
+ cookbook["metadata"]["dependencies"] ||= {}
+ cookbook["metadata"]["attributes"] ||= {}
+ cookbook["metadata"]["recipes"] ||= {}
end
if is_cookbook_artifact
- cookbook.delete('json_class')
+ cookbook.delete("json_class")
else
- cookbook['cookbook_name'] ||= name
- cookbook['json_class'] ||= 'Chef::CookbookVersion'
+ cookbook["cookbook_name"] ||= name
+ cookbook["json_class"] ||= "Chef::CookbookVersion"
end
- cookbook['chef_type'] ||= 'cookbook_version'
- if method == 'MIN'
- cookbook['metadata'].delete('attributes')
- cookbook['metadata'].delete('long_description')
+ cookbook["chef_type"] ||= "cookbook_version"
+ if method == "MIN"
+ cookbook["metadata"].delete("attributes")
+ cookbook["metadata"].delete("long_description")
end
cookbook
end
def self.normalize_environment(environment, name)
- environment['name'] ||= name
- environment['description'] ||= ''
- environment['cookbook_versions'] ||= {}
- environment['json_class'] ||= "Chef::Environment"
- environment['chef_type'] ||= "environment"
- environment['default_attributes'] ||= {}
- environment['override_attributes'] ||= {}
+ environment["name"] ||= name
+ environment["description"] ||= ""
+ environment["cookbook_versions"] ||= {}
+ environment["json_class"] ||= "Chef::Environment"
+ environment["chef_type"] ||= "environment"
+ environment["default_attributes"] ||= {}
+ environment["override_attributes"] ||= {}
environment
end
def self.normalize_group(group, name, orgname)
- group.delete('id')
- if group['actors'].is_a?(Hash)
- group['users'] ||= group['actors']['users']
- group['clients'] ||= group['actors']['clients']
- group['groups'] ||= group['actors']['groups']
- group['actors'] = nil
+ group.delete("id")
+ if group["actors"].is_a?(Hash)
+ group["users"] ||= group["actors"]["users"]
+ group["clients"] ||= group["actors"]["clients"]
+ group["groups"] ||= group["actors"]["groups"]
+ group["actors"] = nil
end
- group['users'] ||= []
- group['clients'] ||= []
- group['actors'] ||= (group['clients'] + group['users'])
- group['groups'] ||= []
- group['orgname'] ||= orgname if orgname
- group['name'] ||= name
- group['groupname'] ||= name
-
- group['users'].uniq!
- group['clients'].uniq!
- group['actors'].uniq!
- group['groups'].uniq!
+ group["users"] ||= []
+ group["clients"] ||= []
+ group["actors"] ||= (group["clients"] + group["users"])
+ group["groups"] ||= []
+ group["orgname"] ||= orgname if orgname
+ group["name"] ||= name
+ group["groupname"] ||= name
+
+ group["users"].uniq!
+ group["clients"].uniq!
+ group["actors"].uniq!
+ group["groups"].uniq!
group
end
def self.normalize_node(node, name)
- node['name'] ||= name
- node['json_class'] ||= 'Chef::Node'
- node['chef_type'] ||= 'node'
- node['chef_environment'] ||= '_default'
- node['override'] ||= {}
- node['normal'] ||= {"tags" => []}
- node['default'] ||= {}
- node['automatic'] ||= {}
- node['run_list'] ||= []
- node['run_list'] = normalize_run_list(node['run_list'])
+ node["name"] ||= name
+ node["json_class"] ||= "Chef::Node"
+ node["chef_type"] ||= "node"
+ node["chef_environment"] ||= "_default"
+ node["override"] ||= {}
+ node["normal"] ||= { "tags" => [] }
+ node["default"] ||= {}
+ node["automatic"] ||= {}
+ node["run_list"] ||= []
+ node["run_list"] = normalize_run_list(node["run_list"])
node
end
def self.normalize_policy(policy, name, revision)
- policy['name'] ||= name
- policy['revision_id'] ||= revision
- policy['run_list'] ||= []
- policy['cookbook_locks'] ||= {}
+ policy["name"] ||= name
+ policy["revision_id"] ||= revision
+ policy["run_list"] ||= []
+ policy["cookbook_locks"] ||= {}
policy
end
def self.normalize_policy_group(policy_group, name)
- policy_group[name] ||= 'name'
- policy_group['policies'] ||= {}
+ policy_group[name] ||= "name"
+ policy_group["policies"] ||= {}
policy_group
end
def self.normalize_organization(org, name)
- org['name'] ||= name
- org['full_name'] ||= name
- org['org_type'] ||= 'Business'
- org['clientname'] ||= "#{name}-validator"
- org['billing_plan'] ||= 'platform-free'
+ org["name"] ||= name
+ org["full_name"] ||= name
+ org["org_type"] ||= "Business"
+ org["clientname"] ||= "#{name}-validator"
+ org["billing_plan"] ||= "platform-free"
org
end
def self.normalize_role(role, name)
- role['name'] ||= name
- role['description'] ||= ''
- role['json_class'] ||= 'Chef::Role'
- role['chef_type'] ||= 'role'
- role['default_attributes'] ||= {}
- role['override_attributes'] ||= {}
- role['run_list'] ||= []
- role['run_list'] = normalize_run_list(role['run_list'])
- role['env_run_lists'] ||= {}
- role['env_run_lists'].each_pair do |env, run_list|
- role['env_run_lists'][env] = normalize_run_list(run_list)
+ role["name"] ||= name
+ role["description"] ||= ""
+ role["json_class"] ||= "Chef::Role"
+ role["chef_type"] ||= "role"
+ role["default_attributes"] ||= {}
+ role["override_attributes"] ||= {}
+ role["run_list"] ||= []
+ role["run_list"] = normalize_run_list(role["run_list"])
+ role["env_run_lists"] ||= {}
+ role["env_run_lists"].each_pair do |env, run_list|
+ role["env_run_lists"][env] = normalize_run_list(run_list)
end
role
end
def self.normalize_run_list(run_list)
- run_list.map{|item|
+ run_list.map {|item|
case item
when /^recipe\[.*\]$/
item # explicit recipe
diff --git a/lib/chef_zero/chef_data/default_creator.rb b/lib/chef_zero/chef_data/default_creator.rb
index 957018c..1ce6253 100644
--- a/lib/chef_zero/chef_data/default_creator.rb
+++ b/lib/chef_zero/chef_data/default_creator.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/chef_data/acl_path'
+require "chef_zero/chef_data/acl_path"
module ChefZero
module ChefData
@@ -24,8 +24,8 @@ module ChefZero
attr_reader :creators
attr_reader :deleted
- PERMISSIONS = %w(create read update delete grant)
- DEFAULT_SUPERUSERS = %w(pivotal)
+ PERMISSIONS = %w{create read update delete grant}
+ DEFAULT_SUPERUSERS = %w{pivotal}
def clear
@creators = { [] => @superusers }
@@ -35,7 +35,7 @@ module ChefZero
def deleted(path)
# acl deletes mean nothing, they are entirely subservient to their
# parent object
- if path[0] == 'acls' || (path[0] == 'organizations' && path[2] == 'acls')
+ if path[0] == "acls" || (path[0] == "organizations" && path[2] == "acls")
return false
end
@@ -54,7 +54,7 @@ module ChefZero
def created(path, creator, create_parents)
# If a parent has been deleted, we will need to clear that.
deleted_index = nil
- 0.upto(path.size-1) do |index|
+ 0.upto(path.size - 1) do |index|
deleted_index = index if @deleted[path[0..index]]
end
@@ -78,32 +78,32 @@ module ChefZero
return nil if deleted?(path)
result = case path[0]
- when 'acls'
- # /acls/*
- object_path = AclPath.get_object_path(path)
- if data_exists?(object_path)
- default_acl(path)
- end
-
- when 'containers'
- if path.size == 2 && exists?(path)
- {}
- end
-
- when 'users'
- if path.size == 2 && data.exists?(path)
- # User is empty user
- {}
- end
-
- when 'organizations'
- if path.size >= 2
- # /organizations/*/**
- if data.exists_dir?(path[0..1])
- get_org_default(path)
- end
- end
- end
+ when "acls"
+ # /acls/*
+ object_path = AclPath.get_object_path(path)
+ if data_exists?(object_path)
+ default_acl(path)
+ end
+
+ when "containers"
+ if path.size == 2 && exists?(path)
+ {}
+ end
+
+ when "users"
+ if path.size == 2 && data.exists?(path)
+ # User is empty user
+ {}
+ end
+
+ when "organizations"
+ if path.size >= 2
+ # /organizations/*/**
+ if data.exists_dir?(path[0..1])
+ get_org_default(path)
+ end
+ end
+ end
result
end
@@ -112,24 +112,24 @@ module ChefZero
return nil if deleted?(path)
if path.size == 0
- return %w(containers users organizations acls)
+ return %w{containers users organizations acls}
end
case path[0]
- when 'acls'
+ when "acls"
if path.size == 1
- [ 'root' ] + (data.list(path + [ 'containers' ]) - [ 'organizations' ])
+ [ "root" ] + (data.list(path + [ "containers" ]) - [ "organizations" ])
else
data.list(AclPath.get_object_path(path))
end
- when 'containers'
- [ 'containers', 'users', 'organizations' ]
+ when "containers"
+ %w{containers users organizations}
- when 'users'
+ when "users"
superusers
- when 'organizations'
+ when "organizations"
if path.size == 1
single_org ? [ single_org ] : []
elsif path.size >= 2 && data.exists_dir?(path[0..1])
@@ -147,32 +147,32 @@ module ChefZero
protected
DEFAULT_ORG_SPINE = {
- 'clients' => {},
- 'cookbook_artifacts' => {},
- 'cookbooks' => {},
- 'data' => {},
- 'environments' => %w(_default),
- 'file_store' => {
- 'checksums' => {}
+ "clients" => {},
+ "cookbook_artifacts" => {},
+ "cookbooks" => {},
+ "data" => {},
+ "environments" => %w{_default},
+ "file_store" => {
+ "checksums" => {},
},
- 'nodes' => {},
- 'policies' => {},
- 'policy_groups' => {},
- 'roles' => {},
- 'sandboxes' => {},
- 'users' => {},
-
- 'org' => {},
- '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' => {}
+ "nodes" => {},
+ "policies" => {},
+ "policy_groups" => {},
+ "roles" => {},
+ "sandboxes" => {},
+ "users" => {},
+
+ "org" => {},
+ "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" => {},
}
def list_org_default(path)
- if path.size >= 3 && path[2] == 'acls'
+ if path.size >= 3 && path[2] == "acls"
if path.size == 3
# /organizations/ORG/acls
- return [ 'root' ] + data.list(path[0..1] + [ 'containers' ])
+ return [ "root" ] + data.list(path[0..1] + [ "containers" ])
elsif path.size == 4
# /organizations/ORG/acls/TYPE
return data.list(path[0..1] + [ path[3] ])
@@ -182,27 +182,27 @@ module ChefZero
end
value = DEFAULT_ORG_SPINE
- 2.upto(path.size-1) do |index|
+ 2.upto(path.size - 1) do |index|
value = nil if @deleted[path[0..index]]
break if !value
value = value[path[index]]
end
result = if value.is_a?(Hash)
- value.keys
- elsif value
- value
- end
+ value.keys
+ elsif value
+ value
+ end
if path.size == 3
- if path[2] == 'clients'
+ if path[2] == "clients"
result << "#{path[1]}-validator"
if osc_compat
result << "#{path[1]}-webui"
end
- elsif path[2] == 'users'
+ elsif path[2] == "users"
if osc_compat
- result << 'admin'
+ result << "admin"
end
end
end
@@ -211,11 +211,11 @@ module ChefZero
end
def get_org_default(path)
- if path[2] == 'acls'
+ if path[2] == "acls"
get_org_acl_default(path)
elsif path.size >= 4
- if path[2] == 'containers' && path.size == 4
+ if path[2] == "containers" && path.size == 4
if exists?(path)
return {}
else
@@ -226,40 +226,40 @@ module ChefZero
# /organizations/(*)/clients/\1-validator
# /organizations/*/environments/_default
# /organizations/*/groups/{admins,billing-admins,clients,users}
- case path[2..-1].join('/')
+ case path[2..-1].join("/")
when "clients/#{path[1]}-validator"
- { 'validator' => 'true' }
+ { "validator" => "true" }
when "clients/#{path[1]}-webui", "users/admin"
if osc_compat
- { 'admin' => 'true' }
+ { "admin" => "true" }
end
when "environments/_default"
{ "description" => "The default Chef environment" }
when "groups/admins"
- admins = data.list(path[0..1] + [ 'users' ]).select do |name|
- user = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ 'users', name ]), :create_additions => false)
- user['admin']
+ admins = data.list(path[0..1] + [ "users" ]).select do |name|
+ user = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ "users", name ]), :create_additions => false)
+ user["admin"]
end
- admins += data.list(path[0..1] + [ 'clients' ]).select do |name|
- client = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ 'clients', name ]), :create_additions => false)
- client['admin']
+ admins += data.list(path[0..1] + [ "clients" ]).select do |name|
+ client = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ "clients", name ]), :create_additions => false)
+ client["admin"]
end
admins += @creators[path[0..1]] if @creators[path[0..1]]
- { 'actors' => admins.uniq }
+ { "actors" => admins.uniq }
when "groups/billing-admins"
{}
when "groups/clients"
- { 'clients' => data.list(path[0..1] + [ 'clients' ]) }
+ { "clients" => data.list(path[0..1] + [ "clients" ]) }
when "groups/users"
- users = data.list(path[0..1] + [ 'users' ])
+ users = data.list(path[0..1] + [ "users" ])
users |= @creators[path[0..1]] if @creators[path[0..1]]
- { 'users' => users }
+ { "users" => users }
when "org"
{}
@@ -273,70 +273,70 @@ module ChefZero
# The actual things containers correspond to don't have to exist, as long as the container does
return nil if !data_exists?(object_path)
basic_acl =
- case path[3..-1].join('/')
- when 'root', 'containers/containers', 'containers/groups'
+ case path[3..-1].join("/")
+ when "root", "containers/containers", "containers/groups"
{
- 'create' => { 'groups' => %w(admins) },
- 'read' => { 'groups' => %w(admins users) },
- 'update' => { 'groups' => %w(admins) },
- 'delete' => { 'groups' => %w(admins) },
- 'grant' => { 'groups' => %w(admins) },
+ "create" => { "groups" => %w{admins} },
+ "read" => { "groups" => %w{admins users} },
+ "update" => { "groups" => %w{admins} },
+ "delete" => { "groups" => %w{admins} },
+ "grant" => { "groups" => %w{admins} },
}
- when 'containers/environments', 'containers/roles', 'containers/policy_groups', 'containers/policies'
+ when "containers/environments", "containers/roles", "containers/policy_groups", "containers/policies"
{
- 'create' => { 'groups' => %w(admins users) },
- 'read' => { 'groups' => %w(admins users clients) },
- 'update' => { 'groups' => %w(admins users) },
- 'delete' => { 'groups' => %w(admins users) },
- 'grant' => { 'groups' => %w(admins) },
+ "create" => { "groups" => %w{admins users} },
+ "read" => { "groups" => %w{admins users clients} },
+ "update" => { "groups" => %w{admins users} },
+ "delete" => { "groups" => %w{admins users} },
+ "grant" => { "groups" => %w{admins} },
}
- when 'containers/cookbooks', 'containers/cookbook_artifacts', 'containers/data'
+ when "containers/cookbooks", "containers/cookbook_artifacts", "containers/data"
{
- 'create' => { 'groups' => %w(admins users clients) },
- 'read' => { 'groups' => %w(admins users clients) },
- 'update' => { 'groups' => %w(admins users clients) },
- 'delete' => { 'groups' => %w(admins users clients) },
- 'grant' => { 'groups' => %w(admins) },
+ "create" => { "groups" => %w{admins users clients} },
+ "read" => { "groups" => %w{admins users clients} },
+ "update" => { "groups" => %w{admins users clients} },
+ "delete" => { "groups" => %w{admins users clients} },
+ "grant" => { "groups" => %w{admins} },
}
- when 'containers/nodes'
+ when "containers/nodes"
{
- 'create' => { 'groups' => %w(admins users clients) },
- 'read' => { 'groups' => %w(admins users clients) },
- 'update' => { 'groups' => %w(admins users) },
- 'delete' => { 'groups' => %w(admins users) },
- 'grant' => { 'groups' => %w(admins) },
+ "create" => { "groups" => %w{admins users clients} },
+ "read" => { "groups" => %w{admins users clients} },
+ "update" => { "groups" => %w{admins users} },
+ "delete" => { "groups" => %w{admins users} },
+ "grant" => { "groups" => %w{admins} },
}
- when 'containers/clients'
+ when "containers/clients"
{
- 'create' => { 'groups' => %w(admins) },
- 'read' => { 'groups' => %w(admins users) },
- 'update' => { 'groups' => %w(admins) },
- 'delete' => { 'groups' => %w(admins users) },
- 'grant' => { 'groups' => %w(admins) },
+ "create" => { "groups" => %w{admins} },
+ "read" => { "groups" => %w{admins users} },
+ "update" => { "groups" => %w{admins} },
+ "delete" => { "groups" => %w{admins users} },
+ "grant" => { "groups" => %w{admins} },
}
- when 'containers/sandboxes'
+ when "containers/sandboxes"
{
- 'create' => { 'groups' => %w(admins users) },
- 'read' => { 'groups' => %w(admins) },
- 'update' => { 'groups' => %w(admins) },
- 'delete' => { 'groups' => %w(admins) },
- 'grant' => { 'groups' => %w(admins) },
+ "create" => { "groups" => %w{admins users} },
+ "read" => { "groups" => %w{admins} },
+ "update" => { "groups" => %w{admins} },
+ "delete" => { "groups" => %w{admins} },
+ "grant" => { "groups" => %w{admins} },
}
- when 'groups/admins', 'groups/clients', 'groups/users'
+ when "groups/admins", "groups/clients", "groups/users"
{
- 'create' => { 'groups' => %w(admins) },
- 'read' => { 'groups' => %w(admins) },
- 'update' => { 'groups' => %w(admins) },
- 'delete' => { 'groups' => %w(admins) },
- 'grant' => { 'groups' => %w(admins) },
+ "create" => { "groups" => %w{admins} },
+ "read" => { "groups" => %w{admins} },
+ "update" => { "groups" => %w{admins} },
+ "delete" => { "groups" => %w{admins} },
+ "grant" => { "groups" => %w{admins} },
}
- when 'groups/billing-admins'
+ when "groups/billing-admins"
{
- 'create' => { 'groups' => %w() },
- 'read' => { 'groups' => %w(billing-admins) },
- 'update' => { 'groups' => %w(billing-admins) },
- 'delete' => { 'groups' => %w() },
- 'grant' => { 'groups' => %w() },
+ "create" => { "groups" => %w{} },
+ "read" => { "groups" => %w{billing-admins} },
+ "update" => { "groups" => %w{billing-admins} },
+ "delete" => { "groups" => %w{} },
+ "grant" => { "groups" => %w{} },
}
else
{}
@@ -352,10 +352,10 @@ module ChefZero
if path
# Non-validator clients own themselves.
- if path.size == 4 && path[0] == 'organizations' && path[2] == 'clients'
+ if path.size == 4 && path[0] == "organizations" && path[2] == "clients"
begin
client = FFI_Yajl::Parser.parse(data.get(path), :create_additions => false)
- if !client['validator']
+ if !client["validator"]
owners |= [ path[3] ]
end
rescue
@@ -367,7 +367,7 @@ module ChefZero
@creators[path].each do |creator|
begin
client = FFI_Yajl::Parser.parse(data.get(path[0..2] + [ creator ]), :create_additions => false)
- next if client['validator']
+ next if client["validator"]
rescue
end
owners |= [ creator ]
@@ -380,7 +380,7 @@ module ChefZero
#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)
+ unless path.size == 4 && path[0] == "organizations" && path[2] == "containers" && !exists?(path)
owners += superusers
end
end
@@ -389,21 +389,21 @@ module ChefZero
owners
end
- def default_acl(acl_path, acl={})
+ def default_acl(acl_path, acl = {})
owners = nil
container_acl = nil
PERMISSIONS.each do |perm|
acl[perm] ||= {}
- acl[perm]['actors'] ||= begin
+ acl[perm]["actors"] ||= begin
owners ||= get_owners(acl_path)
end
- acl[perm]['groups'] ||= begin
+ acl[perm]["groups"] ||= begin
# When we create containers, we don't merge groups (not sure why).
- if acl_path[0] == 'organizations' && acl_path[3] == 'containers'
+ if acl_path[0] == "organizations" && acl_path[3] == "containers"
[]
else
container_acl ||= get_container_acl(acl_path) || {}
- (container_acl[perm] ? container_acl[perm]['groups'] : []) || []
+ (container_acl[perm] ? container_acl[perm]["groups"] : []) || []
end
end
end
@@ -432,15 +432,15 @@ module ChefZero
when 0, 1
return true
when 2
- return path[0] == 'organizations' || (path[0] == 'acls' && path[1] != 'root')
+ return path[0] == "organizations" || (path[0] == "acls" && path[1] != "root")
when 3
# If it has a container, it is a directory.
- return path[0] == 'organizations' &&
- (path[2] == 'acls' || data.exists?(path[0..1] + [ 'containers', path[2] ]))
+ return path[0] == "organizations" &&
+ (path[2] == "acls" || data.exists?(path[0..1] + [ "containers", path[2] ]))
when 4
- return path[0] == 'organizations' && (
- (path[2] == 'acls' && path[1] != 'root') ||
- %w(cookbooks cookbook_artifacts data policies policy_groups).include?(path[2]))
+ return path[0] == "organizations" && (
+ (path[2] == "acls" && path[1] != "root") ||
+ %w{cookbooks cookbook_artifacts data policies policy_groups}.include?(path[2]))
else
return false
end
diff --git a/lib/chef_zero/data_store/data_already_exists_error.rb b/lib/chef_zero/data_store/data_already_exists_error.rb
index 54116d0..60f5b57 100644
--- a/lib/chef_zero/data_store/data_already_exists_error.rb
+++ b/lib/chef_zero/data_store/data_already_exists_error.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-require 'chef_zero/data_store/data_error'
+require "chef_zero/data_store/data_error"
module ChefZero
module DataStore
diff --git a/lib/chef_zero/data_store/data_not_found_error.rb b/lib/chef_zero/data_store/data_not_found_error.rb
index a73d767..508b460 100644
--- a/lib/chef_zero/data_store/data_not_found_error.rb
+++ b/lib/chef_zero/data_store/data_not_found_error.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-require 'chef_zero/data_store/data_error'
+require "chef_zero/data_store/data_error"
module ChefZero
module DataStore
@@ -26,4 +26,4 @@ module ChefZero
end
end
end
-end \ No newline at end of file
+end
diff --git a/lib/chef_zero/data_store/default_facade.rb b/lib/chef_zero/data_store/default_facade.rb
index c941322..5e932d5 100644
--- a/lib/chef_zero/data_store/default_facade.rb
+++ b/lib/chef_zero/data_store/default_facade.rb
@@ -1,5 +1,5 @@
-require 'chef_zero/data_store/interface_v2'
-require 'chef_zero/chef_data/default_creator'
+require "chef_zero/data_store/interface_v2"
+require "chef_zero/chef_data/default_creator"
module ChefZero
module DataStore
@@ -65,7 +65,7 @@ module ChefZero
default_creator.created(path + [ name ], options_hash[:requestor], options.include?(:create_dir))
end
- def get(path, request=nil)
+ def get(path, request = nil)
begin
real_store.get(path, request)
rescue DataNotFoundError
@@ -83,8 +83,8 @@ module ChefZero
real_store.set(path, data, *options)
rescue DataNotFoundError
if options.include?(:create_dir) ||
- options.include?(:create) && default_creator.exists?(path[0..-2]) ||
- default_creator.exists?(path)
+ options.include?(:create) && default_creator.exists?(path[0..-2]) ||
+ default_creator.exists?(path)
real_store.set(path, data, :create, :create_dir, *options)
else
raise
diff --git a/lib/chef_zero/data_store/interface_v1.rb b/lib/chef_zero/data_store/interface_v1.rb
index 8630a35..0a406f5 100644
--- a/lib/chef_zero/data_store/interface_v1.rb
+++ b/lib/chef_zero/data_store/interface_v1.rb
@@ -24,7 +24,7 @@ module ChefZero
end
# Get a file.
- def get(path, request=nil)
+ def get(path, request = nil)
raise "get not implemented by class #{self.class}"
end
diff --git a/lib/chef_zero/data_store/interface_v2.rb b/lib/chef_zero/data_store/interface_v2.rb
index fa1ba41..8c02e2e 100644
--- a/lib/chef_zero/data_store/interface_v2.rb
+++ b/lib/chef_zero/data_store/interface_v2.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/data_store/interface_v1'
+require "chef_zero/data_store/interface_v1"
module ChefZero
module DataStore
diff --git a/lib/chef_zero/data_store/memory_store.rb b/lib/chef_zero/data_store/memory_store.rb
index bfbe9d6..fa2a9cf 100644
--- a/lib/chef_zero/data_store/memory_store.rb
+++ b/lib/chef_zero/data_store/memory_store.rb
@@ -16,16 +16,16 @@
# limitations under the License.
#
-require 'chef_zero/data_store/v2_to_v1_adapter'
-require 'chef_zero/data_store/memory_store_v2'
-require 'chef_zero/data_store/default_facade'
+require "chef_zero/data_store/v2_to_v1_adapter"
+require "chef_zero/data_store/memory_store_v2"
+require "chef_zero/data_store/default_facade"
module ChefZero
module DataStore
class MemoryStore < ChefZero::DataStore::V2ToV1Adapter
def initialize
super
- @real_store = ChefZero::DataStore::DefaultFacade.new(ChefZero::DataStore::MemoryStoreV2.new, 'chef', true)
+ @real_store = ChefZero::DataStore::DefaultFacade.new(ChefZero::DataStore::MemoryStoreV2.new, "chef", true)
clear
end
end
diff --git a/lib/chef_zero/data_store/memory_store_v2.rb b/lib/chef_zero/data_store/memory_store_v2.rb
index d330972..c2f2d8e 100644
--- a/lib/chef_zero/data_store/memory_store_v2.rb
+++ b/lib/chef_zero/data_store/memory_store_v2.rb
@@ -16,9 +16,9 @@
# limitations under the License.
#
-require 'chef_zero/data_store/data_already_exists_error'
-require 'chef_zero/data_store/data_not_found_error'
-require 'chef_zero/data_store/interface_v2'
+require "chef_zero/data_store/data_already_exists_error"
+require "chef_zero/data_store/data_not_found_error"
+require "chef_zero/data_store/interface_v2"
module ChefZero
module DataStore
@@ -58,7 +58,7 @@ module ChefZero
parent[name] = data
end
- def get(path, request=nil)
+ def get(path, request = nil)
value = _get(path)
if value.is_a?(Hash)
raise "get() called on directory #{path.join('/')}"
@@ -81,7 +81,7 @@ module ChefZero
end
def delete(path)
- parent = _get(path[0,path.length-1])
+ parent = _get(path[0, path.length - 1])
if !parent.has_key?(path[-1])
raise DataNotFoundError.new(path)
end
@@ -92,7 +92,7 @@ module ChefZero
end
def delete_dir(path, *options)
- parent = _get(path[0,path.length-1])
+ parent = _get(path[0, path.length - 1])
if !parent.has_key?(path[-1])
raise DataNotFoundError.new(path)
end
@@ -136,14 +136,14 @@ module ChefZero
private
- def _get(path, create_dir=false)
+ def _get(path, create_dir = false)
value = @data
path.each_with_index do |path_part, index|
if !value.has_key?(path_part)
if create_dir
value[path_part] = {}
else
- raise DataNotFoundError.new(path[0,index+1])
+ raise DataNotFoundError.new(path[0, index + 1])
end
end
value = value[path_part]
diff --git a/lib/chef_zero/data_store/raw_file_store.rb b/lib/chef_zero/data_store/raw_file_store.rb
index dce6374..120fc1b 100644
--- a/lib/chef_zero/data_store/raw_file_store.rb
+++ b/lib/chef_zero/data_store/raw_file_store.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-require 'chef_zero/data_store/data_already_exists_error'
-require 'chef_zero/data_store/data_not_found_error'
-require 'chef_zero/data_store/interface_v2'
-require 'fileutils'
+require "chef_zero/data_store/data_already_exists_error"
+require "chef_zero/data_store/data_not_found_error"
+require "chef_zero/data_store/interface_v2"
+require "fileutils"
module ChefZero
module DataStore
@@ -32,7 +32,7 @@ module ChefZero
attr_reader :root
attr_reader :destructible
- def path_to(path, name=nil)
+ def path_to(path, name = nil)
if name
File.join(root, *path, name)
else
@@ -43,7 +43,7 @@ module ChefZero
def clear
if destructible
Dir.entries(root).each do |entry|
- next if entry == '.' || entry == '..'
+ next if entry == "." || entry == ".."
FileUtils.rm_rf(Path.join(root, entry))
end
end
@@ -69,7 +69,7 @@ module ChefZero
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
@@ -79,7 +79,7 @@ module ChefZero
end
end
- def get(path, request=nil)
+ def get(path, request = nil)
begin
return IO.read(path_to(path))
rescue Errno::ENOENT
@@ -92,7 +92,7 @@ module ChefZero
FileUtils.mkdir_p(path_to(path[0..-2]))
end
begin
- mode = File::WRONLY|File::TRUNC|File::BINARY
+ mode = File::WRONLY | File::TRUNC | File::BINARY
if options.include?(:create)
mode |= File::CREAT
end
@@ -129,7 +129,7 @@ module ChefZero
def list(path)
begin
- Dir.entries(path_to(path)).select { |entry| entry != '.' && entry != '..' }.to_a
+ Dir.entries(path_to(path)).select { |entry| entry != "." && entry != ".." }.to_a
rescue Errno::ENOENT
raise DataNotFoundError.new(path)
end
diff --git a/lib/chef_zero/data_store/v1_to_v2_adapter.rb b/lib/chef_zero/data_store/v1_to_v2_adapter.rb
index d9ea6e1..dba35b3 100644
--- a/lib/chef_zero/data_store/v1_to_v2_adapter.rb
+++ b/lib/chef_zero/data_store/v1_to_v2_adapter.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/data_store/interface_v2'
+require "chef_zero/data_store/interface_v2"
module ChefZero
module DataStore
@@ -35,13 +35,13 @@ module ChefZero
end
end
- def get(path, request=nil)
+ def get(path, request = nil)
raise DataNotFoundError.new(path) if skip_organizations?(path)
fix_exceptions do
# Make it so build_uri will include /organizations/ORG inside the V1 data store
if request && request.rest_base_prefix.size == 0
old_base_uri = request.base_uri
- request.base_uri = File.join(request.base_uri, 'organizations', single_org)
+ request.base_uri = File.join(request.base_uri, "organizations", single_org)
end
begin
real_store.get(path[2..-1], request)
@@ -75,8 +75,8 @@ module ChefZero
def list(path)
raise DataNotFoundError.new(path) if skip_organizations?(path)
if path == []
- [ 'organizations' ]
- elsif path == [ 'organizations' ]
+ [ "organizations" ]
+ elsif path == [ "organizations" ]
[ single_org ]
else
fix_exceptions do
@@ -96,7 +96,7 @@ module ChefZero
return false if skip_organizations?(path)
if path == []
true
- elsif path == [ 'organizations' ] || path == [ 'users' ]
+ elsif path == [ "organizations" ] || path == [ "users" ]
true
else
return false if skip_organizations?(path)
@@ -112,11 +112,11 @@ module ChefZero
begin
yield
rescue DataAlreadyExistsError => e
- err = DataAlreadyExistsError.new([ 'organizations', single_org ] + e.path, e)
+ err = DataAlreadyExistsError.new([ "organizations", single_org ] + e.path, e)
err.set_backtrace(e.backtrace)
raise err
rescue DataNotFoundError => e
- err = DataNotFoundError.new([ 'organizations', single_org ] + e.path, e)
+ err = DataNotFoundError.new([ "organizations", single_org ] + e.path, e)
err.set_backtrace(e.backtrace)
raise e
end
@@ -125,7 +125,7 @@ module ChefZero
def skip_organizations?(path, name = nil)
if path == []
false
- elsif path[0] == 'organizations'
+ elsif path[0] == "organizations"
if path.size == 1
false
elsif path.size >= 2 && path[1] != single_org
diff --git a/lib/chef_zero/data_store/v2_to_v1_adapter.rb b/lib/chef_zero/data_store/v2_to_v1_adapter.rb
index d663657..f2cbce0 100644
--- a/lib/chef_zero/data_store/v2_to_v1_adapter.rb
+++ b/lib/chef_zero/data_store/v2_to_v1_adapter.rb
@@ -16,13 +16,13 @@
# limitations under the License.
#
-require 'chef_zero/data_store/interface_v1'
+require "chef_zero/data_store/interface_v1"
module ChefZero
module DataStore
class V2ToV1Adapter < ChefZero::DataStore::InterfaceV1
def initialize
- @single_org = 'chef'
+ @single_org = "chef"
end
attr_reader :real_store
@@ -30,7 +30,7 @@ module ChefZero
def clear
real_store.clear
- real_store.create_dir([ 'organizations' ], single_org, :recursive)
+ real_store.create_dir([ "organizations" ], single_org, :recursive)
end
def create_dir(path, name, *options)
@@ -45,7 +45,7 @@ module ChefZero
end
end
- def get(path, request=nil)
+ def get(path, request = nil)
fix_exceptions do
real_store.get(fix_path(path), request)
end
@@ -100,7 +100,7 @@ module ChefZero
end
def fix_path(path)
- [ 'organizations', single_org ] + path
+ [ "organizations", single_org ] + path
end
end
end
diff --git a/lib/chef_zero/endpoints/acl_endpoint.rb b/lib/chef_zero/endpoints/acl_endpoint.rb
index cca8392..366bb89 100644
--- a/lib/chef_zero/endpoints/acl_endpoint.rb
+++ b/lib/chef_zero/endpoints/acl_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'chef_zero/chef_data/acl_path'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "chef_zero/chef_data/acl_path"
module ChefZero
module Endpoints
@@ -17,10 +17,10 @@ module ChefZero
class AclEndpoint < RestBase
def validate_request(request)
path = request.rest_path[0..-3] # Strip off _acl/PERM
- path = path[0..1] if path.size == 3 && path[0] == 'organizations' && %w(organization organizations).include?(path[2])
+ path = path[0..1] if path.size == 3 && path[0] == "organizations" && %w{organization organizations}.include?(path[2])
acl_path = ChefData::AclPath.get_acl_data_path(path)
perm = request.rest_path[-1]
- if !acl_path || !%w(read create update delete grant).include?(perm)
+ if !acl_path || !%w{read create update delete grant}.include?(perm)
raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
end
[acl_path, perm]
@@ -31,7 +31,7 @@ module ChefZero
acls = FFI_Yajl::Parser.parse(get_data(request, path), :create_additions => false)
acls[perm] = FFI_Yajl::Parser.parse(request.body, :create_additions => false)[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)}" })
end
end
end
diff --git a/lib/chef_zero/endpoints/acls_endpoint.rb b/lib/chef_zero/endpoints/acls_endpoint.rb
index ad9bb31..8565eea 100644
--- a/lib/chef_zero/endpoints/acls_endpoint.rb
+++ b/lib/chef_zero/endpoints/acls_endpoint.rb
@@ -1,7 +1,7 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'chef_zero/chef_data/data_normalizer'
-require 'chef_zero/chef_data/acl_path'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "chef_zero/chef_data/data_normalizer"
+require "chef_zero/chef_data/acl_path"
module ChefZero
module Endpoints
@@ -15,7 +15,7 @@ module ChefZero
class AclsEndpoint < RestBase
def get(request)
path = request.rest_path[0..-2] # Strip off _acl
- path = path[0..1] if path.size == 3 && path[0] == 'organizations' && %w(organization organizations).include?(path[2])
+ path = path[0..1] if path.size == 3 && path[0] == "organizations" && %w{organization organizations}.include?(path[2])
acl_path = ChefData::AclPath.get_acl_data_path(path)
if !acl_path
raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
diff --git a/lib/chef_zero/endpoints/actor_default_key_endpoint.rb b/lib/chef_zero/endpoints/actor_default_key_endpoint.rb
index 3be1475..1985dea 100644
--- a/lib/chef_zero/endpoints/actor_default_key_endpoint.rb
+++ b/lib/chef_zero/endpoints/actor_default_key_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/rest_base'
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/actor_endpoint.rb b/lib/chef_zero/endpoints/actor_endpoint.rb
index dd2caf2..ea5284e 100644
--- a/lib/chef_zero/endpoints/actor_endpoint.rb
+++ b/lib/chef_zero/endpoints/actor_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_object_endpoint'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
@@ -21,10 +21,10 @@ module ChefZero
def delete(request)
result = super
- if request.rest_path[0] == 'users'
- list_data(request, [ 'organizations' ]).each do |org|
+ if request.rest_path[0] == "users"
+ list_data(request, [ "organizations" ]).each do |org|
begin
- delete_data(request, [ 'organizations', org, 'users', request.rest_path[1] ], :data_store_exceptions)
+ delete_data(request, [ "organizations", org, "users", request.rest_path[1] ], :data_store_exceptions)
rescue DataStore::DataNotFoundError
end
end
@@ -38,22 +38,22 @@ module ChefZero
# Find out if we're updating the public key.
request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
- if request_body['public_key'].nil?
+ if request_body["public_key"].nil?
# If public_key is null, then don't overwrite it. Weird patchiness.
body_modified = true
- request_body.delete('public_key')
+ request_body.delete("public_key")
else
updating_public_key = true
end
# Generate private_key if requested.
- if request_body.key?('private_key')
+ if request_body.key?("private_key")
body_modified = true
- if request_body.delete('private_key')
+ if request_body.delete("private_key")
private_key, public_key = server.gen_key_pair
updating_public_key = true
- request_body['public_key'] = public_key
+ request_body["public_key"] = public_key
end
end
@@ -73,22 +73,22 @@ module ChefZero
rename_keys!(request, client_or_user_name)
end
- if request.rest_path[0] == 'users'
+ if request.rest_path[0] == "users"
response = {
- 'uri' => build_uri(request.base_uri, [ 'users', client_or_user_name ])
+ "uri" => build_uri(request.base_uri, [ "users", client_or_user_name ]),
}
else
response = parse_json(result[2])
end
if client?(request)
- response['private_key'] = private_key ? private_key : false
+ response["private_key"] = private_key ? private_key : false
else
- response['private_key'] = private_key if private_key
- response.delete('public_key') unless updating_public_key
+ response["private_key"] = private_key if private_key
+ response.delete("public_key") unless updating_public_key
end
- response.delete('password')
+ response.delete("password")
json_response(result[0], response)
else
@@ -125,7 +125,7 @@ module ChefZero
def rename_keys!(request, new_client_or_user_name)
orig_keys_path = keys_path_base(request)
new_keys_path = orig_keys_path.dup
- .tap {|path| path[-2] = new_client_or_user_name }
+ .tap { |path| path[-2] = new_client_or_user_name }
key_names = list_data_or_else(request, orig_keys_path, nil)
return unless key_names # No keys to move
@@ -154,7 +154,7 @@ module ChefZero
rescue DataStore::DataNotFoundError
end
- def client?(request, rest_path=nil)
+ def client?(request, rest_path = nil)
rest_path ||= request.rest_path
request.rest_path[2] == "clients"
end
@@ -165,7 +165,7 @@ module ChefZero
# /organizations/ORG/users/USER -> /organizations/ORG/user_keys/USER/keys
# /users/USER -> /user_keys/USER
#
- def keys_path_base(request, client_or_user_name=nil)
+ def keys_path_base(request, client_or_user_name = nil)
rest_path = (rest_path || request.rest_path).dup
rest_path = rest_path.dup
case rest_path[-2]
diff --git a/lib/chef_zero/endpoints/actor_key_endpoint.rb b/lib/chef_zero/endpoints/actor_key_endpoint.rb
index f2b65ed..a61d2f3 100644
--- a/lib/chef_zero/endpoints/actor_key_endpoint.rb
+++ b/lib/chef_zero/endpoints/actor_key_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/rest_base'
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/actor_keys_endpoint.rb b/lib/chef_zero/endpoints/actor_keys_endpoint.rb
index f3624d6..00c11d0 100644
--- a/lib/chef_zero/endpoints/actor_keys_endpoint.rb
+++ b/lib/chef_zero/endpoints/actor_keys_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/rest_base'
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -8,7 +8,7 @@ module ChefZero
DEFAULT_PUBLIC_KEY_NAME = "default"
DATE_FORMAT = "%FT%TZ" # e.g. 2015-12-24T21:00:00Z
- def get(request, alt_uri_root=nil)
+ def get(request, alt_uri_root = nil)
path = data_path(request)
# Get actor or 404 if it doesn't exist
@@ -35,7 +35,7 @@ module ChefZero
if generate_keys
private_key, public_key = server.gen_key_pair
else
- public_key = request_body['public_key']
+ public_key = request_body["public_key"]
end
key_name = request_body["name"]
@@ -74,7 +74,6 @@ module ChefZero
actor_data["public_key"] = public_key
set_data(request, actor_path(request), to_json(actor_data))
-
end
# Returns the keys data store path, which is the same as
@@ -90,7 +89,7 @@ module ChefZero
end
end
- def list_key(request, data_path, alt_uri_root=nil)
+ def list_key(request, data_path, alt_uri_root = nil)
key_name, expiration_date =
if data_path[-1] == DEFAULT_PUBLIC_KEY_NAME
[ DEFAULT_PUBLIC_KEY_NAME, "infinity" ]
@@ -111,7 +110,7 @@ module ChefZero
request.rest_path[2] == "clients"
end
- def key_uri(request, key_name, alt_uri_root=nil)
+ def key_uri(request, key_name, alt_uri_root = nil)
uri_root = alt_uri_root.nil? ? request.rest_path : alt_uri_root
build_uri(request.base_uri, [ *uri_root, key_name ])
end
diff --git a/lib/chef_zero/endpoints/actors_endpoint.rb b/lib/chef_zero/endpoints/actors_endpoint.rb
index 6297aed..1dcbe42 100644
--- a/lib/chef_zero/endpoints/actors_endpoint.rb
+++ b/lib/chef_zero/endpoints/actors_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_list_endpoint'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_list_endpoint"
module ChefZero
module Endpoints
@@ -10,13 +10,13 @@ module ChefZero
# apply query filters: if one applies, stop processing rest
# (precendence matches chef-server: https://github.com/chef/chef-server/blob/268a0c9/src/oc_erchef/apps/chef_objects/src/chef_user.erl#L554-L559)
- if value = request.query_params['external_authentication_uid']
- response[2] = filter('external_authentication_uid', value, request, response[2])
- elsif value = request.query_params['email']
- response[2] = filter('email', value, request, response[2])
+ if value = request.query_params["external_authentication_uid"]
+ response[2] = filter("external_authentication_uid", value, request, response[2])
+ elsif value = request.query_params["email"]
+ response[2] = filter("email", value, request, response[2])
end
- if request.query_params['verbose']
+ if request.query_params["verbose"]
results = parse_json(response[2])
results.each do |name, url|
record = get_data(request, request.rest_path + [ name ], :nil)
@@ -35,16 +35,16 @@ module ChefZero
# First, find out if the user actually posted a public key. If not, make
# one.
request_body = parse_json(request.body)
- public_key = request_body['public_key']
+ public_key = request_body["public_key"]
skip_key_create = !request.api_v0? && !request_body["create_key"]
if !public_key && !skip_key_create
private_key, public_key = server.gen_key_pair
- request_body['public_key'] = public_key
+ request_body["public_key"] = public_key
request.body = to_json(request_body)
elsif skip_key_create
- request_body['public_key'] = nil
+ request_body["public_key"] = nil
request.body = to_json(request_body)
end
@@ -55,8 +55,8 @@ module ChefZero
user_data = parse_json(result[2])
key_data = {}
- key_data['private_key'] = private_key if private_key
- key_data['public_key'] = public_key unless request.rest_path[0] == 'users'
+ key_data["private_key"] = private_key if private_key
+ key_data["public_key"] = public_key unless request.rest_path[0] == "users"
response =
if request.api_v0?
diff --git a/lib/chef_zero/endpoints/authenticate_user_endpoint.rb b/lib/chef_zero/endpoints/authenticate_user_endpoint.rb
index 5d5bb3b..fd26798 100644
--- a/lib/chef_zero/endpoints/authenticate_user_endpoint.rb
+++ b/lib/chef_zero/endpoints/authenticate_user_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -7,23 +7,23 @@ module ChefZero
class AuthenticateUserEndpoint < RestBase
def post(request)
request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
- name = request_json['username']
- password = request_json['password']
+ name = request_json["username"]
+ password = request_json["password"]
begin
- user = data_store.get(['users', name])
+ user = data_store.get(["users", name])
rescue ChefZero::DataStore::DataNotFoundError
raise RestErrorResponse.new(401, "Bad username or password")
end
user = FFI_Yajl::Parser.parse(user, :create_additions => false)
- user = ChefData::DataNormalizer.normalize_user(user, name, [ 'username' ], server.options[:osc_compat])
- if user['password'] != password
+ user = ChefData::DataNormalizer.normalize_user(user, name, [ "username" ], server.options[:osc_compat])
+ if user["password"] != password
raise RestErrorResponse.new(401, "Bad username or password")
end
# Include only particular user data in the response
- user.keep_if { |key,value| %w(first_name last_name display_name email username).include?(key) }
+ user.keep_if { |key, value| %w{first_name last_name display_name email username}.include?(key) }
json_response(200, {
- 'status' => 'linked',
- 'user' => user
+ "status" => "linked",
+ "user" => user,
})
end
end
diff --git a/lib/chef_zero/endpoints/container_endpoint.rb b/lib/chef_zero/endpoints/container_endpoint.rb
index bf0a184..588d787 100644
--- a/lib/chef_zero/endpoints/container_endpoint.rb
+++ b/lib/chef_zero/endpoints/container_endpoint.rb
@@ -1,13 +1,13 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_object_endpoint'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
# /organizations/ORG/containers/NAME
class ContainerEndpoint < RestObjectEndpoint
def initialize(server)
- super(server, %w(id containername))
+ super(server, %w{id containername})
end
undef_method(:put)
diff --git a/lib/chef_zero/endpoints/containers_endpoint.rb b/lib/chef_zero/endpoints/containers_endpoint.rb
index 8a4220f..e8708ed 100644
--- a/lib/chef_zero/endpoints/containers_endpoint.rb
+++ b/lib/chef_zero/endpoints/containers_endpoint.rb
@@ -1,12 +1,12 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_list_endpoint'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_list_endpoint"
module ChefZero
module Endpoints
# /organizations/ORG/containers
class ContainersEndpoint < RestListEndpoint
def initialize(server)
- super(server, %w(id containername))
+ super(server, %w{id containername})
end
# create a container.
diff --git a/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb b/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb
index e17fea2..baf80d3 100644
--- a/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/chef_data/data_normalizer'
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb b/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb
index b70e2c4..237f9c9 100644
--- a/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/chef_data/data_normalizer'
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb b/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
index d9fdb20..a105664 100644
--- a/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/chef_data/data_normalizer'
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/cookbook_endpoint.rb b/lib/chef_zero/endpoints/cookbook_endpoint.rb
index 35919ad..7dce172 100644
--- a/lib/chef_zero/endpoints/cookbook_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/endpoints/cookbooks_base'
+require "chef_zero/endpoints/cookbooks_base"
module ChefZero
module Endpoints
@@ -7,19 +7,19 @@ module ChefZero
def get(request)
filter = request.rest_path[3]
case filter
- when '_latest'
+ when "_latest"
result = {}
filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
if versions.size > 0
- result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ['cookbooks', name, versions[0]])
+ result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name, versions[0]])
end
end
json_response(200, result)
- when '_recipes'
+ when "_recipes"
result = []
filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions|
if versions.size > 0
- cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
+ cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]]), :create_additions => false)
result += recipe_names(name, cookbook)
end
end
diff --git a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
index 5502ba0..55acd1a 100644
--- a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
@@ -1,8 +1,8 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_object_endpoint'
-require 'chef_zero/rest_error_response'
-require 'chef_zero/chef_data/data_normalizer'
-require 'chef_zero/data_store/data_not_found_error'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/rest_error_response"
+require "chef_zero/chef_data/data_normalizer"
+require "chef_zero/data_store/data_not_found_error"
module ChefZero
module Endpoints
@@ -23,14 +23,14 @@ module ChefZero
# Honor frozen
if existing_cookbook
existing_cookbook_json = FFI_Yajl::Parser.parse(existing_cookbook, :create_additions => false)
- if existing_cookbook_json['frozen?']
- if request.query_params['force'] != "true"
+ if existing_cookbook_json["frozen?"]
+ if request.query_params["force"] != "true"
raise RestErrorResponse.new(409, "The cookbook #{name} at version #{version} is frozen. Use the 'force' option to override.")
end
# For some reason, you are forever unable to modify "frozen?" on a frozen cookbook.
request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
- if !request_body['frozen?']
- request_body['frozen?'] = true
+ if !request_body["frozen?"]
+ request_body["frozen?"] = true
request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true)
end
end
@@ -74,8 +74,8 @@ module ChefZero
FFI_Yajl::Parser.parse(cookbook, :create_additions => false).each_pair do |key, value|
if value.is_a?(Array)
value.each do |file|
- if file.is_a?(Hash) && file.has_key?('checksum')
- result << file['checksum']
+ if file.is_a?(Hash) && file.has_key?("checksum")
+ result << file["checksum"]
end
end
end
@@ -86,7 +86,7 @@ module ChefZero
private
def hoover_unused_checksums(deleted_checksums, request)
- %w(cookbooks cookbook_artifacts).each do |cookbook_type|
+ %w{cookbooks cookbook_artifacts}.each do |cookbook_type|
begin
cookbooks = data_store.list(request.rest_path[0..1] + [cookbook_type])
rescue ChefZero::DataStore::DataNotFoundError
@@ -106,7 +106,7 @@ module ChefZero
# This deals with an exception on delete, but things can still get deleted
# that shouldn't be.
begin
- delete_data(request, request.rest_path[0..1] + ['file_store', 'checksums', checksum], :data_store_exceptions)
+ delete_data(request, request.rest_path[0..1] + ["file_store", "checksums", checksum], :data_store_exceptions)
rescue ChefZero::DataStore::DataNotFoundError
end
end
diff --git a/lib/chef_zero/endpoints/cookbooks_base.rb b/lib/chef_zero/endpoints/cookbooks_base.rb
index d138af9..10d1b5b 100644
--- a/lib/chef_zero/endpoints/cookbooks_base.rb
+++ b/lib/chef_zero/endpoints/cookbooks_base.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
@@ -11,13 +11,13 @@ module ChefZero
filter_cookbooks(cookbooks_list, constraints, num_versions) do |name, versions|
versions_list = versions.map do |version|
{
- 'url' => build_uri(request.base_uri, request.rest_path[0..1] + ['cookbooks', name, version]),
- 'version' => version
+ "url" => build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name, version]),
+ "version" => version,
}
end
results[name] = {
- 'url' => build_uri(request.base_uri, request.rest_path[0..1] + ['cookbooks', name]),
- 'versions' => versions_list
+ "url" => build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name]),
+ "versions" => versions_list,
}
end
results
@@ -26,8 +26,8 @@ module ChefZero
def all_cookbooks_list(request)
result = {}
# Race conditions exist here (if someone deletes while listing). I don't care.
- data_store.list(request.rest_path[0..1] + ['cookbooks']).each do |name|
- result[name] = data_store.list(request.rest_path[0..1] + ['cookbooks', name])
+ data_store.list(request.rest_path[0..1] + ["cookbooks"]).each do |name|
+ result[name] = data_store.list(request.rest_path[0..1] + ["cookbooks", name])
end
result
end
@@ -48,10 +48,10 @@ module ChefZero
def recipe_names(cookbook_name, cookbook)
result = []
- if cookbook['recipes']
- cookbook['recipes'].each do |recipe|
- if recipe['path'] == "recipes/#{recipe['name']}" && recipe['name'][-3..-1] == '.rb'
- if recipe['name'] == 'default.rb'
+ if cookbook["recipes"]
+ cookbook["recipes"].each do |recipe|
+ if recipe["path"] == "recipes/#{recipe['name']}" && recipe["name"][-3..-1] == ".rb"
+ if recipe["name"] == "default.rb"
result << cookbook_name
end
result << "#{cookbook_name}::#{recipe['name'][0..-4]}"
diff --git a/lib/chef_zero/endpoints/cookbooks_endpoint.rb b/lib/chef_zero/endpoints/cookbooks_endpoint.rb
index 7aaf3e6..e3e2ebe 100644
--- a/lib/chef_zero/endpoints/cookbooks_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbooks_endpoint.rb
@@ -1,14 +1,14 @@
-require 'chef_zero/endpoints/cookbooks_base'
+require "chef_zero/endpoints/cookbooks_base"
module ChefZero
module Endpoints
# /cookbooks
class CookbooksEndpoint < CookbooksBase
def get(request)
- if request.query_params['num_versions'] == 'all'
+ if request.query_params["num_versions"] == "all"
num_versions = nil
- elsif request.query_params['num_versions']
- num_versions = request.query_params['num_versions'].to_i
+ elsif request.query_params["num_versions"]
+ num_versions = request.query_params["num_versions"].to_i
else
num_versions = 1
end
diff --git a/lib/chef_zero/endpoints/data_bag_endpoint.rb b/lib/chef_zero/endpoints/data_bag_endpoint.rb
index f7a6142..2f754cf 100644
--- a/lib/chef_zero/endpoints/data_bag_endpoint.rb
+++ b/lib/chef_zero/endpoints/data_bag_endpoint.rb
@@ -1,14 +1,14 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_list_endpoint'
-require 'chef_zero/endpoints/data_bag_item_endpoint'
-require 'chef_zero/rest_error_response'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_list_endpoint"
+require "chef_zero/endpoints/data_bag_item_endpoint"
+require "chef_zero/rest_error_response"
module ChefZero
module Endpoints
# /data/NAME
class DataBagEndpoint < RestListEndpoint
def initialize(server)
- super(server, 'id')
+ super(server, "id")
end
def post(request)
@@ -16,7 +16,7 @@ module ChefZero
key = identity_keys.map { |k| json[k] }.select { |v| v }.first
response = super(request)
if response[0] == 201
- already_json_response(201, DataBagItemEndpoint::populate_defaults(request, request.body, request.rest_path[3], key))
+ already_json_response(201, DataBagItemEndpoint.populate_defaults(request, request.body, request.rest_path[3], key))
else
response
end
@@ -24,10 +24,10 @@ module ChefZero
def get_key(contents)
data_bag_item = FFI_Yajl::Parser.parse(contents, :create_additions => false)
- if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
- data_bag_item['raw_data']['id']
+ if data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"]
+ data_bag_item["raw_data"]["id"]
else
- data_bag_item['id']
+ data_bag_item["id"]
end
end
@@ -35,9 +35,9 @@ module ChefZero
key = request.rest_path[3]
delete_data_dir(request, request.rest_path, :recursive)
json_response(200, {
- 'chef_type' => 'data_bag',
- 'json_class' => 'Chef::DataBag',
- 'name' => key
+ "chef_type" => "data_bag",
+ "json_class" => "Chef::DataBag",
+ "name" => key,
})
end
end
diff --git a/lib/chef_zero/endpoints/data_bag_item_endpoint.rb b/lib/chef_zero/endpoints/data_bag_item_endpoint.rb
index a1dd71c..79bfedd 100644
--- a/lib/chef_zero/endpoints/data_bag_item_endpoint.rb
+++ b/lib/chef_zero/endpoints/data_bag_item_endpoint.rb
@@ -1,18 +1,18 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_object_endpoint'
-require 'chef_zero/endpoints/data_bag_item_endpoint'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/endpoints/data_bag_item_endpoint"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
# /data/NAME/NAME
class DataBagItemEndpoint < RestObjectEndpoint
def initialize(server)
- super(server, 'id')
+ super(server, "id")
end
def populate_defaults(request, response_json)
- DataBagItemEndpoint::populate_defaults(request, response_json, request.rest_path[3], request.rest_path[4])
+ DataBagItemEndpoint.populate_defaults(request, response_json, request.rest_path[3], request.rest_path[4])
end
def self.populate_defaults(request, response_json, data_bag, data_bag_item)
diff --git a/lib/chef_zero/endpoints/data_bags_endpoint.rb b/lib/chef_zero/endpoints/data_bags_endpoint.rb
index 3694602..03791b0 100644
--- a/lib/chef_zero/endpoints/data_bags_endpoint.rb
+++ b/lib/chef_zero/endpoints/data_bags_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_list_endpoint'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_list_endpoint"
module ChefZero
module Endpoints
@@ -11,11 +11,11 @@ module ChefZero
name = identity_keys.map { |k| json[k] }.select { |v| v }.first
if name.nil?
error(400, "Must specify #{identity_keys.map { |k| k.inspect }.join(' or ')} in JSON")
- elsif exists_data_dir?(request, request.rest_path[0..1] + ['data', name])
+ elsif exists_data_dir?(request, request.rest_path[0..1] + ["data", name])
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])}"})
+ 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])}" })
end
end
end
diff --git a/lib/chef_zero/endpoints/dummy_endpoint.rb b/lib/chef_zero/endpoints/dummy_endpoint.rb
index fe16a7e..08dc30b 100644
--- a/lib/chef_zero/endpoints/dummy_endpoint.rb
+++ b/lib/chef_zero/endpoints/dummy_endpoint.rb
@@ -7,7 +7,6 @@ module ChefZero
# called by #direct_solr_query, once each for roles, nodes, and data bag items. each RSpec example makes
# 3 calls, with the expected sequence of return values [0, 1, 0].
def get(request)
-
# this could be made less brittle, but if things change to have more than 3 cycles, we should really
# be notified by a spec failure.
@mock_values ||= ([0, 1, 0] * 3).map { |val| make_response(val) }
@@ -28,4 +27,3 @@ module ChefZero
end
end
end
-
diff --git a/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb
index 2554c98..692244d 100644
--- a/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/cookbooks_base'
+require "ffi_yajl"
+require "chef_zero/endpoints/cookbooks_base"
module ChefZero
module Endpoints
@@ -8,12 +8,12 @@ module ChefZero
def get(request)
cookbook_name = request.rest_path[5]
environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
- constraints = environment['cookbook_versions'] || {}
+ constraints = environment["cookbook_versions"] || {}
cookbook_versions = list_data(request, request.rest_path[0..1] + request.rest_path[4..5])
- if request.query_params['num_versions'] == 'all'
+ if request.query_params["num_versions"] == "all"
num_versions = nil
- elsif request.query_params['num_versions']
- num_versions = request.query_params['num_versions'].to_i
+ elsif request.query_params["num_versions"]
+ num_versions = request.query_params["num_versions"].to_i
else
num_versions = nil
end
diff --git a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
index b11687b..8e693b5 100644
--- a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'chef_zero/rest_error_response'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "chef_zero/rest_error_response"
module ChefZero
module Endpoints
@@ -8,26 +8,26 @@ module ChefZero
class EnvironmentCookbookVersionsEndpoint < RestBase
def post(request)
- cookbook_names = list_data(request, request.rest_path[0..1] + ['cookbooks'])
+ cookbook_names = list_data(request, request.rest_path[0..1] + ["cookbooks"])
# Get the list of cookbooks and versions desired by the runlist
desired_versions = {}
- run_list = FFI_Yajl::Parser.parse(request.body, :create_additions => false)['run_list']
+ run_list = FFI_Yajl::Parser.parse(request.body, :create_additions => false)["run_list"]
run_list.each do |run_list_entry|
if run_list_entry =~ /(.+)::.+\@(.+)/ || run_list_entry =~ /(.+)\@(.+)/
raise RestErrorResponse.new(412, "No such cookbook: #{$1}") if !cookbook_names.include?($1)
- raise RestErrorResponse.new(412, "No such cookbook version for cookbook #{$1}: #{$2}") if !list_data(request, request.rest_path[0..1] + ['cookbooks', $1]).include?($2)
+ raise RestErrorResponse.new(412, "No such cookbook version for cookbook #{$1}: #{$2}") if !list_data(request, request.rest_path[0..1] + ["cookbooks", $1]).include?($2)
desired_versions[$1] = [ $2 ]
else
- desired_cookbook = run_list_entry.split('::')[0]
+ desired_cookbook = run_list_entry.split("::")[0]
raise RestErrorResponse.new(412, "No such cookbook: #{desired_cookbook}") if !cookbook_names.include?(desired_cookbook)
- desired_versions[desired_cookbook] = list_data(request, request.rest_path[0..1] + ['cookbooks', desired_cookbook])
+ desired_versions[desired_cookbook] = list_data(request, request.rest_path[0..1] + ["cookbooks", desired_cookbook])
end
end
# Filter by environment constraints
environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
- environment_constraints = environment['cookbook_versions'] || {}
+ environment_constraints = environment["cookbook_versions"] || {}
desired_versions.each_key do |name|
desired_versions = filter_by_constraint(desired_versions, name, environment_constraints[name])
@@ -48,8 +48,8 @@ module ChefZero
result = {}
solved.each_pair do |name, versions|
- cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
- result[name] = ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, name, versions[0], request.base_uri, 'MIN')
+ cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]]), :create_additions => false)
+ result[name] = ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, name, versions[0], request.base_uri, "MIN")
end
json_response(200, result)
end
@@ -74,9 +74,9 @@ module ChefZero
new_unsolved = unsolved[1..-1]
# Pick this cookbook, and add dependencies
- cookbook_obj = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', solve_for, desired_version]), :create_additions => false)
- cookbook_metadata = cookbook_obj['metadata'] || {}
- cookbook_dependencies = cookbook_metadata['dependencies'] || {}
+ cookbook_obj = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", solve_for, desired_version]), :create_additions => false)
+ cookbook_metadata = cookbook_obj["metadata"] || {}
+ cookbook_dependencies = cookbook_metadata["dependencies"] || {}
dep_not_found = false
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
@@ -84,12 +84,12 @@ module ChefZero
if !new_desired_versions.has_key?(dep_name)
new_unsolved = 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])
+ if !exists_data_dir?(request, request.rest_path[0..1] + ["cookbooks", dep_name])
@last_missing_dep = dep_name.to_s
dep_not_found = true
break
end
- new_desired_versions[dep_name] = list_data(request, request.rest_path[0..1] + ['cookbooks', dep_name])
+ new_desired_versions[dep_name] = list_data(request, request.rest_path[0..1] + ["cookbooks", dep_name])
new_desired_versions = filter_by_constraint(new_desired_versions, dep_name, environment_constraints[dep_name])
end
new_desired_versions = filter_by_constraint(new_desired_versions, dep_name, dep_constraint)
diff --git a/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb
index 166caa3..c243bd0 100644
--- a/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/cookbooks_base'
+require "ffi_yajl"
+require "chef_zero/endpoints/cookbooks_base"
module ChefZero
module Endpoints
@@ -7,11 +7,11 @@ module ChefZero
class EnvironmentCookbooksEndpoint < CookbooksBase
def get(request)
environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
- constraints = environment['cookbook_versions'] || {}
- if request.query_params['num_versions'] == 'all'
+ constraints = environment["cookbook_versions"] || {}
+ if request.query_params["num_versions"] == "all"
num_versions = nil
- elsif request.query_params['num_versions']
- num_versions = request.query_params['num_versions'].to_i
+ elsif request.query_params["num_versions"]
+ num_versions = request.query_params["num_versions"].to_i
else
num_versions = 1
end
diff --git a/lib/chef_zero/endpoints/environment_endpoint.rb b/lib/chef_zero/endpoints/environment_endpoint.rb
index 9d89f44..6d256e8 100644
--- a/lib/chef_zero/endpoints/environment_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_object_endpoint'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/environment_nodes_endpoint.rb b/lib/chef_zero/endpoints/environment_nodes_endpoint.rb
index e8eaca2..cffe596 100644
--- a/lib/chef_zero/endpoints/environment_nodes_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_nodes_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -10,10 +10,10 @@ module ChefZero
get_data(request, request.rest_path[0..3])
result = {}
- list_data(request, request.rest_path[0..1] + ['nodes']).each do |name|
- node = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['nodes', name]), :create_additions => false)
- if node['chef_environment'] == request.rest_path[3]
- result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ['nodes', name])
+ list_data(request, request.rest_path[0..1] + ["nodes"]).each do |name|
+ node = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["nodes", name]), :create_additions => false)
+ if node["chef_environment"] == request.rest_path[3]
+ result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ["nodes", name])
end
end
json_response(200, result)
diff --git a/lib/chef_zero/endpoints/environment_recipes_endpoint.rb b/lib/chef_zero/endpoints/environment_recipes_endpoint.rb
index 4ecd7e0..8165a68 100644
--- a/lib/chef_zero/endpoints/environment_recipes_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_recipes_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/cookbooks_base'
+require "ffi_yajl"
+require "chef_zero/endpoints/cookbooks_base"
module ChefZero
module Endpoints
@@ -7,11 +7,11 @@ module ChefZero
class EnvironmentRecipesEndpoint < CookbooksBase
def get(request)
environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
- constraints = environment['cookbook_versions'] || {}
+ constraints = environment["cookbook_versions"] || {}
result = []
filter_cookbooks(all_cookbooks_list(request), constraints, 1) do |name, versions|
if versions.size > 0
- cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
+ cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]]), :create_additions => false)
result += recipe_names(name, cookbook)
end
end
diff --git a/lib/chef_zero/endpoints/environment_role_endpoint.rb b/lib/chef_zero/endpoints/environment_role_endpoint.rb
index 2a87bb4..b05f28a 100644
--- a/lib/chef_zero/endpoints/environment_role_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_role_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/cookbooks_base'
+require "ffi_yajl"
+require "chef_zero/endpoints/cookbooks_base"
module ChefZero
module Endpoints
@@ -8,7 +8,7 @@ module ChefZero
class EnvironmentRoleEndpoint < CookbooksBase
def get(request)
# 404 if environment does not exist
- if request.rest_path[2] == 'environments'
+ if request.rest_path[2] == "environments"
environment_path = request.rest_path[0..1] + request.rest_path[2..3]
role_path = request.rest_path[0..1] + request.rest_path[4..5]
else
@@ -20,16 +20,16 @@ module ChefZero
role = FFI_Yajl::Parser.parse(get_data(request, role_path), :create_additions => false)
environment_name = environment_path[3]
- if environment_name == '_default'
- run_list = role['run_list']
+ if environment_name == "_default"
+ run_list = role["run_list"]
else
- if role['env_run_lists']
- run_list = role['env_run_lists'][environment_name]
+ if role["env_run_lists"]
+ run_list = role["env_run_lists"][environment_name]
else
run_list = nil
end
end
- json_response(200, { 'run_list' => run_list })
+ json_response(200, { "run_list" => run_list })
end
end
end
diff --git a/lib/chef_zero/endpoints/file_store_file_endpoint.rb b/lib/chef_zero/endpoints/file_store_file_endpoint.rb
index 4e20a5d..90b51da 100644
--- a/lib/chef_zero/endpoints/file_store_file_endpoint.rb
+++ b/lib/chef_zero/endpoints/file_store_file_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/rest_base'
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -10,7 +10,7 @@ module ChefZero
end
def get(request)
- [200, {"Content-Type" => 'application/x-binary'}, get_data(request) ]
+ [200, { "Content-Type" => "application/x-binary" }, get_data(request) ]
end
def put(request)
diff --git a/lib/chef_zero/endpoints/group_endpoint.rb b/lib/chef_zero/endpoints/group_endpoint.rb
index 7404d4d..fc21946 100644
--- a/lib/chef_zero/endpoints/group_endpoint.rb
+++ b/lib/chef_zero/endpoints/group_endpoint.rb
@@ -1,13 +1,13 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_object_endpoint'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
# /organizations/ORG/groups/NAME
class GroupEndpoint < RestObjectEndpoint
def initialize(server)
- super(server, %w(id groupname))
+ super(server, %w{id groupname})
end
def populate_defaults(request, response_json)
diff --git a/lib/chef_zero/endpoints/groups_endpoint.rb b/lib/chef_zero/endpoints/groups_endpoint.rb
index 3e75293..47cd101 100644
--- a/lib/chef_zero/endpoints/groups_endpoint.rb
+++ b/lib/chef_zero/endpoints/groups_endpoint.rb
@@ -1,12 +1,12 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_list_endpoint'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_list_endpoint"
module ChefZero
module Endpoints
# /organizations/ORG/groups/NAME
class GroupsEndpoint < RestListEndpoint
def initialize(server)
- super(server, %w(id groupname))
+ super(server, %w{id groupname})
end
end
end
diff --git a/lib/chef_zero/endpoints/license_endpoint.rb b/lib/chef_zero/endpoints/license_endpoint.rb
index 8638875..ec85834 100644
--- a/lib/chef_zero/endpoints/license_endpoint.rb
+++ b/lib/chef_zero/endpoints/license_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -9,15 +9,15 @@ module ChefZero
def get(request)
node_count = 0
- list_data(request, [ 'organizations' ]).each do |orgname|
- node_count += list_data(request, [ 'organizations', orgname, 'nodes' ]).size
+ list_data(request, [ "organizations" ]).each do |orgname|
+ node_count += list_data(request, [ "organizations", orgname, "nodes" ]).size
end
json_response(200, {
"limit_exceeded" => (node_count > MAX_NODE_COUNT) ? true : false,
"node_license" => MAX_NODE_COUNT,
"node_count" => node_count,
- "upgrade_url" => 'http://blah.com'
+ "upgrade_url" => "http://blah.com",
})
end
end
diff --git a/lib/chef_zero/endpoints/node_endpoint.rb b/lib/chef_zero/endpoints/node_endpoint.rb
index f2bb8ba..af0e9e0 100644
--- a/lib/chef_zero/endpoints/node_endpoint.rb
+++ b/lib/chef_zero/endpoints/node_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_object_endpoint'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
@@ -28,4 +28,3 @@ module ChefZero
end
end
end
-
diff --git a/lib/chef_zero/endpoints/node_identifiers_endpoint.rb b/lib/chef_zero/endpoints/node_identifiers_endpoint.rb
index 9f89a98..68aa01f 100644
--- a/lib/chef_zero/endpoints/node_identifiers_endpoint.rb
+++ b/lib/chef_zero/endpoints/node_identifiers_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'uuidtools'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "uuidtools"
module ChefZero
module Endpoints
@@ -8,10 +8,10 @@ module ChefZero
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.gsub('-',''),
- :authz_id => '0'*32,
- :org_id => UUIDTools::UUID.parse_raw(request.rest_path[0..1].to_s).to_s.gsub('-','') }
+ 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("-") }
json_response(200, result)
else
raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}")
diff --git a/lib/chef_zero/endpoints/nodes_endpoint.rb b/lib/chef_zero/endpoints/nodes_endpoint.rb
index 8b9d852..6011506 100644
--- a/lib/chef_zero/endpoints/nodes_endpoint.rb
+++ b/lib/chef_zero/endpoints/nodes_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_object_endpoint'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
@@ -32,4 +32,3 @@ module ChefZero
end
end
end
-
diff --git a/lib/chef_zero/endpoints/not_found_endpoint.rb b/lib/chef_zero/endpoints/not_found_endpoint.rb
index ddf1246..4c23800 100644
--- a/lib/chef_zero/endpoints/not_found_endpoint.rb
+++ b/lib/chef_zero/endpoints/not_found_endpoint.rb
@@ -1,10 +1,10 @@
-require 'ffi_yajl'
+require "ffi_yajl"
module ChefZero
module Endpoints
class NotFoundEndpoint
def call(request)
- return [404, {"Content-Type" => "application/json"}, FFI_Yajl::Encoder.encode({"error" => ["Object not found: #{request.env['REQUEST_PATH']}"]}, :pretty => true)]
+ return [404, { "Content-Type" => "application/json" }, FFI_Yajl::Encoder.encode({ "error" => ["Object not found: #{request.env['REQUEST_PATH']}"] }, :pretty => true)]
end
end
end
diff --git a/lib/chef_zero/endpoints/organization_association_request_endpoint.rb b/lib/chef_zero/endpoints/organization_association_request_endpoint.rb
index 974d2c3..09be738 100644
--- a/lib/chef_zero/endpoints/organization_association_request_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_association_request_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
index 72b0e4d..aeba290 100644
--- a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -7,22 +7,22 @@ module ChefZero
class OrganizationAssociationRequestsEndpoint < RestBase
def post(request)
json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
- username = json['user']
+ username = json["user"]
orgname = request.rest_path[1]
id = "#{username}-#{orgname}"
- if exists_data?(request, [ 'organizations', orgname, 'users', username ])
+ if exists_data?(request, [ "organizations", orgname, "users", username ])
raise RestErrorResponse.new(409, "User #{username} is already in organization #{orgname}")
end
- create_data(request, request.rest_path, username, '{}')
+ create_data(request, request.rest_path, username, "{}")
json_response(201, { "uri" => build_uri(request.base_uri, request.rest_path + [ id ]) })
end
def get(request)
orgname = request.rest_path[1]
ChefZero::Endpoints::OrganizationUserBase.get(self, request) do |username|
- { "id" => "#{username}-#{orgname}", 'username' => username }
+ { "id" => "#{username}-#{orgname}", "username" => username }
end
end
end
diff --git a/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb b/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb
index cc39a00..174235e 100644
--- a/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -7,18 +7,18 @@ module ChefZero
class OrganizationAuthenticateUserEndpoint < RestBase
def post(request)
request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
- name = request_json['name']
- password = request_json['password']
+ name = request_json["name"]
+ password = request_json["password"]
begin
- user = data_store.get(request.rest_path[0..-2] + ['users', name])
+ user = data_store.get(request.rest_path[0..-2] + ["users", name])
user = FFI_Yajl::Parser.parse(user, :create_additions => false)
- verified = user['password'] == password
+ verified = user["password"] == password
rescue DataStore::DataNotFoundError
verified = false
end
json_response(200, {
- 'name' => name,
- 'verified' => !!verified
+ "name" => name,
+ "verified" => !!verified,
})
end
end
diff --git a/lib/chef_zero/endpoints/organization_endpoint.rb b/lib/chef_zero/endpoints/organization_endpoint.rb
index a5512db..108073d 100644
--- a/lib/chef_zero/endpoints/organization_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_endpoint.rb
@@ -1,37 +1,37 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
# /organizations/NAME
class OrganizationEndpoint < RestBase
def get(request)
- org = get_data(request, request.rest_path + [ 'org' ])
+ org = get_data(request, request.rest_path + [ "org" ])
already_json_response(200, populate_defaults(request, org))
end
def put(request)
- org = FFI_Yajl::Parser.parse(get_data(request, request.rest_path + [ 'org' ]), :create_additions => false)
+ org = FFI_Yajl::Parser.parse(get_data(request, request.rest_path + [ "org" ]), :create_additions => false)
new_org = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
new_org.each do |key, value|
org[key] = value
end
save_org = FFI_Yajl::Encoder.encode(org, :pretty => true)
- if new_org['name'] != request.rest_path[-1]
+ 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")
end
- set_data(request, request.rest_path + [ 'org' ], save_org)
+ set_data(request, request.rest_path + [ "org" ], save_org)
json_response(200, {
"uri" => "#{build_uri(request.base_uri, request.rest_path)}",
- "name" => org['name'],
- "org_type" => org['org_type'],
- "full_name" => org['full_name']
+ "name" => org["name"],
+ "org_type" => org["org_type"],
+ "full_name" => org["full_name"],
})
end
def delete(request)
- org = get_data(request, request.rest_path + [ 'org' ])
+ org = get_data(request, request.rest_path + [ "org" ])
delete_data_dir(request, request.rest_path, :recursive)
already_json_response(200, populate_defaults(request, org))
end
diff --git a/lib/chef_zero/endpoints/organization_user_base.rb b/lib/chef_zero/endpoints/organization_user_base.rb
index d4ccf44..5be119d 100644
--- a/lib/chef_zero/endpoints/organization_user_base.rb
+++ b/lib/chef_zero/endpoints/organization_user_base.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb b/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb
index 953edc1..ad10377 100644
--- a/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/rest_base'
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/organization_user_endpoint.rb b/lib/chef_zero/endpoints/organization_user_endpoint.rb
index 8fd97d4..9418e53 100644
--- a/lib/chef_zero/endpoints/organization_user_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_user_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -8,16 +8,16 @@ module ChefZero
def get(request)
username = request.rest_path[3]
get_data(request) # 404 if user is not in org
- user = get_data(request, [ 'users', username ])
+ user = get_data(request, [ "users", username ])
user = FFI_Yajl::Parser.parse(user, :create_additions => false)
- json_response(200, ChefData::DataNormalizer.normalize_user(user, username, ['username'], server.options[:osc_compat], request.method))
+ json_response(200, ChefData::DataNormalizer.normalize_user(user, username, ["username"], server.options[:osc_compat], request.method))
end
def delete(request)
user = get_data(request)
delete_data(request)
user = FFI_Yajl::Parser.parse(user, :create_additions => false)
- json_response(200, ChefData::DataNormalizer.normalize_user(user, request.rest_path[3], ['username'], server.options[:osc_compat]))
+ json_response(200, ChefData::DataNormalizer.normalize_user(user, request.rest_path[3], ["username"], server.options[:osc_compat]))
end
# Note: post to a named org user is not permitted, alllow invalid method handling (405)
diff --git a/lib/chef_zero/endpoints/organization_user_key_endpoint.rb b/lib/chef_zero/endpoints/organization_user_key_endpoint.rb
index e0c114c..8e1cfc1 100644
--- a/lib/chef_zero/endpoints/organization_user_key_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_user_key_endpoint.rb
@@ -1,5 +1,5 @@
-require 'chef_zero/rest_base'
-require 'chef_zero/endpoints/actor_keys_endpoint'
+require "chef_zero/rest_base"
+require "chef_zero/endpoints/actor_keys_endpoint"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb b/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb
index 96a84fe..c08e3fa 100644
--- a/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/rest_base'
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/organization_users_endpoint.rb b/lib/chef_zero/endpoints/organization_users_endpoint.rb
index 861c670..7473776 100644
--- a/lib/chef_zero/endpoints/organization_users_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_users_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'chef_zero/endpoints/organization_user_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "chef_zero/endpoints/organization_user_base"
module ChefZero
module Endpoints
@@ -9,28 +9,28 @@ module ChefZero
def post(request)
orgname = request.rest_path[1]
json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
- username = json['username']
+ username = json["username"]
- if exists_data?(request, [ 'organizations', orgname, 'users', username ])
+ if exists_data?(request, [ "organizations", orgname, "users", username ])
raise RestErrorResponse.new(409, "User #{username} is already in organization #{orgname}")
end
- users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
+ users = get_data(request, [ "organizations", orgname, "groups", "users" ])
users = FFI_Yajl::Parser.parse(users, :create_additions => false)
- create_data(request, request.rest_path, username, '{}')
+ create_data(request, request.rest_path, username, "{}")
# /organizations/ORG/association_requests/USERNAME-ORG
begin
- delete_data(request, [ 'organizations', orgname, 'association_requests', username], :data_store_exceptions)
+ delete_data(request, [ "organizations", orgname, "association_requests", username], :data_store_exceptions)
rescue DataStore::DataNotFoundError
end
# Add the user to the users group if it isn't already there
- 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))
+ 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))
end
json_response(201, { "uri" => build_uri(request.base_uri, request.rest_path + [ username ]) })
end
diff --git a/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb b/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb
index a840515..d9bac29 100644
--- a/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'uuidtools'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "uuidtools"
module ChefZero
module Endpoints
@@ -8,12 +8,12 @@ module ChefZero
class OrganizationValidatorKeyEndpoint < RestBase
def post(request)
org_name = request.rest_path[-2]
- validator_path = [ 'organizations', org_name, 'clients', "#{org_name}-validator"]
+ validator_path = [ "organizations", org_name, "clients", "#{org_name}-validator"]
validator = FFI_Yajl::Parser.parse(get_data(request, validator_path), :create_additions => false)
private_key, public_key = server.gen_key_pair
- validator['public_key'] = public_key
+ validator["public_key"] = public_key
set_data(request, validator_path, FFI_Yajl::Encoder.encode(validator, :pretty => true))
- json_response(200, { 'private_key' => private_key })
+ json_response(200, { "private_key" => private_key })
end
end
end
diff --git a/lib/chef_zero/endpoints/organizations_endpoint.rb b/lib/chef_zero/endpoints/organizations_endpoint.rb
index 41bf03b..52fca5f 100644
--- a/lib/chef_zero/endpoints/organizations_endpoint.rb
+++ b/lib/chef_zero/endpoints/organizations_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'uuidtools'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "uuidtools"
module ChefZero
module Endpoints
@@ -16,8 +16,8 @@ module ChefZero
def post(request)
contents = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
- name = contents['name']
- full_name = contents['full_name']
+ name = contents["name"]
+ full_name = contents["full_name"]
if name.nil?
error(400, "Must specify 'name' in JSON")
elsif full_name.nil?
@@ -28,32 +28,31 @@ module ChefZero
create_data_dir(request, request.rest_path, name, :requestor => request.requestor)
org = {
- "guid" => UUIDTools::UUID.random_create.to_s.gsub('-', ''),
- "assigned_at" => Time.now.to_s
+ "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
validator_name = "#{name}-validator"
- validator_path = org_path + [ 'clients', validator_name ]
+ validator_path = org_path + [ "clients", validator_name ]
private_key, public_key = server.gen_key_pair
validator = FFI_Yajl::Encoder.encode({
- 'validator' => true,
- 'public_key' => public_key
+ "validator" => true,
+ "public_key" => public_key,
}, :pretty => true)
set_data(request, validator_path, validator)
end
-
json_response(201, {
"uri" => "#{build_uri(request.base_uri, org_path)}",
"name" => name,
"org_type" => org["org_type"],
"full_name" => full_name,
"clientname" => validator_name,
- "private_key" => private_key
+ "private_key" => private_key,
})
end
end
diff --git a/lib/chef_zero/endpoints/policies_endpoint.rb b/lib/chef_zero/endpoints/policies_endpoint.rb
index 37493da..f830c5c 100644
--- a/lib/chef_zero/endpoints/policies_endpoint.rb
+++ b/lib/chef_zero/endpoints/policies_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/chef_data/data_normalizer'
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
@@ -15,7 +15,7 @@ module ChefZero
response_data[policy_name] = {
uri: policy_uri,
- revisions: hashify_list(revisions)
+ revisions: hashify_list(revisions),
}
end
diff --git a/lib/chef_zero/endpoints/policy_endpoint.rb b/lib/chef_zero/endpoints/policy_endpoint.rb
index d8c1bc8..5c77a7c 100644
--- a/lib/chef_zero/endpoints/policy_endpoint.rb
+++ b/lib/chef_zero/endpoints/policy_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/chef_data/data_normalizer'
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/policy_group_endpoint.rb b/lib/chef_zero/endpoints/policy_group_endpoint.rb
index 54732c8..573dc17 100644
--- a/lib/chef_zero/endpoints/policy_group_endpoint.rb
+++ b/lib/chef_zero/endpoints/policy_group_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
@@ -11,7 +11,7 @@ module ChefZero
def get(request)
data = {
uri: build_uri(request.base_uri, request.rest_path),
- policies: get_policy_group_policies(request)
+ policies: get_policy_group_policies(request),
}
json_response(200, data)
end
@@ -24,7 +24,7 @@ module ChefZero
policy_names = list_data(request, policies_path)
policy_names.each do |policy_name|
revision = parse_json(get_data(request, policies_path + [policy_name]))
- policies_revisions[policy_name] = { revision_id: revision}
+ policies_revisions[policy_name] = { revision_id: revision }
end
policies_revisions
@@ -37,7 +37,7 @@ module ChefZero
data = {
uri: build_uri(request.base_uri, request.rest_path),
- policies: policy_group_policies
+ policies: policy_group_policies,
}
json_response(200, data)
end
diff --git a/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb b/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb
index d227905..2643dd3 100644
--- a/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb
+++ b/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
@@ -74,7 +74,6 @@ module ChefZero
policy_path = request.rest_path[0..1] + ["policies", policy_name,
"revisions", current_revision_id]
-
full_policy_doc = parse_json(get_data(request, policy_path))
full_policy_doc = ChefData::DataNormalizer.normalize_policy(full_policy_doc, policy_name, current_revision_id)
return json_response(200, full_policy_doc)
diff --git a/lib/chef_zero/endpoints/policy_groups_endpoint.rb b/lib/chef_zero/endpoints/policy_groups_endpoint.rb
index f17db8d..a706268 100644
--- a/lib/chef_zero/endpoints/policy_groups_endpoint.rb
+++ b/lib/chef_zero/endpoints/policy_groups_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
@@ -26,7 +26,7 @@ module ChefZero
end
response_data[group_name] = {
- uri: build_uri(request.base_uri, group_path)
+ uri: build_uri(request.base_uri, group_path),
}
response_data[group_name][:policies] = policies unless policies.empty?
end
diff --git a/lib/chef_zero/endpoints/policy_revision_endpoint.rb b/lib/chef_zero/endpoints/policy_revision_endpoint.rb
index 6a77d26..64e2dca 100644
--- a/lib/chef_zero/endpoints/policy_revision_endpoint.rb
+++ b/lib/chef_zero/endpoints/policy_revision_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/chef_data/data_normalizer'
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/policy_revisions_endpoint.rb b/lib/chef_zero/endpoints/policy_revisions_endpoint.rb
index 7c20a24..27e019e 100644
--- a/lib/chef_zero/endpoints/policy_revisions_endpoint.rb
+++ b/lib/chef_zero/endpoints/policy_revisions_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/chef_data/data_normalizer'
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/principal_endpoint.rb b/lib/chef_zero/endpoints/principal_endpoint.rb
index 64c6986..ebd8315 100644
--- a/lib/chef_zero/endpoints/principal_endpoint.rb
+++ b/lib/chef_zero/endpoints/principal_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -9,33 +9,33 @@ module ChefZero
def get(request)
name = request.rest_path[-1]
# If /organizations/ORG/users/NAME exists, use this user (only org members have precedence over clients). hey are an org member.
- json = get_data(request, request.rest_path[0..1] + [ 'users', name ], :nil)
+ json = get_data(request, request.rest_path[0..1] + [ "users", name ], :nil)
if json
- type = 'user'
+ type = "user"
org_member = true
else
# If /organizations/ORG/clients/NAME exists, use the client.
- json = get_data(request, request.rest_path[0..1] + [ 'clients', name ], :nil)
+ json = get_data(request, request.rest_path[0..1] + [ "clients", name ], :nil)
if json
- type = 'client'
+ type = "client"
org_member = true
else
# If there is no client with that name, check for a user (/users/NAME) and return that with
# org_member = false.
- json = get_data(request, [ 'users', name ], :nil)
+ json = get_data(request, [ "users", name ], :nil)
if json
- type = 'user'
+ type = "user"
org_member = false
end
end
end
if json
principal_data = {
- 'name' => name,
- 'type' => type,
- 'public_key' => FFI_Yajl::Parser.parse(json)['public_key'] || PUBLIC_KEY,
- 'authz_id' => '0'*32,
- 'org_member' => org_member
+ "name" => name,
+ "type" => type,
+ "public_key" => FFI_Yajl::Parser.parse(json)["public_key"] || PUBLIC_KEY,
+ "authz_id" => "0" * 32,
+ "org_member" => org_member,
}
response_data =
@@ -47,7 +47,7 @@ module ChefZero
json_response(200, response_data)
else
- error(404, 'Principal not found')
+ error(404, "Principal not found")
end
end
end
diff --git a/lib/chef_zero/endpoints/rest_list_endpoint.rb b/lib/chef_zero/endpoints/rest_list_endpoint.rb
index d6556cf..0f01a68 100644
--- a/lib/chef_zero/endpoints/rest_list_endpoint.rb
+++ b/lib/chef_zero/endpoints/rest_list_endpoint.rb
@@ -1,11 +1,11 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
# Typical REST list endpoint (/roles or /data/BAG)
class RestListEndpoint < RestBase
- def initialize(server, identity_keys = [ 'name' ])
+ def initialize(server, identity_keys = [ "name" ])
super(server)
identity_keys = [ identity_keys ] if identity_keys.is_a?(String)
@identity_keys = identity_keys
@@ -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])}" })
end
end
diff --git a/lib/chef_zero/endpoints/rest_object_endpoint.rb b/lib/chef_zero/endpoints/rest_object_endpoint.rb
index 7e839c0..1f0e9ce 100644
--- a/lib/chef_zero/endpoints/rest_object_endpoint.rb
+++ b/lib/chef_zero/endpoints/rest_object_endpoint.rb
@@ -1,12 +1,12 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
-require 'chef_zero/rest_error_response'
+require "ffi_yajl"
+require "chef_zero/rest_base"
+require "chef_zero/rest_error_response"
module ChefZero
module Endpoints
# Typical REST leaf endpoint (/roles/NAME or /data/BAG/NAME)
class RestObjectEndpoint < RestBase
- def initialize(server, identity_keys = [ 'name' ])
+ def initialize(server, identity_keys = [ "name" ])
super(server)
identity_keys = [ identity_keys ] if identity_keys.is_a?(String)
@identity_keys = identity_keys
diff --git a/lib/chef_zero/endpoints/role_endpoint.rb b/lib/chef_zero/endpoints/role_endpoint.rb
index 0325169..654afca 100644
--- a/lib/chef_zero/endpoints/role_endpoint.rb
+++ b/lib/chef_zero/endpoints/role_endpoint.rb
@@ -1,6 +1,6 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_object_endpoint'
-require 'chef_zero/chef_data/data_normalizer'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/chef_data/data_normalizer"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/endpoints/role_environments_endpoint.rb b/lib/chef_zero/endpoints/role_environments_endpoint.rb
index d56930a..a408138 100644
--- a/lib/chef_zero/endpoints/role_environments_endpoint.rb
+++ b/lib/chef_zero/endpoints/role_environments_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -7,7 +7,7 @@ module ChefZero
class RoleEnvironmentsEndpoint < RestBase
def get(request)
role = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false)
- json_response(200, [ '_default' ] + (role['env_run_lists'].keys || []))
+ json_response(200, [ "_default" ] + (role["env_run_lists"].keys || []))
end
end
end
diff --git a/lib/chef_zero/endpoints/sandbox_endpoint.rb b/lib/chef_zero/endpoints/sandbox_endpoint.rb
index c6a3508..b83a4ca 100644
--- a/lib/chef_zero/endpoints/sandbox_endpoint.rb
+++ b/lib/chef_zero/endpoints/sandbox_endpoint.rb
@@ -1,6 +1,6 @@
-require 'chef_zero/rest_base'
-require 'chef_zero/rest_error_response'
-require 'ffi_yajl'
+require "chef_zero/rest_base"
+require "chef_zero/rest_error_response"
+require "ffi_yajl"
module ChefZero
module Endpoints
@@ -8,8 +8,8 @@ module ChefZero
class SandboxEndpoint < RestBase
def put(request)
existing_sandbox = FFI_Yajl::Parser.parse(get_data(request), :create_additions => false)
- existing_sandbox['checksums'].each do |checksum|
- if !exists_data?(request, request.rest_path[0..1] + ['file_store', 'checksums', checksum])
+ existing_sandbox["checksums"].each do |checksum|
+ if !exists_data?(request, request.rest_path[0..1] + ["file_store", "checksums", checksum])
raise RestErrorResponse.new(503, "Checksum not uploaded: #{checksum}")
end
end
@@ -17,9 +17,9 @@ module ChefZero
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
+ :checksums => existing_sandbox["checksums"],
+ :create_time => existing_sandbox["create_time"],
+ :is_completed => true,
})
end
end
diff --git a/lib/chef_zero/endpoints/sandboxes_endpoint.rb b/lib/chef_zero/endpoints/sandboxes_endpoint.rb
index 88314f7..815ff14 100644
--- a/lib/chef_zero/endpoints/sandboxes_endpoint.rb
+++ b/lib/chef_zero/endpoints/sandboxes_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -13,15 +13,15 @@ module ChefZero
def post(request)
sandbox_checksums = []
- needed_checksums = FFI_Yajl::Parser.parse(request.body, :create_additions => false)['checksums']
+ needed_checksums = FFI_Yajl::Parser.parse(request.body, :create_additions => false)["checksums"]
result_checksums = {}
needed_checksums.keys.each do |needed_checksum|
- if list_data(request, request.rest_path[0..1] + ['file_store', 'checksums']).include?(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 }
else
result_checksums[needed_checksum] = {
:needs_upload => true,
- :url => build_uri(request.base_uri, request.rest_path[0..1] + ['file_store', 'checksums', needed_checksum])
+ :url => build_uri(request.base_uri, request.rest_path[0..1] + ["file_store", "checksums", needed_checksum]),
}
sandbox_checksums << needed_checksum
end
@@ -29,20 +29,20 @@ module ChefZero
# There is an obvious race condition here.
id = @next_id.to_s
- @next_id+=1
+ @next_id += 1
- time_str = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S%z')
+ time_str = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S%z")
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
+ :checksums => sandbox_checksums,
}, :pretty => true))
json_response(201, {
:uri => build_uri(request.base_uri, request.rest_path + [id]),
:checksums => result_checksums,
- :sandbox_id => id
+ :sandbox_id => id,
})
end
end
diff --git a/lib/chef_zero/endpoints/search_endpoint.rb b/lib/chef_zero/endpoints/search_endpoint.rb
index 63d7f4a..01cfc56 100644
--- a/lib/chef_zero/endpoints/search_endpoint.rb
+++ b/lib/chef_zero/endpoints/search_endpoint.rb
@@ -1,9 +1,9 @@
-require 'ffi_yajl'
-require 'chef_zero/endpoints/rest_object_endpoint'
-require 'chef_zero/chef_data/data_normalizer'
-require 'chef_zero/rest_error_response'
-require 'chef_zero/solr/solr_parser'
-require 'chef_zero/solr/solr_doc'
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/chef_data/data_normalizer"
+require "chef_zero/rest_error_response"
+require "chef_zero/solr/solr_parser"
+require "chef_zero/solr/solr_doc"
module ChefZero
module Endpoints
@@ -12,7 +12,7 @@ module ChefZero
def get(request)
orgname = request.rest_path[1]
results = search(request, orgname)
- results['rows'] = results['rows'].map { |name,uri,value,search_value| value }
+ results["rows"] = results["rows"].map { |name, uri, value, search_value| value }
json_response(200, results)
rescue ChefZero::Solr::ParseError
bad_search_request(request)
@@ -22,7 +22,7 @@ module ChefZero
orgname = request.rest_path[1]
full_results = search(request, orgname)
keys = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
- partial_results = full_results['rows'].map do |name, uri, doc, search_value|
+ partial_results = full_results["rows"].map do |name, uri, doc, search_value|
data = {}
keys.each_pair do |key, path|
if path.size > 0
@@ -36,14 +36,14 @@ module ChefZero
end
end
{
- 'url' => uri,
- 'data' => data
+ "url" => uri,
+ "data" => data,
}
end
json_response(200, {
- 'rows' => partial_results,
- 'start' => full_results['start'],
- 'total' => full_results['total']
+ "rows" => partial_results,
+ "start" => full_results["start"],
+ "total" => full_results["total"],
})
rescue ChefZero::Solr::ParseError
bad_search_request(request)
@@ -52,53 +52,55 @@ module ChefZero
private
def bad_search_request(request)
- query_string = request.query_params['q']
- resp = {"error" => ["invalid search query: '#{query_string}'"]}
+ query_string = request.query_params["q"]
+ resp = { "error" => ["invalid search query: '#{query_string}'"] }
json_response(400, resp)
end
def search_container(request, index, orgname)
- relative_parts, normalize_proc = case index
- when 'client'
- [ ['clients'], Proc.new { |client, name| ChefData::DataNormalizer.normalize_client(client, name, orgname) } ]
- when 'node'
- [ ['nodes'], Proc.new { |node, name| ChefData::DataNormalizer.normalize_node(node, name) } ]
- when 'environment'
- [ ['environments'], Proc.new { |environment, name| ChefData::DataNormalizer.normalize_environment(environment, name) } ]
- when 'role'
- [ ['roles'], Proc.new { |role, name| ChefData::DataNormalizer.normalize_role(role, name) } ]
- else
- [ ['data', index], Proc.new { |data_bag_item, id| ChefData::DataNormalizer.normalize_data_bag_item(data_bag_item, index, id, 'DELETE') } ]
- end
+ relative_parts, normalize_proc =
+ case index
+ when "client"
+ [ ["clients"], Proc.new { |client, name| ChefData::DataNormalizer.normalize_client(client, name, orgname) } ]
+ when "node"
+ [ ["nodes"], Proc.new { |node, name| ChefData::DataNormalizer.normalize_node(node, name) } ]
+ when "environment"
+ [ ["environments"], Proc.new { |environment, name| ChefData::DataNormalizer.normalize_environment(environment, name) } ]
+ when "role"
+ [ ["roles"], Proc.new { |role, name| ChefData::DataNormalizer.normalize_role(role, name) } ]
+ else
+ [ ["data", index], Proc.new { |data_bag_item, id| ChefData::DataNormalizer.normalize_data_bag_item(data_bag_item, index, id, "DELETE") } ]
+ end
+
[
request.rest_path[0..1] + relative_parts,
- normalize_proc
+ normalize_proc,
]
end
def expand_for_indexing(value, index, id)
- if index == 'node'
+ if index == "node"
result = {}
- deep_merge!(value['default'] || {}, result)
- deep_merge!(value['normal'] || {}, result)
- deep_merge!(value['override'] || {}, result)
- deep_merge!(value['automatic'] || {}, result)
- result['recipe'] = []
- result['role'] = []
- if value['run_list']
- value['run_list'].each do |run_list_entry|
+ deep_merge!(value["default"] || {}, result)
+ deep_merge!(value["normal"] || {}, result)
+ deep_merge!(value["override"] || {}, result)
+ deep_merge!(value["automatic"] || {}, result)
+ result["recipe"] = []
+ result["role"] = []
+ if value["run_list"]
+ value["run_list"].each do |run_list_entry|
if run_list_entry =~ /^(recipe|role)\[(.*)\]/
result[$1] << $2
end
end
end
value.each_pair do |key, value|
- result[key] = value unless %w(default normal override automatic).include?(key)
+ result[key] = value unless %w{default normal override automatic}.include?(key)
end
result
- elsif !%w(client environment role).include?(index)
- ChefData::DataNormalizer.normalize_data_bag_item(value, index, id, 'GET')
+ elsif !%w{client environment role}.include?(index)
+ ChefData::DataNormalizer.normalize_data_bag_item(value, index, id, "GET")
else
value
end
@@ -107,12 +109,12 @@ module ChefZero
def search(request, orgname = nil)
# Extract parameters
index = request.rest_path[3]
- query_string = request.query_params['q'] || '*:*'
+ query_string = request.query_params["q"] || "*:*"
solr_query = ChefZero::Solr::SolrParser.new(query_string).parse
- sort_string = request.query_params['sort']
- start = request.query_params['start']
+ sort_string = request.query_params["sort"]
+ start = request.query_params["start"]
start = start.to_i if start
- rows = request.query_params['rows']
+ rows = request.query_params["rows"]
rows = rows.to_i if rows
# Get the search container
@@ -133,18 +135,18 @@ module ChefZero
# Sort
if sort_string
sort_key, sort_order = sort_string.split(/\s+/, 2)
- result = result.sort_by { |name,uri,value,search_value| ChefZero::Solr::SolrDoc.new(search_value, name)[sort_key] }
+ result = result.sort_by { |name, uri, value, search_value| ChefZero::Solr::SolrDoc.new(search_value, name)[sort_key] }
result = result.reverse if sort_order == "DESC"
end
# Paginate
if start
- result = result[start..start+(rows||-1)]
+ result = result[start..start + (rows || -1)]
end
{
- 'rows' => result,
- 'start' => start || 0,
- 'total' => total
+ "rows" => result,
+ "start" => start || 0,
+ "total" => total,
}
end
diff --git a/lib/chef_zero/endpoints/searches_endpoint.rb b/lib/chef_zero/endpoints/searches_endpoint.rb
index 10deac3..748a93c 100644
--- a/lib/chef_zero/endpoints/searches_endpoint.rb
+++ b/lib/chef_zero/endpoints/searches_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/rest_base'
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -7,7 +7,7 @@ module ChefZero
def get(request)
# Get the result
result_hash = {}
- indices = (%w(client environment node role) + data_store.list(request.rest_path[0..1] + ['data'])).sort
+ indices = (%w{client environment node role} + data_store.list(request.rest_path[0..1] + ["data"])).sort
indices.each do |index|
result_hash[index] = build_uri(request.base_uri, request.rest_path + [index])
end
diff --git a/lib/chef_zero/endpoints/server_api_version_endpoint.rb b/lib/chef_zero/endpoints/server_api_version_endpoint.rb
index 8ddeaba..a66d3f3 100644
--- a/lib/chef_zero/endpoints/server_api_version_endpoint.rb
+++ b/lib/chef_zero/endpoints/server_api_version_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/rest_base'
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -6,7 +6,7 @@ module ChefZero
class ServerAPIVersionEndpoint < RestBase
API_VERSION = 1
def get(request)
- json_response(200, {"min_api_version"=>MIN_API_VERSION, "max_api_version"=>MAX_API_VERSION},
+ json_response(200, { "min_api_version" => MIN_API_VERSION, "max_api_version" => MAX_API_VERSION },
request_version: request.api_version, response_version: API_VERSION)
end
end
diff --git a/lib/chef_zero/endpoints/system_recovery_endpoint.rb b/lib/chef_zero/endpoints/system_recovery_endpoint.rb
index be438f8..385101d 100644
--- a/lib/chef_zero/endpoints/system_recovery_endpoint.rb
+++ b/lib/chef_zero/endpoints/system_recovery_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -7,19 +7,19 @@ module ChefZero
class SystemRecoveryEndpoint < RestBase
def post(request)
request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
- name = request_json['username']
- password = request_json['password']
- user = get_data(request, request.rest_path[0..-2] + ['users', name], :nil)
+ name = request_json["username"]
+ password = request_json["password"]
+ user = get_data(request, request.rest_path[0..-2] + ["users", name], :nil)
if !user
raise RestErrorResponse.new(403, "Nonexistent user")
end
user = FFI_Yajl::Parser.parse(user, :create_additions => false)
- user = ChefData::DataNormalizer.normalize_user(user, name, [ 'username' ], server.options[:osc_compat])
- if !user['recovery_authentication_enabled']
+ user = ChefData::DataNormalizer.normalize_user(user, name, [ "username" ], server.options[:osc_compat])
+ if !user["recovery_authentication_enabled"]
raise RestErrorResponse.new(403, "Only users with recovery_authentication_enabled=true may use /system_recovery to log in")
end
- if user['password'] != password
+ if user["password"] != password
raise RestErrorResponse.new(401, "Incorrect password")
end
diff --git a/lib/chef_zero/endpoints/user_association_request_endpoint.rb b/lib/chef_zero/endpoints/user_association_request_endpoint.rb
index a83849f..424557e 100644
--- a/lib/chef_zero/endpoints/user_association_request_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_association_request_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -14,26 +14,26 @@ module ChefZero
orgname = $1
json = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
- association_request_path = [ 'organizations', orgname, 'association_requests', username ]
- if json['response'] == 'accept'
- users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
+ association_request_path = [ "organizations", orgname, "association_requests", username ]
+ if json["response"] == "accept"
+ users = get_data(request, [ "organizations", orgname, "groups", "users" ])
users = FFI_Yajl::Parser.parse(users, :create_additions => false)
delete_data(request, association_request_path)
- create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
+ create_data(request, [ "organizations", orgname, "users" ], username, "{}")
# Add the user to the users group if it isn't already there
- 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))
+ 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))
end
- elsif json['response'] == 'reject'
+ elsif json["response"] == "reject"
delete_data(request, association_request_path)
else
raise RestErrorResponse.new(400, "response parameter was missing or set to the wrong value (must be accept or reject)")
end
- json_response(200, { 'organization' => { 'name' => orgname } })
+ json_response(200, { "organization" => { "name" => orgname } })
end
end
end
diff --git a/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb b/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb
index ae8ba9b..617b2b1 100644
--- a/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -9,8 +9,8 @@ module ChefZero
get_data(request, request.rest_path[0..-3])
username = request.rest_path[1]
- result = list_data(request, [ 'organizations' ]).select do |org|
- exists_data?(request, [ 'organizations', org, 'association_requests', username ])
+ result = list_data(request, [ "organizations" ]).select do |org|
+ exists_data?(request, [ "organizations", org, "association_requests", username ])
end
json_response(200, { "value" => result.size })
end
diff --git a/lib/chef_zero/endpoints/user_association_requests_endpoint.rb b/lib/chef_zero/endpoints/user_association_requests_endpoint.rb
index d8dc6eb..c8db13b 100644
--- a/lib/chef_zero/endpoints/user_association_requests_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_association_requests_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -8,8 +8,8 @@ module ChefZero
def get(request)
get_data(request, request.rest_path[0..-2])
username = request.rest_path[1]
- result = list_data(request, [ 'organizations' ]).select do |org|
- exists_data?(request, [ 'organizations', org, 'association_requests', username ])
+ result = list_data(request, [ "organizations" ]).select do |org|
+ exists_data?(request, [ "organizations", org, "association_requests", username ])
end
result = result.map { |org| { "id" => "#{username}-#{org}", "orgname" => org } }
json_response(200, result)
diff --git a/lib/chef_zero/endpoints/user_organizations_endpoint.rb b/lib/chef_zero/endpoints/user_organizations_endpoint.rb
index 3eb13c4..03eae68 100644
--- a/lib/chef_zero/endpoints/user_organizations_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_organizations_endpoint.rb
@@ -1,5 +1,5 @@
-require 'ffi_yajl'
-require 'chef_zero/rest_base'
+require "ffi_yajl"
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
@@ -7,11 +7,11 @@ module ChefZero
class UserOrganizationsEndpoint < RestBase
def get(request)
username = request.rest_path[1]
- result = list_data(request, [ 'organizations' ]).select do |orgname|
- exists_data?(request, [ 'organizations', orgname, 'users', username ])
+ result = list_data(request, [ "organizations" ]).select do |orgname|
+ exists_data?(request, [ "organizations", orgname, "users", username ])
end
result = result.map do |orgname|
- org = get_data(request, [ 'organizations', orgname, 'org' ])
+ org = get_data(request, [ "organizations", orgname, "org" ])
org = FFI_Yajl::Parser.parse(org, :create_additions => false)
{ "organization" => ChefData::DataNormalizer.normalize_organization(org, orgname) }
end
diff --git a/lib/chef_zero/endpoints/version_endpoint.rb b/lib/chef_zero/endpoints/version_endpoint.rb
index d38c33e..c51e893 100644
--- a/lib/chef_zero/endpoints/version_endpoint.rb
+++ b/lib/chef_zero/endpoints/version_endpoint.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/rest_base'
+require "chef_zero/rest_base"
module ChefZero
module Endpoints
diff --git a/lib/chef_zero/log.rb b/lib/chef_zero/log.rb
index 5ab1c6a..f14395e 100644
--- a/lib/chef_zero/log.rb
+++ b/lib/chef_zero/log.rb
@@ -1,4 +1,4 @@
-require 'mixlib/log'
+require "mixlib/log"
module ChefZero
class Log
diff --git a/lib/chef_zero/rest_base.rb b/lib/chef_zero/rest_base.rb
index 929aa8f..c2bc5ee 100644
--- a/lib/chef_zero/rest_base.rb
+++ b/lib/chef_zero/rest_base.rb
@@ -1,7 +1,7 @@
-require 'chef_zero/rest_request'
-require 'chef_zero/rest_error_response'
-require 'chef_zero/data_store/data_not_found_error'
-require 'chef_zero/chef_data/acl_path'
+require "chef_zero/rest_request"
+require "chef_zero/rest_error_response"
+require "chef_zero/data_store/data_not_found_error"
+require "chef_zero/chef_data/acl_path"
module ChefZero
class RestBase
@@ -34,7 +34,7 @@ module ChefZero
"error" => "invalid-x-ops-server-api-version",
"message" => "Specified version #{version} not supported",
"min_api_version" => MIN_API_VERSION,
- "max_api_version" => MAX_API_VERSION
+ "max_api_version" => MAX_API_VERSION,
}
return json_response(406,
@@ -51,11 +51,11 @@ module ChefZero
method = request.method.downcase.to_sym
if !self.respond_to?(method)
accept_methods = [:get, :put, :post, :delete].select { |m| self.respond_to?(m) }
- accept_methods_str = accept_methods.map { |m| m.to_s.upcase }.join(', ')
- return [405, {"Content-Type" => "text/plain", "Allow" => accept_methods_str}, "Bad request method for '#{request.env['REQUEST_PATH']}': #{request.env['REQUEST_METHOD']}"]
+ accept_methods_str = accept_methods.map { |m| m.to_s.upcase }.join(", ")
+ return [405, { "Content-Type" => "text/plain", "Allow" => accept_methods_str }, "Bad request method for '#{request.env['REQUEST_PATH']}': #{request.env['REQUEST_METHOD']}"]
end
- if json_only && !accepts?(request, 'application', 'json')
- return [406, {"Content-Type" => "text/plain"}, "Must accept application/json"]
+ if json_only && !accepts?(request, "application", "json")
+ return [406, { "Content-Type" => "text/plain" }, "Must accept application/json"]
end
# Dispatch to get()/post()/put()/delete()
begin
@@ -73,12 +73,12 @@ module ChefZero
def accepts?(request, category, type)
# If HTTP_ACCEPT is not sent at all, assume it accepts anything
# This parses as per http://tools.ietf.org/html/rfc7231#section-5.3
- return true if !request.env['HTTP_ACCEPT']
- accepts = request.env['HTTP_ACCEPT'].split(/,\s*/).map { |x| x.split(';',2)[0].strip }
- return accepts.include?("#{category}/#{type}") || accepts.include?("#{category}/*") || accepts.include?('*/*')
+ return true if !request.env["HTTP_ACCEPT"]
+ accepts = request.env["HTTP_ACCEPT"].split(/,\s*/).map { |x| x.split(";", 2)[0].strip }
+ return accepts.include?("#{category}/#{type}") || accepts.include?("#{category}/*") || accepts.include?("*/*")
end
- def get_data(request, rest_path=nil, *options)
+ def get_data(request, rest_path = nil, *options)
rest_path ||= request.rest_path
rest_path = rest_path.map { |v| URI.decode(v) }
begin
@@ -94,7 +94,7 @@ module ChefZero
end
end
- def list_data(request, rest_path=nil, *options)
+ def list_data(request, rest_path = nil, *options)
rest_path ||= request.rest_path
begin
data_store.list(rest_path)
@@ -107,7 +107,7 @@ module ChefZero
end
end
- def delete_data(request, rest_path=nil, *options)
+ def delete_data(request, rest_path = nil, *options)
rest_path ||= request.rest_path
begin
data_store.delete(rest_path, *options)
@@ -196,17 +196,17 @@ module ChefZero
end
end
- def exists_data?(request, rest_path=nil)
+ def exists_data?(request, rest_path = nil)
rest_path ||= request.rest_path
data_store.exists?(rest_path)
end
- def exists_data_dir?(request, rest_path=nil)
+ def exists_data_dir?(request, rest_path = nil)
rest_path ||= request.rest_path
data_store.exists_dir?(rest_path)
end
- def error(response_code, error, opts={})
+ def error(response_code, error, opts = {})
json_response(response_code, { "error" => [ error ] }, opts)
end
@@ -223,7 +223,7 @@ module ChefZero
#
# @return (see #already_json_response)
#
- def json_response(response_code, data, options={})
+ def json_response(response_code, data, options = {})
options = { pretty: true }.merge(options)
do_pretty_json = !!options.delete(:pretty) # make sure we have a proper Boolean.
json = FFI_Yajl::Encoder.encode(data, pretty: do_pretty_json)
@@ -231,7 +231,7 @@ module ChefZero
end
def text_response(response_code, text)
- [response_code, {"Content-Type" => "text/plain"}, text]
+ [response_code, { "Content-Type" => "text/plain" }, text]
end
# Returns an Array with the response code, HTTP headers, and JSON body.
@@ -245,7 +245,7 @@ module ChefZero
#
# @return [Array(Fixnum, Hash{String => String}, String)]
#
- def already_json_response(response_code, json_text, options={})
+ def already_json_response(response_code, json_text, options = {})
version_header = FFI_Yajl::Encoder.encode(
"min_version" => MIN_API_VERSION.to_s,
"max_version" => MAX_API_VERSION.to_s,
@@ -255,7 +255,7 @@ module ChefZero
headers = {
"Content-Type" => "application/json",
- "X-Ops-Server-API-Version" => version_header
+ "X-Ops-Server-API-Version" => version_header,
}
headers.merge!(options[:headers]) if options[:headers]
@@ -266,7 +266,7 @@ module ChefZero
def build_uri(base_uri, rest_path)
if server.options[:single_org]
# Strip off /organizations/chef if we are in single org mode
- if rest_path[0..1] != [ 'organizations', server.options[:single_org] ]
+ if rest_path[0..1] != [ "organizations", server.options[:single_org] ]
raise "Unexpected URL #{rest_path[0..1]} passed to build_uri in single org mode"
end
@@ -314,8 +314,8 @@ module ChefZero
def policy_name_invalid?(name)
!name.is_a?(String) ||
- name.size > 255 ||
- name =~ /[+ !]/
+ name.size > 255 ||
+ name =~ /[+ !]/
end
end
end
diff --git a/lib/chef_zero/rest_request.rb b/lib/chef_zero/rest_request.rb
index c12ea31..4e82fb4 100644
--- a/lib/chef_zero/rest_request.rb
+++ b/lib/chef_zero/rest_request.rb
@@ -1,4 +1,4 @@
-require 'rack/request'
+require "rack/request"
module ChefZero
class RestRequest
@@ -15,10 +15,10 @@ module ChefZero
def base_uri
# Load balancer awareness
- if env['HTTP_X_FORWARDED_PROTO']
- scheme = env['HTTP_X_FORWARDED_PROTO']
+ if env["HTTP_X_FORWARDED_PROTO"]
+ scheme = env["HTTP_X_FORWARDED_PROTO"]
else
- scheme = env['rack.url_scheme']
+ scheme = env["rack.url_scheme"]
end
@base_uri ||= "#{scheme}://#{env['HTTP_HOST']}#{env['SCRIPT_NAME']}"
end
@@ -28,7 +28,7 @@ module ChefZero
end
def api_version
- @env['HTTP_X_OPS_SERVER_API_VERSION'] || ZERO
+ @env["HTTP_X_OPS_SERVER_API_VERSION"] || ZERO
end
def api_v0?
@@ -36,15 +36,15 @@ module ChefZero
end
def requestor
- @env['HTTP_X_OPS_USERID']
+ @env["HTTP_X_OPS_USERID"]
end
def method
- @env['REQUEST_METHOD']
+ @env["REQUEST_METHOD"]
end
def rest_path
- @rest_path ||= rest_base_prefix + env['PATH_INFO'].split('/').select { |part| part != "" }
+ @rest_path ||= rest_base_prefix + env["PATH_INFO"].split("/").select { |part| part != "" }
end
def rest_path=(rest_path)
@@ -56,7 +56,7 @@ module ChefZero
end
def body
- @body ||= env['rack.input'].read
+ @body ||= env["rack.input"].read
end
def query_params
@@ -72,9 +72,9 @@ module ChefZero
def to_s
result = "#{method} #{rest_path.join('/')}"
if query_params.size > 0
- result << "?#{query_params.map { |k,v| "#{k}=#{v}" }.join('&') }"
+ result << "?#{query_params.map { |k, v| "#{k}=#{v}" }.join('&') }"
end
- if body.chomp != ''
+ if body.chomp != ""
result << "\n--- #{method} BODY ---\n"
result << body
result << "\n" if !body.end_with?("\n")
diff --git a/lib/chef_zero/rest_router.rb b/lib/chef_zero/rest_router.rb
index a93af8b..2b5e129 100644
--- a/lib/chef_zero/rest_router.rb
+++ b/lib/chef_zero/rest_router.rb
@@ -1,4 +1,4 @@
-require 'pp'
+require "pp"
module ChefZero
class RestRouter
@@ -33,40 +33,40 @@ module ChefZero
private
- def find_endpoint(clean_path)
- _, endpoint = routes.find { |route, endpoint| route.match(clean_path) }
- endpoint || not_found
- end
+ def find_endpoint(clean_path)
+ _, endpoint = routes.find { |route, endpoint| route.match(clean_path) }
+ endpoint || not_found
+ end
- def log_request(request)
- ChefZero::Log.debug do
- "#{request.method} /#{request.rest_path.join("/")}".tap do |msg|
- next unless request.method =~ /^(POST|PUT)$/
+ def log_request(request)
+ ChefZero::Log.debug do
+ "#{request.method} /#{request.rest_path.join("/")}".tap do |msg|
+ next unless request.method =~ /^(POST|PUT)$/
- if request.body.nil? || request.body.empty?
- msg << " (no body)"
- else
- msg << [
- "",
- "--- #{request.method} BODY ---",
- request.body.chomp,
- "--- END #{request.method} BODY ---"
- ].join("\n")
- end
+ if request.body.nil? || request.body.empty?
+ msg << " (no body)"
+ else
+ msg << [
+ "",
+ "--- #{request.method} BODY ---",
+ request.body.chomp,
+ "--- END #{request.method} BODY ---",
+ ].join("\n")
end
end
-
- ChefZero::Log.debug { request.pretty_inspect }
end
- def log_response(response)
- ChefZero::Log.debug {
- [ "",
- "--- RESPONSE (#{response[0]}) ---",
- response[2].chomp,
- "--- END RESPONSE ---",
- ].join("\n")
- }
- end
+ ChefZero::Log.debug { request.pretty_inspect }
+ end
+
+ def log_response(response)
+ ChefZero::Log.debug {
+ [ "",
+ "--- RESPONSE (#{response[0]}) ---",
+ response[2].chomp,
+ "--- END RESPONSE ---",
+ ].join("\n")
+ }
+ end
end
end
diff --git a/lib/chef_zero/rspec.rb b/lib/chef_zero/rspec.rb
index 8867f37..53f4776 100644
--- a/lib/chef_zero/rspec.rb
+++ b/lib/chef_zero/rspec.rb
@@ -1,6 +1,6 @@
-require 'tempfile'
-require 'chef_zero/server'
-require 'chef_zero/rest_request'
+require "tempfile"
+require "chef_zero/server"
+require "chef_zero/rest_request"
module ChefZero
module RSpec
@@ -25,7 +25,7 @@ module ChefZero
# Set up configuration so that clients will point to the server
self.server = ChefZero::Server.new(chef_server_options)
- self.client_key = Tempfile.new(['chef_zero_client_key', '.pem'])
+ self.client_key = Tempfile.new(["chef_zero_client_key", ".pem"])
client_key.write(ChefZero::PRIVATE_KEY)
client_key.close
# Start the server
@@ -84,7 +84,7 @@ module ChefZero
else
Chef::Config.chef_server_url = ChefZero::RSpec.server.url
end
- Chef::Config.node_name = 'admin'
+ Chef::Config.node_name = "admin"
Chef::Config.client_key = ChefZero::RSpec.client_key.path
Chef::Config.http_retry_count = 0
end
@@ -103,7 +103,7 @@ module ChefZero
end
module WhenTheChefServerClassMethods
- def organization(name, org = '{}', &block)
+ def organization(name, org = "{}", &block)
before(chef_server_options[:server_scope]) { organization(name, org, &block) }
end
@@ -175,8 +175,8 @@ module ChefZero
end
module WhenTheChefServerInstanceMethods
- def organization(name, org = '{}', &block)
- ChefZero::RSpec.server.data_store.set([ 'organizations', name, 'org' ], dejsonize(org), :create_dir, :create)
+ def organization(name, org = "{}", &block)
+ ChefZero::RSpec.server.data_store.set([ "organizations", name, "org" ], dejsonize(org), :create_dir, :create)
prev_org_name = @current_org
@current_org = name
prev_object_path = @current_object_path
@@ -192,7 +192,7 @@ module ChefZero
end
def acl_for(path, data)
- ChefZero::RSpec.server.load_data({ 'acls' => { path => data } }, current_org)
+ ChefZero::RSpec.server.load_data({ "acls" => { path => data } }, current_org)
end
def acl(data)
@@ -201,14 +201,14 @@ module ChefZero
def client(name, data, &block)
with_object_path("clients/#{name}") do
- ChefZero::RSpec.server.load_data({ 'clients' => { name => data } }, current_org)
+ ChefZero::RSpec.server.load_data({ "clients" => { name => data } }, current_org)
instance_eval(&block) if block_given?
end
end
def container(name, data, &block)
with_object_path("containers/#{name}") do
- ChefZero::RSpec.server.load_data({ 'containers' => { name => data } }, current_org)
+ ChefZero::RSpec.server.load_data({ "containers" => { name => data } }, current_org)
instance_eval(&block) if block_given?
end
end
@@ -217,14 +217,14 @@ 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['metadata.rb'].nil?
- data.delete('metadata.rb')
+ if data.has_key?("metadata.rb")
+ if data["metadata.rb"].nil?
+ data.delete("metadata.rb")
end
else
- data['metadata.rb'] = "name #{name.inspect}; version #{version.inspect}"
+ data["metadata.rb"] = "name #{name.inspect}; version #{version.inspect}"
end
- ChefZero::RSpec.server.load_data({ 'cookbooks' => { "#{name}-#{version}" => data.merge(options) }}, current_org)
+ ChefZero::RSpec.server.load_data({ "cookbooks" => { "#{name}-#{version}" => data.merge(options) } }, current_org)
instance_eval(&block) if block_given?
end
end
@@ -233,78 +233,78 @@ 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['metadata.rb'].nil?
- data.delete('metadata.rb')
+ if data.has_key?("metadata.rb")
+ if data["metadata.rb"].nil?
+ data.delete("metadata.rb")
end
else
- data['metadata.rb'] = "name #{name.inspect}"
+ data["metadata.rb"] = "name #{name.inspect}"
end
- ChefZero::RSpec.server.load_data({ 'cookbook_artifacts' => { "#{name}-#{identifier}" => data } }, current_org)
+ ChefZero::RSpec.server.load_data({ "cookbook_artifacts" => { "#{name}-#{identifier}" => data } }, current_org)
instance_eval(&block) if block_given?
end
end
def data_bag(name, data, &block)
with_object_path("data/#{name}") do
- ChefZero::RSpec.server.load_data({ 'data' => { name => data }}, current_org)
+ ChefZero::RSpec.server.load_data({ "data" => { name => data } }, current_org)
instance_eval(&block) if block_given?
end
end
def environment(name, data, &block)
with_object_path("environments/#{name}") do
- ChefZero::RSpec.server.load_data({ 'environments' => { name => data } }, current_org)
+ ChefZero::RSpec.server.load_data({ "environments" => { name => data } }, current_org)
instance_eval(&block) if block_given?
end
end
def group(name, data, &block)
with_object_path("groups/#{name}") do
- ChefZero::RSpec.server.load_data({ 'groups' => { name => data } }, current_org)
+ ChefZero::RSpec.server.load_data({ "groups" => { name => data } }, current_org)
instance_eval(&block) if block_given?
end
end
def node(name, data, &block)
with_object_path("nodes/#{name}") do
- ChefZero::RSpec.server.load_data({ 'nodes' => { name => data } }, current_org)
+ ChefZero::RSpec.server.load_data({ "nodes" => { name => data } }, current_org)
instance_eval(&block) if block_given?
end
end
def org_invite(*usernames)
- ChefZero::RSpec.server.load_data({ 'invites' => usernames }, current_org)
+ ChefZero::RSpec.server.load_data({ "invites" => usernames }, current_org)
end
def org_member(*usernames)
- ChefZero::RSpec.server.load_data({ 'members' => usernames }, current_org)
+ ChefZero::RSpec.server.load_data({ "members" => usernames }, current_org)
end
def policy(name, version, data, &block)
with_object_path("policies/#{name}") do
- ChefZero::RSpec.server.load_data({ 'policies' => { name => { version => data } } }, current_org)
+ ChefZero::RSpec.server.load_data({ "policies" => { name => { version => data } } }, current_org)
instance_eval(&block) if block_given?
end
end
def policy_group(name, data, &block)
with_object_path("policy_groups/#{name}") do
- ChefZero::RSpec.server.load_data({ 'policy_groups' => { name => data } }, current_org)
+ ChefZero::RSpec.server.load_data({ "policy_groups" => { name => data } }, current_org)
instance_eval(&block) if block_given?
end
end
def role(name, data, &block)
with_object_path("roles/#{name}") do
- ChefZero::RSpec.server.load_data({ 'roles' => { name => data } }, current_org)
+ ChefZero::RSpec.server.load_data({ "roles" => { name => data } }, current_org)
instance_eval(&block) if block_given?
end
end
def sandbox(name, data, &block)
with_object_path("sandboxes/#{name}") do
- ChefZero::RSpec.server.load_data({ 'sandboxes' => { name => data } }, current_org)
+ ChefZero::RSpec.server.load_data({ "sandboxes" => { name => data } }, current_org)
instance_eval(&block) if block_given?
end
end
@@ -312,14 +312,14 @@ module ChefZero
def user(name, data, &block)
if ChefZero::RSpec.server.options[:osc_compat]
with_object_path("users/#{name}") do
- ChefZero::RSpec.server.load_data({ 'users' => { name => data }}, current_org)
+ ChefZero::RSpec.server.load_data({ "users" => { name => data } }, current_org)
instance_eval(&block) if block_given?
end
else
old_object_path = @current_object_path
@current_object_path = "users/#{name}"
begin
- ChefZero::RSpec.server.load_data({ 'users' => { name => data }}, current_org)
+ ChefZero::RSpec.server.load_data({ "users" => { name => data } }, current_org)
instance_eval(&block) if block_given?
ensure
@current_object_path = old_object_path
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index 19744b1..dd83fe3 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -16,113 +16,113 @@
# limitations under the License.
#
-require 'openssl'
-require 'open-uri'
-require 'rubygems'
-require 'timeout'
-require 'stringio'
-
-require 'rack'
-require 'webrick'
-require 'webrick/https'
-
-require 'chef_zero'
-require 'chef_zero/socketless_server_map'
-require 'chef_zero/chef_data/cookbook_data'
-require 'chef_zero/chef_data/acl_path'
-require 'chef_zero/rest_router'
-require 'chef_zero/data_store/memory_store_v2'
-require 'chef_zero/data_store/v1_to_v2_adapter'
-require 'chef_zero/data_store/default_facade'
-require 'chef_zero/version'
-
-require 'chef_zero/endpoints/rest_list_endpoint'
-require 'chef_zero/endpoints/authenticate_user_endpoint'
-require 'chef_zero/endpoints/acls_endpoint'
-require 'chef_zero/endpoints/acl_endpoint'
-require 'chef_zero/endpoints/actor_endpoint'
-require 'chef_zero/endpoints/actors_endpoint'
-require 'chef_zero/endpoints/actor_key_endpoint'
-require 'chef_zero/endpoints/organization_user_key_endpoint'
-require 'chef_zero/endpoints/organization_user_default_key_endpoint'
-require 'chef_zero/endpoints/organization_user_keys_endpoint'
-require 'chef_zero/endpoints/actor_default_key_endpoint'
-require 'chef_zero/endpoints/actor_keys_endpoint'
-require 'chef_zero/endpoints/cookbooks_endpoint'
-require 'chef_zero/endpoints/cookbook_endpoint'
-require 'chef_zero/endpoints/cookbook_version_endpoint'
-require 'chef_zero/endpoints/cookbook_artifacts_endpoint'
-require 'chef_zero/endpoints/cookbook_artifact_endpoint'
-require 'chef_zero/endpoints/cookbook_artifact_identifier_endpoint'
-require 'chef_zero/endpoints/containers_endpoint'
-require 'chef_zero/endpoints/container_endpoint'
-require 'chef_zero/endpoints/controls_endpoint'
-require 'chef_zero/endpoints/dummy_endpoint'
-require 'chef_zero/endpoints/data_bags_endpoint'
-require 'chef_zero/endpoints/data_bag_endpoint'
-require 'chef_zero/endpoints/data_bag_item_endpoint'
-require 'chef_zero/endpoints/groups_endpoint'
-require 'chef_zero/endpoints/group_endpoint'
-require 'chef_zero/endpoints/environment_endpoint'
-require 'chef_zero/endpoints/environment_cookbooks_endpoint'
-require 'chef_zero/endpoints/environment_cookbook_endpoint'
-require 'chef_zero/endpoints/environment_cookbook_versions_endpoint'
-require 'chef_zero/endpoints/environment_nodes_endpoint'
-require 'chef_zero/endpoints/environment_recipes_endpoint'
-require 'chef_zero/endpoints/environment_role_endpoint'
-require 'chef_zero/endpoints/license_endpoint'
-require 'chef_zero/endpoints/node_endpoint'
-require 'chef_zero/endpoints/nodes_endpoint'
-require 'chef_zero/endpoints/node_identifiers_endpoint'
-require 'chef_zero/endpoints/organizations_endpoint'
-require 'chef_zero/endpoints/organization_endpoint'
-require 'chef_zero/endpoints/organization_association_requests_endpoint'
-require 'chef_zero/endpoints/organization_association_request_endpoint'
-require 'chef_zero/endpoints/organization_authenticate_user_endpoint'
-require 'chef_zero/endpoints/organization_users_endpoint'
-require 'chef_zero/endpoints/organization_user_endpoint'
-require 'chef_zero/endpoints/organization_validator_key_endpoint'
-require 'chef_zero/endpoints/policies_endpoint'
-require 'chef_zero/endpoints/policy_endpoint'
-require 'chef_zero/endpoints/policy_revisions_endpoint'
-require 'chef_zero/endpoints/policy_revision_endpoint'
-require 'chef_zero/endpoints/policy_groups_endpoint'
-require 'chef_zero/endpoints/policy_group_endpoint'
-require 'chef_zero/endpoints/policy_group_policy_endpoint'
-require 'chef_zero/endpoints/principal_endpoint'
-require 'chef_zero/endpoints/role_endpoint'
-require 'chef_zero/endpoints/role_environments_endpoint'
-require 'chef_zero/endpoints/sandboxes_endpoint'
-require 'chef_zero/endpoints/sandbox_endpoint'
-require 'chef_zero/endpoints/searches_endpoint'
-require 'chef_zero/endpoints/search_endpoint'
-require 'chef_zero/endpoints/system_recovery_endpoint'
-require 'chef_zero/endpoints/user_association_requests_endpoint'
-require 'chef_zero/endpoints/user_association_requests_count_endpoint'
-require 'chef_zero/endpoints/user_association_request_endpoint'
-require 'chef_zero/endpoints/user_organizations_endpoint'
-require 'chef_zero/endpoints/file_store_file_endpoint'
-require 'chef_zero/endpoints/not_found_endpoint'
-require 'chef_zero/endpoints/version_endpoint'
-require 'chef_zero/endpoints/server_api_version_endpoint'
+require "openssl"
+require "open-uri"
+require "rubygems"
+require "timeout"
+require "stringio"
+
+require "rack"
+require "webrick"
+require "webrick/https"
+
+require "chef_zero"
+require "chef_zero/socketless_server_map"
+require "chef_zero/chef_data/cookbook_data"
+require "chef_zero/chef_data/acl_path"
+require "chef_zero/rest_router"
+require "chef_zero/data_store/memory_store_v2"
+require "chef_zero/data_store/v1_to_v2_adapter"
+require "chef_zero/data_store/default_facade"
+require "chef_zero/version"
+
+require "chef_zero/endpoints/rest_list_endpoint"
+require "chef_zero/endpoints/authenticate_user_endpoint"
+require "chef_zero/endpoints/acls_endpoint"
+require "chef_zero/endpoints/acl_endpoint"
+require "chef_zero/endpoints/actor_endpoint"
+require "chef_zero/endpoints/actors_endpoint"
+require "chef_zero/endpoints/actor_key_endpoint"
+require "chef_zero/endpoints/organization_user_key_endpoint"
+require "chef_zero/endpoints/organization_user_default_key_endpoint"
+require "chef_zero/endpoints/organization_user_keys_endpoint"
+require "chef_zero/endpoints/actor_default_key_endpoint"
+require "chef_zero/endpoints/actor_keys_endpoint"
+require "chef_zero/endpoints/cookbooks_endpoint"
+require "chef_zero/endpoints/cookbook_endpoint"
+require "chef_zero/endpoints/cookbook_version_endpoint"
+require "chef_zero/endpoints/cookbook_artifacts_endpoint"
+require "chef_zero/endpoints/cookbook_artifact_endpoint"
+require "chef_zero/endpoints/cookbook_artifact_identifier_endpoint"
+require "chef_zero/endpoints/containers_endpoint"
+require "chef_zero/endpoints/container_endpoint"
+require "chef_zero/endpoints/controls_endpoint"
+require "chef_zero/endpoints/dummy_endpoint"
+require "chef_zero/endpoints/data_bags_endpoint"
+require "chef_zero/endpoints/data_bag_endpoint"
+require "chef_zero/endpoints/data_bag_item_endpoint"
+require "chef_zero/endpoints/groups_endpoint"
+require "chef_zero/endpoints/group_endpoint"
+require "chef_zero/endpoints/environment_endpoint"
+require "chef_zero/endpoints/environment_cookbooks_endpoint"
+require "chef_zero/endpoints/environment_cookbook_endpoint"
+require "chef_zero/endpoints/environment_cookbook_versions_endpoint"
+require "chef_zero/endpoints/environment_nodes_endpoint"
+require "chef_zero/endpoints/environment_recipes_endpoint"
+require "chef_zero/endpoints/environment_role_endpoint"
+require "chef_zero/endpoints/license_endpoint"
+require "chef_zero/endpoints/node_endpoint"
+require "chef_zero/endpoints/nodes_endpoint"
+require "chef_zero/endpoints/node_identifiers_endpoint"
+require "chef_zero/endpoints/organizations_endpoint"
+require "chef_zero/endpoints/organization_endpoint"
+require "chef_zero/endpoints/organization_association_requests_endpoint"
+require "chef_zero/endpoints/organization_association_request_endpoint"
+require "chef_zero/endpoints/organization_authenticate_user_endpoint"
+require "chef_zero/endpoints/organization_users_endpoint"
+require "chef_zero/endpoints/organization_user_endpoint"
+require "chef_zero/endpoints/organization_validator_key_endpoint"
+require "chef_zero/endpoints/policies_endpoint"
+require "chef_zero/endpoints/policy_endpoint"
+require "chef_zero/endpoints/policy_revisions_endpoint"
+require "chef_zero/endpoints/policy_revision_endpoint"
+require "chef_zero/endpoints/policy_groups_endpoint"
+require "chef_zero/endpoints/policy_group_endpoint"
+require "chef_zero/endpoints/policy_group_policy_endpoint"
+require "chef_zero/endpoints/principal_endpoint"
+require "chef_zero/endpoints/role_endpoint"
+require "chef_zero/endpoints/role_environments_endpoint"
+require "chef_zero/endpoints/sandboxes_endpoint"
+require "chef_zero/endpoints/sandbox_endpoint"
+require "chef_zero/endpoints/searches_endpoint"
+require "chef_zero/endpoints/search_endpoint"
+require "chef_zero/endpoints/system_recovery_endpoint"
+require "chef_zero/endpoints/user_association_requests_endpoint"
+require "chef_zero/endpoints/user_association_requests_count_endpoint"
+require "chef_zero/endpoints/user_association_request_endpoint"
+require "chef_zero/endpoints/user_organizations_endpoint"
+require "chef_zero/endpoints/file_store_file_endpoint"
+require "chef_zero/endpoints/not_found_endpoint"
+require "chef_zero/endpoints/version_endpoint"
+require "chef_zero/endpoints/server_api_version_endpoint"
module ChefZero
class Server
DEFAULT_OPTIONS = {
- :host => ['127.0.0.1'],
+ :host => ["127.0.0.1"],
:port => 8889,
:log_level => :warn,
:generate_real_keys => true,
- :single_org => 'chef',
- :ssl => false
+ :single_org => "chef",
+ :ssl => false,
}.freeze
GLOBAL_ENDPOINTS = [
- '/license',
- '/version',
- '/server_api_version'
+ "/license",
+ "/version",
+ "/server_api_version",
]
def initialize(options = {})
@@ -164,9 +164,9 @@ module ChefZero
# @return [String]
#
def url
- sch = @options[:ssl] ? 'https' : 'http'
+ sch = @options[:ssl] ? "https" : "http"
hosts = Array(@options[:host])
- @url ||= if hosts.first.include?(':')
+ @url ||= if hosts.first.include?(":")
URI("#{sch}://[#{hosts.first}]:#{port}").to_s
else
URI("#{sch}://#{hosts.first}:#{port}").to_s
@@ -178,7 +178,6 @@ module ChefZero
"chefzero://localhost:#{port}"
end
-
#
# The data store for this server (default is in-memory).
#
@@ -230,7 +229,7 @@ module ChefZero
if publish
output = publish.respond_to?(:puts) ? publish : STDOUT
- output.puts <<-EOH.gsub(/^ {10}/, '')
+ output.puts <<-EOH.gsub(/^ {10}/, "")
>> Starting Chef Zero (v#{ChefZero::VERSION})...
EOH
end
@@ -239,14 +238,14 @@ module ChefZero
if publish
output = publish.respond_to?(:puts) ? publish : STDOUT
- output.puts <<-EOH.gsub(/^ {10}/, '')
+ output.puts <<-EOH.gsub(/^ {10}/, "")
>> WEBrick (v#{WEBrick::VERSION}) on Rack (v#{Rack.release}) is listening at #{url}
>> Press CTRL+C to stop
EOH
end
- %w[INT TERM].each do |signal|
+ %w{INT TERM}.each do |signal|
Signal.trap(signal) do
puts "\n>> Stopping Chef Zero..."
@server.shutdown
@@ -285,15 +284,15 @@ module ChefZero
:AccessLog => [],
:Logger => WEBrick::Log.new(StringIO.new, 7),
:RequestTimeout => 300,
- :SSLEnable => options[:ssl],
- :SSLOptions => ssl_opts,
- :SSLCertName => [ [ 'CN', WEBrick::Utils::getservername ] ],
+ :SSLEnable => options[:ssl],
+ :SSLOptions => ssl_opts,
+ :SSLCertName => [ [ "CN", WEBrick::Utils.getservername ] ],
:StartCallback => proc {
@running = true
}
)
- ENV['HTTPS'] = 'on' if options[:ssl]
- @server.mount('/', Rack::Handler::WEBrick, app)
+ ENV["HTTPS"] = "on" if options[:ssl]
+ @server.mount("/", Rack::Handler::WEBrick, app)
# Pick a port
# If options[:port] can be an Enumerator, an Array, or an Integer,
@@ -377,7 +376,7 @@ module ChefZero
if generate_real_keys?
private_key = OpenSSL::PKey::RSA.new(2048)
public_key = private_key.public_key.to_s
- public_key.sub!(/^-----BEGIN RSA PUBLIC KEY-----/, '-----BEGIN PUBLIC KEY-----')
+ public_key.sub!(/^-----BEGIN RSA PUBLIC KEY-----/, "-----BEGIN PUBLIC KEY-----")
public_key.sub!(/-----END RSA PUBLIC KEY-----(\s+)$/, '-----END PUBLIC KEY-----\1')
[private_key.to_s, public_key]
else
@@ -418,84 +417,84 @@ module ChefZero
# }
def load_data(contents, org_name = nil)
org_name ||= options[:single_org]
- if org_name.nil? && contents.keys != [ 'users' ]
+ if org_name.nil? && contents.keys != [ "users" ]
raise "Must pass an org name to load_data or run in single_org mode"
end
- %w(clients containers environments groups nodes roles sandboxes).each do |data_type|
+ %w{clients containers environments groups nodes roles sandboxes}.each do |data_type|
if contents[data_type]
dejsonize_children(contents[data_type]).each_pair do |name, data|
- data_store.set(['organizations', org_name, data_type, name], data, :create)
+ data_store.set(["organizations", org_name, data_type, name], data, :create)
end
end
end
- if contents['users']
- dejsonize_children(contents['users']).each_pair do |name, data|
+ if contents["users"]
+ dejsonize_children(contents["users"]).each_pair do |name, data|
if options[:osc_compat]
- data_store.set(['organizations', org_name, 'users', name], data, :create)
+ data_store.set(["organizations", org_name, "users", name], data, :create)
else
# Create the user and put them in the org
- data_store.set(['users', name], data, :create)
+ data_store.set(["users", name], data, :create)
if org_name
- data_store.set(['organizations', org_name, 'users', name], '{}', :create)
+ data_store.set(["organizations", org_name, "users", name], "{}", :create)
end
end
end
end
- if contents['members']
- contents['members'].each do |name|
- data_store.set(['organizations', org_name, 'users', name], '{}', :create)
+ if contents["members"]
+ contents["members"].each do |name|
+ data_store.set(["organizations", org_name, "users", name], "{}", :create)
end
end
- if contents['invites']
- contents['invites'].each do |name|
- data_store.set(['organizations', org_name, 'association_requests', name], '{}', :create)
+ if contents["invites"]
+ contents["invites"].each do |name|
+ data_store.set(["organizations", org_name, "association_requests", name], "{}", :create)
end
end
- if contents['acls']
- dejsonize_children(contents['acls']).each do |path, acl|
- path = [ 'organizations', org_name ] + path.split('/')
+ if contents["acls"]
+ dejsonize_children(contents["acls"]).each do |path, acl|
+ path = [ "organizations", org_name ] + path.split("/")
path = ChefData::AclPath.get_acl_data_path(path)
ChefZero::RSpec.server.data_store.set(path, acl)
end
end
- if contents['data']
- contents['data'].each_pair do |key, data_bag|
- data_store.create_dir(['organizations', org_name, 'data'], key, :recursive)
+ if contents["data"]
+ contents["data"].each_pair do |key, data_bag|
+ data_store.create_dir(["organizations", org_name, "data"], key, :recursive)
dejsonize_children(data_bag).each do |item_name, item|
- data_store.set(['organizations', org_name, 'data', key, item_name], item, :create)
+ data_store.set(["organizations", org_name, "data", key, item_name], item, :create)
end
end
end
- if contents['policies']
- contents['policies'].each_pair do |policy_name, policy_struct|
+ if contents["policies"]
+ contents["policies"].each_pair do |policy_name, policy_struct|
# data_store.create_dir(['organizations', org_name, 'policies', policy_name], "revisions", :recursive)
dejsonize_children(policy_struct).each do |revision, policy_data|
- data_store.set(['organizations', org_name, 'policies', policy_name,
+ data_store.set(["organizations", org_name, "policies", policy_name,
"revisions", revision], policy_data, :create, :create_dir)
end
end
end
- if contents['policy_groups']
- contents['policy_groups'].each_pair do |group_name, group|
- group['policies'].each do |policy_name, policy_revision|
- data_store.set(['organizations', org_name, 'policy_groups', group_name, 'policies', policy_name], FFI_Yajl::Encoder.encode(policy_revision['revision_id'], :pretty => true), :create, :create_dir)
+ if contents["policy_groups"]
+ contents["policy_groups"].each_pair do |group_name, group|
+ group["policies"].each do |policy_name, policy_revision|
+ data_store.set(["organizations", org_name, "policy_groups", group_name, "policies", policy_name], FFI_Yajl::Encoder.encode(policy_revision["revision_id"], :pretty => true), :create, :create_dir)
end
end
end
- %w(cookbooks cookbook_artifacts).each do |cookbook_type|
+ %w{cookbooks cookbook_artifacts}.each do |cookbook_type|
if contents[cookbook_type]
contents[cookbook_type].each_pair do |name_version, cookbook|
- if cookbook_type == 'cookbook_artifacts'
- name, dash, identifier = name_version.rpartition('-')
+ if cookbook_type == "cookbook_artifacts"
+ name, dash, identifier = name_version.rpartition("-")
cookbook_data = ChefData::CookbookData.to_hash(cookbook, name, identifier)
elsif name_version =~ /(.+)-(\d+\.\d+\.\d+)$/
cookbook_data = ChefData::CookbookData.to_hash(cookbook, $1, $2)
@@ -503,12 +502,12 @@ module ChefZero
cookbook_data = ChefData::CookbookData.to_hash(cookbook, name_version)
end
raise "No version specified" if !cookbook_data[:version]
- data_store.create_dir(['organizations', org_name, cookbook_type], cookbook_data[:cookbook_name], :recursive)
- data_store.set(['organizations', org_name, cookbook_type, cookbook_data[:cookbook_name], cookbook_data[:version]], FFI_Yajl::Encoder.encode(cookbook_data, :pretty => true), :create)
+ data_store.create_dir(["organizations", org_name, cookbook_type], cookbook_data[:cookbook_name], :recursive)
+ data_store.set(["organizations", org_name, cookbook_type, cookbook_data[:cookbook_name], cookbook_data[:version]], FFI_Yajl::Encoder.encode(cookbook_data, :pretty => true), :create)
cookbook_data.values.each do |files|
next unless files.is_a? Array
files.each do |file|
- data_store.set(['organizations', org_name, 'file_store', 'checksums', file[:checksum]], get_file(cookbook, file[:path]), :create)
+ data_store.set(["organizations", org_name, "file_store", "checksums", file[:checksum]], get_file(cookbook, file[:path]), :create)
end
end
end
@@ -536,48 +535,48 @@ module ChefZero
def endpoints
result = if options[:osc_compat]
- # OSC-only
- [
- [ "/organizations/*/users", ActorsEndpoint.new(self) ],
- [ "/organizations/*/users/*", ActorEndpoint.new(self) ],
- [ "/organizations/*/authenticate_user", OrganizationAuthenticateUserEndpoint.new(self) ]
- ]
- else
- # EC-only
- [
- [ "/organizations/*/users", OrganizationUsersEndpoint.new(self) ],
- [ "/organizations/*/users/*", OrganizationUserEndpoint.new(self) ],
- [ "/users", ActorsEndpoint.new(self, 'username') ],
- [ "/users/*", ActorEndpoint.new(self, 'username') ],
- [ "/users/*/_acl", AclsEndpoint.new(self) ],
- [ "/users/*/_acl/*", AclEndpoint.new(self) ],
- [ "/users/*/association_requests", UserAssociationRequestsEndpoint.new(self) ],
- [ "/users/*/association_requests/count", UserAssociationRequestsCountEndpoint.new(self) ],
- [ "/users/*/association_requests/*", UserAssociationRequestEndpoint.new(self) ],
- [ "/users/*/keys", ActorKeysEndpoint.new(self) ],
- [ "/users/*/keys/default", ActorDefaultKeyEndpoint.new(self) ],
- [ "/users/*/keys/*", ActorKeyEndpoint.new(self) ],
- [ "/users/*/organizations", UserOrganizationsEndpoint.new(self) ],
- [ "/authenticate_user", AuthenticateUserEndpoint.new(self) ],
- [ "/system_recovery", SystemRecoveryEndpoint.new(self) ],
- [ "/license", LicenseEndpoint.new(self) ],
- [ "/organizations", OrganizationsEndpoint.new(self) ],
- [ "/organizations/*", OrganizationEndpoint.new(self) ],
- [ "/organizations/*/_validator_key", OrganizationValidatorKeyEndpoint.new(self) ],
- [ "/organizations/*/association_requests", OrganizationAssociationRequestsEndpoint.new(self) ],
- [ "/organizations/*/association_requests/*", OrganizationAssociationRequestEndpoint.new(self) ],
- [ "/organizations/*/containers", ContainersEndpoint.new(self) ],
- [ "/organizations/*/containers/*", ContainerEndpoint.new(self) ],
- [ "/organizations/*/groups", GroupsEndpoint.new(self) ],
- [ "/organizations/*/groups/*", GroupEndpoint.new(self) ],
- [ "/organizations/*/organization/_acl", AclsEndpoint.new(self) ],
- [ "/organizations/*/organizations/_acl", AclsEndpoint.new(self) ],
- [ "/organizations/*/*/*/_acl", AclsEndpoint.new(self) ],
- [ "/organizations/*/organization/_acl/*", AclEndpoint.new(self) ],
- [ "/organizations/*/organizations/_acl/*", AclEndpoint.new(self) ],
- [ "/organizations/*/*/*/_acl/*", AclEndpoint.new(self) ]
- ]
- end
+ # OSC-only
+ [
+ [ "/organizations/*/users", ActorsEndpoint.new(self) ],
+ [ "/organizations/*/users/*", ActorEndpoint.new(self) ],
+ [ "/organizations/*/authenticate_user", OrganizationAuthenticateUserEndpoint.new(self) ],
+ ]
+ else
+ # EC-only
+ [
+ [ "/organizations/*/users", OrganizationUsersEndpoint.new(self) ],
+ [ "/organizations/*/users/*", OrganizationUserEndpoint.new(self) ],
+ [ "/users", ActorsEndpoint.new(self, "username") ],
+ [ "/users/*", ActorEndpoint.new(self, "username") ],
+ [ "/users/*/_acl", AclsEndpoint.new(self) ],
+ [ "/users/*/_acl/*", AclEndpoint.new(self) ],
+ [ "/users/*/association_requests", UserAssociationRequestsEndpoint.new(self) ],
+ [ "/users/*/association_requests/count", UserAssociationRequestsCountEndpoint.new(self) ],
+ [ "/users/*/association_requests/*", UserAssociationRequestEndpoint.new(self) ],
+ [ "/users/*/keys", ActorKeysEndpoint.new(self) ],
+ [ "/users/*/keys/default", ActorDefaultKeyEndpoint.new(self) ],
+ [ "/users/*/keys/*", ActorKeyEndpoint.new(self) ],
+ [ "/users/*/organizations", UserOrganizationsEndpoint.new(self) ],
+ [ "/authenticate_user", AuthenticateUserEndpoint.new(self) ],
+ [ "/system_recovery", SystemRecoveryEndpoint.new(self) ],
+ [ "/license", LicenseEndpoint.new(self) ],
+ [ "/organizations", OrganizationsEndpoint.new(self) ],
+ [ "/organizations/*", OrganizationEndpoint.new(self) ],
+ [ "/organizations/*/_validator_key", OrganizationValidatorKeyEndpoint.new(self) ],
+ [ "/organizations/*/association_requests", OrganizationAssociationRequestsEndpoint.new(self) ],
+ [ "/organizations/*/association_requests/*", OrganizationAssociationRequestEndpoint.new(self) ],
+ [ "/organizations/*/containers", ContainersEndpoint.new(self) ],
+ [ "/organizations/*/containers/*", ContainerEndpoint.new(self) ],
+ [ "/organizations/*/groups", GroupsEndpoint.new(self) ],
+ [ "/organizations/*/groups/*", GroupEndpoint.new(self) ],
+ [ "/organizations/*/organization/_acl", AclsEndpoint.new(self) ],
+ [ "/organizations/*/organizations/_acl", AclsEndpoint.new(self) ],
+ [ "/organizations/*/*/*/_acl", AclsEndpoint.new(self) ],
+ [ "/organizations/*/organization/_acl/*", AclEndpoint.new(self) ],
+ [ "/organizations/*/organizations/_acl/*", AclEndpoint.new(self) ],
+ [ "/organizations/*/*/*/_acl/*", AclEndpoint.new(self) ],
+ ]
+ end
result + [
# Both
[ "/dummy", DummyEndpoint.new(self) ],
@@ -630,7 +629,7 @@ module ChefZero
[ "/server_api_version", ServerAPIVersionEndpoint.new(self) ],
# Internal
- [ "/organizations/*/file_store/**", FileStoreFileEndpoint.new(self) ]
+ [ "/organizations/*/file_store/**", FileStoreFileEndpoint.new(self) ],
]
end
@@ -646,13 +645,13 @@ module ChefZero
router.not_found = NotFoundEndpoint.new
if options[:single_org]
- rest_base_prefix = [ 'organizations', options[:single_org] ]
+ rest_base_prefix = [ "organizations", options[:single_org] ]
else
rest_base_prefix = []
end
@app = proc do |env|
begin
- prefix = global_endpoint?(env['PATH_INFO']) ? [] : rest_base_prefix
+ prefix = global_endpoint?(env["PATH_INFO"]) ? [] : rest_base_prefix
request = RestRequest.new(env, prefix)
if @on_request_proc
@@ -670,10 +669,10 @@ module ChefZero
end
# Insert Server header
- response[1]['Server'] = 'chef-zero'
+ response[1]["Server"] = "chef-zero"
# Add CORS header
- response[1]['Access-Control-Allow-Origin'] = '*'
+ response[1]["Access-Control-Allow-Origin"] = "*"
# Puma expects the response to be an array (chunked responses). Since
# we are statically generating data, we won't ever have said chunked
@@ -705,7 +704,7 @@ module ChefZero
def get_file(directory, path)
value = directory
- path.split('/').each do |part|
+ path.split("/").each do |part|
value = value[part]
end
value
diff --git a/lib/chef_zero/socketless_server_map.rb b/lib/chef_zero/socketless_server_map.rb
index 99351a1..655047a 100644
--- a/lib/chef_zero/socketless_server_map.rb
+++ b/lib/chef_zero/socketless_server_map.rb
@@ -16,8 +16,8 @@
# limitations under the License.
#
-require 'thread'
-require 'singleton'
+require "thread"
+require "singleton"
module ChefZero
@@ -89,4 +89,3 @@ module ChefZero
end
end
-
diff --git a/lib/chef_zero/solr/query/binary_operator.rb b/lib/chef_zero/solr/query/binary_operator.rb
index 6d9b219..e733102 100644
--- a/lib/chef_zero/solr/query/binary_operator.rb
+++ b/lib/chef_zero/solr/query/binary_operator.rb
@@ -18,13 +18,13 @@ module ChefZero
def matches_doc?(doc)
case @operator
- when 'AND'
+ when "AND"
left.matches_doc?(doc) && right.matches_doc?(doc)
- when 'OR'
+ when "OR"
left.matches_doc?(doc) || right.matches_doc?(doc)
- when '^'
+ when "^"
left.matches_doc?(doc)
- when ':'
+ when ":"
if left.respond_to?(:literal_string) && left.literal_string
values = doc[left.literal_string]
else
@@ -36,13 +36,13 @@ module ChefZero
def matches_values?(values)
case @operator
- when 'AND'
+ when "AND"
left.matches_values?(values) && right.matches_values?(values)
- when 'OR'
+ when "OR"
left.matches_values?(values) || right.matches_values?(values)
- when '^'
+ when "^"
left.matches_values?(values)
- when ':'
+ when ":"
raise ": does not work inside a : or term"
end
end
diff --git a/lib/chef_zero/solr/query/phrase.rb b/lib/chef_zero/solr/query/phrase.rb
index f229da9..d345a8e 100644
--- a/lib/chef_zero/solr/query/phrase.rb
+++ b/lib/chef_zero/solr/query/phrase.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/solr/query/regexpable_query'
+require "chef_zero/solr/query/regexpable_query"
module ChefZero
module Solr
diff --git a/lib/chef_zero/solr/query/range_query.rb b/lib/chef_zero/solr/query/range_query.rb
index 625c0bb..76ec828 100644
--- a/lib/chef_zero/solr/query/range_query.rb
+++ b/lib/chef_zero/solr/query/range_query.rb
@@ -15,7 +15,7 @@ module ChefZero
def matches_values?(values)
values.any? do |value|
- unless @from == '*'
+ unless @from == "*"
case @from <=> value
when -1
return false
@@ -23,7 +23,7 @@ module ChefZero
return false if !@from_inclusive
end
end
- unless @to == '*'
+ unless @to == "*"
case value <=> @to
when 1
return false
diff --git a/lib/chef_zero/solr/query/regexpable_query.rb b/lib/chef_zero/solr/query/regexpable_query.rb
index cebc011..62d7fc7 100644
--- a/lib/chef_zero/solr/query/regexpable_query.rb
+++ b/lib/chef_zero/solr/query/regexpable_query.rb
@@ -16,6 +16,7 @@ module ChefZero
def matches_doc?(doc)
matches_values?(doc[DEFAULT_FIELD])
end
+
def matches_values?(values)
values.any? { |value| !@regexp.match(value).nil? }
end
diff --git a/lib/chef_zero/solr/query/term.rb b/lib/chef_zero/solr/query/term.rb
index 23f4a72..e106519 100644
--- a/lib/chef_zero/solr/query/term.rb
+++ b/lib/chef_zero/solr/query/term.rb
@@ -1,4 +1,4 @@
-require 'chef_zero/solr/query/regexpable_query'
+require "chef_zero/solr/query/regexpable_query"
module ChefZero
module Solr
@@ -11,19 +11,19 @@ module ChefZero
regexp_string = ""
index = 0
while index < term.length
- if term[index] == '*'
+ if term[index] == "*"
regexp_string << "#{WORD_CHARACTER}*"
literal_string = nil
index += 1
- elsif term[index] == '?'
+ elsif term[index] == "?"
regexp_string << WORD_CHARACTER
literal_string = nil
index += 1
- elsif term[index] == '~'
+ elsif term[index] == "~"
raise "~ unsupported"
else
if term[index] == '\\'
- index = index+1
+ index = index + 1
if index >= term.length
raise "Backslash at end of string '#{term}'"
end
diff --git a/lib/chef_zero/solr/query/unary_operator.rb b/lib/chef_zero/solr/query/unary_operator.rb
index a873932..e83683c 100644
--- a/lib/chef_zero/solr/query/unary_operator.rb
+++ b/lib/chef_zero/solr/query/unary_operator.rb
@@ -16,9 +16,9 @@ module ChefZero
def matches_doc?(doc)
case @operator
- when '-', 'NOT'
+ when "-", "NOT"
!operand.matches_doc?(doc)
- when '+'
+ when "+"
# TODO This operator uses relevance to eliminate other, unrelated
# expressions. +a OR b means "if it has b but not a, don't return it"
raise "+ not supported yet, because it is hard."
@@ -27,9 +27,9 @@ module ChefZero
def matches_values?(values)
case @operator
- when '-', 'NOT'
+ when "-", "NOT"
!operand.matches_values?(values)
- when '+'
+ when "+"
# TODO This operator uses relevance to eliminate other, unrelated
# expressions. +a OR b means "if it has b but not a, don't return it"
raise "+ not supported yet, because it is hard."
diff --git a/lib/chef_zero/solr/solr_doc.rb b/lib/chef_zero/solr/solr_doc.rb
index 6476d48..b25ea15 100644
--- a/lib/chef_zero/solr/solr_doc.rb
+++ b/lib/chef_zero/solr/solr_doc.rb
@@ -15,12 +15,12 @@ module ChefZero
def matching_values(&block)
result = []
key_values(nil, @json) do |key, value|
- if block.call(key)
+ if yield(key)
result << value.to_s
end
end
# Handle manufactured value(s)
- if block.call('X_CHEF_id_CHEF_X')
+ if yield("X_CHEF_id_CHEF_X")
result << @id.to_s
end
@@ -32,7 +32,7 @@ module ChefZero
def key_values(key_so_far, value, &block)
if value.is_a?(Hash)
value.each_pair do |child_key, child_value|
- block.call(child_key, child_value.to_s)
+ yield(child_key, child_value.to_s)
if key_so_far
new_key = "#{key_so_far}_#{child_key}"
key_values(new_key, child_value, &block)
@@ -45,7 +45,7 @@ module ChefZero
key_values(key_so_far, child_value, &block)
end
else
- block.call(key_so_far || 'text', value.to_s)
+ yield(key_so_far || "text", value.to_s)
end
end
end
diff --git a/lib/chef_zero/solr/solr_parser.rb b/lib/chef_zero/solr/solr_parser.rb
index 99da5fe..2bf2125 100644
--- a/lib/chef_zero/solr/solr_parser.rb
+++ b/lib/chef_zero/solr/solr_parser.rb
@@ -1,9 +1,9 @@
-require 'chef_zero/solr/query/binary_operator'
-require 'chef_zero/solr/query/unary_operator'
-require 'chef_zero/solr/query/term'
-require 'chef_zero/solr/query/phrase'
-require 'chef_zero/solr/query/range_query'
-require 'chef_zero/solr/query/subquery'
+require "chef_zero/solr/query/binary_operator"
+require "chef_zero/solr/query/unary_operator"
+require "chef_zero/solr/query/term"
+require "chef_zero/solr/query/phrase"
+require "chef_zero/solr/query/range_query"
+require "chef_zero/solr/query/subquery"
module ChefZero
module Solr
@@ -40,19 +40,20 @@ module ChefZero
# Operators
operator = peek_operator_token
if operator
- @index+=operator.length
+ @index += operator.length
operator
else
# Everything that isn't whitespace or an operator, is part of a term
# (characters plus backslashed escaped characters)
start_index = @index
- begin
+ loop do
if @query_string[@index] == '\\'
- @index+=1
+ @index += 1
end
- @index+=1 if !eof?
- end while !eof? && peek_term_token
- @query_string[start_index..@index-1]
+ @index += 1 if !eof?
+ break if eof? || !peek_term_token
+ end
+ @query_string[start_index..@index - 1]
end
end
@@ -66,15 +67,15 @@ module ChefZero
def peek_term_token
return nil if @query_string[@index] =~ /\s/
op = peek_operator_token
- return !op || op == '-'
+ return !op || op == "-"
end
def peek_operator_token
- if ['"', '+', '-', '!', '(', ')', '{', '}', '[', ']', '^', ':'].include?(@query_string[@index])
+ if ['"', "+", "-", "!", "(", ")", "{", "}", "[", "]", "^", ":"].include?(@query_string[@index])
return @query_string[@index]
else
- result = @query_string[@index..@index+1]
- if ['&&', '||'].include?(result)
+ result = @query_string[@index..@index + 1]
+ if ["&&", "||"].include?(result)
return result
end
end
@@ -91,19 +92,19 @@ module ChefZero
# Expression is over when we hit a close paren or eof
# (peek_token has the side effect of skipping whitespace for us, so we
# really know if we're at eof or not)
- until peek_token == ')' || eof?
+ until peek_token == ")" || eof?
operator = peek_token
if binary_operator?(operator)
next_token
else
# If 2 terms are next to each other, the default operator is OR
- operator = 'OR'
+ operator = "OR"
end
next_expression = read_single_expression
# Build the operator, taking precedence into account
if result.is_a?(Query::BinaryOperator) &&
- binary_operator_precedence(operator) > binary_operator_precedence(result.operator)
+ binary_operator_precedence(operator) > binary_operator_precedence(result.operator)
# a+b*c -> a+(b*c)
new_right = Query::BinaryOperator.new(result.right, operator, next_expression)
result = Query::BinaryOperator.new(result.left, result.operator, new_right)
@@ -142,7 +143,7 @@ module ChefZero
Query::Phrase.new(phrase_terms)
# If it's the start of a range query, build that
- elsif token == '{' || token == '['
+ elsif token == "{" || token == "["
left = next_token
parse_error(left, "Expected left term in range query") if !left
to = next_token
@@ -150,17 +151,17 @@ module ChefZero
right = next_token
parse_error(right, "Expected left term in range query") if !right
end_range = next_token
- parse_error(right, "Expected end range '#{end_range}") if !['}', ']'].include?(end_range)
- Query::RangeQuery.new(left, right, token == '[', end_range == ']')
+ parse_error(right, "Expected end range '#{end_range}") if !["}", "]"].include?(end_range)
+ Query::RangeQuery.new(left, right, token == "[", end_range == "]")
- elsif token == '('
+ elsif token == "("
subquery = read_expression
close_paren = next_token
- parse_error(close_paren, "Expected ')'") if close_paren != ')'
+ parse_error(close_paren, "Expected ')'") if close_paren != ")"
Query::Subquery.new(subquery)
# If it's the end of a closure, raise an exception
- elsif ['}',']',')'].include?(token)
+ elsif ["}", "]", ")"].include?(token)
parse_error(token, "Unexpected end paren")
# If it's a binary operator, raise an exception
@@ -170,7 +171,7 @@ module ChefZero
# Otherwise it's a term.
else
term = Query::Term.new(token)
- if peek_token == ':'
+ if peek_token == ":"
Query::BinaryOperator.new(term, next_token, read_single_expression)
else
term
@@ -179,27 +180,27 @@ module ChefZero
end
def unary_operator?(token)
- [ 'NOT', '+', '-' ].include?(token)
+ [ "NOT", "+", "-" ].include?(token)
end
def binary_operator?(token)
- [ 'AND', 'OR', '^', ':'].include?(token)
+ [ "AND", "OR", "^", ":"].include?(token)
end
def binary_operator_precedence(token)
case token
- when '^'
+ when "^"
4
- when ':'
+ when ":"
3
- when 'AND'
+ when "AND"
2
- when 'OR'
+ when "OR"
1
end
end
- DEFAULT_FIELD = 'text'
+ DEFAULT_FIELD = "text"
end
end
end
diff --git a/lib/chef_zero/version.rb b/lib/chef_zero/version.rb
index c884f44..77fff14 100644
--- a/lib/chef_zero/version.rb
+++ b/lib/chef_zero/version.rb
@@ -1,3 +1,3 @@
module ChefZero
- VERSION = '4.8.0'
+ VERSION = "4.8.0"
end