summaryrefslogtreecommitdiff
path: root/chef/lib
diff options
context:
space:
mode:
authorSeth Chisamore <schisamo@opscode.com>2012-10-29 16:06:54 -0400
committerSeth Chisamore <schisamo@opscode.com>2012-10-30 09:47:38 -0400
commit8f2b289f56db71c3509c521cd9959298fa0ee9bb (patch)
treeaeb492b335833584a970d7a23b3e680302b349f3 /chef/lib
parent862d971eed1c11e6990b1c08f00cac67a10a2e79 (diff)
downloadchef-8f2b289f56db71c3509c521cd9959298fa0ee9bb.tar.gz
[OC-3564] remove Chef::IndexQueue
This class was only used by Chef server components and has been succeeded by Erchef.
Diffstat (limited to 'chef/lib')
-rw-r--r--chef/lib/chef/api_client.rb9
-rw-r--r--chef/lib/chef/config.rb10
-rw-r--r--chef/lib/chef/cookbook_version.rb3
-rw-r--r--chef/lib/chef/data_bag.rb3
-rw-r--r--chef/lib/chef/data_bag_item.rb3
-rw-r--r--chef/lib/chef/environment.rb3
-rw-r--r--chef/lib/chef/index_queue.rb29
-rw-r--r--chef/lib/chef/index_queue/amqp_client.rb116
-rw-r--r--chef/lib/chef/index_queue/consumer.rb76
-rw-r--r--chef/lib/chef/index_queue/indexable.rb109
-rw-r--r--chef/lib/chef/node.rb4
-rw-r--r--chef/lib/chef/openid_registration.rb50
-rw-r--r--chef/lib/chef/role.rb4
-rw-r--r--chef/lib/chef/sandbox.rb21
-rw-r--r--chef/lib/chef/webui_user.rb57
15 files changed, 62 insertions, 435 deletions
diff --git a/chef/lib/chef/api_client.rb b/chef/lib/chef/api_client.rb
index f95978afba..e2a0a41096 100644
--- a/chef/lib/chef/api_client.rb
+++ b/chef/lib/chef/api_client.rb
@@ -22,7 +22,6 @@ require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
require 'chef/couchdb'
require 'chef/certificate'
-require 'chef/index_queue'
require 'chef/mash'
require 'chef/json_compat'
require 'chef/search/query'
@@ -32,7 +31,6 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
DESIGN_DOCUMENT = {
@@ -60,12 +58,6 @@ class Chef
}
}
- INDEX_OBJECT_TYPE = 'client'.freeze
-
- def self.index_object_type
- INDEX_OBJECT_TYPE
- end
-
attr_accessor :couchdb_rev, :couchdb_id, :couchdb
# Create a new Chef::ApiClient object.
@@ -168,7 +160,6 @@ class Chef
client.admin(o["admin"])
client.couchdb_rev = o["_rev"]
client.couchdb_id = o["_id"]
- client.index_id = client.couchdb_id
client
end
diff --git a/chef/lib/chef/config.rb b/chef/lib/chef/config.rb
index 5fd50d3bda..b60427ca57 100644
--- a/chef/lib/chef/config.rb
+++ b/chef/lib/chef/config.rb
@@ -229,16 +229,6 @@ class Chef
# Where should chef-solo download recipes from?
recipe_url nil
- # Parameters for connecting to RabbitMQ
- amqp_host '0.0.0.0'
- amqp_port '5672'
- amqp_user 'chef'
- amqp_pass 'testing'
- amqp_vhost '/chef'
- # Setting this to a UUID string also makes the queue durable
- # (persist across rabbitmq restarts)
- amqp_consumer_id "default"
-
# Sets the version of the signed header authentication protocol to use (see
# the 'mixlib-authorization' project for more detail). Currently, versions
# 1.0 and 1.1 are available; however, the chef-server must first be
diff --git a/chef/lib/chef/cookbook_version.rb b/chef/lib/chef/cookbook_version.rb
index a6f95e2c3b..ef28bf8d50 100644
--- a/chef/lib/chef/cookbook_version.rb
+++ b/chef/lib/chef/cookbook_version.rb
@@ -113,7 +113,6 @@ class Chef
# TODO: timh/cw: 5-24-2010: mutators for files (e.g., recipe_filenames=,
# recipe_filenames.insert) should dirty the manifest so it gets regenerated.
class CookbookVersion
- include Chef::IndexQueue::Indexable
include Comparable
COOKBOOK_SEGMENTS = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
@@ -779,7 +778,6 @@ class Chef
end
if o.has_key?("_id")
cookbook_version.couchdb_id = o["_id"] if o.has_key?("_id")
- cookbook_version.index_id = cookbook_version.couchdb_id
o.delete("_id")
end
# We want the Chef::Cookbook::Metadata object to always be inflated
@@ -962,7 +960,6 @@ class Chef
def couchdb_id=(value)
@couchdb_id = value
- @index_id = value
end
def <=>(o)
diff --git a/chef/lib/chef/data_bag.rb b/chef/lib/chef/data_bag.rb
index 32188c0861..e270dde062 100644
--- a/chef/lib/chef/data_bag.rb
+++ b/chef/lib/chef/data_bag.rb
@@ -23,7 +23,6 @@ require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
require 'chef/couchdb'
require 'chef/data_bag_item'
-require 'chef/index_queue'
require 'chef/mash'
require 'chef/json_compat'
@@ -32,7 +31,6 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
VALID_NAME = /^[\-[:alnum:]_]+$/
@@ -123,7 +121,6 @@ class Chef
bag.name(o["name"])
bag.couchdb_rev = o["_rev"] if o.has_key?("_rev")
bag.couchdb_id = o["_id"] if o.has_key?("_id")
- bag.index_id = bag.couchdb_id
bag
end
diff --git a/chef/lib/chef/data_bag_item.rb b/chef/lib/chef/data_bag_item.rb
index 87bde509a5..170c7d9ad0 100644
--- a/chef/lib/chef/data_bag_item.rb
+++ b/chef/lib/chef/data_bag_item.rb
@@ -24,7 +24,6 @@ require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
require 'chef/couchdb'
-require 'chef/index_queue'
require 'chef/data_bag'
require 'chef/mash'
require 'chef/json_compat'
@@ -36,7 +35,6 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
VALID_ID = /^[\-[:alnum:]_]+$/
@@ -175,7 +173,6 @@ class Chef
end
if o.has_key?("_id")
bag_item.couchdb_id = o["_id"]
- bag_item.index_id = bag_item.couchdb_id
o.delete("_id")
end
bag_item.raw_data = Mash.new(o["raw_data"])
diff --git a/chef/lib/chef/environment.rb b/chef/lib/chef/environment.rb
index 1e2cea282b..745b5bb55f 100644
--- a/chef/lib/chef/environment.rb
+++ b/chef/lib/chef/environment.rb
@@ -23,7 +23,6 @@ require 'chef/mash'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
require 'chef/couchdb'
-require 'chef/index_queue'
require 'chef/version_constraint'
class Chef
@@ -33,7 +32,6 @@ class Chef
include Chef::Mixin::ParamsValidate
include Chef::Mixin::FromFile
- include Chef::IndexQueue::Indexable
COMBINED_COOKBOOK_CONSTRAINT = /(.+)(?:[\s]+)((?:#{Chef::VersionConstraint::OPS.join('|')})(?:[\s]+).+)$/.freeze
@@ -78,7 +76,6 @@ class Chef
def couchdb_id=(value)
@couchdb_id = value
- self.index_id = value
end
def chef_server_rest
diff --git a/chef/lib/chef/index_queue.rb b/chef/lib/chef/index_queue.rb
deleted file mode 100644
index b350949aae..0000000000
--- a/chef/lib/chef/index_queue.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Author:: Daniel DeLeo (<dan@kallistec.com>)
-# Copyright:: Copyright (c) 2009 Daniel DeLeo
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require "singleton"
-require "bunny"
-
-require "chef/index_queue/amqp_client"
-require "chef/index_queue/indexable"
-require "chef/index_queue/consumer"
-
-class Chef
- module IndexQueue
- end
-end
diff --git a/chef/lib/chef/index_queue/amqp_client.rb b/chef/lib/chef/index_queue/amqp_client.rb
deleted file mode 100644
index a7d155f4d1..0000000000
--- a/chef/lib/chef/index_queue/amqp_client.rb
+++ /dev/null
@@ -1,116 +0,0 @@
-#
-# Author:: Daniel DeLeo (<dan@kallistec.com>)
-# Copyright:: Copyright (c) 2009 Daniel DeLeo
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-class Chef
- module IndexQueue
- class AmqpClient
- VNODES = 1024
-
- include Singleton
-
- def initialize
- reset!
- end
-
- def reset!
- @amqp_client && amqp_client.connected? && amqp_client.stop
- @amqp_client = nil
- @exchange = nil
- end
-
- def stop
- @amqp_client && @amqp_client.stop
- end
-
- def amqp_client
- unless @amqp_client
- begin
- @amqp_client = Bunny.new(amqp_opts)
- Chef::Log.debug "Starting AMQP connection with client settings: #{@amqp_client.inspect}"
- @amqp_client.start
- @amqp_client.qos(:prefetch_count => 1)
- rescue Bunny::ServerDownError => e
- Chef::Log.fatal "Could not connect to rabbitmq. Is it running, reachable, and configured correctly?"
- raise e
- rescue Bunny::ProtocolError => e
- Chef::Log.fatal "Connection to rabbitmq refused. Check your rabbitmq configuration and chef's amqp* settings"
- raise e
- end
- end
- @amqp_client
- end
-
- def exchange
- @exchange ||= amqp_client.exchange("chef-indexer", :durable => true, :type => :fanout)
- end
-
- def disconnected!
- Chef::Log.error("Disconnected from the AMQP Broker (RabbitMQ)")
- @amqp_client = nil
- reset!
- end
-
- def queue_for_object(obj_id)
- retries = 0
- vnode_tag = obj_id_to_int(obj_id) % VNODES
- begin
- yield amqp_client.queue("vnode-#{vnode_tag}", :passive => false, :durable => true, :exclusive => false, :auto_delete => false)
- rescue Bunny::ServerDownError, Bunny::ConnectionError, Errno::ECONNRESET
- disconnected!
- if (retries += 1) < 2
- Chef::Log.info("Attempting to reconnect to the AMQP broker")
- retry
- else
- Chef::Log.fatal("Could not re-connect to the AMQP broker, giving up")
- raise
- end
- end
- end
-
- private
-
- # Sometimes object ids are "proper" UUIDs, like "64bc00eb-120b-b6a2-ec0e-34fc90d151be"
- # and sometimes they omit the dashes, like "64bc00eb120bb6a2ec0e34fc90d151be"
- # UUIDTools uses different methods to parse the different styles.
- def obj_id_to_int(obj_id)
- UUIDTools::UUID.parse(obj_id).to_i
- rescue ArgumentError
- UUIDTools::UUID.parse_hexdigest(obj_id).to_i
- end
-
- def durable_queue?
- !!Chef::Config[:amqp_consumer_id]
- end
-
- def consumer_id
- Chef::Config[:amqp_consumer_id] || UUIDTools::UUID.random_create.to_s
- end
-
- def amqp_opts
- { :spec => '08',
- :host => Chef::Config[:amqp_host],
- :port => Chef::Config[:amqp_port],
- :user => Chef::Config[:amqp_user],
- :pass => Chef::Config[:amqp_pass],
- :vhost => Chef::Config[:amqp_vhost]}
- end
-
- end
- end
-end
-
diff --git a/chef/lib/chef/index_queue/consumer.rb b/chef/lib/chef/index_queue/consumer.rb
deleted file mode 100644
index 8701cffa47..0000000000
--- a/chef/lib/chef/index_queue/consumer.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# Author:: Daniel DeLeo (<dan@kallistec.com>)
-# Copyright:: Copyright (c) 2009 Daniel DeLeo
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-class Chef
- module IndexQueue
- module Consumer
- module ClassMethods
- def expose(*methods)
- @exposed_methods = Array(@exposed_methods)
- @exposed_methods += methods
- end
-
- def exposed_methods
- @exposed_methods || []
- end
-
- def whitelisted?(method_name)
- exposed_methods.include?(method_name)
- end
- end
-
- def self.included(including_class)
- including_class.send(:extend, ClassMethods)
- end
-
- def run
- Chef::Log.debug("Starting Index Queue Consumer")
- AmqpClient.instance.queue # triggers connection setup
-
- begin
- AmqpClient.instance.queue.subscribe(:ack => true, :timeout => false) do |message|
- call_action_for_message(message)
- end
- rescue Bunny::ConnectionError, Errno::ECONNRESET, Bunny::ServerDownError
- AmqpClient.instance.disconnected!
- Chef::Log.warn "Connection to rabbitmq lost. attempting to reconnect"
- sleep 1
- retry
- end
- end
- alias :start :run
-
- def call_action_for_message(message)
- amqp_payload = Chef::JSONCompat.from_json(message[:payload], :create_additions => false, :max_nesting => false)
- action = amqp_payload["action"].to_sym
- app_payload = amqp_payload["payload"]
- assert_method_whitelisted(action)
- send(action, app_payload)
- end
-
- private
-
- def assert_method_whitelisted(method_name)
- unless self.class.whitelisted?(method_name)
- raise ArgumentError, "non-exposed method #{method_name} called via index queue"
- end
- end
-
- end
- end
-end
diff --git a/chef/lib/chef/index_queue/indexable.rb b/chef/lib/chef/index_queue/indexable.rb
deleted file mode 100644
index 73fd08bbb5..0000000000
--- a/chef/lib/chef/index_queue/indexable.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-#
-# Author:: Daniel DeLeo (<dan@kallistec.com>)
-# Author:: Seth Falcon (<seth@opscode.com>)
-# Copyright:: Copyright (c) 2009 Daniel DeLeo
-# Copyright:: Copyright (c) 2010 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-require 'chef/json_compat'
-
-class Chef
- module IndexQueue
- module Indexable
-
- module ClassMethods
-
- def index_object_type(explicit_type_name=nil)
- @index_object_type = explicit_type_name.to_s if explicit_type_name
- @index_object_type
- end
-
- # Resets all metadata used for indexing to nil. Used for testing
- def reset_index_metadata!
- @index_object_type = nil
- end
-
- end
-
- def self.included(including_class)
- including_class.send(:extend, ClassMethods)
- end
-
- attr_accessor :index_id
-
- def index_object_type
- self.class.index_object_type || Mixin::ConvertToClassName.snake_case_basename(self.class.name)
- end
-
- def with_indexer_metadata(indexer_metadata={})
- # changing input param symbol keys to strings, as the keys in hash that goes to solr are expected to be strings [cb]
- # Ruby 1.9 hates you, cb [dan]
- with_metadata = {}
- indexer_metadata.each_key do |key|
- with_metadata[key.to_s] = indexer_metadata[key]
- end
-
- with_metadata["type"] ||= self.index_object_type
- with_metadata["id"] ||= self.index_id
- with_metadata["database"] ||= Chef::Config[:couchdb_database]
- with_metadata["item"] ||= self.to_hash
- with_metadata["enqueued_at"] ||= Time.now.utc.to_i
-
- raise ArgumentError, "Type, Id, or Database missing in index operation: #{with_metadata.inspect}" if (with_metadata["id"].nil? or with_metadata["type"].nil?)
- with_metadata
- end
-
- def add_to_index(metadata={})
- Chef::Log.debug("Pushing item to index queue for addition: #{self.with_indexer_metadata(metadata)}")
- object_with_metadata = with_indexer_metadata(metadata)
- obj_id = object_with_metadata["id"]
- obj = {:action => :add, :payload => self.with_indexer_metadata(metadata)}
-
- publish_object(obj_id, obj)
- end
-
- def delete_from_index(metadata={})
- Chef::Log.debug("Pushing item to index queue for deletion: #{self.with_indexer_metadata(metadata)}")
- object_with_metadata = with_indexer_metadata(metadata)
- obj_id = object_with_metadata["id"]
- obj = {:action => :delete, :payload => self.with_indexer_metadata(metadata)}
-
- publish_object(obj_id, obj)
- end
-
- private
-
- # Uses the publisher to update the object's queue. If
- # Chef::Config[:persistent_queue] is true, the update is wrapped
- # in a transaction.
- def publish_object(object_id, object)
- publisher = AmqpClient.instance
- begin
- publisher.amqp_client.tx_select if Chef::Config[:persistent_queue]
- publisher.queue_for_object(object_id) do |queue|
- queue.publish(Chef::JSONCompat.to_json(object), :persistent => Chef::Config[:persistent_queue])
- end
- publisher.amqp_client.tx_commit if Chef::Config[:persistent_queue]
- rescue
- publisher.amqp_client.tx_rollback if Chef::Config[:persistent_queue]
- raise
- end
-
- true
- end
-
- end
- end
-end
diff --git a/chef/lib/chef/node.rb b/chef/lib/chef/node.rb
index 1229e0db28..8efa43e149 100644
--- a/chef/lib/chef/node.rb
+++ b/chef/lib/chef/node.rb
@@ -32,7 +32,6 @@ require 'chef/couchdb'
require 'chef/rest'
require 'chef/run_list'
require 'chef/node/attribute'
-require 'chef/index_queue'
require 'chef/mash'
require 'chef/json_compat'
require 'chef/search/query'
@@ -54,7 +53,6 @@ class Chef
include Chef::Mixin::CheckHelper
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
DESIGN_DOCUMENT = {
"version" => 11,
@@ -167,7 +165,6 @@ class Chef
def couchdb_id=(value)
@couchdb_id = value
- @index_id = value
end
# Used by DSL
@@ -504,7 +501,6 @@ class Chef
end
node.couchdb_rev = o["_rev"] if o.has_key?("_rev")
node.couchdb_id = o["_id"] if o.has_key?("_id")
- node.index_id = node.couchdb_id
node
end
diff --git a/chef/lib/chef/openid_registration.rb b/chef/lib/chef/openid_registration.rb
index f7bb9595d9..7af720cabd 100644
--- a/chef/lib/chef/openid_registration.rb
+++ b/chef/lib/chef/openid_registration.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,18 +19,16 @@
require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/couchdb'
-require 'chef/index_queue'
require 'digest/sha1'
require 'chef/json_compat'
class Chef
class OpenIDRegistration
-
+
attr_accessor :name, :salt, :validated, :password, :couchdb_rev, :admin
-
+
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
-
+
DESIGN_DOCUMENT = {
"version" => 3,
"language" => "javascript",
@@ -77,7 +75,7 @@ class Chef
},
},
}
-
+
# Create a new Chef::OpenIDRegistration object.
def initialize()
@name = nil
@@ -88,18 +86,18 @@ class Chef
@couchdb_rev = nil
@couchdb = Chef::CouchDB.new
end
-
+
def name=(n)
@name = n.gsub(/\./, '_')
end
-
+
# Set the password for this object.
- def set_password(password)
+ def set_password(password)
@salt = generate_salt
- @password = encrypt_password(@salt, password)
+ @password = encrypt_password(@salt, password)
end
-
- # Serialize this object as a hash
+
+ # Serialize this object as a hash
def to_json(*a)
attributes = Hash.new
recipes = Array.new
@@ -115,7 +113,7 @@ class Chef
result["_rev"] = @couchdb_rev if @couchdb_rev
result.to_json(*a)
end
-
+
# Create a Chef::Node from JSON
def self.json_create(o)
me = new
@@ -127,7 +125,7 @@ class Chef
me.couchdb_rev = o["_rev"] if o.has_key?("_rev")
me
end
-
+
# List all the Chef::OpenIDRegistration objects in the CouchDB. If inflate is set to true, you will get
# the full list of all registration objects. Otherwise, you'll just get the IDs
def self.list(inflate=false)
@@ -138,50 +136,50 @@ class Chef
rs["rows"].collect { |r| r["key"] }
end
end
-
+
def self.cdb_list(*args)
list(*args)
end
-
+
# Load an OpenIDRegistration by name from CouchDB
def self.load(name)
Chef::CouchDB.new.load("openid_registration", name)
end
-
+
# Whether or not there is an OpenID Registration with this key.
def self.has_key?(name)
Chef::CouchDB.new.has_key?("openid_registration", name)
end
-
+
# Remove this OpenIDRegistration from the CouchDB
def destroy
@couchdb.delete("openid_registration", @name, @couchdb_rev)
end
-
+
# Save this OpenIDRegistration to the CouchDB
def save
results = @couchdb.store("openid_registration", @name, self)
@couchdb_rev = results["rev"]
end
-
+
# Set up our CouchDB design document
def self.create_design_document(couchdb=nil)
couchdb ||= Chef::CouchDB.new
couchdb.create_design_document("registrations", DESIGN_DOCUMENT)
end
-
+
protected
-
+
def generate_salt
salt = Time.now.to_s
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
1.upto(30) { |i| salt << chars[rand(chars.size-1)] }
salt
end
-
+
def encrypt_password(salt, password)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end
-
+
end
end
diff --git a/chef/lib/chef/role.rb b/chef/lib/chef/role.rb
index c428472f1f..79b71c3995 100644
--- a/chef/lib/chef/role.rb
+++ b/chef/lib/chef/role.rb
@@ -23,7 +23,6 @@ require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
require 'chef/couchdb'
require 'chef/run_list'
-require 'chef/index_queue'
require 'chef/mash'
require 'chef/json_compat'
require 'chef/search/query'
@@ -33,7 +32,6 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
DESIGN_DOCUMENT = {
"version" => 6,
@@ -77,7 +75,6 @@ class Chef
def couchdb_id=(value)
@couchdb_id = value
- self.index_id = value
end
def chef_server_rest
@@ -215,7 +212,6 @@ class Chef
role.env_run_lists(env_run_list_hash)
role.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- role.index_id = role.couchdb_id
role.couchdb_id = o["_id"] if o.has_key?("_id")
role
end
diff --git a/chef/lib/chef/sandbox.rb b/chef/lib/chef/sandbox.rb
index 4d05a1db70..9522594c20 100644
--- a/chef/lib/chef/sandbox.rb
+++ b/chef/lib/chef/sandbox.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,9 +23,9 @@ class Chef
attr_accessor :is_completed, :create_time
alias_method :is_completed?, :is_completed
attr_reader :guid
-
+
alias :name :guid
-
+
attr_accessor :couchdb, :couchdb_id, :couchdb_rev
# list of checksum ids
@@ -37,7 +37,7 @@ class Chef
"views" => {
"all" => {
"map" => <<-EOJS
- function(doc) {
+ function(doc) {
if (doc.chef_type == "sandbox") {
emit(doc.guid, doc);
}
@@ -73,8 +73,8 @@ class Chef
},
}
}
-
- # Creates a new Chef::Sandbox object.
+
+ # Creates a new Chef::Sandbox object.
#
# === Returns
# object<Chef::Sandbox>:: Duh. :)
@@ -116,7 +116,6 @@ class Chef
end
if o.has_key?("_id")
sandbox.couchdb_id = o["_id"]
- #sandbox.index_id = sandbox.couchdb_id
o.delete("_id")
end
sandbox
@@ -125,15 +124,15 @@ class Chef
##
# Couchdb
##
-
+
def self.create_design_document(couchdb=nil)
(couchdb || Chef::CouchDB.new).create_design_document("sandboxes", DESIGN_DOCUMENT)
end
-
+
def self.cdb_list(inflate=false, couchdb=nil)
rs = (couchdb || Chef::CouchDB.new).list("sandboxes", inflate)
lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
+ rs["rows"].collect { |r| r[lookup] }
end
def self.cdb_load(guid, couchdb=nil)
diff --git a/chef/lib/chef/webui_user.rb b/chef/lib/chef/webui_user.rb
index e0dbde4a61..3cb1854c8d 100644
--- a/chef/lib/chef/webui_user.rb
+++ b/chef/lib/chef/webui_user.rb
@@ -7,9 +7,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,52 +19,51 @@
require 'chef/config'
require 'chef/mixin/params_validate'
-require 'chef/index_queue'
require 'digest/sha1'
require 'chef/json_compat'
-
+
class Chef
class WebUIUser
-
+
attr_accessor :name, :validated, :admin, :openid, :couchdb
attr_reader :password, :salt, :couchdb_id, :couchdb_rev
-
+
include Chef::Mixin::ParamsValidate
-
+
# Create a new Chef::WebUIUser object.
def initialize(opts={})
@name, @salt, @password = opts['name'], opts['salt'], opts['password']
@openid = opts['openid']
@admin = false
end
-
+
def name=(n)
@name = n.gsub(/\./, '_')
end
-
+
def admin?
admin
end
-
+
# Set the password for this object.
- def set_password(password, confirm_password=password)
+ def set_password(password, confirm_password=password)
raise ArgumentError, "Passwords do not match" unless password == confirm_password
raise ArgumentError, "Password cannot be blank" if (password.nil? || password.length==0)
raise ArgumentError, "Password must be a minimum of 6 characters" if password.length < 6
generate_salt
- @password = encrypt_password(password)
+ @password = encrypt_password(password)
end
-
+
def set_openid(given_openid)
@openid = given_openid
- end
-
+ end
+
def verify_password(given_password)
encrypt_password(given_password) == @password
- end
-
- # Serialize this object as a hash
+ end
+
+ # Serialize this object as a hash
def to_json(*a)
attributes = Hash.new
recipes = Array.new
@@ -77,11 +76,11 @@ class Chef
'admin' => admin,
'chef_type' => 'webui_user',
}
- result["_id"] = @couchdb_id if @couchdb_id
+ result["_id"] = @couchdb_id if @couchdb_id
result["_rev"] = @couchdb_rev if @couchdb_rev
result.to_json(*a)
end
-
+
# Create a Chef::WebUIUser from JSON
def self.json_create(o)
me = new(o)
@@ -96,7 +95,7 @@ class Chef
def self.chef_server_rest
Chef::REST.new(Chef::Config[:chef_server_url])
end
-
+
def self.list(inflate=false)
if inflate
response = Hash.new
@@ -108,17 +107,17 @@ class Chef
chef_server_rest.get_rest("users")
end
end
-
+
# Load a User by name
def self.load(name)
chef_server_rest.get_rest("users/#{name}")
end
-
+
# Remove this WebUIUser via the REST API
def destroy
chef_server_rest.delete_rest("users/#{@name}")
end
-
+
# Save this WebUIUser via the REST API
def save
begin
@@ -132,25 +131,25 @@ class Chef
end
self
end
-
+
# Create the WebUIUser via the REST API
def create
chef_server_rest.post_rest("users", self)
self
end
-
+
protected
-
+
def generate_salt
@salt = Time.now.to_s
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
1.upto(30) { |i| @salt << chars[rand(chars.size-1)] }
@salt
end
-
+
def encrypt_password(password)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end
-
+
end
end