Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
HejdaJakub committed May 15, 2023
2 parents faf2536 + 13a1e86 commit 3fb4c91
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 143 deletions.
12 changes: 12 additions & 0 deletions gen/dhus
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/perl

use strict;
use warnings;
use File::Basename;
use perunDataGenerator;

local $::SERVICE_NAME = basename($0);
local $::PROTOCOL_VERSION = "3.0.0";
local $::SKIP_NON_VALID_MEMBERS = 1;

perunDataGenerator::generateUsersDataInJSON;
41 changes: 15 additions & 26 deletions gen/k5login_root
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,36 @@ use File::Basename;

local $::SERVICE_NAME = basename($0);
local $::PROTOCOL_VERSION = "3.0.0";
my $SCRIPT_VERSION = "3.1.2";
my $SCRIPT_VERSION = "3.2.0";

perunServicesInit::init;
my $directory = perunServicesInit::getDirectory;
my $data = perunServicesInit::getHashedDataWithGroups;


our $A_PRINCIPAL; *A_PRINCIPAL = \'urn:perun:user:attribute-def:def:kerberosAdminPrincipal';
our $A_USER_STATUS; *A_USER_STATUS = \'urn:perun:member:attribute-def:core:status';
our $A_GROUP_DESTINATIONS; *A_GROUP_DESTINATIONS = \'urn:perun:group:attribute-def:def:listOfDestinations';

my %outputByDestination = ('all' => undef);
my $kerberosLogins = (); # $kerberosLogins->{principal} = 1

foreach my $resourceId ($data->getResourceIds()) {

foreach my $groupId ($data->getGroupIdsForResource( resource => $resourceId )) {
my @generatedDataDestination = ('all');
if(defined $data->getGroupAttributeValue(group => $groupId, attrName => $A_GROUP_DESTINATIONS )) {
@generatedDataDestination = @{$data->getGroupAttributeValue(group => $groupId, attrName => $A_GROUP_DESTINATIONS )};
}
foreach my $memberId ($data->getMemberIdsForResource(resource => $resourceId)) {

foreach my $memberId ($data->getMemberIdsForResourceAndGroup(resource => $resourceId, group => $groupId )) {
next if $data->getMemberAttributeValue( member => $memberId, attrName => $A_USER_STATUS ) ne 'VALID';
push @{$outputByDestination{$_}}, $data->getUserAttributeValue( member => $memberId, attrName => $A_PRINCIPAL ) foreach @generatedDataDestination;
}
next if $data->getMemberAttributeValue( member => $memberId, attrName => $A_USER_STATUS ) ne 'VALID';

}
}
my $principal = $data->getUserAttributeValue( member => $memberId, attrName => $A_PRINCIPAL );
$kerberosLogins->{$principal} = 1;

}

####### output ######################
{
local $, = "\n";
local $\ = "\n";
}

for my $destination (keys %outputByDestination) {
my $destinationDirectory = getDestinationDirectory $destination;
my $service_file_name = "$destinationDirectory/$::SERVICE_NAME";
open SERVICE_FILE,">$service_file_name" or die "Cannot open $service_file_name: $! \n";
print SERVICE_FILE sort &uniqList(@{$outputByDestination{$destination}}, @{$outputByDestination{"all"}});
close(SERVICE_FILE);
}
####### output file ######################
my $service_file_name = "$directory/$::SERVICE_NAME";
open SERVICE_FILE,">$service_file_name" or die "Cannot open $service_file_name: $! \n";
foreach my $principal (sort keys %$kerberosLogins) {
print SERVICE_FILE $principal . "\n";
}
close(SERVICE_FILE);

perunServicesInit::finalize;
9 changes: 9 additions & 0 deletions gen/perunDataGenerator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ use Exporter 'import';
our $JSON_FORMAT = "json";
our @EXPORT = qw($JSON_FORMAT);

our $A_MEMBER_STATUS; *A_MEMBER_STATUS = \'urn:perun:member:attribute-def:core:status';

