[p4perl] Creating Users
Scott Lavender
scott.lavender at visiprise.com
Wed Mar 8 05:32:44 PST 2006
Tony,
Thanks for the reply. My goal is to create a script for creating new users that automates all of the individual tasks that are starting to get tedious. This is also a good opportunity for me to get a handle on scripting in general with Perforce.
I come from an extensive background in ClearCase. Over the years I've developed many scripts used by both myself as an administrator and by my user base. They have been spoiled with all of the things they can do with my scripts. So, they expect the same as we transition over to Perforce.
Back to the script... I want to take a users full name and do the following:
1) Create a user based on the full name as lowercase <first initial><last name>.
2) Set the new users Email address to include our domain name.
3) Initialize user password. ( We use strong passwords. Eventual LDAP authentication. )
4) Add the user to the primary users group.
5) Add the user to any other groups as needed.
So, far I have code to perform the first two steps:
_____
require P4;
my $p4 = new P4;
$p4->ParseForms();
$p4->Connect or die ( "Failed to connect to Perforce Server" );
@newUsers = ( "Test User" ); # Will come from user prompting and/or file.
foreach $newUser ( @newUsers )
{
createUser( $newUser );
}
sub getUsername {
my ( $fullName ) = @_; # Assumes complete "Firstname Lastname"
$fullName =~ m/^\s*(\w)\w*\s+(\w+)\s*$/;
$userName = lc($1) . lc($2);
return $userName;
}
sub createUser {
my ( $fullName ) = @_; # Assumes complete "Firstname Lastname"
$userName = getUsername( $fullName );
# Initiate new user creation
my $user = $p4->FetchUser( $userName );
# Modify user data
$user->{ "Email" } = "$userName\@visiprise.com";
$user->{ "FullName" } = "$fullName";
# Save new user
$p4->SetInput( $user );
$p4->Run("user", "-fi");
# Set Password
# Add to base user group.
# Add to other groups.
}
_____
Any input on the remaining steps.
Thanks.....Scott...
-----Original Message-----
From: Tony Smith [ <mailto:tony at perforce.com> mailto:tony at perforce.com]
Sent: Wednesday, March 08, 2006 6:21 AM
To: p4perl at perforce.com
Cc: Scott Lavender
Subject: Re: [p4perl] Creating Users
Hi Scott,
On Tuesday 07 March 2006 19:45, Scott Lavender wrote:
> Thanks for the help David. It works great. But, I have a follow up
> question. After modifying the user hash, what would be the corresponding
> way to save/create the user? I though it would be:
>
> $p4->SaveUser( $user );
>
> But, this does not seem to work.
If you're attempting to modify another user's details, you will need to invoke
the power of the '-f' flag. This should do the trick:
$p4->SaveUser( "-f", $user );
Note also that when things don't 'seem to work', it's worth printing the
output returned from the command and the contents of the $p4->Errors() and
$p4->Warnings() arrays. They'll yield valuable clues.
You can also use $p4->DebugLevel( 3 ) (in the latest builds of P4Perl) to see
way more information than you really want.
Tony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://maillist.perforce.com/pipermail/p4perl/attachments/20060308/74f96185/attachment.html
More information about the p4perl
mailing list