You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Patrick Aljord <pa...@gmail.com> on 2008/06/23 06:09:07 UTC

couchdb and blobs (using only couchdb or couchrest)

Hey all,

I'm trying to store openid associations in couchdb docs, it works ok
except for stocking the openid secret and server_url because they are
blobs so I get an error (at least with couchrest which is the
interface I use). What would be the best way to deal with those blobs?
Attachments I guess? any tips welcome.

Thanks in advance

Pat

Re: couchdb and blobs (using only couchdb or couchrest)

Posted by Arved Sandstrom <as...@eastlink.ca>.
----- Original Message ----- 
From: "Noah Slater" <ns...@apache.org>
To: <co...@incubator.apache.org>
Sent: Monday, June 23, 2008 9:05 AM
Subject: Re: couchdb and blobs (using only couchdb or couchrest)


> On Sun, Jun 22, 2008 at 11:56:44PM -0500, Patrick Aljord wrote:
>> it does work indeed by using the Util.to_base64(secret) that comes
>> with openid but I'm not sure the secret is meant to be saved in base64
>
> It surely doesn't matter how you save it.
>
> I am guessing you could hand scribe it on some papyrus in ROT13, but as 
> long as
> you decode it and hand back the original byte sequence, everything should 
> be OK.

Reminds me of a very common remark related to CORBA IORs (Interoperable 
Object References)...you could write the stringified reference on a message 
in a bottle and transmit it by ocean if you so desired...

AHS 


Re: couchdb and blobs (using only couchdb or couchrest)

Posted by Noah Slater <ns...@apache.org>.
On Sun, Jun 22, 2008 at 11:56:44PM -0500, Patrick Aljord wrote:
> it does work indeed by using the Util.to_base64(secret) that comes
> with openid but I'm not sure the secret is meant to be saved in base64

It surely doesn't matter how you save it.

I am guessing you could hand scribe it on some papyrus in ROT13, but as long as
you decode it and hand back the original byte sequence, everything should be OK.

-- 
Noah Slater, http://people.apache.org/~nslater/

Re: couchdb and blobs (using only couchdb or couchrest)

Posted by Patrick Aljord <pa...@gmail.com>.
On Sun, Jun 22, 2008 at 11:46 PM, Chris Anderson <jc...@grabb.it> wrote:
> You might try a base64 encoded version of the blob. That's the
> standard way to stringify this sort of thing anyway.
>
>>

it does work indeed by using the Util.to_base64(secret) that comes
with openid but I'm not sure the secret is meant to be saved in base64
(other openid data store from AR or DM don't do the to_base64
conversion before saving and they save as blob). ruby-openid does come
with a from_base64 too though so I could use that I guess for
retrieving the docs. Thanks by the way.

Re: couchdb and blobs (using only couchdb or couchrest)

Posted by Chris Anderson <jc...@grabb.it>.
On Sun, Jun 22, 2008 at 9:43 PM, Chris Anderson <jc...@grabb.it> wrote:
> On Sun, Jun 22, 2008 at 9:40 PM, Patrick Aljord <pa...@gmail.com> wrote:
>
>> JSON::GeneratorError: source sequence is illegal/malformed
>
> I hate those! (But they are not my bug...)

More context: I think they are caused when the byte-array you feed
JSON contains sequences which don't map to a valid Unicode code-point.
You might try a base64 encoded version of the blob. That's the
standard way to stringify this sort of thing anyway.

>
> --
> Chris Anderson
> http://jchris.mfdz.com
>



-- 
Chris Anderson
http://jchris.mfdz.com

Re: couchdb and blobs (using only couchdb or couchrest)

Posted by Patrick Aljord <pa...@gmail.com>.
 blob
=> "F\264\354Xa\027\025M\254\324\235fN]c\375\310\216\373Q"

(gem install ruby-openid might help reproduce it but you probably know that)

Re: couchdb and blobs (using only couchdb or couchrest)

Posted by Chris Anderson <jc...@grabb.it>.
On Sun, Jun 22, 2008 at 9:40 PM, Patrick Aljord <pa...@gmail.com> wrote:

> JSON::GeneratorError: source sequence is illegal/malformed

I hate those! (But they are not my bug...)

Can you give an example of what blob looks like?


-- 
Chris Anderson
http://jchris.mfdz.com

Re: couchdb and blobs (using only couchdb or couchrest)

Posted by Patrick Aljord <pa...@gmail.com>.
Here is how to reproduce the issue:

require 'openid'

@cr = CouchRest.new("http://localhost:5984")
@db = @cr.create_db('couchrest-testy')
blob = OpenID::CryptUtil.hmac_sha1('foo', 'bar')
response = @db.save({:key => blob})

and it gives:
JSON::GeneratorError: source sequence is illegal/malformed
        from /home/pat/gitreps/mymerbapp/lib/couchrest/lib/couch_rest.rb:50:in
`to_json'
        from /home/pat/gitreps/mymerbapp/lib/couchrest/lib/couch_rest.rb:50:in
`post'
        from /home/pat/gitreps/mymerbapp/lib/couchrest/lib/database.rb:54:in
`save'
        from (irb):59
        from :0

not sure if this is a couchrest specific bug, jchris? :)

Re: couchdb and blobs (using only couchdb or couchrest)

Posted by Chris Anderson <jc...@grabb.it>.
On Sun, Jun 22, 2008 at 9:09 PM, Patrick Aljord <pa...@gmail.com> wrote:
> Hey all,
>
> I'm trying to store openid associations in couchdb docs, it works ok
> except for stocking the openid secret and server_url because they are
> blobs so I get an error (at least with couchrest which is the
> interface I use). What would be the best way to deal with those blobs?
> Attachments I guess? any tips welcome.

Pat,

I'd be interested to see more details about your error, and what you
are trying to do generally. I can't think of a reason why CouchDB
would have problems storing your data. The attachment API is generally
useful for larger files that you wouldn't want to access wrapped in
JSON - you should be able to solve your problem without resorting to
attachments.

Can you give a specific example of the data you are storing and how
you are attempting to do it? Maybe posting an example IRB session to
pastie.org would be helpful. There very well could be some edge cases
in CouchRest that I haven't run into yet, and seeing your code in
action will help.

Chris

-- 
Chris Anderson
http://jchris.mfdz.com