# Generate user and user_facility required attributes for each user into JSON file.
# Subroutine uses perunServicesInit which REQUIRE access to $::SERVICE_NAME and $::PROTOCOL_VERSION.
# This can be achieved by following lines in your main script: (for example)
# local $::SERVICE_NAME = "passwd";
# local $::PROTOCOL_VERSION = "3.0.0";
# If not valid VO members should be skipped, member status attribute needs to be set on service and set
# local $::SKIP_NON_VALID_MEMBERS = 1;
sub generateUsersDataInJSON {
perunServicesInit::init;

Expand Down Expand Up @@ -45,6 +49,11 @@ sub generateUsersDataInJSON {
####### prepare data ######################
my %usersIds = ();
foreach my $memberId ($data->getMemberIdsForFacility()) {

if ($::SKIP_NON_VALID_MEMBERS) {
next if $data->getMemberAttributeValue( member => $memberId, attrName => $A_MEMBER_STATUS ) ne 'VALID';
}

my $userId = $data->getUserIdForMember(member => $memberId);
if (exists($usersIds{$userId})) {
next;
Expand Down
3 changes: 0 additions & 3 deletions gen/zabbix_mu
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ foreach my $resourceId ($data->getResourceIds()) {
unless ($userData->{$uco} || (!defined $groupName && !defined $role)) {
my $firstName = $data->getUserAttributeValue( member => $memberId, attrName => $A_USER_FIRSTNAME );
my $lastName = $data->getUserAttributeValue( member => $memberId, attrName => $A_USER_LASTNAME );
if (!defined $role) {
$role = [];
}
my $user = {
identifier => $uco,
firstName => $firstName,
Expand Down
4 changes: 4 additions & 0 deletions send/dhus
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
export SERVICE_NAME="dhus"

python3 generic_sender.py "$1" "$2" "$3"
2 changes: 1 addition & 1 deletion send/send_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def prepare_temporary_directory() -> tempfile.TemporaryDirectory:
so it is removed afterwards with all its content.
:return: created temporary directory
"""
return tempfile.TemporaryDirectory(prefix="perun-send.", dir=TEMPORARY_DIR, ignore_cleanup_errors=True)
return tempfile.TemporaryDirectory(prefix="perun-send.", dir=TEMPORARY_DIR)


def copy_files_to_directory(path_from: str, path_to: str, name_pattern: re.Pattern = None) -> None:
Expand Down
138 changes: 26 additions & 112 deletions send/tinia
Original file line number Diff line number Diff line change
@@ -1,119 +1,33 @@
#!/bin/bash
#!/usr/bin/env python3

SERVICE_NAME="tinia"
import send_lib
import sys
import re

FACILITY_NAME=$1
DESTINATION=$2
DESTINATION_TYPE=$3
service_name = "tinia"

if [ -z "$DESTINATION" ]; then
echo "Missing Destination argument (DB NAME there)" >&2
exit 231
fi
send_lib.check_input_fields(sys.argv, destination_type_required=True)

if [ -z "$FACILITY_NAME" ]; then
echo "Missing FacilityName argument" >&2
exit 232
fi
facility = sys.argv[1]
destination = sys.argv[2]
destination_type = sys.argv[3]

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
send_lib.check_destination_type_allowed(destination_type, "service-specific")
send_lib.check_destination_format(destination, destination_type, send_lib.SIMPLE_PATTERN)

#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 tinia_process 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="./tinia_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
dbname = destination

service_files_dir = send_lib.get_gen_folder(facility, service_name)
send_lib.create_lock(service_name, dbname)

# copy service file to temporary directory
with send_lib.prepare_temporary_directory() as tmp_dir:
send_lib.copy_files_to_directory(service_files_dir, tmp_dir, re.compile(service_name))
scriptpath = "./tinia_process.pl"
process = send_lib.exec_script(scriptpath, ["-d", dbname, "-p", tmp_dir, "-s", service_name])
process.wait()
stdout, stderr = process.communicate()
print(stdout.decode())
if process.returncode != 0:
send_lib.die_with_error("Slave script ends with return code: " + str(process.returncode))
41 changes: 41 additions & 0 deletions slave/process-dhus/bin/process-dhus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

PROTOCOL_VERSION='3.0.0'

function process {

E_MISSING_DST_PATH=(50 'Missing path of handling script (DST_SCRIPT), need to be set in pre_script.')
E_MISSING_DST_EXIST=(51 'Handling script does not exist at the specified location (' + "${DST_SCRIPT}" + '), please check that the correct path is set in pre_script')
E_MISSING_DST_EXEC=(52 'Handling script is not executable (' + "${DST_SCRIPT}" + '), please check that the correct permissions are set')

E_MISSING_CONF_PATH=(53 'Missing path of configuration (DST_CONF), need to be set in pre_script.')
E_MISSING_CONF_EXIST=(54 'Configuration does not exist at the specified location (' + "${DST_CONF}" + '), please check that the correct path is set in pre_script')

if [ -z ${DST_SCRIPT} ]; then
log_msg E_MISSING_DST_PATH
fi

if [ ! -f ${DST_SCRIPT} ]; then
log_msg E_MISSING_DST_EXIST
fi

if [ ! -x ${DST_SCRIPT} ]; then
log_msg E_MISSING_DST_EXEC
fi

if [ -z ${DST_CONF} ]; then
log_msg E_MISSING_CONF_PATH
fi

if [ ! -d ${DST_CONF} ]; then
log_msg E_MISSING_CONF_EXIST
fi

create_lock

FROM_PERUN="${WORK_DIR}"

${DST_SCRIPT} -f $FROM_PERUN -c $DST_CONF

exit $?
}
5 changes: 5 additions & 0 deletions slave/process-dhus/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
perun-slave-process-dhus (3.0.0) stable; urgency=low

* New service dhus

-- Johana Supikova <[email protected]> Wed, 12 Apr 2023 14:32:00 +0200
7 changes: 7 additions & 0 deletions slave/process-dhus/conf/example-pre_10_set_variables
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# set handling script
#DST_SCRIPT=/tmp/dhus.py

# set configuration path - specific config will be retrieved by facility name (e.g. /etc/dhus/facility.yml)
#DST_CONF=/etc/dhus/
1 change: 1 addition & 0 deletions slave/process-dhus/dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perun-slave-base
1 change: 1 addition & 0 deletions slave/process-dhus/rpm.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perun-slave-base
1 change: 1 addition & 0 deletions slave/process-dhus/short_desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package for perun service - dhus
2 changes: 1 addition & 1 deletion slave/process-zabbix-mu/bin/process-zabbix_mu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function process {

FROM_PERUN="${WORK_DIR}/zabbix_mu.json"

java -jar ${DST_SCRIPT} $FROM_PERUN
${DST_SCRIPT} $FROM_PERUN

exit $?
}

0 comments on commit 3fb4c91

Please sign in to comment.