From 44ca800007452f20a9f09538b46b23b4064b3e83 Mon Sep 17 00:00:00 2001 From: Michal Stava Date: Tue, 3 May 2022 14:00:10 +0200 Subject: [PATCH 1/6] feat(o365_mu_users_export): new scripts for o365 mu * propagates logins of o365 accounts * added gen and send scripts --- gen/o365_mu_users_export | 58 +++++++++++++ send/o365_mu_users_export | 119 +++++++++++++++++++++++++++ send/o365_mu_users_export_process.pl | 114 +++++++++++++++++++++++++ 3 files changed, 291 insertions(+) create mode 100755 gen/o365_mu_users_export create mode 100755 send/o365_mu_users_export create mode 100755 send/o365_mu_users_export_process.pl diff --git a/gen/o365_mu_users_export b/gen/o365_mu_users_export new file mode 100755 index 00000000..0c96064f --- /dev/null +++ b/gen/o365_mu_users_export @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use perunServicesInit; +use perunServicesUtils; +use Data::Dumper; +use utf8; + +local $::SERVICE_NAME = "o365_mu_users_export"; +local $::PROTOCOL_VERSION = "3.0.0"; +my $SCRIPT_VERSION = "3.0.0"; + +perunServicesInit::init; +my $DIRECTORY = perunServicesInit::getDirectory; +my $data = perunServicesInit::getHashedHierarchicalData; + +#Constants +our $A_UF_LOGIN; *A_UF_LOGIN = \'urn:perun:user_facility:attribute-def:virt:login'; +our $A_UF_O365_STATE; *A_UF_O365_STATE = \'urn:perun:user_facility:attribute-def:def:o365InternalUserState'; +our $A_UF_DISABLE_O365_MAIL_FORWARD; *A_UF_DISABLE_O365_MAIL_FORWARD = \'urn:perun:user_facility:attribute-def:def:disableO365MailForward'; +our $A_UF_O365_STORE_AND_FORWARD; *A_UF_O365_STORE_AND_FORWARD = \'urn:perun:user_facility:attribute-def:def:o365MailStoreAndForward'; + +my $validLogins = {}; + +#RULES: +#1] any user who has UCO +#2] status of user in o365 is not 0 +#3] disableMailForward == true +#OR +#3] disableMailForward == false AND mailStoreAndForward == true +foreach my $memberId ( $data->getMemberIdsForFacility() ) { + my $uco = $data->getUserFacilityAttributeValue( member => $memberId, attrName => $A_UF_LOGIN ); + #skip all users without UCO + next unless $uco; + my $o365Status = $data->getUserFacilityAttributeValue( member => $memberId, attrName => $A_UF_O365_STATE ); + #skip all users with 0 or empty value in status attribute (everything except 0 is OK here) + next unless $o365Status; + my $disableMailForward = $data->getUserFacilityAttributeValue( member => $memberId, attrName => $A_UF_DISABLE_O365_MAIL_FORWARD ); + my $storeAndForward = $data->getUserFacilityAttributeValue( member => $memberId, attrName => $A_UF_O365_STORE_AND_FORWARD ); + unless( $disableMailForward ) { + #skip users with set forward without storing a copy + next unless $storeAndForward; + } + #if all rules are met, add uco to the list + $validLogins->{$uco} = $uco; +} + +my $fileName = "$DIRECTORY/$::SERVICE_NAME"; +open FILE,">$fileName" or die "Cannot open $fileName: $! \n"; +binmode FILE, ":utf8"; + +foreach my $uco (sort keys %{$validLogins}) { + print FILE $uco . "\n"; +} + +close (FILE); +perunServicesInit::finalize; diff --git a/send/o365_mu_users_export b/send/o365_mu_users_export new file mode 100755 index 00000000..ab6f7fbd --- /dev/null +++ b/send/o365_mu_users_export @@ -0,0 +1,119 @@ +#!/bin/bash + +SERVICE_NAME="o365_mu_users_export" + +FACILITY_NAME=$1 +DESTINATION=$2 +DESTINATION_TYPE=$3 + +if [ -z "$DESTINATION" ]; then + echo "Missing Destination argument (DB NAME there)" >&2 + exit 231 +fi + +if [ -z "$FACILITY_NAME" ]; then + echo "Missing FacilityName argument" >&2 + exit 232 +fi + +if [ -z "$DESTINATION_TYPE" ]; then + echo "Destination type of this service can't be empty" >&2 + exit 233; +else + TYPE="service-specific" + if [ "$DESTINATION_TYPE" != "$TYPE" ]; then + echo "Destination type of this service need to be $TYPE" >&2 + exit 234; + fi +fi + +#Destination is name of database on oracle in localhost tnsnames file +DBNAME=$DESTINATION + +SERVICE_FILES_BASE_DIR="`pwd`/../gen/spool" +SERVICE_FILES_DIR="$SERVICE_FILES_BASE_DIR/$FACILITY_NAME/$SERVICE_NAME" + +#Just safety check. This should not happen. +if [ ! -d "$SERVICE_FILES_DIR" ]; then echo '$SERVICE_FILES_DIR: '$SERVICE_FILES_DIR' is not a directory' >&2 ; exit 1; fi + +#Create lock (same like in slave) +LOCK_DIR=${LOCK_DIR:=/var/lock} +LOCK_FILE="${LOCK_DIR}/perunv3-${SERVICE_NAME}-$DBNAME.lock" +LOCK_PIDFILE="$LOCK_FILE/pid" + +function create_lock { + if mkdir "${LOCK_FILE}"; then + trap 'rm -r -f "${LOCK_FILE}"' EXIT + echo $$ > "$LOCK_PIDFILE"; + if [ $? -ne 0 ]; then + echo "Can't create lock file." >&2 + exit 250 + fi + else + # lock file exists, check for existence of concurrent process + if ps ax | grep "$SERVICE_NAME" | sed 's/^\([0-9]\+\).*/\1/' | grep "\(^\| \)`cat $LOCK_PIDFILE`\( \|$\)"; then + # concurrent process is running - this skript must terminate + echo "Concuret process o365_mu_users_export is running" >&2 + exit 249 + else + # lock is not valid; it should be deleted + rm -r "$LOCK_FILE" + if [ $? -ne 0 ]; then + echo "Can't remove not valid lock file." >&2 + exit 248 + fi + echo "Invalid lock file found and deleted: $LOCK_FILE" >&2 + mkdir "${LOCK_FILE}" + if [ $? -ne 0 ]; then + echo "Can't create lock after removing invalid lock." >&2 + exit 247 + fi + trap 'rm -r -f "${LOCK_FILE}"' EXIT + echo $$ > "$LOCK_PIDFILE" + if [ $? -ne 0 ]; then + echo "Can't create lock file after removing invalid lock file." >&2 + exit 246 + fi + fi + fi +} + +create_lock + +TMP_HOSTNAME_DIR="`mktemp -d /tmp/perun-send.XXXXXXXXXX`" +if [ $? -ne 0 ]; then + echo "Can't create temporary dir" >&2 + exit 255 +fi + +#prepare removing of temporary files and dirs after exit of script +trap 'rm -r -f "${LOCK_FILE}" "${TMP_HOSTNAME_DIR}"' EXIT + +cp $SERVICE_FILES_DIR/$SERVICE_NAME $TMP_HOSTNAME_DIR +if [ $? -ne 0 ]; then + echo "Can't copy service file to temporary dir" >&2 + exit 254 +fi + +EXECSCRIPT="./o365_mu_users_export_process.pl" + +if [ ! -f "$EXECSCRIPT" ]; then + echo "Can't locate process script!" >&2 + exit 253 +fi + +$EXECSCRIPT -d $DBNAME -p $TMP_HOSTNAME_DIR -s $SERVICE_NAME + +ERRORCODE=$? +if [ $ERRORCODE -ne 0 ]; then + echo "Process exit with error" >&2 + exit $ERRORCODE +fi + +ERR_CODE=$? + +if [ $ERR_CODE -ne 0 ]; then + echo "Slave script ends with return code: $ERR_CODE" >&2 +fi + +exit $ERR_CODE diff --git a/send/o365_mu_users_export_process.pl b/send/o365_mu_users_export_process.pl new file mode 100755 index 00000000..b5cdce9f --- /dev/null +++ b/send/o365_mu_users_export_process.pl @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use DBI; +use Getopt::Long qw(:config no_ignore_case); +use Data::Dumper; + +my $username; +my $password; +my $dbname; +my $database; +my $pathToServiceFile; +my $serviceName; +my $tableName; + +GetOptions ("dbname|d=s" => \$dbname, "pathToServiceFile|p=s" => \$pathToServiceFile, "serviceName|s=s" => \$serviceName); + +if(!defined $dbname) { + print "Missing DBNAME to process service.\n"; + exit 10; +} + +if(!defined $pathToServiceFile) { + print "Missing path to file with generated data to process service.\n"; + exit 11; +} + +if(!defined $serviceName) { + print "Missing info about service name to process service.\n"; + exit 12; +} + +my $filename = "$pathToServiceFile/$serviceName"; +if(! -f $filename) { + print "Missing service file with data.\n"; + exit 13; +} + +my $configPath = "/etc/perun/services/$serviceName/$dbname"; +open FILE, $configPath or die "Could not open config file $configPath: $!"; +while(my $line = ) { + if($line =~ /^username: .*/) { + $username = ($line =~ m/^username: (.*)$/)[0]; + } elsif($line =~ /^password: .*/) { + $password = ($line =~ m/^password: (.*)$/)[0]; + } elsif($line =~ /^tablename: .*/) { + $tableName = ($line =~ m/^tablename: (.*)$/)[0]; + } elsif($line =~ /^database: .*/) { + $database = ($line =~ m/^database: (.*)$/)[0]; + } +} + +if(!defined($password) || !defined($username) || !defined($tableName) || !defined($database)) { + print "Can't get config data from config file.\n"; + exit 14; +} + +#Main Structure +my $validLogins = {}; + +open FILE, $filename or die "Could not open $filename: $!"; +while(my $line = ) { + chomp( $line ); + $validLogins->{$line} = $line; +} +close FILE; + +my $dbh = DBI->connect("dbi:Oracle:$database",$username, $password,{RaiseError=>1,AutoCommit=>0,LongReadLen=>65536, ora_charset => 'AL32UTF8'}) or die "Connect to database $database Error!\n"; + +#statistic and information variables +my $skipped = 0; +my $inserted = 0; +my $deleted = 0; + +#return all logins from the table +my $loginsInTable = {}; +my $allLoginsFromTable = $dbh->prepare(qq{select distinct uco from $tableName}); +$allLoginsFromTable->execute(); +while(my $alft = $allLoginsFromTable->fetch) { + $loginsInTable->{$$alft[0]} = $$alft[0]; +} + +#insert new logins +foreach my $uco (sort keys %$validLogins) { + if($loginsInTable->{$uco}) { + $skipped++; + } else { + my $insertLogin = $dbh->prepare(qq{INSERT INTO $tableName (uco) VALUES (?)}); + $insertLogin->execute($uco); + $inserted++; + } +} + +#remove old logins +foreach my $uco (sort keys %$loginsInTable) { + unless($validLogins->{$uco}) { + my $deleteLogin = $dbh->prepare(qq{DELETE from $tableName where uco=?}); + $deleteLogin->execute($uco); + $deleted++; + } +} + +commit $dbh; +$dbh->disconnect(); + +#Info about operations +print "================================\n"; +print "Inserted:\t$inserted\n"; +print "Skipped: \t$skipped\n"; +print "Deleted: \t$deleted\n"; +print "================================\n"; + +exit 0; From 99a99750dfdfeb2f5b3af926d65c9cd2e0e3e8e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johana=20Sup=C3=ADkov=C3=A1?= Date: Mon, 16 May 2022 15:32:57 +0200 Subject: [PATCH 2/6] feat: removed redundant filterExpiredMembers parameter * the parameter was passed by perun services' gen scripts as flag if members with expired group status should be included in the retrieved data * the information is now stored in the database with the service object and does not need to be passed separately anymore BREAKING CHANGE: removed filterExpiredMembers parameter --- gen/ad_admin_group_mu_ucn | 4 ++-- gen/ad_admin_user_mu_ucn | 4 ++-- gen/ad_group_mu_ucn | 4 ++-- gen/ad_user_mu_ucn | 4 ++-- gen/arcgis_licenses_mu | 4 ++-- gen/insight_mu | 4 ++-- gen/netbox | 4 ++-- gen/perunServicesInit.pm | 24 ++++++------------------ 8 files changed, 20 insertions(+), 32 deletions(-) diff --git a/gen/ad_admin_group_mu_ucn b/gen/ad_admin_group_mu_ucn index 6532a639..4912af73 100755 --- a/gen/ad_admin_group_mu_ucn +++ b/gen/ad_admin_group_mu_ucn @@ -9,7 +9,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; local $::SERVICE_NAME = "ad_admin_group_mu_ucn"; local $::PROTOCOL_VERSION = "3.0.0"; -my $SCRIPT_VERSION = "3.0.0"; +my $SCRIPT_VERSION = "3.0.1"; sub addMemberToGroup; sub processWorkplaces; @@ -23,7 +23,7 @@ my $DIRECTORY = perunServicesInit::getDirectory; my $fileName = "$DIRECTORY/$::SERVICE_NAME".".ldif"; #Get hierarchical data without expired members -my $data = perunServicesInit::getHashedDataWithGroups(1); +my $data = perunServicesInit::getHashedDataWithGroups; my $DEBUG = 0; #Constants diff --git a/gen/ad_admin_user_mu_ucn b/gen/ad_admin_user_mu_ucn index 451d1e68..d6ac5ddf 100755 --- a/gen/ad_admin_user_mu_ucn +++ b/gen/ad_admin_user_mu_ucn @@ -10,13 +10,13 @@ use Encode; local $::SERVICE_NAME = "ad_admin_user_mu_ucn"; local $::PROTOCOL_VERSION = "3.0.0"; -my $SCRIPT_VERSION = "3.0.0"; +my $SCRIPT_VERSION = "3.0.1"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; my $fileName = "$DIRECTORY/$::SERVICE_NAME".".ldif"; -my $data = perunServicesInit::getHashedHierarchicalData(1); +my $data = perunServicesInit::getHashedHierarchicalData; #Constants our $A_F_DOMAIN; *A_F_DOMAIN = \'urn:perun:facility:attribute-def:def:adDomain'; diff --git a/gen/ad_group_mu_ucn b/gen/ad_group_mu_ucn index 0a543fb2..d5608ddc 100755 --- a/gen/ad_group_mu_ucn +++ b/gen/ad_group_mu_ucn @@ -11,7 +11,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; local $::SERVICE_NAME = "ad_group_mu_ucn"; local $::PROTOCOL_VERSION = "3.0.0"; -my $SCRIPT_VERSION = "3.0.4"; +my $SCRIPT_VERSION = "3.0.5"; sub addMemberToGroup; sub processWorkplaces; @@ -26,7 +26,7 @@ my $fileName = "$DIRECTORY/$::SERVICE_NAME".".ldif"; my $baseDnFileName = "$DIRECTORY/baseDN"; # Get hierarchical data without expired members -my $data = perunServicesInit::getHashedDataWithGroups(1); +my $data = perunServicesInit::getHashedDataWithGroups; my $DEBUG = 0; #Constants diff --git a/gen/ad_user_mu_ucn b/gen/ad_user_mu_ucn index 80b965f7..33ca47ad 100755 --- a/gen/ad_user_mu_ucn +++ b/gen/ad_user_mu_ucn @@ -8,14 +8,14 @@ use utf8; local $::SERVICE_NAME = "ad_user_mu_ucn"; local $::PROTOCOL_VERSION = "3.0.0"; -my $SCRIPT_VERSION = "3.0.1"; +my $SCRIPT_VERSION = "3.0.2"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; my $fileName = "$DIRECTORY/$::SERVICE_NAME".".ldif"; my $baseDnFileName = "$DIRECTORY/baseDN"; -my $data = perunServicesInit::getHashedHierarchicalData(1); +my $data = perunServicesInit::getHashedHierarchicalData; #Constants our $A_F_BASE_DN; *A_F_BASE_DN = \'urn:perun:facility:attribute-def:def:adBaseDN'; diff --git a/gen/arcgis_licenses_mu b/gen/arcgis_licenses_mu index ceee079c..b1da29e5 100755 --- a/gen/arcgis_licenses_mu +++ b/gen/arcgis_licenses_mu @@ -8,11 +8,11 @@ use JSON::XS; use utf8; our $SERVICE_NAME = "arcgis_licenses_mu"; -our $PROTOCOL_VERSION = "3.0.0"; +our $PROTOCOL_VERSION = "3.0.1"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; -my $data = perunServicesInit::getHashedDataWithGroups(1); +my $data = perunServicesInit::getHashedDataWithGroups; #Constants our $A_USER_FIRST_NAME; *A_USER_FIRST_NAME = \'urn:perun:user:attribute-def:core:firstName'; diff --git a/gen/insight_mu b/gen/insight_mu index 24692555..b37ccc23 100755 --- a/gen/insight_mu +++ b/gen/insight_mu @@ -9,12 +9,12 @@ use POSIX qw(strftime); our $SERVICE_NAME = "insight_mu"; our $PROTOCOL_VERSION = "3.0.0"; -my $SCRIPT_VERSION = "3.0.0"; +my $SCRIPT_VERSION = "3.0.1"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; # get only valid members -my $data = perunServicesInit::getHashedDataWithGroups(1); +my $data = perunServicesInit::getHashedDataWithGroups; # CONSTANTS our $A_USER_ID; *A_USER_ID = \'urn:perun:user:attribute-def:core:id'; diff --git a/gen/netbox b/gen/netbox index 63ca50b9..c2124f6d 100755 --- a/gen/netbox +++ b/gen/netbox @@ -9,14 +9,14 @@ use Data::Dumper; our $SERVICE_NAME = "netbox"; our $PROTOCOL_VERSION = "3.0.0"; -my $SCRIPT_VERSION = "3.0.0"; +my $SCRIPT_VERSION = "3.0.1"; my $file_name_users = "netbox_users"; my $file_name_groups = "netbox_groups"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; -my $data = perunServicesInit::getHashedHierarchicalData(1); +my $data = perunServicesInit::getHashedHierarchicalData; #Constants our $A_RESOURCE_GROUP_NAME; *A_RESOURCE_GROUP_NAME = \'urn:perun:resource:attribute-def:def:netboxGroupName'; diff --git a/gen/perunServicesInit.pm b/gen/perunServicesInit.pm index 29c8be48..4fdf65e4 100644 --- a/gen/perunServicesInit.pm +++ b/gen/perunServicesInit.pm @@ -144,54 +144,42 @@ sub getFacility { sub getHashedHierarchicalData { if(defined $local_data) { return $local_data; } - my $filterExpiredMembers = shift; - unless($filterExpiredMembers) { $filterExpiredMembers = 0; } - my $data = $servicesAgent->getHashedHierarchicalData(service => $service->getId, facility => $facility->getId, filterExpiredMembers => $filterExpiredMembers, consentEval => $CONSENT_EVAL); + my $data = $servicesAgent->getHashedHierarchicalData(service => $service->getId, facility => $facility->getId, consentEval => $CONSENT_EVAL); logData $data, 'hashedHierarchicalData'; return $data; } sub getHierarchicalData { if(defined $local_data) { return $local_data; } - my $filterExpiredMembers = shift; - unless($filterExpiredMembers) { $filterExpiredMembers = 0; } - my $data = $servicesAgent->getHierarchicalData(service => $service->getId, facility => $facility->getId, filterExpiredMembers => $filterExpiredMembers); + my $data = $servicesAgent->getHierarchicalData(service => $service->getId, facility => $facility->getId); logData $data, 'hierarchicalData'; return $data; } sub getFlatData { if(defined $local_data) { return $local_data; } - my $filterExpiredMembers = shift; - unless($filterExpiredMembers) { $filterExpiredMembers = 0; } - my $data = $servicesAgent->getFlatData(service => $service->getId, facility => $facility->getId, filterExpiredMembers => $filterExpiredMembers); + my $data = $servicesAgent->getFlatData(service => $service->getId, facility => $facility->getId); logData $data, 'flatData'; return $data; } sub getHashedDataWithGroups { if(defined $local_data) { return $local_data; } - my $filterExpiredMembers = shift; - unless($filterExpiredMembers) { $filterExpiredMembers = 0; } - my $data = $servicesAgent->getHashedDataWithGroups(service => $service->getId, facility => $facility->getId, filterExpiredMembers => $filterExpiredMembers, consentEval => $CONSENT_EVAL); + my $data = $servicesAgent->getHashedDataWithGroups(service => $service->getId, facility => $facility->getId, consentEval => $CONSENT_EVAL); logData $data, 'hashedDataWithGroups'; return $data; } sub getDataWithGroups { if(defined $local_data) { return $local_data; } - my $filterExpiredMembers = shift; - unless($filterExpiredMembers) { $filterExpiredMembers = 0; } - my $data = $servicesAgent->getDataWithGroups(service => $service->getId, facility => $facility->getId, filterExpiredMembers => $filterExpiredMembers); + my $data = $servicesAgent->getDataWithGroups(service => $service->getId, facility => $facility->getId); logData $data, 'dataWithGroups'; return $data; } sub getDataWithVos { if(defined $local_data) { return $local_data; } - my $filterExpiredMembers = shift; - unless($filterExpiredMembers) { $filterExpiredMembers = 0; } - my $data = $servicesAgent->getDataWithVos(service => $service->getId, facility => $facility->getId, filterExpiredMembers => $filterExpiredMembers); + my $data = $servicesAgent->getDataWithVos(service => $service->getId, facility => $facility->getId); logData $data, 'dataWithVos'; return $data; } From 5526398c94bfc977149501891bc75158c4f196b0 Mon Sep 17 00:00:00 2001 From: Michal Stava Date: Wed, 11 May 2022 12:22:45 +0200 Subject: [PATCH 3/6] feat(o365_mu): removing and preserving resource mailboxes - Because of technical issues with updating resource mailboxes data, we were unable to finish migration of last version of this service to production envrionment. The logic about resource mailboxes should be removed, but there is a plan to further work on it in the future. For this reason it was preserved and only removed from main code. - Main parts of the code were commented and they are not processed any more. - All methodes and variables were preserved (but we are not using them) - Sorting of emails were removed, because of cache in send script. Cached data are not sorted so the record from gen script and the record from cache would differ even if they are same in the context of content. --- gen/o365_mu | 53 +++++++++++++------- send/o365-connector.pl | 107 +++++++++++++++++++++------------------- send/o365_mu | 3 +- send/o365_mu_process.pl | 80 +++++++++++++++++------------- 4 files changed, 138 insertions(+), 105 deletions(-) diff --git a/gen/o365_mu b/gen/o365_mu index 7130d434..4a356d3e 100755 --- a/gen/o365_mu +++ b/gen/o365_mu @@ -16,8 +16,8 @@ sub saveUsersToFile; sub saveGroupsToFile; our $SERVICE_NAME = "o365_mu"; -our $PROTOCOL_VERSION = "3.0.0"; -my $SCRIPT_VERSION = "3.0.1"; +our $PROTOCOL_VERSION = "3.1.0"; +my $SCRIPT_VERSION = "3.1.1"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; @@ -39,6 +39,19 @@ our $A_UF_O365_STORE_AND_FORWARD; *A_UF_O365_STORE_AND_FORWARD = our $A_UF_O365_LICENCE; *A_UF_O365_LICENCE = \'urn:perun:user_facility:attribute-def:def:o365Licence'; our $A_R_IS_FOR_O365_GROUP; *A_R_IS_FOR_O365_GROUP = \'urn:perun:resource:attribute-def:def:isForO365Group'; our $A_F_ID; *A_F_ID = \'urn:perun:facility:attribute-def:core:id'; + +our $UPN_TEXT = "UPN"; +our $MAIL_FORWARD_TEXT = "mailForward"; +our $ARCHIVE_TEXT = "archive"; +our $STORE_AND_FORWARD_TEXT = "storeAndForward"; +our $EMAIL_ADDRESSES = "emailAddresses"; + +###------------------------------------------------------------------------------ +### RESOURCE MAILBOXES CONFIGURATION +### WARNING: These variables are for purpose of resource mail boxes configuration +### and we are not using them at this moment! We still want to preserve +### this for continuing a work on service in the future. +###------------------------------------------------------------------------------ our $A_R_O365_RES_NAME; *A_R_O365_RES_NAME = \'urn:perun:resource:attribute-def:def:o365ResourceName'; our $A_R_O365_RES_ALIAS; *A_R_O365_RES_ALIAS = \'urn:perun:resource:attribute-def:def:o365ResourceAlias'; our $A_R_O365_RES_EMAIL_ADDRESES; *A_R_O365_RES_EMAIL_ADDRESES = \'urn:perun:resource:attribute-def:def:o365ResourceEmailAddresses'; @@ -66,7 +79,6 @@ our $A_GR_O365_RES_BOOK_IN_POLICY; *A_GR_O365_RES_BOOK_IN_POLICY = our $A_GR_O365_RES_REQUEST_IN_POLICY; *A_GR_O365_RES_REQUEST_IN_POLICY = \'urn:perun:group_resource:attribute-def:def:o365ResourceRequestInPolicy'; our $A_GR_O365_RES_REQUEST_OUT_OF_POLICY; *A_GR_O365_RES_REQUEST_OUT_OF_POLICY = \'urn:perun:group_resource:attribute-def:def:o365ResourceRequestOutOfPolicy'; our $A_GR_O365_RES_DELEGATES; *A_GR_O365_RES_DELEGATES = \'urn:perun:group_resource:attribute-def:def:o365ResourceDelegates'; - our $RES_NAME_TEXT = "RES_NAME"; our $RES_ALIAS_TEXT = "RES_ALIAS"; our $RES_EMAIL_ADDRESES_TEXT = "RES_EMAIL_ADDRESES"; @@ -94,11 +106,12 @@ our $RES_DELEGATES_TEXT = "RES_DELEGATES"; our $RES_BOOK_IN_POLICY_TEXT = "RES_BOOK_IN_POLICY"; our $RES_REQUEST_IN_POLICY_TEXT = "RES_REQUEST_IN_POLICY"; our $RES_REQUEST_OUT_OF_POLICY_TEXT = "RES_REQUEST_OUT_OF_POLICY"; -our $UPN_TEXT = "UPN"; -our $MAIL_FORWARD_TEXT = "mailForward"; -our $ARCHIVE_TEXT = "archive"; -our $STORE_AND_FORWARD_TEXT = "storeAndForward"; -our $EMAIL_ADDRESSES = "emailAddresses"; + +our $resourceMails = {}; +my $resourceMailsFileName = "$DIRECTORY/$::SERVICE_NAME-resource-mails"; +###------------------------------------------------------------------------------ +### END of RESOURCE MAILBOXES CONFIGURATION +###------------------------------------------------------------------------------ #Default forwarding domain for MU our $DEFAULT_FORWARDING_DOMAIN = '@mo.muni.cz'; @@ -109,7 +122,6 @@ our $DEFAULT_FORWARDING_DOMAIN = '@mo.muni.cz'; our $users = {}; our $groups = {}; -our $resourceMails = {}; #------------------------------------------------------------------------- # PROCESSING FACILITY @@ -135,12 +147,12 @@ foreach my $resourceId ( $data->getResourceIds() ) { my $usersFileName = "$DIRECTORY/$::SERVICE_NAME-users"; my $groupsFileName = "$DIRECTORY/$::SERVICE_NAME-groups"; -my $resourceMailsFileName = "$DIRECTORY/$::SERVICE_NAME-resource-mails"; my $facilityIdFileName = "$DIRECTORY/$::SERVICE_NAME-facilityId"; saveUsersToFile $usersFileName, $users; saveGroupsToFile $groupsFileName, $groups; -saveResourceMailsToFile $resourceMailsFileName, $resourceMails; +###we don't want to process resource mailboxes until further change +#saveResourceMailsToFile $resourceMailsFileName, $resourceMails; saveFacilityIdToFile $facilityIdFileName, $facilityId; #------------------------------------------------------------------------- @@ -164,20 +176,21 @@ sub processResource { #define attributes for processing o365 groups and o365 resource maling lists my $isForO365Group = $data->getResourceAttributeValue( resource => $resourceId, attrName => $A_R_IS_FOR_O365_GROUP ); - my $resName = $data->getResourceAttributeValue( resource => $resourceId, attrName => $A_R_O365_RES_NAME ); + #my $resName = $data->getResourceAttributeValue( resource => $resourceId, attrName => $A_R_O365_RES_NAME ); #process all members from resource (users data) foreach my $memberId ($data->getMemberIdsForResource( resource => $resourceId )) { processResourceMember $memberId; } + ### Skip of processing resource mails #if resource mail name exists, process it as resource mail (resource-mails data) - if($resName) { - #prevent duplicity in resource name - if($resourceMails->{$resName}) { die "There is a duplicity of two Resources with the same resourceMailName: $resName\n"; } - - processResourceMail $resourceId; - } + #if($resName) { + # #prevent duplicity in resource name + # if($resourceMails->{$resName}) { die "There is a duplicity of two Resources with the same resourceMailName: $resName\n"; } + # + # processResourceMail $resourceId; + #} #if resource is set as o365 resource, process it with all it's groups (groups data) if($isForO365Group) { @@ -301,7 +314,9 @@ sub processResourceMember { } else { warn "Can't find emails for user with UCO: $UCO \n"; } - my $emailsString = join(',', sort @emailsArray); + #do not use sorting because of cache in send script (cache does not have sorted emails and such records would need to be updated even if there is no really change) + #my $emailsString = join(',', sort @emailsArray); + my $emailsString = join(',', @emailsArray); unless($users->{$UCO}) { $users->{$UCO}->{$UPN_TEXT} = $UCO . "@" . $domainName; diff --git a/send/o365-connector.pl b/send/o365-connector.pl index acea7507..b03dd666 100755 --- a/send/o365-connector.pl +++ b/send/o365-connector.pl @@ -97,13 +97,17 @@ our $COMMAND_GET_O365_GROUP = "Get-MuniO365Group"; our $COMMAND_GET_MAILBOX = "Get-MuniMailbox"; our $COMMAND_GET_SHAREBOX = "Get-MuniSharebox"; -our $COMMAND_GET_RESOURCE = "Get-MuniResource"; -our $COMMAND_GET_RESOURCES = "Get-MuniResources"; our $COMMAND_SET_GROUP = "Set-MuniGroup"; our $COMMAND_SET_MAILBOX = "Set-MuniMailBox"; +our $COMMAND_TEST_MUNI_ERROR = "Test-MuniError"; + +### RESOURCE MAILBOXES commands - not used, only preserved +our $COMMAND_GET_RESOURCE = "Get-MuniResource"; +our $COMMAND_GET_RESOURCES = "Get-MuniResources"; our $COMMAND_SET_RESOURCE = "Set-MuniResource"; our $COMMAND_REMOVE_RESOURCE = "Remove-MuniResource"; -our $COMMAND_TEST_MUNI_ERROR = "Test-MuniError"; +### End of RESOURCE MAILBOXES commands + #Basic content of every call our %content = (); #"WaitMsec" => $MAX_WAIT_MSEC @@ -206,32 +210,33 @@ sub help { "forwarding|f=s" => \$argForw, "emails|e=s" => \$argEmailAddresses, 'contacts|t=s@{1,}' => \@argContacts, - "alias|A=s" => \$argResAlias, - 'resEmails|B=s@{1,}' => \@argResEmails, - "displayName|C=s" => \$argResDisplayName, - "type|D=s" => \$argResType, - "capacity|E=i" => \$argResCapacity, - "additionalResponse|F=s" => \$argResAdditionalResponse, - "extMeetingMsg|G=i" => \$argResExtMeetingMsg, - "allowConflicts|H=i" => \$argResAllowConflicts, - "bookingWindow|I=i" => \$argResBookingWindow, - "percentageAllowed|J=i" => \$argResPercentageAllowed, - "enforceSchedHorizon|K=i" => \$argResEnforceSchedHorizon, - "maxConflictInstances|L=i" => \$argResMaxConflictInstances, - "maxDuration|M=i" => \$argResMaxDuration, - "schedDuringWorkHours|N=i" => \$argResSchedDuringWorkHours, - "allBookInPolicy|O=i" => \$argResAllBookInPolicy, - "allReqInPolicy|P=i" => \$argResAllRequestInPolicy, - "allReqOutOfPolicy|Q=i" => \$argResAllReqOutOfPolicy, - 'workingDays|R=s@{1,}' => \@argResWorkingDays, - "workingHoursStart|T=s" => \$argResWorkingHoursStart, - "workingHoursEnd|U=s" => \$argResWorkingHoursEnd, - "allowRecurMeetings|V=i" => \$argResAllowRecurMeetings, - "addAdditionalResp|X=i" => \$argResAddAdditionalResp, - 'delegates|Y=s{1,}' => \@argResDelegates, - 'bookInPolicy|Z=s{1,}' => \@argResBookInPolicy, - 'requestInPolicy|x=s{1,}' => \@argResRequestInPolicy, - 'requestOutOfPolicy|y=s{1,}' => \@argResRequestOutOfPolicy + "alias|A=s" => \$argResAlias + ### Resource mailboxes parameters are not used, only preserved + #'resEmails|B=s@{1,}' => \@argResEmails, + #"displayName|C=s" => \$argResDisplayName, + #"type|D=s" => \$argResType, + #"capacity|E=i" => \$argResCapacity, + #"additionalResponse|F=s" => \$argResAdditionalResponse, + #"extMeetingMsg|G=i" => \$argResExtMeetingMsg, + #"allowConflicts|H=i" => \$argResAllowConflicts, + #"bookingWindow|I=i" => \$argResBookingWindow, + #"percentageAllowed|J=i" => \$argResPercentageAllowed, + #"enforceSchedHorizon|K=i" => \$argResEnforceSchedHorizon, + #"maxConflictInstances|L=i" => \$argResMaxConflictInstances, + #"maxDuration|M=i" => \$argResMaxDuration, + #"schedDuringWorkHours|N=i" => \$argResSchedDuringWorkHours, + #"allBookInPolicy|O=i" => \$argResAllBookInPolicy, + #"allReqInPolicy|P=i" => \$argResAllRequestInPolicy, + #"allReqOutOfPolicy|Q=i" => \$argResAllReqOutOfPolicy, + #'workingDays|R=s@{1,}' => \@argResWorkingDays, + #"workingHoursStart|T=s" => \$argResWorkingHoursStart, + #"workingHoursEnd|U=s" => \$argResWorkingHoursEnd, + #"allowRecurMeetings|V=i" => \$argResAllowRecurMeetings, + #"addAdditionalResp|X=i" => \$argResAddAdditionalResp, + #'delegates|Y=s{1,}' => \@argResDelegates, + #'bookInPolicy|Z=s{1,}' => \@argResBookInPolicy, + #'requestInPolicy|x=s{1,}' => \@argResRequestInPolicy, + #'requestOutOfPolicy|y=s{1,}' => \@argResRequestOutOfPolicy ) || die help; #Check existence of mandatory parameters @@ -265,13 +270,20 @@ sub help { setMailbox ( $COMMAND_STATUS_SET, undef, $argIdent, $argDeliv, $argArch, $argForw, $argEmailAddresses ); } elsif ($argCommand eq $COMMAND_SET_GROUP) { setGroup ( $COMMAND_STATUS_SET, undef, $argIdent, \@argContacts); -} elsif ($argCommand eq $COMMAND_SET_RESOURCE) { - setResourceMail ( $COMMAND_STATUS_SET, undef, $argIdent, $argResAlias, \@argResEmails, $argResDisplayName, $argResType, - $argResCapacity, $argResAdditionalResponse, $argResExtMeetingMsg, $argResAllowConflicts, $argResBookingWindow, - $argResPercentageAllowed, $argResEnforceSchedHorizon, $argResMaxConflictInstances, $argResMaxDuration, $argResSchedDuringWorkHours, - $argResAllBookInPolicy, $argResAllRequestInPolicy, $argResAllReqOutOfPolicy, \@argResWorkingDays, $argResWorkingHoursStart, - $argResWorkingHoursEnd, $argResAllowRecurMeetings, $argResAddAdditionalResp, \@argResDelegates, \@argResBookInPolicy, - \@argResRequestInPolicy, \@argResRequestOutOfPolicy); +### Resource mailboxes commands are not allowed, only preserved +#} elsif ($argCommand eq $COMMAND_SET_RESOURCE) { +# setResourceMail ( $COMMAND_STATUS_SET, undef, $argIdent, $argResAlias, \@argResEmails, $argResDisplayName, $argResType, +# $argResCapacity, $argResAdditionalResponse, $argResExtMeetingMsg, $argResAllowConflicts, $argResBookingWindow, +# $argResPercentageAllowed, $argResEnforceSchedHorizon, $argResMaxConflictInstances, $argResMaxDuration, $argResSchedDuringWorkHours, +# $argResAllBookInPolicy, $argResAllRequestInPolicy, $argResAllReqOutOfPolicy, \@argResWorkingDays, $argResWorkingHoursStart, +# $argResWorkingHoursEnd, $argResAllowRecurMeetings, $argResAddAdditionalResp, \@argResDelegates, \@argResBookInPolicy, +# \@argResRequestInPolicy, \@argResRequestOutOfPolicy); +#} elsif ($argCommand eq $COMMAND_GET_RESOURCE) { +# getResourceMail ( $COMMAND_STATUS_SET, undef, $argIdent); +#} elsif ($argCommand eq $COMMAND_GET_RESOURCES) { +# getResourceMails ( $COMMAND_STATUS_SET, undef); +#} elsif ($argCommand eq $COMMAND_REMOVE_RESOURCE) { +# removeResourceMail ( $COMMAND_STATUS_SET, undef, $argIdent); } elsif ($argCommand eq $COMMAND_PING_EMAIL) { pingEmail ( $COMMAND_STATUS_SET, undef, $argIdent); } elsif ($argCommand eq $COMMAND_GET_CONTACT) { @@ -284,12 +296,6 @@ sub help { getO365Group ( $COMMAND_STATUS_SET, undef, $argIdent); } elsif ($argCommand eq $COMMAND_GET_SHAREBOX) { getSharebox ( $COMMAND_STATUS_SET, undef, $argIdent); -} elsif ($argCommand eq $COMMAND_GET_RESOURCE) { - getResourceMail ( $COMMAND_STATUS_SET, undef, $argIdent); -} elsif ($argCommand eq $COMMAND_GET_RESOURCES) { - getResourceMails ( $COMMAND_STATUS_SET, undef); -} elsif ($argCommand eq $COMMAND_REMOVE_RESOURCE) { - removeResourceMail ( $COMMAND_STATUS_SET, undef, $argIdent); } elsif ($argCommand eq $COMMAND_TEST_MUNI_ERROR) { testMuniError ( $COMMAND_STATUS_SET, undef, $argIdent); } else { @@ -1222,18 +1228,19 @@ sub resolveOutputByCommandName { return getSharebox ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); } elsif ($actualCommand eq $COMMAND_GET_MAILBOX) { return getMailbox ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); - } elsif ($actualCommand eq $COMMAND_GET_RESOURCE) { - return getResourceMail ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); - } elsif ($actualCommand eq $COMMAND_GET_RESOURCES) { - return getResourceMails ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); + ### Resource mailboxes commands are not supported any more, only preserved + #} elsif ($actualCommand eq $COMMAND_GET_RESOURCE) { + # return getResourceMail ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); + #} elsif ($actualCommand eq $COMMAND_GET_RESOURCES) { + # return getResourceMails ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); + #} elsif ($actualCommand eq $COMMAND_SET_RESOURCE) { + # return setResourceMail ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); + #} elsif ($actualCommand eq $COMMAND_REMOVE_RESOURCE) { + # return removeResourceMail ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); } elsif ($actualCommand eq $COMMAND_SET_GROUP) { return setGroup ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); } elsif ($actualCommand eq $COMMAND_SET_MAILBOX) { return setMailbox ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); - } elsif ($actualCommand eq $COMMAND_SET_RESOURCE) { - return setResourceMail ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); - } elsif ($actualCommand eq $COMMAND_REMOVE_RESOURCE) { - return removeResourceMail ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); } elsif ($actualCommand eq $COMMAND_TEST_MUNI_ERROR) { return testMuniError ( $COMMAND_STATUS_RESOLVE, $jsonOutput ); } else { diff --git a/send/o365_mu b/send/o365_mu index 18c8a150..14f134b2 100755 --- a/send/o365_mu +++ b/send/o365_mu @@ -101,7 +101,8 @@ trap 'rm -r -f "${LOCK_FILE}" "${TMP_HOSTNAME_DIR}"' EXIT #copy all needed files to the temporary directory cp $SERVICE_FILES_DIR/$SERVICE_NAME-users $TMP_HOSTNAME_DIR cp $SERVICE_FILES_DIR/$SERVICE_NAME-groups $TMP_HOSTNAME_DIR -cp $SERVICE_FILES_DIR/$SERVICE_NAME-resource-mails $TMP_HOSTNAME_DIR; +### We are not using resource mailboxes any more, this code will be preserved for further use +#cp $SERVICE_FILES_DIR/$SERVICE_NAME-resource-mails $TMP_HOSTNAME_DIR; cp $SERVICE_FILES_DIR/$SERVICE_NAME-facilityId $TMP_HOSTNAME_DIR if [ $? -ne 0 ]; then echo "Can't copy service file to temporary dir" >&2 diff --git a/send/o365_mu_process.pl b/send/o365_mu_process.pl index bfd3e91c..5a78e497 100755 --- a/send/o365_mu_process.pl +++ b/send/o365_mu_process.pl @@ -57,9 +57,6 @@ my $OPERATION_GROUP = "group"; my $OPERATION_GROUP_CHANGED = $OPERATION_GROUP . "-CHANGED"; my $OPERATION_GROUP_NOT_CHANGED = $OPERATION_GROUP . "-NOT_CHANGED"; -my $OPERATION_RESOURCE_MAIL = "resourceMail"; -my $OPERATION_RESOURCE_MAIL_REMOVED = $OPERATION_RESOURCE_MAIL . "-REMOVED"; -my $OPERATION_RESOURCE_MAIL_CHANGED = $OPERATION_RESOURCE_MAIL . "-CHANGED"; my $OPERATION_END = "end"; #signal end of the operation my $OPERATION_SYNC = "synchronize"; #signal to synchronize with other threads my $ARGUMENT = "argument"; @@ -73,6 +70,12 @@ my $PLAIN_TEXT_OBJECT_TEXT = "plainTextObject"; my $AD_GROUP_NAME_TEXT = "adGroupName"; my $SEND_AS_TEXT = "sendAs"; + +### RESOURCE MAILBOXES CONFIGURATION +### We are not using these variables, we just want to preserve them for further use +my $OPERATION_RESOURCE_MAIL = "resourceMail"; +my $OPERATION_RESOURCE_MAIL_REMOVED = $OPERATION_RESOURCE_MAIL . "-REMOVED"; +my $OPERATION_RESOURCE_MAIL_CHANGED = $OPERATION_RESOURCE_MAIL . "-CHANGED"; my $RES_NAME_TEXT = "RES_NAME"; my $RES_ALIAS_TEXT = "RES_ALIAS"; my $RES_EMAIL_ADDRESES_TEXT = "RES_EMAIL_ADDRESES"; @@ -100,6 +103,7 @@ my $RES_BOOK_IN_POLICY_TEXT = "RES_BOOK_IN_POLICY"; my $RES_REQUEST_IN_POLICY_TEXT = "RES_REQUEST_IN_POLICY"; my $RES_REQUEST_OUT_OF_POLICY_TEXT = "RES_REQUEST_OUT_OF_POLICY"; +### END OF RESOURCE MAILBOXES CONFIGURATION #needed global variables and constants for this script my $instanceName; @@ -146,12 +150,13 @@ exit 14; } +### Don't check Resource mialboxes file existence #resource-mails data filename from perun need to exists (even if it is empty) -my $resourceMailsDataFilename = "$pathToServiceFile/$serviceName-resource-mails"; -if(! -f $resourceMailsDataFilename) { - print "ERROR - Missing service file with data about resource mails.\n"; - exit 14; -} +#my $resourceMailsDataFilename = "$pathToServiceFile/$serviceName-resource-mails"; +#if(! -f $resourceMailsDataFilename) { +# print "ERROR - Missing service file with data about resource mails.\n"; +# exit 14; +#} #file with facility id from gen (can't be empty) my $facilityIdFilename = "$pathToServiceFile/$serviceName-facilityId"; @@ -181,8 +186,9 @@ #read new data about groups from PERUN my $newGroupsStruc = readDataAboutGroups $groupsDataFilename; +### don't read data about resource mailboxes #read new data about resource mails from PERUN -my $newResourceMailsStruc = readDataAboutResourceMails $resourceMailsDataFilename; +#my $newResourceMailsStruc = readDataAboutResourceMails $resourceMailsDataFilename; #Read data (cache) about last state of users my $lastUsersStruc = {}; @@ -196,9 +202,10 @@ $lastGroupsStruc = readDataAboutGroups $lastStateOfGroupsFilename; } +### don't read data about resources mailboxes in o365 #read data about existing resources from o365 proxy -my $lastResourceMailsStruc = readDataAboutResourceMailsFromO365Proxy; -unless($lastResourceMailsStruc) { $lastResourceMailsStruc = {}; } +#my $lastResourceMailsStruc = readDataAboutResourceMailsFromO365Proxy; +#unless($lastResourceMailsStruc) { $lastResourceMailsStruc = {}; } #prepare new cache files my $newUsersCache = new File::Temp( UNLINK => 1 ); @@ -257,30 +264,32 @@ $jobQueue->enqueue($job); } -waitForSynchronize; - +### don't process jobs for working with resource mailboxes +# +#waitForSynchronize; +# #create and submit jobs for working with resource-mail's objects -foreach my $key (keys %$newResourceMailsStruc) { - my $newResourceMail = $newResourceMailsStruc->{$key}; - - my $job = { $OPERATION => $OPERATION_RESOURCE_MAIL_CHANGED, $ARGUMENT => $newResourceMail }; - - #add job to the queue to process it by threads - $jobQueue->enqueue($job); -} - -waitForSynchronize; - +#foreach my $key (keys %$newResourceMailsStruc) { +# my $newResourceMail = $newResourceMailsStruc->{$key}; +# +# my $job = { $OPERATION => $OPERATION_RESOURCE_MAIL_CHANGED, $ARGUMENT => $newResourceMail }; +# +# #add job to the queue to process it by threads +# $jobQueue->enqueue($job); +#} +# +#waitForSynchronize; +# #we need to also remove not existing resource from o365 proxy -foreach my $key (keys %$lastResourceMailsStruc) { - my $newResourceMail = $newResourceMailsStruc->{$key}; - unless($newResourceMail) { - #resource mail no longer exists, we should remove it - my $job = { $OPERATION => $OPERATION_RESOURCE_MAIL_REMOVED, $ARGUMENT => $lastResourceMailsStruc->{$key} }; - #add job to the queue to process it by threads - $jobQueue->enqueue($job); - } -} +#foreach my $key (keys %$lastResourceMailsStruc) { +# my $newResourceMail = $newResourceMailsStruc->{$key}; +# unless($newResourceMail) { +# #resource mail no longer exists, we should remove it +# my $job = { $OPERATION => $OPERATION_RESOURCE_MAIL_REMOVED, $ARGUMENT => $lastResourceMailsStruc->{$key} }; +# #add job to the queue to process it by threads +# $jobQueue->enqueue($job); +# } +#} #wait for all threads to finish waitForThreads; @@ -329,8 +338,9 @@ sub processTasks { $sucess = processGroup( $job->{$ARGUMENT} , $job->{$OPERATION} ); } elsif ($job->{$OPERATION} =~ $OPERATION_USER) { $sucess = processUser( $job->{$ARGUMENT} , $job->{$OPERATION} ); - } elsif ($job->{$OPERATION} =~ $OPERATION_RESOURCE_MAIL) { - $sucess = processResourceMail( $job->{$ARGUMENT}, $job->{$OPERATION} ); + ### don't process resource mailboxes jobs there + #} elsif ($job->{$OPERATION} =~ $OPERATION_RESOURCE_MAIL) { + # $sucess = processResourceMail( $job->{$ARGUMENT}, $job->{$OPERATION} ); } else { print "ERROR - UNKNOWN OPERATION: " . $job->{$OPERATION} . " was skipped!\n"; $sucess = 0; From f432b63413df719e305f3ed65f3142a425ae49d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Zl=C3=A1mal?= Date: Wed, 25 May 2022 10:46:48 +0200 Subject: [PATCH 4/6] feat(arcgis_licenses_mu): sort json output to be comparable - Make sure JSON output is sorted in order to easily compare it between script runs when implementation changes. - Sort entries by UCO. - Trailing whitespace cleanup. --- gen/arcgis_licenses_mu | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gen/arcgis_licenses_mu b/gen/arcgis_licenses_mu index b1da29e5..b21f828f 100755 --- a/gen/arcgis_licenses_mu +++ b/gen/arcgis_licenses_mu @@ -24,7 +24,7 @@ our $A_RESOURCE_ARCGIS_AFFILIATION; *A_RESOURCE_ARCGIS_AFFILIATION = \'urn:perun #Headers my $firstNameHeader = "firstName"; -my $lastNameHeader = "lastName"; +my $lastNameHeader = "lastName"; my $loginHeader = "UCO"; my $rolesHeader = "roles"; my $affiliationHeader = "isActive"; @@ -37,16 +37,16 @@ my $usersWithRoles = {}; my $facilityId = $data->getFacilityId; foreach my $resourceId ( $data->getResourceIds() ) { - + my $roleOnResource = $data->getResourceAttributeValue( attrName => $A_RESOURCE_ARCGIS_ROLE, resource => $resourceId ); my $isResourceActiveForAffiliation = $data->getResourceAttributeValue( attrName => $A_RESOURCE_ARCGIS_AFFILIATION, resource => $resourceId ); - #process all members on resource + #process all members on resource foreach my $memberId ($data->getMemberIdsForResource( resource => $resourceId )) { #skip not VALID members in VO my $statusInVo = $data->getMemberAttributeValue( attrName => $A_MEMBER_STATUS, member => $memberId ); if( $statusInVo ne $statusValid ) { next; } - + my $UCO = $data->getUserFacilityAttributeValue( attrName => $A_USER_LOGIN, member => $memberId, facility => $facilityId ); #if user not exists, create record for him first @@ -87,11 +87,14 @@ for my $key (keys %{$usersWithRoles}) { push @data, $userRecord; } +# order all entries by UCO +@data = sort { $a->{$loginHeader} <=> $b->{$loginHeader} } @data; + #print json to the file my $file = "$DIRECTORY/$::SERVICE_NAME.json"; open FILE,">$file" or die "Cannot open $file: $! \n"; binmode(FILE); -print FILE JSON::XS->new->utf8->pretty->encode(\@data); +print FILE JSON::XS->new->utf8->pretty->canonical->encode(\@data); close (FILE) or die "Cannot close $file: $! \n"; perunServicesInit::finalize; From 343194faad7a5c5467de48fba2f95803a60077e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Zl=C3=A1mal?= Date: Wed, 25 May 2022 11:36:19 +0200 Subject: [PATCH 5/6] feat(insight_mu): sort json output to be comparable - Make sure JSON output si sorted in order to easily compare it between script runs when implementation changes. - Sort person entries by UCO, groups and workplaces entries by ExternalObjectID, which is our groupId. - Sort also members of groups and workplaces by UCO. --- gen/insight_mu | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gen/insight_mu b/gen/insight_mu index b37ccc23..4aa505b7 100755 --- a/gen/insight_mu +++ b/gen/insight_mu @@ -9,7 +9,7 @@ use POSIX qw(strftime); our $SERVICE_NAME = "insight_mu"; our $PROTOCOL_VERSION = "3.0.0"; -my $SCRIPT_VERSION = "3.0.1"; +my $SCRIPT_VERSION = "3.0.2"; perunServicesInit::init; my $DIRECTORY = perunServicesInit::getDirectory; @@ -80,7 +80,7 @@ foreach my $resourceId ($data->getResourceIds()) { }; $memberDataById->{$uco} = $person; } - my @membersList = keys %members; + my @membersList = sort { $a <=> $b } keys %members; # decide whether group or workplace depending on defined VAZPR attribute unless ( defined $groupVAZPR ) { my $group = { @@ -117,6 +117,14 @@ my @groupValues = values(%$groupDataById); my @workplaceValues = values(%$workplaceDataById); my @personValues = values(%$memberDataById); +# sort persons by UCO +@personValues = sort { $a->{'UCO'} <=> $b->{'UCO'} } @personValues; +# sort groups by externalObjectId = Group ID +@groupValues = sort { $a->{'ExternalObjectID'} <=> $b->{'ExternalObjectID'} } @groupValues; +# sort workplaces by externalObjectId = Group ID +@workplaceValues = sort { $a->{'ExternalObjectID'} <=> $b->{'ExternalObjectID'} } @workplaceValues; + + # get data in desired format my $groupData = { data => {Contact => [{Group => [{PerunGroup => \@groupValues}]}]} From 5aa897e0e6c88ce494c4bd7c276dd3d8ca34e6f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Zl=C3=A1mal?= Date: Wed, 25 May 2022 13:40:07 +0200 Subject: [PATCH 6/6] fix(netbox): fixed path to shared configuration - Path should be /etc/perun/services/ --- send/netbox | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/send/netbox b/send/netbox index 26476b24..23268d0a 100755 --- a/send/netbox +++ b/send/netbox @@ -35,8 +35,8 @@ my $users_file_name = "$service_files_dir/netbox_users"; my $groups_file_name = "$service_files_dir/netbox_groups"; # Authorization TOKEN -open(my $file, '<', "/etc/perun/perun-services/$service_name/$service_name") - or die("Can't open /etc/perun/perun-services/$service_name/$service_name: $!\n"); +open(my $file, '<', "/etc/perun/services/$service_name/$service_name") + or die("Can't open /etc/perun/services/$service_name/$service_name: $!\n"); my $TOKEN = <$file>; chomp($TOKEN); close $file;