Class: OpenID::Store::CouchDB
- Inherits:
-
Interface
- Object
- Interface
- OpenID::Store::CouchDB
- Defined in:
- lib/openid/store/couchdb.rb,
lib/openid/store/couchdb/nonce.rb,
lib/openid/store/couchdb/association.rb
Overview
From what I can tell, the original openid-store-couchdb isn’t entirely complete, and there seems to be no word on the progress of integrating it into Chef proper. Also, it makes use of CouchDB features I don’t yet support in hideabed.
Also note that OpenID is largely going away in Chef 0.8, so we really just need a stopgap measure.
Defined Under Namespace
Classes: Association, Nonce
Instance Method Summary collapse
-
#cleanup_associations ⇒ Object
Remove expired associations from the store.
-
#cleanup_nonces ⇒ Object
Remove expired nonces from the store.
-
#get_association(server_url, handle = nil) ⇒ Object
Returns a Association object from storage that matches the server_url.
-
#initialize(*args) ⇒ CouchDB
constructor
A new instance of CouchDB.
-
#remove_association(server_url, handle) ⇒ Object
If there is a matching association, remove it from the store and return true, otherwise return false.
-
#store_association(server_url, association) ⇒ Object
Put a Association object into storage.
-
#use_nonce(server_url, timestamp, salt) ⇒ Object
Return true if the nonce has not been used before, and store it for a while to make sure someone doesn’t try to use the same value again.
Constructor Details
#initialize(*args) ⇒ CouchDB
Returns a new instance of CouchDB.
20 21 22 23 |
# File 'lib/openid/store/couchdb.rb', line 20 def initialize(*args) Association.create_design_document Nonce.create_design_document end |
Instance Method Details
#cleanup_associations ⇒ Object
Remove expired associations from the store. Not called during normal library operation, this method is for store admins to keep their storage from filling up with expired data.
62 63 64 |
# File 'lib/openid/store/couchdb.rb', line 62 def cleanup_associations raise NotImplementedError end |
#cleanup_nonces ⇒ Object
Remove expired nonces from the store. Discards any nonce that is old enough that it wouldn’t pass use_nonce Not called during normal library operation, this method is for store admins to keep their storage from filling up with expired data.
84 85 86 |
# File 'lib/openid/store/couchdb.rb', line 84 def cleanup_nonces raise NotImplementedError end |
#get_association(server_url, handle = nil) ⇒ Object
Returns a Association object from storage that matches the server_url. Returns nil if no such association is found or if the one matching association is expired. (Is allowed to GC expired associations when found.)
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/openid/store/couchdb.rb', line 42 def get_association(server_url, handle=nil) if document = Association.load(server_url, handle) if document.expired? document.destroy nil else document.association end end end |
#remove_association(server_url, handle) ⇒ Object
If there is a matching association, remove it from the store and return true, otherwise return false.
55 56 57 |
# File 'lib/openid/store/couchdb.rb', line 55 def remove_association(server_url, handle) Association.destroy(server_url, handle) end |
#store_association(server_url, association) ⇒ Object
Put a Association object into storage. When implementing a store, don’t assume that there are any limitations on the character set of the server_url. In particular, expect to see unescaped non-url-safe characters in the server_url field.
29 30 31 32 33 34 35 36 |
# File 'lib/openid/store/couchdb.rb', line 29 def store_association(server_url, association) if document = Association.load(server_url, association.handle) document.association = association document.save else Association.create(server_url, association) end end |
#use_nonce(server_url, timestamp, salt) ⇒ Object
Return true if the nonce has not been used before, and store it for a while to make sure someone doesn’t try to use the same value again. Return false if the nonce has already been used or if the timestamp is not current. You can use OpenID::Store::Nonce::SKEW for your timestamp window.
server_url
-
URL of the server from which the nonce originated
timestamp
-
time the nonce was created in seconds since unix epoch
salt
-
A random string that makes two nonces issued by a server in the same second unique
76 77 78 |
# File 'lib/openid/store/couchdb.rb', line 76 def use_nonce(server_url, , salt) Nonce.create(server_url, , salt) end |