Parent

Class/Module Index [+]

Quicksearch

Chef::OpenIDRegistration

Constants

DESIGN_DOCUMENT

Attributes

admin[RW]
couchdb_rev[RW]
name[RW]
password[RW]
salt[RW]
validated[RW]

Public Class Methods

cdb_list(*args) click to toggle source
# File lib/chef/openid_registration.rb, line 142
def self.cdb_list(*args)
  list(*args)
end
create_design_document(couchdb=nil) click to toggle source

Set up our CouchDB design document

# 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) click to toggle source

Whether or not there is an OpenID Registration with this key.

# 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) click to toggle source

Create a Chef::Node from JSON

# 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) click to toggle source

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

# 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
load(name) click to toggle source

Load an OpenIDRegistration by name from CouchDB

# File lib/chef/openid_registration.rb, line 147
def self.load(name)
  Chef::CouchDB.new.load("openid_registration", name)
end
new() click to toggle source

Create a new Chef::OpenIDRegistration object.

# 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

Public Instance Methods

destroy() click to toggle source

Remove this OpenIDRegistration from the CouchDB

# File lib/chef/openid_registration.rb, line 157
def destroy
  @couchdb.delete("openid_registration", @name, @couchdb_rev)
end
name=(n) click to toggle source
# File lib/chef/openid_registration.rb, line 92
def name=(n)
  @name = n.gsub(/\./, '_')
end
save() click to toggle source

Save this OpenIDRegistration to the CouchDB

# 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) click to toggle source

Set the password for this object.

# File lib/chef/openid_registration.rb, line 97
def set_password(password) 
  @salt = generate_salt
  @password = encrypt_password(@salt, password)      
end
to_json(*a) click to toggle source

Serialize this object as a hash

# 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

Protected Instance Methods

encrypt_password(salt, password) click to toggle source
# File lib/chef/openid_registration.rb, line 182
def encrypt_password(salt, password)
  Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end
generate_salt() click to toggle source
# File lib/chef/openid_registration.rb, line 175
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.