clojurewerkz / spyglass

A Clojure Memcached client (also: Couchbase, Kestrel). Built on top of SpyMemcached, supports ASCII and binary protocols, strives to be 100% feature complete.
http://clojurememcached.info
67 stars 17 forks source link

Add custom net.spy.memcached.auth.AuthDescriptor. #9

Closed ecmendenhall closed 11 years ago

ecmendenhall commented 11 years ago
Fixes issue #6.

+ Fix SASL authentication errors for Heroku users.
+ Allow passing an optional auth-type argument to
  spyglass.client/bin-connection.
+ Pull out net.spy.memcached.auth.AuthDescriptor
  construction to spyglass.client/auth-descriptor
  function. Passing :plain or :cram-md5 keywords
  specifies an auth mechanism. (AuthDescriptors
  initialized with AuthDescriptor/typical threw
  authentication errors for users connecting to
  Heroku's default memcached servers).

Six months later and I've learned enough Clojure/Java to figure this out. This should fix authentication errors for users connecting to the default Heroku memcache add-ons.

Memcachier (one of the Heroku memcache add-on services) suggests using spymemcached version 2.8.9 or earlier. A spymemcached issue suggests creating an AuthDescriptor configured for plain auth only. In combination, these two fixes solve my original issue.

To downgrade to spymemcached 2.8.9 for use with Heroku, add it as a project.clj dependency and add an exclusion to the spyglass dependency. Also, make sure to include the spy-memcached maven repository:

(defproject my-great-project "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [clojurewerkz/spyglass "1.1.0-beta4-SNAPSHOT"
                  :exclusions [spy/spymemcached]]
                 [spy/spymemcached "2.8.9"]]
  :repositories {"spy-memcached" {:url "http://files.couchbase.com/maven2/"}})

Then, add a :plain argument to any calls to client/bin-connection to use a custom AuthDescriptor configured for plain authentication, e.g.:

(spyglass.client/bin-connection memcache-server memcache-username memcache-password :plain)

If you need a connection configured with cram-md5 only, that's a keyword option, too. This is an optional arg—calling bin-connection without the extra keyword returns the original AuthDescriptor/typical.

I'm not sure how to write an automated test for this, but it doesn't break any existing ones. I've tested this fix successfully by hand with both default Heroku memcached services.

michaelklishin commented 11 years ago

:+1: