+1 Good catch

Normally expand_path deals with non-existent directories fine, but in this
case it can't predict what the users home direct will be if (when) the user
is eventually created.  I wonder if we should specify the missing user as a
resource, like so:

     raise Puppet::Error, "Target not defined and User[#{user}] does not
exist yet; perhaps you forgot a 'require => ...'?"

-- Markus

On Fri, May 7, 2010 at 8:12 AM, Sean Millichamp <[email protected]> wrote:

> If the target is not specified it is automatically set to the user's
> home directory.  If the user does not exist when the generation of
> the target path occurs then an ArgumentError exception is raised
> but not caught.  This patch catches the ArgumentError and raises
> a Puppet::Error instead to more gracefully notify the user and allow
> any remaining resources to be applied.
>
> Signed-off-by: Sean Millichamp <[email protected]>
> ---
>  lib/puppet/provider/ssh_authorized_key/parsed.rb |    6 +++++-
>  spec/unit/provider/ssh_authorized_key/parsed.rb  |   12 ++++++++++++
>  2 files changed, 17 insertions(+), 1 deletions(-)
>
> diff --git a/lib/puppet/provider/ssh_authorized_key/parsed.rb
> b/lib/puppet/provider/ssh_authorized_key/parsed.rb
> index fb4d095..b222e51 100644
> --- a/lib/puppet/provider/ssh_authorized_key/parsed.rb
> +++ b/lib/puppet/provider/ssh_authorized_key/parsed.rb
> @@ -54,7 +54,11 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed,
>     end
>
>     def target
> -        @resource.should(:target) ||
> File.expand_path("~%s/.ssh/authorized_keys" % user)
> +        begin
> +            @resource.should(:target) ||
> File.expand_path("~%s/.ssh/authorized_keys" % user)
> +        rescue
> +            raise Puppet::Error, "Target not defined and/or specified user
> does not exist yet"
> +        end
>     end
>
>     def user
> diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb
> b/spec/unit/provider/ssh_authorized_key/parsed.rb
> index fc3f550..1fefd40 100755
> --- a/spec/unit/provider/ssh_authorized_key/parsed.rb
> +++ b/spec/unit/provider/ssh_authorized_key/parsed.rb
> @@ -202,5 +202,17 @@ describe provider_class do
>                 proc { @provider.flush }.should raise_error
>             end
>         end
> +
> +        describe "and a invalid user has been specified with no target" do
> +            before :each do
> +                @resource.stubs(:should).with(:user).returns
> "thisusershouldnotexist"
> +                @resource.stubs(:should).with(:target).returns nil
> +            end
> +
> +            it "should catch an exception and raise a Puppet error" do
> +                lambda { @provider.flush }.should
> raise_error(Puppet::Error)
> +            end
> +        end
> +
>     end
>  end
> --
> 1.6.6.1
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<puppet-dev%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/puppet-dev?hl=en.
>
>


-- 
-----------------------------------------------------------
The power of accurate observation is
commonly called cynicism by those
who have not got it.  ~George Bernard Shaw
------------------------------------------------------------

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to