Skip to content

Commit be27b2e

Browse files
committed
Merge branch 'master' into production
2 parents 0fae6a4 + ca8f78f commit be27b2e

14 files changed

Lines changed: 374 additions & 81 deletions

gen/ad_group_vsup_o365

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ perunServicesInit::finalize;
123123

124124

125125
#
126-
# returns 1 if the the latest of given expiration is either in the future, or in the 21 days grace period
126+
# returns 1 if the the latest of given expiration is either in the future, or in the 28 days grace period
127127
# otherwise, returns 0
128128
#
129129
sub isActive() {
@@ -156,7 +156,7 @@ sub isActive() {
156156
# Add time 23:59:59 to the date, since we want accounts to be active on the last day
157157
$latest_expiration = $latest_expiration + 86399;
158158

159-
if (($latest_expiration + (21*24*60*60)) > $currentDate->epoch) {
159+
if (($latest_expiration + (28*24*60*60)) > $currentDate->epoch) {
160160
return 1;
161161
}
162162

gen/ad_user_vsup

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ perunServicesInit::finalize;
250250
# Returns Windows FILETIME timestamp of users account expiration
251251
# - in case of expiration on 1.1.4000 -> Zero is returned as "expiration = never".
252252
# - in case of any other exact date, pick the largest (future). If it comes from study system (KOS),
253-
# add 21 days grace period.
253+
# add 28 days grace period.
254254
#
255255
sub calculateExpiration() {
256256

@@ -285,9 +285,9 @@ sub calculateExpiration() {
285285
return 0;
286286
}
287287

288-
# (will) expire by studies - add 21 days grace period
288+
# (will) expire by studies - add 28 days grace period
289289
if ($expirationKosTime and ($latest_expiration == $expirationKosTime->epoch)) {
290-
$result = $latest_expiration + (21*24*60*60);
290+
$result = $latest_expiration + (28*24*60*60);
291291
} else {
292292
# Expired by employment or manual - push exact date
293293
$result = $latest_expiration;

gen/ftps_generic

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use File::Basename;
6+
use perunDataGenerator;
7+
8+
local $::SERVICE_NAME = basename($0);
9+
local $::PROTOCOL_VERSION = "3.0.0";
10+
11+
perunDataGenerator::generateUsersDataInJSON;

gen/perunDataGenerator.pm

Lines changed: 181 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,85 @@ use Exporter 'import';
99
our $JSON_FORMAT = "json";
1010
our @EXPORT = qw($JSON_FORMAT);
1111

12-
our $A_MEMBER_STATUS; *A_MEMBER_STATUS = \'urn:perun:member:attribute-def:core:status';
12+
our $USER_ATTR_PREFIX = "urn:perun:user:";
13+
our $USER_FACILITY_ATTR_PREFIX = "urn:perun:user_facility:";
14+
our $MEMBER_ATTR_PREFIX = "urn:perun:member:";
15+
our $MEMBER_RESOURCE_ATTR_PREFIX = "urn:perun:member_resource:";
16+
our $RESOURCE_ATTR_PREFIX = "urn:perun:resource:";
17+
our $FACILITY_ATTR_PREFIX = "urn:perun:facility:";
1318

14-
# Generate user and user_facility required attributes for each user into JSON file.
15-
# Subroutine uses perunServicesInit which REQUIRE access to $::SERVICE_NAME and $::PROTOCOL_VERSION.
16-
# This can be achieved by following lines in your main script: (for example)
17-
# local $::SERVICE_NAME = "passwd";
18-
# local $::PROTOCOL_VERSION = "3.0.0";
19-
# If not valid VO members should be skipped, member status attribute needs to be set on service and set
20-
# local $::SKIP_NON_VALID_MEMBERS = 1;
21-
sub generateUsersDataInJSON {
22-
perunServicesInit::init;
19+
our $A_MEMBER_STATUS; *A_MEMBER_STATUS = \'urn:perun:member:attribute-def:core:status';
2320

24-
my $DIRECTORY = perunServicesInit::getDirectory;
25-
my $data = perunServicesInit::getHashedHierarchicalData;
26-
my $agent = perunServicesInit->getAgent;
27-
my $attributesAgent = $agent->getAttributesAgent;
28-
my $servicesAgent = $agent->getServicesAgent;
29-
my $service = $servicesAgent->getServiceByName( name => $::SERVICE_NAME);
21+
# Returns attribute definitions related to specified entity (entities) type(s)
22+
sub getRequiredAttributesByType {
23+
my $requiredAttributesDefinitions = shift;
24+
my $attributePrefix = shift;
25+
my @requiredAttributes = ();
3026

31-
my @requiredAttributesDefinitions = $attributesAgent->getRequiredAttributesDefinition(service => $service->getId);
32-
my @userRequiredAttributes = ();
33-
my @userFacilityRequiredAttributes = ();
34-
foreach my $attrDef (@requiredAttributesDefinitions) {
35-
# if attribute's namespace starts with "urn:perun:user:"
36-
my $o = index $attrDef->getNamespace, "urn:perun:user:";
27+
foreach my $attrDef (@$requiredAttributesDefinitions) {
28+
my $o = index $attrDef->getNamespace, $attributePrefix;
3729
if ($o == 0) {
38-
push @userRequiredAttributes, $attrDef;
30+
push @requiredAttributes, $attrDef;
3931
next;
4032
}
41-
$o = index $attrDef->getNamespace, "urn:perun:user_facility:";
42-
if ($o == 0) {
43-
push @userFacilityRequiredAttributes, $attrDef;
33+
}
34+
35+
return @requiredAttributes;
36+
}
37+
38+
sub prepareMembersData {
39+
my $data = shift;
40+
my $userIds = shift;
41+
my $resourceId = shift;
42+
my $memberRequiredAttributes = shift;
43+
my $memberResourceRequiredAttributes = shift;
44+
45+
my @members = ();
46+
foreach my $memberId ($data->getMemberIdsForResource(resource => $resourceId)) {
47+
my $memberData = {};
48+
my $perunUserId = $data->getUserIdForMember(member => $memberId);
49+
if (! exists $userIds->{$perunUserId}) {
50+
# user was skipped
4451
next;
4552
}
53+
$memberData->{"link_id"} = $userIds->{$perunUserId};
54+
55+
foreach my $memberAttribute (@$memberRequiredAttributes) {
56+
my $attrValue = $data->getMemberAttributeValue(member => $memberId, attrName => $memberAttribute->getName);
57+
# In case there is an undefined boolean attribute, we have to change it to false
58+
if ($memberAttribute->getType eq "boolean" && !defined $attrValue) {
59+
$memberData->{$memberAttribute->getName} = \0;
60+
} else {
61+
$memberData->{$memberAttribute->getName} = $attrValue;
62+
}
63+
}
64+
65+
foreach my $memberResourceAttribute (@$memberResourceRequiredAttributes) {
66+
my $attrValue = $data->getMemberResourceAttributeValue(member => $memberId, resource => $resourceId, attrName => $memberResourceAttribute->getName);
67+
# In case there is an undefined boolean attribute, we have to change it to false
68+
if ($memberResourceAttribute->getType eq "boolean" && !defined $attrValue) {
69+
$memberData->{$memberResourceAttribute->getName} = \0;
70+
} else {
71+
$memberData->{$memberResourceAttribute->getName} = $attrValue;
72+
}
73+
}
74+
75+
push @members, $memberData;
4676
}
47-
my @users;
77+
return \@members;
78+
}
79+
80+
# Prepares structure of user attributes
81+
# If addLinkId is true, it will add "link_id" property which is returned in the usersIds structure as {"perunUserId": linkId}
82+
sub prepareUsersData {
83+
my $data = shift;
84+
my $userRequiredAttributes = shift;
85+
my $userFacilityRequiredAttributes = shift;
86+
my $addLinkId = shift;
4887

49-
####### prepare data ######################
5088
my %usersIds = ();
89+
my $linkIdCounter = 0;
90+
my @users = ();
5191
foreach my $memberId ($data->getMemberIdsForFacility()) {
5292

5393
if ($::SKIP_NON_VALID_MEMBERS) {
@@ -58,11 +98,12 @@ sub generateUsersDataInJSON {
5898
if (exists($usersIds{$userId})) {
5999
next;
60100
} else {
61-
$usersIds{$userId} = 0;
101+
$linkIdCounter++;
102+
$usersIds{$userId} = $linkIdCounter;
62103
}
63104
my $userData = {};
64105

65-
foreach my $userAttribute (@userRequiredAttributes) {
106+
foreach my $userAttribute (@$userRequiredAttributes) {
66107
my $attrValue = $data->getUserAttributeValue(member => $memberId, attrName => $userAttribute->getName);
67108
# In case there is an undefined boolean attribute, we have to change it to false
68109
if ($userAttribute->getType eq "boolean" && !defined $attrValue) {
@@ -72,7 +113,7 @@ sub generateUsersDataInJSON {
72113
}
73114
}
74115

75-
foreach my $userFacilityAttribute (@userFacilityRequiredAttributes) {
116+
foreach my $userFacilityAttribute (@$userFacilityRequiredAttributes) {
76117
my $attrValue = $data->getUserFacilityAttributeValue(member => $memberId, attrName => $userFacilityAttribute->getName);
77118
# In case there is an undefined boolean attribute, we have to change it to false
78119
if ($userFacilityAttribute->getType eq "boolean" && !defined $attrValue) {
@@ -81,13 +122,120 @@ sub generateUsersDataInJSON {
81122
$userData->{$userFacilityAttribute->getName} = $attrValue;
82123
}
83124
}
125+
126+
if ($addLinkId) {
127+
$userData->{"link_id"} = $linkIdCounter;
128+
}
84129
push @users, $userData;
85130
}
86131

87-
####### output file ######################
132+
return (\@users, \%usersIds);
133+
}
134+
135+
=c
136+
Generate user and user_facility required attributes for each user into JSON file.
137+
Subroutine uses perunServicesInit which REQUIRE access to $::SERVICE_NAME and $::PROTOCOL_VERSION.
138+
This can be achieved by following lines in your main script: (for example)
139+
local $::SERVICE_NAME = "passwd";
140+
local $::PROTOCOL_VERSION = "3.0.0";
141+
If not valid VO members should be skipped, member status attribute needs to be set on service and set
142+
local $::SKIP_NON_VALID_MEMBERS = 1;
143+
=cut
144+
sub generateUsersDataInJSON {
145+
perunServicesInit::init;
146+
147+
my $DIRECTORY = perunServicesInit::getDirectory;
148+
my $data = perunServicesInit::getHashedHierarchicalData;
149+
my $agent = perunServicesInit->getAgent;
150+
my $attributesAgent = $agent->getAttributesAgent;
151+
my $servicesAgent = $agent->getServicesAgent;
152+
my $service = $servicesAgent->getServiceByName( name => $::SERVICE_NAME);
153+
154+
my @requiredAttributesDefinitions = $attributesAgent->getRequiredAttributesDefinition(service => $service->getId);
155+
my @userRequiredAttributes = getRequiredAttributesByType(\@requiredAttributesDefinitions, $USER_ATTR_PREFIX);
156+
my @userFacilityRequiredAttributes = getRequiredAttributesByType(\@requiredAttributesDefinitions, $USER_FACILITY_ATTR_PREFIX);
157+
158+
my ($users, $ids) = prepareUsersData($data, \@userRequiredAttributes, \@userFacilityRequiredAttributes);
159+
160+
my $fileName = "$DIRECTORY/$::SERVICE_NAME";
161+
open FILE, ">$fileName" or die "Cannot open $fileName: $! \n";
162+
print FILE JSON::XS->new->utf8->pretty->canonical->encode($users);
163+
close FILE or die "Cannot close $fileName: $! \n";
164+
165+
perunServicesInit::finalize;
166+
}
167+
168+
=c
169+
Generate user, user_facility, member, member_resource, resource and facility required attributes into JSON file.
170+
The result structure is:
171+
{
172+
"facility_attribute_name": "facility_attribute_value",
173+
"users" => [{"user_attribute_name": "user_attribute_value",
174+
"link_id": id linking user to its members}]
175+
"groups" => [{"resource_attribute_name": "resource_attribute_value",
176+
"members": [{"member_attribute_name": "member_attribute_value",
177+
"link_id": id of user this member belongs to}]}]
178+
}
179+
Subroutine uses perunServicesInit which REQUIRE access to $::SERVICE_NAME and $::PROTOCOL_VERSION.
180+
This can be achieved by following lines in your main script: (for example)
181+
local $::SERVICE_NAME = "passwd";
182+
local $::PROTOCOL_VERSION = "3.0.0";
183+
If not valid VO members should be skipped, member status attribute needs to be set on service and set
184+
local $::SKIP_NON_VALID_MEMBERS = 1;
185+
=cut
186+
sub generateMemberUsersDataInJson {
187+
perunServicesInit::init;
188+
189+
my $DIRECTORY = perunServicesInit::getDirectory;
190+
my $data = perunServicesInit::getHashedHierarchicalData;
191+
my $agent = perunServicesInit->getAgent;
192+
my $attributesAgent = $agent->getAttributesAgent;
193+
my $servicesAgent = $agent->getServicesAgent;
194+
my $service = $servicesAgent->getServiceByName( name => $::SERVICE_NAME);
195+
196+
my @requiredAttributesDefinitions = $attributesAgent->getRequiredAttributesDefinition(service => $service->getId);
197+
198+
my @userRequiredAttributes = getRequiredAttributesByType(\@requiredAttributesDefinitions, $USER_ATTR_PREFIX);
199+
my @userFacilityRequiredAttributes = getRequiredAttributesByType(\@requiredAttributesDefinitions, $USER_FACILITY_ATTR_PREFIX);
200+
my ($users, $userIds) = prepareUsersData($data, \@userRequiredAttributes, \@userFacilityRequiredAttributes, 1);
201+
202+
my @facilityRequiredAttributes = getRequiredAttributesByType(\@requiredAttributesDefinitions, $FACILITY_ATTR_PREFIX);
203+
my @resourceRequiredAttributes = getRequiredAttributesByType(\@requiredAttributesDefinitions, $RESOURCE_ATTR_PREFIX);
204+
my @memberRequiredAttributes = getRequiredAttributesByType(\@requiredAttributesDefinitions, $MEMBER_ATTR_PREFIX);
205+
my @memberResourceRequiredAttributes = getRequiredAttributesByType(\@requiredAttributesDefinitions, $MEMBER_RESOURCE_ATTR_PREFIX);
206+
207+
my $result = {};
208+
$result->{"users"} = $users;
209+
$result->{"groups"} = ();
210+
211+
foreach my $facilityAttribute (@facilityRequiredAttributes) {
212+
my $attrValue = $data->getFacilityAttributeValue(attrName => $facilityAttribute->getName);
213+
# In case there is an undefined boolean attribute, we have to change it to false
214+
if ($facilityAttribute->getType eq "boolean" && !defined $attrValue) {
215+
$result->{$facilityAttribute->getName} = \0;
216+
} else {
217+
$result->{$facilityAttribute->getName} = $attrValue;
218+
}
219+
}
220+
221+
foreach my $resourceId ($data->getResourceIds()) {
222+
my $resource = {};
223+
foreach my $resourceAttribute (@resourceRequiredAttributes) {
224+
my $attrValue = $data->getResourceAttributeValue(resource => $resourceId, attrName => $resourceAttribute->getName);
225+
# In case there is an undefined boolean attribute, we have to change it to false
226+
if ($resourceAttribute->getType eq "boolean" && !defined $attrValue) {
227+
$resource->{$resourceAttribute->getName} = \0;
228+
} else {
229+
$resource->{$resourceAttribute->getName} = $attrValue;
230+
}
231+
}
232+
$resource->{"members"} = prepareMembersData($data, $userIds, $resourceId, \@memberRequiredAttributes, \@memberResourceRequiredAttributes);
233+
push @{$result->{"groups"}}, $resource;
234+
}
235+
88236
my $fileName = "$DIRECTORY/$::SERVICE_NAME";
89237
open FILE, ">$fileName" or die "Cannot open $fileName: $! \n";
90-
print FILE JSON::XS->new->utf8->pretty->canonical->encode(\@users);
238+
print FILE JSON::XS->new->utf8->pretty->canonical->encode($result);
91239
close FILE or die "Cannot close $fileName: $! \n";
92240

93241
perunServicesInit::finalize;

gen/sshkeys

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ foreach my $memberId ($data->getMemberIdsForFacility()) {
3030

3131
####### output ######################
3232
for my $login (keys %sshKeys) {
33-
open SERVICE_FILE,">$sshkeysDirectory/$login" or die "Cannot open $sshkeysDirectory/$login: $! \n";
33+
open (SERVICE_FILE,">:encoding(UTF-8)","$sshkeysDirectory/$login") or die "Cannot open $sshkeysDirectory/$login: $! \n";
3434
print SERVICE_FILE join "\n", @{$sshKeys{$login}}, "\n" if defined $sshKeys{$login};
3535
close SERVICE_FILE;
3636
}

gen/vsup_google_groups

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ perunServicesInit::finalize;
123123
#
124124
# Calculate if user is expired or not.
125125
#
126-
# 1. param - expiration in KOS (studies)
126+
# 1. param - expiration in KOS (studies) (we will add 28 days grace period to the calculation)
127127
# 2. param - expiration in DC2 (employees)
128128
# 3. param - manually set expiration
129129
#
@@ -140,8 +140,9 @@ sub isExpired() {
140140
my $expirationDc2Time = ($expirationDc2) ? Time::Piece->strptime($expirationDc2,"%Y-%m-%d") : undef;
141141
my $expirationManTime = ($expirationMan) ? Time::Piece->strptime($expirationMan,"%Y-%m-%d") : undef;
142142

143+
# Extend KOS studies expiration with 28 days if there is a defined value
143144
my @expirations = ();
144-
if (defined $expirationKosTime) { push(@expirations, $expirationKosTime->epoch); }
145+
if (defined $expirationKosTime) { push(@expirations, ($expirationKosTime->epoch + (28*24*60*60))); }
145146
if (defined $expirationDc2Time) { push(@expirations, $expirationDc2Time->epoch); }
146147
if (defined $expirationManTime) { push(@expirations, $expirationManTime->epoch); }
147148

gen/vsup_k4

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ perunServicesInit::finalize;
195195
# Returns Unix timestamp of users account expiration
196196
# - in case of expiration on 1.1.4000 -> Zero is returned as "expiration = never".
197197
# - in case of any other exact date, pick the largest (future). If it comes from study system (KOS),
198-
# add 21 days grace period.
198+
# add 28 days grace period.
199199
#
200200
sub calculateExpiration() {
201201

@@ -230,9 +230,9 @@ sub calculateExpiration() {
230230
return 0;
231231
}
232232

233-
# (will) expire by studies - add 21 days grace period
233+
# (will) expire by studies - add 28 days grace period
234234
if ($expirationKosTime and ($latest_expiration == $expirationKosTime->epoch)) {
235-
$result = $latest_expiration + (21*24*60*60);
235+
$result = $latest_expiration + (28*24*60*60);
236236
} else {
237237
# Expired by employment or manual - push exact date
238238
$result = $latest_expiration;

send/VsupIfis.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ sub load_is() {
5858
my $dbh = DBI->connect("dbi:Pg:dbname=$db_name;host=$hostname;port=$port", $db_user, $db_password,{ RaiseError=>1, AutoCommit=>0 }) or die "Connect to database $db_name Error!\n";
5959

6060
# Select query for input database (IS) - all students with UCO_PERUN not null and STUD_DO >= now or null
61-
my $sth = $dbh->prepare(qq{select distinct ex_is2idm_studia.UCO_PERUN as UCO, NS, 'STU' as TYP_VZTAHU, STUD_FORMA as DRUH_VZTAHU, ex_is2idm_studia.ID_STUDIA as VZTAH_CISLO, STUD_FORMA as STU_FORMA, STUD_STAV as STUD_STAV, STUD_TYP as STU_PROGR, STUD_OD, STUD_DO, KARTA_LIC as KARTA_IDENT from ex_is2idm_studia left join ex_is2idm_adresy on ex_is2idm_studia.ID_STUDIA=ex_is2idm_adresy.ID_STUDIA where ex_is2idm_studia.UCO_PERUN is not null and (STUD_DO >= CURRENT_DATE OR STUD_DO is NULL)});
61+
my $sth = $dbh->prepare(qq{select distinct ex_is2idm_studia.UCO_PERUN as UCO, NS, 'STU' as TYP_VZTAHU, STUD_FORMA as DRUH_VZTAHU, ex_is2idm_studia.ID_STUDIA as VZTAH_CISLO, STUD_FORMA as STU_FORMA, STUD_STAV as STUD_STAV, STUD_TYP as STU_PROGR, STUD_OD, case when STUD_DO is not null then STUD_DO+28 ELSE STUD_DO END as STUD_DO, KARTA_LIC as KARTA_IDENT from ex_is2idm_studia left join ex_is2idm_adresy on ex_is2idm_studia.ID_STUDIA=ex_is2idm_adresy.ID_STUDIA where ex_is2idm_studia.UCO_PERUN is not null and (STUD_DO >= CURRENT_DATE-28 OR STUD_DO is NULL)});
6262
$sth->execute();
6363

6464
# Structure to store data from input database (IS)

send/bbmri_collections

100644100755
File mode changed.

send/bbmri_networks

100644100755
File mode changed.

0 commit comments

Comments
 (0)