Skip to content

Commit

Permalink
Merge pull request #750 from xflord/scs_it4i_extension
Browse files Browse the repository at this point in the history
feat(scs_it4i): extend the service to include more attributes
  • Loading branch information
Johaney-s authored Dec 7, 2022
2 parents 299c277 + 1b48b26 commit 6e8e1cb
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions gen/scs_it4i
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,30 @@ use File::Basename;

our $SERVICE_NAME = basename($0);
our $PROTOCOL_VERSION = "3.0.0";
my $SCRIPT_VERSION = "3.0.0";
my $SCRIPT_VERSION = "3.0.1";

perunServicesInit::init;
my $DIRECTORY = perunServicesInit::getDirectory;
my $data = perunServicesInit::getHashedHierarchicalData;

#Constants
our $A_USER_LOGIN_EINFRA; *A_USER_LOGIN_EINFRA = \'urn:perun:user:attribute-def:def:login-namespace:einfra';
our $A_ORGANIZATION; *A_ORGANIZATION = \'urn:perun:user:attribute-def:def:organization';
our $A_BLOCK_COLLISION; *A_BLOCK_COLLISION = \'urn:perun:user:attribute-def:def:it4iBlockCollision';

our $A_USER_LOGIN_EINFRA_PERSIST; *A_USER_LOGIN_EINFRA_PERSIST = \'urn:perun:user:attribute-def:virt:login-namespace:einfraid-persistent';
our $A_ORGANIZATION; *A_ORGANIZATION = \'urn:perun:user:attribute-def:def:organization';
our $A_BLOCK_COLLISION; *A_BLOCK_COLLISION = \'urn:perun:user:attribute-def:def:it4iBlockCollision';
our $A_COMMON_NAME; *A_COMMON_NAME = \'urn:perun:user:attribute-def:core:commonName';
our $A_DISPLAY_NAME; *A_DISPLAY_NAME = \'urn:perun:user:attribute-def:core:displayName';
our $A_FIRST_NAME; *A_FIRST_NAME = \'urn:perun:user:attribute-def:core:firstName';
our $A_LAST_NAME; *A_LAST_NAME = \'urn:perun:user:attribute-def:core:lastName';
our $A_MIDDLE_NAME; *A_MIDDLE_NAME = \'urn:perun:user:attribute-def:core:middleName';
our $A_TITLE_AFTER; *A_TITLE_AFTER = \'urn:perun:user:attribute-def:core:titleAfter';
our $A_TITLE_BEFORE; *A_TITLE_BEFORE = \'urn:perun:user:attribute-def:core:titleBefore';
our $A_UUID; *A_UUID = \'urn:perun:user:attribute-def:core:uuid';
our $A_COUNTRY; *A_COUNTRY = \'urn:perun:user:attribute-def:def:country';
our $A_PREF_LANGUAGE; *A_PREF_LANGUAGE = \'urn:perun:user:attribute-def:def:preferredLanguage';
our $A_PREF_MAIL; *A_PREF_MAIL = \'urn:perun:user:attribute-def:def:preferredMail';
our $A_INSTIT_COUNTRIES; *A_INSTIT_COUNTRIES = \'urn:perun:user:attribute-def:virt:institutionsCountries';


my $service_file_name = "$DIRECTORY/$::SERVICE_NAME";

Expand All @@ -25,17 +39,27 @@ my $users;
foreach my $memberId ($data->getMemberIdsForFacility()) {

my $collision = $data->getUserAttributeValue( member => $memberId, attrName => $A_BLOCK_COLLISION );
my $login = $data->getUserAttributeValue( member => $memberId, attrName => $A_USER_LOGIN_EINFRA );
my $org = $data->getUserAttributeValue( member => $memberId, attrName => $A_ORGANIZATION ) || "";
my $login = $data->getUserAttributeValue( member => $memberId, attrName => $A_USER_LOGIN_EINFRA_PERSIST ) || "";

# Check if user is not prohibited in IT4I !!
if (defined $collision) {
die "Login '$login' has collision with old IT4I data. Propagations was stopped for safety."
}

$users->{$login}->{"uuid"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_UUID) || "";
$users->{$login}->{"login"} = $login;
$users->{$login}->{"organization"} = $org;
$users->{$login}->{"citizenship"} = ""; # TODO
$users->{$login}->{"commonName"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_COMMON_NAME ) || "";
$users->{$login}->{"displayName"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_DISPLAY_NAME ) || "";
$users->{$login}->{"firstName"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_FIRST_NAME ) || "";
$users->{$login}->{"lastName"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_LAST_NAME ) || "";
$users->{$login}->{"middleName"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_MIDDLE_NAME) || "";
$users->{$login}->{"titleAfter"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_TITLE_AFTER ) || "";
$users->{$login}->{"titleBefore"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_TITLE_BEFORE ) || "";
$users->{$login}->{"citizenship"} = "";
$users->{$login}->{"country"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_COUNTRY ) || "";
$users->{$login}->{"organization"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_ORGANIZATION ) || "";
$users->{$login}->{"preferredLanguage"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_PREF_LANGUAGE ) || "";
$users->{$login}->{"preferredMail"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_PREF_MAIL ) || "";
$users->{$login}->{"institutionsCountries"} = $data->getUserAttributeValue( member => $memberId, attrName => $A_INSTIT_COUNTRIES ) || [];

}

Expand All @@ -46,7 +70,7 @@ foreach my $login (sort keys %{$users}) {
}

####### output file ######################
open SERVICE_FILE, ">:encoding(UTF-8)", "$service_file_name" or die "Cannot open $service_file_name: $! \n";
open SERVICE_FILE, ">$service_file_name" or die "Cannot open $service_file_name: $! \n";
print SERVICE_FILE JSON::XS->new->utf8->pretty->canonical->encode(\@result);
close(SERVICE_FILE);
#####################################################
Expand Down

0 comments on commit 6e8e1cb

Please sign in to comment.