From ea33ebfbe6fe6829dff5b343a3810adb300737de Mon Sep 17 00:00:00 2001 From: Michal Stava Date: Fri, 10 Jun 2022 14:36:51 +0200 Subject: [PATCH] feat(users_emails): new scripts for getting all users mails * get all emails from users on the facility (no matter the VO) * added gen, send and slave scripts --- gen/users_emails | 44 +++++++++++++++++++ send/users_emails | 4 ++ .../bin/process-users_emails.sh | 24 ++++++++++ slave/process-users-emails/changelog | 5 +++ slave/process-users-emails/dependencies | 1 + slave/process-users-emails/rpm.dependencies | 1 + slave/process-users-emails/short_desc | 1 + 7 files changed, 80 insertions(+) create mode 100755 gen/users_emails create mode 100755 send/users_emails create mode 100755 slave/process-users-emails/bin/process-users_emails.sh create mode 100644 slave/process-users-emails/changelog create mode 100644 slave/process-users-emails/dependencies create mode 100644 slave/process-users-emails/rpm.dependencies create mode 100644 slave/process-users-emails/short_desc diff --git a/gen/users_emails b/gen/users_emails new file mode 100755 index 00000000..3c2ef08c --- /dev/null +++ b/gen/users_emails @@ -0,0 +1,44 @@ +#!/usr/bin/perl +use strict; +use warnings; +use perunServicesInit; +use perunServicesUtils; +use File::Basename; +use utf8; + +binmode STDOUT, ":utf8"; + +our $SERVICE_NAME = basename($0); +our $PROTOCOL_VERSION = "3.0.0"; +my $SCRIPT_VERSION = "3.0.0"; + +perunServicesInit::init; +my $DIRECTORY = perunServicesInit::getDirectory; +my $data = perunServicesInit::getHashedHierarchicalData; + +#Constants +our $A_MEMBER_MAILS; *A_MEMBER_MAILS = \'urn:perun:member:attribute-def:virt:mails'; + +my $service_file_name = "$DIRECTORY/$::SERVICE_NAME"; + +my $emailsStruc = {}; + +##################################### +foreach my $memberId ($data->getMemberIdsForFacility()) { + my $emails = $data->getMemberAttributeValue(attrName => $A_MEMBER_MAILS, member => $memberId); + foreach my $email (@$emails) { + $emailsStruc->{$email} = 1; + } +} + +####### FILE WITH EMAILS ###### +open SERVICE_FILE,">$service_file_name" or die "Cannot open $service_file_name: $! \n"; +binmode SERVICE_FILE, ":utf8"; + +foreach my $email (sort keys %$emailsStruc) { + print SERVICE_FILE $email . "\n"; +} + +close(SERVICE_FILE); + +perunServicesInit::finalize; diff --git a/send/users_emails b/send/users_emails new file mode 100755 index 00000000..9f630896 --- /dev/null +++ b/send/users_emails @@ -0,0 +1,4 @@ +#!/bin/bash +SERVICE_NAME="users_emails" + +. generic_send diff --git a/slave/process-users-emails/bin/process-users_emails.sh b/slave/process-users-emails/bin/process-users_emails.sh new file mode 100755 index 00000000..3a011f64 --- /dev/null +++ b/slave/process-users-emails/bin/process-users_emails.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +PROTOCOL_VERSION='3.0.0' + +function process { + DST_DIR="/tmp/" + + ### Status codes + I_CHANGED=(0 "${DST_FILE} updated") + E_CANNOT_COPY=(50 'Cannot copy file ${FROM_PERUN} to ${DST_DIR}/${DST_FILE}') + + FROM_PERUN="${WORK_DIR}/users_emails" + DST_FILE="users_emails" + + create_lock + + cp "${FROM_PERUN}" "${DST_DIR}/${DST_FILE}" + + if [ $? -eq 0 ]; then + log_msg I_CHANGED + else + log_msg E_CANNOT_COPY + fi +} diff --git a/slave/process-users-emails/changelog b/slave/process-users-emails/changelog new file mode 100644 index 00000000..2a147af4 --- /dev/null +++ b/slave/process-users-emails/changelog @@ -0,0 +1,5 @@ +perun-slave-process-users-emails (3.1.1) stable; urgency=low + + * New package version for perun-slave-process-users-emails + + -- Michal Stava Fri, 10 Jun 2022 14:34:00 +0200 diff --git a/slave/process-users-emails/dependencies b/slave/process-users-emails/dependencies new file mode 100644 index 00000000..a6717984 --- /dev/null +++ b/slave/process-users-emails/dependencies @@ -0,0 +1 @@ +perun-slave-base diff --git a/slave/process-users-emails/rpm.dependencies b/slave/process-users-emails/rpm.dependencies new file mode 100644 index 00000000..a6717984 --- /dev/null +++ b/slave/process-users-emails/rpm.dependencies @@ -0,0 +1 @@ +perun-slave-base diff --git a/slave/process-users-emails/short_desc b/slave/process-users-emails/short_desc new file mode 100644 index 00000000..8976d04d --- /dev/null +++ b/slave/process-users-emails/short_desc @@ -0,0 +1 @@ +Package for perun service - users_emails