[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Subversion Ruby Bindings access to URL

Jacob Burkhart

5/4/2007 3:35:00 PM

So I struggled through the installation of swig, subversion and the
ruby bindings, and now I want to connect to subversion from ruby.

It turns out this is usually done through the filesystem with:

Svn::Repos.open

But, I don't have filesystem access to my repository, I only have web
access

So I need to do something like this:

url = 'http://trac-hacks.swapoff.or...
ctx = Svn::Client::Context.new
cb = Svn::Ra::Callbacks.new(ctx.auth_baton)
cb.auth_baton = Svn::Core.auth_open([])
cfg = Svn::Core::config_get_config(nil)
s = Svn::Ra::Session.open(url, cfg, cb)
st = s.stat(", 1)

(from: http://www.oneofthewolves.com/2007/03/06/ruby-subversion-bindings-finally-some-documentation/#c...)

The problem with that one, is that there's no way to pass in my
username and password for htaccess

Looking at the swig and other documentation It seems I need to pass a
C struct struct svn_auth_provider_object_t

To Svn::Core.auth_open([])

And that C struct needs to also contain a function pointer to a
function that then returns username and password somehow?

00149 typedef struct svn_auth_provider_object_t
00150 {
00151 const svn_auth_provider_t *vtable;
00152 void *provider_baton;
00153
00154 } svn_auth_provider_object_t;

http://svn.collab.net/svn-doxygen/group__auth...


So it seems I need to figure out how to implement a C function pointer
from ruby over swig, I'm guessing this isn't possible....

So, if that's the case I was thinking maybe I could use a Proxy server
to proxy localhost:2901 or some other random port over to my real
repository URL and pass the authentication username and password
through the proxy

Does anybody have any suggestions for such a proxy? perhaps on
implemented in ruby.


And, does anybody have any other suggestions for what I could try to
in order to connect to my remote (And authenticated) repository via
ruby subversion bindings?


thanks,
Jacob

9 Answers

Brian Candler

5/4/2007 6:43:00 PM

0

On Sat, May 05, 2007 at 12:35:09AM +0900, Jacob Burkhart wrote:
> So I need to do something like this:
>
> url = 'http://trac-hacks.swapoff.or...
> ctx = Svn::Client::Context.new
> cb = Svn::Ra::Callbacks.new(ctx.auth_baton)
> cb.auth_baton = Svn::Core.auth_open([])
> cfg = Svn::Core::config_get_config(nil)
> s = Svn::Ra::Session.open(url, cfg, cb)
> st = s.stat(", 1)
>
> (from:
> http://www.oneofthewolves.com/2007/03/06/ruby-subversion-bindings-finally-some-documentation/#c...)
>
> The problem with that one, is that there's no way to pass in my
> username and password for htaccess

I'm sure you can - probably doing something with the auth_baton.
Unfortunately I've not tried it myself yet, as I've not needed it.

The "Practical Subversion" book has a whole chapter on using the API though.

> Looking at the swig and other documentation It seems I need to pass a
> C struct struct svn_auth_provider_object_t
>
> To Svn::Core.auth_open([])

I expect there's a corresponding wrapped object already in the Swig
interface. You just have to work out how to create it.

If you can google for an example written in some other language (e.g.
python) you should be able to make it work.

B.

Jacob Burkhart

5/4/2007 9:24:00 PM

0

require 'svn/client'
require 'svn/ra'

url = '___'

ctx = Svn::Client::Context.new

cb = Svn::Ra::Callbacks.new(ctx.auth_baton)

provider = Proc.new do
|cred, realm, default, may_save, pool|

simplecreds = Svn::Ext::Core::Svn_auth_cred_simple_t.new
simplecreds.username = "___"
simplecreds.password = "___"

simplecreds
end

cb.auth_baton = Svn::Core.auth_open(
[
Svn::Client::get_simple_prompt_provider(provider, 2)
])

cfg = Svn::Core::config_get_config(nil)

s = Svn::Ra::Session.open(url, cfg, cb)

st = s.stat('', 1)

puts <<EOS
Status of node(#{url})
created revision = #{st.created_rev}
committed time = #{Time.at(st.time / 1_000_000)}
author = #{st.last_author}
size = #{st.size}
EOS



There it is!


Now that I've figured out how to connect... I realize that the
Svn::Client interface and the Svn::Repos APIS are completely
different... and my original goal of making Retrospectiva work or
remote repositories is looking a lot bleaker.

Kouhei Sutou

5/6/2007 1:57:00 AM

0

Juanse Pérez herrero

10/28/2007 11:56:00 AM

0

I am trying to authenticate to remote svn using the ruby bindings.

I create my provider as follows

provider = Proc.new do |cred, args |
cred = Svn::Ext::Core::Svn_auth_cred_simple_t.new
cred.username = username
cred.password = password
cred
end

These are snippets from Client.rb

I have been playing around with rdebug to find out that my auth
information gets lost (see comments).

def add_simple_prompt_provider(retry_limit, prompt=Proc.new)
args = [retry_limit]
klass = Core::AuthCredSimple
add_prompt_provider("simple", args, prompt, klass)
end

def add_prompt_provider(name, args, prompt, cred_class)
# the prompt parameter arrives ok
# prompt.call().username is my username
real_prompt = Proc.new do |*prompt_args|
cred = cred_class.new
prompt.call(cred, *prompt_args)
cred
end

# here real_prompt.call().username returns nil (!!!!)
method_name = "swig_rb_auth_get_#{name}_prompt_provider"
baton, pro = Core.__send__(method_name, real_prompt, *args)
[...]

Am I doing something wrong?

Any help is appreciated

--
Posted via http://www.ruby-....

Kouhei Sutou

10/28/2007 2:41:00 PM

0

Juanse Pérez herrero

10/28/2007 3:07:00 PM

0

The code I am using

username = "*****"
password = "*****"
root = "svn+ssh://******/trunk"

ctx = Svn::Client::Context.new

provider = Proc.new do |cred, realm, default, may_save, pool|
cred.username = username
cred.password = password
cred
end

cb = Svn::Ra::Callbacks.new(ctx.auth_baton)
cb.auth_baton =
Svn::Core.auth_open([Svn::Client::get_simple_prompt_provider(provider,
2)])

session = Svn::Ra::Session.open(root, Svn::Core::config_get_config(nil),
cb)

If anyone got svn bindings auth working please post
--
Posted via http://www.ruby-....

Kouhei Sutou

10/28/2007 3:23:00 PM

0

Juanse Pérez herrero

10/28/2007 3:56:00 PM

0

Hi

Thanks a lot for your answers Kouhei,

I have to admit it I don't know that much what I am doing

I just know I want to browse dirs and get file contents for a remote
subversion repos

I know Session.dir and Session.file work ok on a public repos and do
what I expect (I have tried that successfully), so it should be a matter
of getting an auth session for the repos username/password

This seems to me the function to connect with ra
Ra::Session.open(url, config={}, callbacks=nil)

I am wondering if anyone has gotten this auth stuff done

Cheers



--
Posted via http://www.ruby-....

Kouhei Sutou

10/28/2007 4:06:00 PM

0