Re: [Catalyst] Additional scripts accessing the Model and Config?

2012-06-08 Thread Luis Muñoz

On Jun 8, 2012, at 5:04 PM, Tomas Doran wrote:

> Sorry - I'm confused - how does calling into the app to get stuff as 
> $self->application_name->model('Foo')->some_method(@stuff)

How does the Model, called like that, would know the details of where it is 
supposed to connect? Things like the DSN, username, password, etc are in config 
files whose reading is triggered "magically" by the Catalyst infrastructure. 
However that is not present when running as a script.

This is the reason for my question.

-lem



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Additional scripts accessing the Model and Config?

2012-06-08 Thread Luis Muñoz

On Jun 8, 2012, at 1:15 PM, Tomas Doran wrote:

> You don't.
> $c implies a web request context, which you don't have.

That explains a lot :-)

> You can, however, call things as class methods, so:
> 
> $self->application_name->model('DB')->schema->foo
> 
> should work from inside your script, for example.

But still, I would like to have access to the configuration data (for instance, 
how to setup the database/ldap/whatever Model, etc). Does that happen as well 
when using the class method?

Best regards

-lem


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Additional scripts accessing the Model and Config?

2012-06-07 Thread Luis Muñoz
Hi there,

During the last couple of days I've been trying various ways to do this, but it 
all seems more complicated than it should be.

I have a Catalyst app that implements a number of controllers that modify data 
through a model. Let's say it's a DBIC model for simplicity. I need to write 
various sets of scripts to be run from the command line, that will access the 
data and produce reports that are to be fed to other processes.

What I would like is to have a simple construct where the body of the script 
would be something like this

  #!/usr/bin/perl

  use strict;
  use warnings;

  use Catalyst::ScriptRunner;
  Catalyst::ScriptRunner->run('My::Fancy::App', 'Dump');

  exit 0;

And then in My::Fancy::App::Script::Dump.pm I would have the main body of the 
script, in a way similar to what the _create.pl et al scripts operate.

The part that's stumping me is how to go within Dump.pm about obtaining a $c 
that allows me to get to the configuration (taken from the same place where the 
web application takes it) and the model. 

My current (simplified) contents of the Dump.pm file are as follows:

  package My::Fancy::App::Script::Dump;
  use Moose;
  use MooseX::Types::Moose qw/Bool Str/;
  use namespace::autoclean;

  has output => (
  traits=> [qw(Getopt)],
  cmd_aliases   => 'o',
  isa   => Str,
  is=> 'ro',
  documentation => 'Output name for the generated file(s)',
  );

  sub run {
  my ($self) = @_;

  printf ( "some_custom_data=%s\n", $self->my_custom_db_config ( 
'custom.data' ));

  die ( "Error: Must specify things to process using --thing\n" ) 
  unless $self->tld;
  $self->_getopt_full_usage if !$self->ARGV->[0];
  $self->_getopt_full_usage ();
  }

  __PACKAGE__->meta->make_immutable;

Where ->my_custom_db_config is a method that fetches process-specific 
configuration from the Schema. I would like to access things like ->log, 
->model and the utility methods that I use in the Controllers from within the 
script. And of course, I would like to use the same configuration file.

Has anybody dealt with a similar problem before? Or am I on my own :-)

Best regards

-lem
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] problem with Apache and FastCGI

2012-05-27 Thread Luis Muñoz
Write a small cgi script that dumps the environment and take a look. You might 
be surprised

-lem

Frank Schwach  wrote:

Hi Robert,

Thanks for your help!
I'm logged onto the server as the user that runs Apache and I can run 
the fcgi start-up script (so I can execute the shebang line) as that 
user, so Apache should be able to run it, as far as I can see. Right now 
I don't know where to start looking for the problem. BTW: I can also 
verify in "ps" that apache is actually running as that user I log in 
with in.

Frank



On 26/05/12 23:10, Robert Wohlfarth wrote:
> On Sat, May 26, 2012 at 12:39 PM, Frank Schwach  > wrote:
>
> Why does Apache claim myapp_fastcgi.pl 
> doesn't exist when it does?
>
> If you get this error:
>
> |FastCGI: can't start server "/tmp/myapp/script/myapp_fastcgi.pl
> " (pid 15460), execle() failed: No such
> file or directory
> |
>
> when the file *is* there, and its owner is |nobody|, that's just a
> bad error message from Apache. The real cause is that the shebang
> line in |myapp_fastcgi.pl | could not be
> executed.
>
>
> The shebang in one of my projects reads "#!/usr/bin/env perl". Does 
> the Apache user have permissions to execute both "/usr/bin/env" and 
> "perl"?
>
> Can it find "perl" in the PATH? The Apache environment may have a 
> totally different PATH (or none at all).
> -- 
> Robert Wohlfarth
>
>
>
>_

> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/


-- 
The Wellcome Trust Sanger Institute is operated by Genome Research 
Limited, a charity registered in England with number 1021457 and a 
company registered in England with number 2742969, whose registered 
office is 215 Euston Road, London, NW1 2BE. 

_

List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] LDAP question

2012-05-21 Thread Luis Muñoz

On May 21, 2012, at 5:12 PM, Kenneth S Mclane wrote:

> I'm getting closer. I'm wondering if I need to find out what form they are 
> encrypting the password in? It defaults to SHA-1, but I do not know if that 
> is correct. 

You do not need that because you're not dealing with the hashes directly. By 
asking the directory to authenticate, you're offloading that problem.

Best regards.

-lem


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] LDAP question

2012-05-21 Thread Luis Muñoz

On May 21, 2012, at 12:02 PM, Kenneth S Mclane wrote:

> I have no control over the LDAP server, How would I change things so the 
> submitted username and password would be inserted as the credentials to be 
> used as the initial bind? 

You use that from the client.

Below is a snippet from a configuration file from a tool we use at $work for 
managing LDAP entries. It works in the way I described before.

Pay attention to the binddn (the account to do the initial bind) and basedn 
(the place where you begin your search for a matching username, using the 
filter expression). Start simple and build up your expression to narrow down 
the tuples that it can retrieve. I'm pro very strict filters based on object 
types, but there are perhaps other opinions.

Best regards

-lem

--8<

# Configure the authentication subsystem. This is the component that
# validates the current password for change requests. This service is
# provided by Catalyst::Authentication::Store::LDAP.
# 
# The ldap realm is mandatory, as this is used not only for
# authentication but for access to the user's LDAP entry, both for
# searching and for updating it. This means that we need to use a
# binddn with enough privileges to read and write to the
# directory. It's not enough to rely on the users' credentials for
# rebinding, because in the case of a password recovery, we don't have
# user credentials.

authentication:
  default_realm: ldap
  realms:
ldap:
  credential:
class:  Password
password_field: password
password_type:  self_check
  store:
class:  LDAP
ldap_server:localhost:3389
binddn: cn=your_initial_id,dc=domain,dc=com,dc=INVALID
bindpw: Y0urS3cr3tB!ndP@$sw0rd
user_basedn:
ou=The,ou=Container,ou=Hierarchy,dc=domain,dc=com,dc=INVALID
user_filter:(&(objectClass=inetOrgPerson)(|(uid=%s)(email=%s)))
user_field: uid
use_roles:  0


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] LDAP question

2012-05-21 Thread Luis Muñoz

On May 21, 2012, at 11:42 AM, Robert Wohlfarth wrote:

> The standard Catalyst::Authentication::Store::LDAP does not work with this 
> model.

I've been told that the "right" way to do authentication against LDAP is

* bind with a read-only set of credentials
* Lookup the user's entry (here is where you apply your base and filters)
* Try to bind with the just-found DN and the user-supplied password

The first set of credentials has just enough privileges (via ACLs) so that only 
the required search can be performed. This scheme has the advantage of not 
allowing annon bound sessions to search your tree while supporting user 
hierarchies (that can change as the directory is reorganized).

Best regards.

-lem


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Best practice for configuration file placement

2012-05-16 Thread Luis Muñoz

On May 17, 2012, at 12:02 AM, John Napiorkowski wrote:

> I would think you could build something into the makefile.PL that would copy 
> this stuff to /etc for production.  

Well, in my case I'm using a .deb that will place the vanilla config file in 
the /etc dir. However I want to make sure that this is where the ConfigLoader 
plugin will look. I'll try and use the snippet you provided (should work 
according to docs).

Thanks!

-lem


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Best practice for configuration file placement

2012-05-16 Thread Luis Muñoz
Hi there,

I've failed in locating this question as a FAQ, so I would appreciate some 
guidance.

I've written a Catalyst application that will be deployed in Debian. We want to 
keep config files under /etc/some_app/ so naturally, I would like to add this 
path to the ones to be searched by ConfigLoader. The application's main .pm 
contains:

  use Catalyst ( qw/
ConfigLoader
  # ...
/
  );

We'll want to run the application under nginx/FastCGI. I realize that I can 
simply set the environment appropriately in the startup rc script but before 
doing that, I was wondering what would be the "best practice" way to achieve 
this?

Best regards.

-lem


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/