-
Notifications
You must be signed in to change notification settings - Fork 19
[WIP] Add LDAP sync to Revbank #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
my $ldap_base = 'ou=People,dc=example,dc=com'; | ||
|
||
my $revbank_file = File::Spec->catfile(File::HomeDir->my_home, '.revbank', 'accounts'); | ||
my $log_file = '/var/log/revbank_ldap_sync.log'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RevBank normally doesn't write outside its own data directory.
my @only_in_ldap = grep { !$revbank_hash{$_} } @ldap_users; | ||
my @only_in_revbank = grep { !$ldap_hash{$_} } @revbank_users; | ||
|
||
foreach my $user (@only_in_ldap) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plugins typically run their code in hooks, or the command
sub. Maybe this is intended as a script to run from a regular shell? If so, the file should probably go in the contrib/
directory instead of plugins/
.
return @uids; | ||
} | ||
|
||
sub get_revbank_users { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use RevBank::Accounts::names()
for this.
open my $fh, '<', $file or die "Could not open revbank file: $file: $!"; | ||
my @users; | ||
while (<$fh>) { | ||
next if /^\s*-/; # skip system transactions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System accounts currently begin with +
, -
, or *
. You could use RevBank::Accounts::is_special() instead of a regex, so your logic always aligns with what revbank uses.
my @users; | ||
while (<$fh>) { | ||
next if /^\s*-/; # skip system transactions | ||
if (/^(\w+)\s+/) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RevBank has valid user names that start with a non-\w character.
my $line = sprintf "%-20s +0.00 %s +@%s\n", $user, $ts, $ts; | ||
|
||
open my $fh, '>>', $file or die "Could not write to $file: $!"; | ||
print $fh $line; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use RevBank::Accounts::create()
for this.
If you're rolling your own implementation, consider at least supporting the global lock.
Work in progress, lots of loose ends, needs some rework.