Class: Chef::OpenIDRegistration
- Inherits:
-
Object
- Object
- Chef::OpenIDRegistration
- Includes:
- 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.
Class Method Summary collapse
-
.create_design_document ⇒ 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 node from the CouchDB.
-
#initialize ⇒ OpenIDRegistration
constructor
Create a new Chef::OpenIDRegistration object.
-
#save ⇒ Object
Save this node 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 Mixin::ParamsValidate
Constructor Details
#initialize ⇒ OpenIDRegistration
Create a new Chef::OpenIDRegistration object.
81 82 83 84 85 86 87 88 89 |
# File 'lib/chef/openid_registration.rb', line 81 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
.create_design_document ⇒ Object
Set up our CouchDB design document
163 164 165 |
# File 'lib/chef/openid_registration.rb', line 163 def self.create_design_document Chef::CouchDB.new.create_design_document("registrations", DESIGN_DOCUMENT) end |
.has_key?(name) ⇒ Boolean
Whether or not there is an OpenID Registration with this key.
147 148 149 |
# File 'lib/chef/openid_registration.rb', line 147 def self.has_key?(name) Chef::CouchDB.new.has_key?("openid_registration", name) end |
.json_create(o) ⇒ Object
Create a Chef::Node from JSON
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/chef/openid_registration.rb', line 119 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
132 133 134 135 136 137 138 139 |
# File 'lib/chef/openid_registration.rb', line 132 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 node from the CouchDB
152 153 154 |
# File 'lib/chef/openid_registration.rb', line 152 def destroy @couchdb.delete("openid_registration", @name, @couchdb_rev) end |
#save ⇒ Object
Save this node to the CouchDB
157 158 159 160 |
# File 'lib/chef/openid_registration.rb', line 157 def save results = @couchdb.store("openid_registration", @name, self) @couchdb_rev = results["rev"] end |
#set_password(password) ⇒ Object
Set the password for this object.
96 97 98 99 |
# File 'lib/chef/openid_registration.rb', line 96 def set_password(password) @salt = generate_salt @password = encrypt_password(@salt, password) end |
#to_json(*a) ⇒ Object
Serialize this object as a hash
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/chef/openid_registration.rb', line 102 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 |