Skip to content

Commit d3ba0ec

Browse files
author
Marcin Przepiorowski
committed
Merge branch 'issue#97' into develop
2 parents f363a6e + aa03a91 commit d3ba0ec

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
lines changed

bin/dx_ctl_users.pl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
'username=s' => \(my $username),
5555
'password=s' => \(my $password),
5656
'timeout=n' => \(my $timeout),
57+
'sshkeyfile=s' => \(my $sshkeyfile),
5758
'force' => \(my $force),
5859
'all' => (\my $all),
5960
'version' => \(my $print_version),
@@ -90,7 +91,8 @@
9091
exit (1);
9192
}
9293

93-
} elsif ((lc $action eq 'lock') || (lc $action eq 'unlock') || (lc $action eq 'password') || (lc $action eq 'timeout')) {
94+
} elsif ((lc $action eq 'lock') || (lc $action eq 'unlock') || (lc $action eq 'password') || (lc $action eq 'timeout')
95+
|| (lc $action eq 'sshkey') ) {
9496

9597
if (!defined($username)) {
9698
print "Parameter -username is required for action $action\n";
@@ -104,6 +106,12 @@
104106
exit (1);
105107
}
106108

109+
if ((lc $action eq 'sshkey') && !defined($sshkeyfile)) {
110+
print "Parameter -sshkeyfile is required for action $action\n";
111+
pod2usage(-verbose => 1, -input=>\*DATA);
112+
exit (1);
113+
}
114+
107115
} else {
108116
print "Unknown action $action\n";
109117
pod2usage(-verbose => 1, -input=>\*DATA);
@@ -134,7 +142,13 @@
134142
}
135143

136144
if (defined($file) || defined($username)) {
137-
$ret = $ret + process_user($engine_obj, $file, $action, $username, $jscontainers, $timeout);
145+
if (lc $action eq 'sshkey') {
146+
my $users_obj = new Users ($engine_obj, undef, $debug);
147+
my $loginuser = $users_obj->getCurrentUser();
148+
$ret = $ret + $users_obj->setSSHkey($username, $loginuser->{userType}, $sshkeyfile);
149+
} else {
150+
$ret = $ret + process_user($engine_obj, $file, $action, $username, $jscontainers, $timeout);
151+
}
138152
}
139153

140154
if (defined($profile)) {
@@ -350,10 +364,11 @@ =head1 SYNOPSIS
350364
351365
dx_ctl_users [ -engine|d <delphix identifier> | -all ] [ -configfile file ]
352366
[-action import] <-file filename | -profile filename >
353-
-action lock|unlock|password|timeout
367+
-action lock|unlock|password|timeout|sshkey
354368
-username name|all
355369
[-password password]
356370
[-timeout timeout]
371+
[-sshkeyfile filename]
357372
[-help|?]
358373
[-debug]
359374
@@ -386,7 +401,7 @@ =head2 Options
386401
387402
=over 4
388403
389-
=item B<-action import|lock|unlock|password>
404+
=item B<-action import|lock|unlock|password|sshkey>
390405
Action for a particular user or file
391406
Actions:
392407
@@ -395,6 +410,7 @@ =head2 Options
395410
- unlock - enable (unlock) user account
396411
- password - change user password
397412
- timeout - change user timeout
413+
- sshkey - set a user SSH key
398414
399415
=item B<-username user|all>
400416
Username for particular action.
@@ -406,6 +422,9 @@ =head2 Options
406422
=item B<-timeout time>
407423
Update a timeout for an user. Timeout is set in minutes
408424
425+
=item B<-sshkeyfile filename>
426+
File with one or more SSH public key to set for user
427+
409428
=item B<-file filename>
410429
CSV file name with user definition and actions. Field list as follow:
411430
@@ -549,4 +568,9 @@ =head1 EXAMPLES
549568
User js deleted.
550569
User js created.
551570
571+
Setting a SSH key for user
572+
573+
dx_ctl_users -d 53 -action sshkey -username admin -sshkeyfile /tmp/id_rsa.pub
574+
SSH key for admin set.
575+
552576
=cut

lib/Databases.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ sub LoadDBList
190190
} else {
191191
logger($self->{_debug},"config name - not available ",2);
192192
}
193-
logger($self->{_debug},"Source config to assign " . Dumper $self->{_sourceconfigs}->getSourceConfig($configname),2);
193+
logger($self->{_debug},"Source config to assign ",2);
194+
my $sc = Dumper $self->{_sourceconfigs}->getSourceConfig($configname);
195+
logger($self->{_debug}, $sc , 2);
194196
$db->{"sourceConfig"} = $self->{_sourceconfigs}->getSourceConfig($configname);
195197

196198
#added to keep object

lib/User_obj.pm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ sub setNames {
9292
}
9393

9494

95+
# Procedure setSSHkey
96+
# parameters:
97+
# - $sshkey
98+
99+
sub setSSHkey {
100+
my $self = shift;
101+
my $sshkey = shift;
102+
103+
logger($self->{_debug}, "Entering User_obj::setSSHkey",1);
104+
$self->{_new}->{publicKey} = $sshkey;
105+
}
106+
95107
# Procedure getAuthType
96108
# Return:
97109
# - Native / LDAP

lib/Users.pm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,4 +518,36 @@ sub unlockUser
518518
return $ret;
519519
}
520520

521+
sub setSSHkey
522+
{
523+
my $self = shift;
524+
my $username = shift;
525+
my $usertype = shift;
526+
my $sshfile = shift;
527+
528+
my $ret = 0;
529+
my $user = $self->getUserByName($username, $usertype);
530+
531+
if (defined($user) ) {
532+
my $FD;
533+
open($FD,$sshfile) or die("Can't open file $sshfile $!" );
534+
my @sshkeylines = <$FD>;
535+
close $FD;
536+
$user->setSSHkey(\@sshkeylines);
537+
if ($user->updateUser() ) {
538+
print "Problem with ssh key setting. \n";
539+
$ret = $ret + 1;
540+
} else {
541+
print "SSH key(s) for $username set. \n";
542+
}
543+
544+
}
545+
else {
546+
print "User $username doesn't exist. Can't set SSH key\n";
547+
$ret = $ret + 1;
548+
}
549+
550+
return $ret;
551+
}
552+
521553
1;

0 commit comments

Comments
 (0)