Class: Chef::OpenIDRegistration
- Includes:
- IndexQueue::Indexable, Mixin::ParamsValidate
- Defined in:
- lib/chef/openid_registration.rb
Constant Summary collapse
- DESIGN_DOCUMENT =
{ "version" => 3, "language" => "javascript", "views" => { "all" => { "map" => <<-EOJS function(doc) { if (doc.chef_type == "openid_registration") { emit(doc.name, doc); } } EOJS }, "all_id" => { "map" => <<-EOJS function(doc) { if (doc.chef_type == "openid_registration") { emit(doc.name, doc.name); } } EOJS }, "validated" => { "map" => <<-EOJS function(doc) { if (doc.chef_type == "openid_registration") { if (doc.validated == true) { emit(doc.name, doc); } } } EOJS }, "unvalidated" => { "map" => <<-EOJS function(doc) { if (doc.chef_type == "openid_registration") { if (doc.validated == false) { emit(doc.name, doc); } } } EOJS }, }, }
Instance Attribute Summary collapse
-
#admin ⇒ Object
Returns the value of attribute admin.
-
#couchdb_rev ⇒ Object
Returns the value of attribute couchdb_rev.
-
#name ⇒ Object
Returns the value of attribute name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#salt ⇒ Object
Returns the value of attribute salt.
-
#validated ⇒ Object
Returns the value of attribute validated.
Attributes included from IndexQueue::Indexable
Class Method Summary collapse
- .cdb_list(*args) ⇒ Object
-
.create_design_document(couchdb = nil) ⇒ Object
Set up our CouchDB design document.
-
.has_key?(name) ⇒ Boolean
Whether or not there is an OpenID Registration with this key.
-
.json_create(o) ⇒ Object
Create a Chef::Node from JSON.
-
.list(inflate = false) ⇒ Object
List all the Chef::OpenIDRegistration objects in the CouchDB.
-
.load(name) ⇒ Object
Load an OpenIDRegistration by name from CouchDB.
Instance Method Summary collapse
-
#destroy ⇒ Object
Remove this OpenIDRegistration from the CouchDB.
-
#initialize ⇒ OpenIDRegistration
constructor
Create a new Chef::OpenIDRegistration object.
-
#save ⇒ Object
Save this OpenIDRegistration to the CouchDB.
-
#set_password(password) ⇒ Object
Set the password for this object.
-
#to_json(*a) ⇒ Object
Serialize this object as a hash.
Methods included from IndexQueue::Indexable
#add_to_index, #delete_from_index, included, #index_object_type, #with_indexer_metadata
Methods included from Mixin::ParamsValidate
Constructor Details
#initialize ⇒ OpenIDRegistration
Create a new Chef::OpenIDRegistration object.
82 83 84 85 86 87 88 89 90 |
# File 'lib/chef/openid_registration.rb', line 82 def initialize() @name = nil @salt = nil @password = nil @validated = false @admin = false @couchdb_rev = nil @couchdb = Chef::CouchDB.new end |
Instance Attribute Details
#admin ⇒ Object
Returns the value of attribute admin.
29 30 31 |
# File 'lib/chef/openid_registration.rb', line 29 def admin @admin end |
#couchdb_rev ⇒ Object
Returns the value of attribute couchdb_rev.
29 30 31 |
# File 'lib/chef/openid_registration.rb', line 29 def couchdb_rev @couchdb_rev end |
#name ⇒ Object
Returns the value of attribute name.
29 30 31 |
# File 'lib/chef/openid_registration.rb', line 29 def name @name end |
#password ⇒ Object
Returns the value of attribute password.
29 30 31 |
# File 'lib/chef/openid_registration.rb', line 29 def password @password end |
#salt ⇒ Object
Returns the value of attribute salt.
29 30 31 |
# File 'lib/chef/openid_registration.rb', line 29 def salt @salt end |
#validated ⇒ Object
Returns the value of attribute validated.
29 30 31 |
# File 'lib/chef/openid_registration.rb', line 29 def validated @validated end |
Class Method Details
.cdb_list(*args) ⇒ Object
142 143 144 |
# File 'lib/chef/openid_registration.rb', line 142 def self.cdb_list(*args) list(*args) end |
.create_design_document(couchdb = nil) ⇒ Object
Set up our CouchDB design document
168 169 170 171 |
# File 'lib/chef/openid_registration.rb', line 168 def self.create_design_document(couchdb=nil) couchdb ||= Chef::CouchDB.new couchdb.create_design_document("registrations", DESIGN_DOCUMENT) end |
.has_key?(name) ⇒ Boolean
Whether or not there is an OpenID Registration with this key.
152 153 154 |
# File 'lib/chef/openid_registration.rb', line 152 def self.has_key?(name) Chef::CouchDB.new.has_key?("openid_registration", name) end |
.json_create(o) ⇒ Object
Create a Chef::Node from JSON
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/chef/openid_registration.rb', line 120 def self.json_create(o) me = new me.name = o["name"] me.salt = o["salt"] me.password = o["password"] me.validated = o["validated"] me.admin = o["admin"] me.couchdb_rev = o["_rev"] if o.has_key?("_rev") me end |
.list(inflate = false) ⇒ Object
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
133 134 135 136 137 138 139 140 |
# File 'lib/chef/openid_registration.rb', line 133 def self.list(inflate=false) rs = Chef::CouchDB.new.list("registrations", inflate) if inflate rs["rows"].collect { |r| r["value"] } else rs["rows"].collect { |r| r["key"] } end end |
Instance Method Details
#destroy ⇒ Object
Remove this OpenIDRegistration from the CouchDB
157 158 159 |
# File 'lib/chef/openid_registration.rb', line 157 def destroy @couchdb.delete("openid_registration", @name, @couchdb_rev) end |
#save ⇒ Object
Save this OpenIDRegistration to the CouchDB
162 163 164 165 |
# File 'lib/chef/openid_registration.rb', line 162 def save results = @couchdb.store("openid_registration", @name, self) @couchdb_rev = results["rev"] end |
#set_password(password) ⇒ Object
Set the password for this object.
97 98 99 100 |
# File 'lib/chef/openid_registration.rb', line 97 def set_password(password) @salt = generate_salt @password = encrypt_password(@salt, password) end |
#to_json(*a) ⇒ Object
Serialize this object as a hash
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/chef/openid_registration.rb', line 103 def to_json(*a) attributes = Hash.new recipes = Array.new result = { 'name' => @name, 'json_class' => self.class.name, 'salt' => @salt, 'password' => @password, 'validated' => @validated, 'admin' => @admin, 'chef_type' => 'openid_registration', } result["_rev"] = @couchdb_rev if @couchdb_rev result.to_json(*a) end |