Subversion Ruby Bindings access to URL

J

Jacob Burkhart

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.org/svn'
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/...dings-finally-some-documentation/#comment-137)

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__fns.html


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
 
B

Brian Candler

So I need to do something like this:

url = 'http://trac-hacks.swapoff.org/svn'
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/...dings-finally-some-documentation/#comment-137)

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.
 
J

Jacob Burkhart

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.
 
K

Kouhei Sutou

Hi,

In <[email protected]>
"Re: Subversion Ruby Bindings access to URL" on Sat, 5 May 2007 06:23:56 +0900,
Jacob Burkhart said:
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

require 'svn/client'

url = '___'

ctx = Svn::Client::Context.new
ctx.add_simple_prompt_provider(2) do |cred, realm, user_name, may_save|
cred.username = "___"
cred.password = "___"
end

ctx.info(url) do |path, info|
puts <<EOS
Status of node(#{info.url})
created revision = #{info.last_changed_rev}
committed time = #{Time.from_apr_time(info.last_changed_date)}
author = #{info.last_changed_author}
EOS
end

Test cases of the Ruby bindings for Subversion may help you:
https://svn.collab.net/repos/svn/trunk/subversion/bindings/swig/ruby/test/

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.

Svn::Client interface is similar to svn command interface.


Thanks,
 
J

Juanse Pérez herrero

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
 
K

Kouhei Sutou

Hi,

In <[email protected]>
"Re: Subversion Ruby Bindings access to URL" on Sun, 28 Oct 2007 20:5=
5:36 +0900,
Juanse_P=E9rez_herrero said:
I am trying to authenticate to remote svn using the ruby bindings.
=
I create my provider as follows
=
provider =3D Proc.new do |cred, args |
cred =3D Svn::Ext::Core::Svn_auth_cred_simple_t.new
cred.username =3D username
cred.password =3D password
cred
end ...
Am I doing something wrong?

Why do you override 'cred' variable value? Just use 'cred'
passed as the first argument:

provider =3D Proc.new do |cred, args|
cred.username =3D username
cred.password =3D password
end


Thanks,
 
J

Juanse Pérez herrero

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
 
K

Kouhei Sutou

Hi,

In <[email protected]>
"Re: Subversion Ruby Bindings access to URL" on Mon, 29 Oct 2007 00:0=
6:35 +0900,
Juanse_P=E9rez_herrero said:
The code I am using
=
username =3D "*****"
password =3D "*****"
root =3D "svn+ssh://******/trunk"
=
ctx =3D Svn::Client::Context.new
=
provider =3D Proc.new do |cred, realm, default, may_save, pool|
cred.username =3D username
cred.password =3D password
cred
end
=
cb =3D Svn::Ra::Callbacks.new(ctx.auth_baton)
cb.auth_baton =3D =
Svn::Core.auth_open([Svn::Client::get_simple_prompt_provider(provider=
, =
session =3D Svn::Ra::Session.open(root, Svn::Core::config_get_config(=
nil), =

Why do you use Svn::Ra::Session directly?
Does Svn::Core::Context satisfy you?

What error did you get?


Thanks,
 
J

Juanse Pérez herrero

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top