Skip to content

[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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wgroenewold
Copy link

Work in progress, lots of loose ends, needs some rework.

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';
Copy link
Contributor

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) {
Copy link
Contributor

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 {
Copy link
Contributor

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
Copy link
Contributor

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+/) {
Copy link
Contributor

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;
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants