-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWG_SECURITY_export_tm1_users_for_paw.pro
355 lines (308 loc) · 9.98 KB
/
WG_SECURITY_export_tm1_users_for_paw.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
601,100
602,"WG_SECURITY_export_tm1_users_for_paw"
562,"NULL"
586,
585,
564,
565,"k\oCt99j3aYa?DCjuYL4Da\h0`1O<9_32k^]sK7NPJdE\z:kla4SfnV6O;Wg6DY0L0?bbN]2n9:KjNO3?A\R>Kuo=>Mx79hVBMA^zyk:B>xxl2eA9;iMjVz@hOTS;[]h7z`blafzSXEQgn_ckL\m<hsd@>H>HFiaau<IOdouXX6e_HdE?ZnAn2i?GcRbt`ckzWcxHth>"
559,1
928,0
593,
594,
595,
597,
598,
596,
800,
801,
566,0
567,","
588,","
589,"."
568,""""
570,
571,All
569,0
592,0
599,1000
560,4
pIBMCloud
pEnvironments
pDirective
pOnPremNamespace
561,4
2
2
2
2
590,4
pIBMCloud,"Y / N"
pEnvironments,"Alpro|Alpro - alprotst|Beaulieu ICT nv|Beaulieu ICT nv - bigdev|Beaulieu ICT nv - bigqas, or empty (if not IBMCloud)"
pDirective,"ADD / REMOVE"
pOnPremNamespace,"Alpro"
637,4
pIBMCloud,"IBM Cloud (Y = Yes, all else = No)"
pEnvironments,"Environment name ? (could be | delimited) (empty for on-premise)"
pDirective,"Directive ? (ADD or REMOVE)"
pOnPremNamespace,"On-premise namespace ? (to unlock additional functionality)"
577,0
578,0
579,0
580,0
581,0
582,0
603,0
572,248
#****Begin: Generated Statements***
#****End: Generated Statements****
#Region IntroduceThisProcess
####################################################
# Wim Gielis
# June 2024
# https://www.wimgielis.com
####################################################
#
# This process can help us create PAW users, based on (the same) TM1 users.
# Both IBM cloud and on-premise installations can be supported.
# A different CSV file layout is generated depending on the installation.
#
# Fields in a custom CSV file for the IBM Cloud:
# - Mandatory fields: Login ID, First Name, Last Name
# - Optional fields: Role, Environment, Directive
#
# Fields in a custom CSV file for an on-premise installation:
# - Mandatory fields: Login ID, First Name, Last Name, Status
# - Optional fields: Role, Email, Directive
#
# The pOnPremNamespace parameter is for instance used in:
# it the }Clients dimension does not have attributes for first name and last name,
# then the }TM1_DefaultDisplayValue alias value could be split on a space after removing the Namespace and a slash.
#
# For the different environment(s) in the IBM Cloud, it is easy to first take a manual export of the users.
# The CSV file export will contain the exact name for the environment that IBM Cloud expects.
#
# Work in progress:
# - Escape the , characters that could occur in some attribute values
# - What if some attributes do not exist or some attribute values are empty ?
#
####################################################
#####
# Add the following process(es) to this TM1 model:
# - TECH_folder for output
#####
#EndRegion IntroduceThisProcess
#Region CallThisProcess
## call this custom process as, for instance:
If( 1 = 0 );
ExecuteProcess( 'WG_SECURITY_export_tm1_users_for_paw'
, 'pIBMCloud', 'Y / N'
, 'pEnvironments', 'Beaulieu ICT nv|Beaulieu ICT nv - bigdev|Beaulieu ICT nv - bigqas, or empty'
, 'pDirective', 'ADD / REMOVE'
, 'pOnPremNamespace', 'Beaulieu'
);
EndIf;
#EndRegion CallThisProcess
cSeparator = '|';
cDim = '}Clients';
c0 = 'all_clients';
c1 = '}TM1_DefaultDisplayValue';
c2 = 'Email';
c3 = 'First Name';
c4 = 'Last Name';
# Test the parameter values
pIBMCloud = Trim( pIBMCloud );
pDirective = Trim( pDirective );
If( pDirective @<> 'ADD' & pDirective @<> 'REMOVE' );
vMessage = 'The ''pDirective'' parameter should be either ''ADD'' or ''REMOVE''. However, the user provided: ''' | pDirective | '''.';
LogOutput( 'ERROR', vMessage );
ProcessError;
EndIf;
# Where do we output text files and import them again afterwards
StringGlobalVariable( 'cDestination_Folder' );
ExecuteProcess( 'TECH_folder for output', 'pSubfolder', 'Export TM1 users for PAW', 'pMainFolder', '1+' );
# The CSV file for the output
vFile = cDestination_Folder | 'all-users' | Timst( Now, '\Y-\m-\d \h\i\s' ) | '.csv';
SetOutputCharacterSet( vFile, 'TM1CS_UTF8' );
DatasourceAsciiDelimiter = ',';
DatasourceAsciiQuoteCharacter = '';
DatasourceAsciiDecimalSeparator = '';
DatasourceAsciiThousandSeparator = '';
# A header for the CSV file
If( pIBMCloud @= 'Y' );
TextOutput( vFile, 'Login Id', 'First Name', 'Last Name', 'Role', 'Environment', 'Directive', 'Last Login' );
Else;
TextOutput( vFile, 'Login Id', 'First Name', 'Last Name', 'Role', 'Email', 'Status', 'Directive', 'Last Login' );
EndIf;
# Retrieve all clients in the model
SubsetCreateByMDX( c0, 'TM1SubsetAll( [ ' | cDim | '] )', 1 );
If( SubsetExists( cDim, c0 ) = 0 );
vMessage = 'The subset with all clients on the dimension ''' | cDim | ''' could not be created successfully.';
LogOutput( 'ERROR', vMessage );
DataSourceType = 'NULL';
ProcessError;
EndIf;
vNameExtraction = 0;
# Loop over the clients
c = 1;
While( c <= SubsetGetSize( cDim, c0 ));
vClient = SubsetGetElementName( cDim, c0, c );
# Gather the file contents as properties of the client
vDisabled = CellGetN( '}ClientProperties', vClient, 'IsDisabled' );
vReadOnly = CellGetN( '}ClientProperties', vClient, 'ReadOnlyUser' );
vAdmin = CellGetS( '}ClientGroups', vClient, 'ADMIN' );
vDirective = pDirective;
vLast_Login = '';
vClient_DisplayName = '';
vEmail_Address = '';
vFirst_Name = '';
vLast_Name = '';
If( Dimix( '}ElementAttributes_' | cDim, c1 ) > 0 );
vClient_DisplayName = Attrs( cDim, vClient, c1 );
If( vClient_DisplayName @= '' );
vClient_DisplayName = vClient;
EndIf;
Else;
vClient_DisplayName = vClient;
EndIf;
If( Dimix( '}ElementAttributes_' | cDim, c2 ) > 0 );
vEmail_Address = Attrs( cDim, vClient, c2 );
Else;
vEmail_Address = Expand( 'Unknown email for %vClient_DisplayName%' );
EndIf;
If( Dimix( '}ElementAttributes_' | cDim, c3 ) > 0 );
vFirst_Name = Attrs( cDim, vClient, c3 );
# Else;
# vFirst_Name = vClient;
EndIf;
If( Dimix( '}ElementAttributes_' | cDim, c4 ) > 0 );
vLast_Name = Attrs( cDim, vClient, c4 );
# Else;
# vLast_Name = vClient;
EndIf;
# unlocking extra functionality to extract first name/last name:
# maybe the }TM1_DefaultDisplayValue alias value can be split on a space
# we might need to remove the namespace first
If( vFirst_Name @= '' );
If( vLast_Name @= '' );
If( Dimix( '}ElementAttributes_' | cDim, c1 ) > 0 );
vNameExtraction = 1;
vClient_DisplayName = Trim( Attrs( cDim, vClient, c1 ));
If( vClient_DisplayName @<> '' );
If( pOnPremNamespace @<> '' );
If( Subst( vClient_DisplayName, 1, Long( pOnPremNamespace )) @= pOnPremNamespace );
If( Subst( vClient_DisplayName, Long( pOnPremNamespace ) + 1, 1 ) @= '\' %
Subst( vClient_DisplayName, Long( pOnPremNamespace ) + 1, 1 ) @= '/' );
vClient_DisplayName = Delet( vClient_DisplayName, 1, Long( pOnPremNamespace ) + 1 );
EndIf;
EndIf;
EndIf;
If( Scan( ' ', vClient_DisplayName ) > 1 );
vFirst_Name = Subst( vClient_DisplayName, 1, Scan( ' ', vClient_DisplayName ) - 1 );
vLast_Name = Delet( vClient_DisplayName, 1, Scan( ' ', vClient_DisplayName ));
EndIf;
EndIf;
EndIf;
EndIf;
EndIf;
If( vAdmin @<> '' );
vRole = 'Administrator';
ElseIf( vReadOnly <> 0 );
vRole = 'Consumer';
Else;
vRole = 'Consumer';
# vRole = 'Analyst';
# vRole = 'Modeler';
EndIf;
# A "warning text" near the top of the CSV file
If( c = 1 );
If( vNameExtraction = 1 );
TextOutput( vFile, '' );
TextOutput( vFile, '' );
TextOutput( vFile, ' ATTENTION ! The extraction code has tried to come up with sensible first and last names for clients.' );
TextOutput( vFile, ' In case they are swapped please turn around the column entries/headers.' );
TextOutput( vFile, '' );
TextOutput( vFile, ' Also, remove this notification text prior to uploading the generated CSV file in PA.' );
TextOutput( vFile, '' );
TextOutput( vFile, '' );
EndIf;
EndIf;
# Output to text file
If( pIBMCloud @= 'Y' );
vLogin_ID = vEmail_Address;
# Loop over the environments to create entries in the CSV file
vEnvironments = Trim( pEnvironments );
If( Subst( vEnvironments, Long( vEnvironments ) - Long( cSeparator ) + 1, Long( cSeparator )) @<> cSeparator );
vEnvironments = vEnvironments | cSeparator;
EndIf;
r = Scan( cSeparator, vEnvironments );
While( r > 0 );
vEnvironment = Subst( vEnvironments, 1, r - 1 );
# Update the text file output
TextOutput( vFile, vLogin_ID, vFirst_Name, vLast_Name, vRole, vEnvironment, vDirective, vLast_Login );
vEnvironments = Delet( vEnvironments, 1, r + Long( cSeparator ) - 1 );
r = Scan( cSeparator, vEnvironments );
End;
Else;
vLogin_ID = vClient;
If( vDisabled = 0 );
vStatus = 'ACTIVE';
Else;
vStatus = 'SUSPENDED';
EndIf;
If( vEmail_Address @= '' );
vEmail_Address = 'NOT_SET';
EndIf;
# Update the text file output
TextOutput( vFile, vLogin_ID, vFirst_Name, vLast_Name, vRole, vEmail_Address, vStatus, vDirective, vLast_Login );
EndIf;
c = c + 1;
End;
573,3
#****Begin: Generated Statements***
#****End: Generated Statements****
574,3
#****Begin: Generated Statements***
#****End: Generated Statements****
575,3
#****Begin: Generated Statements***
#****End: Generated Statements****
576,CubeAction=1511DataAction=1503CubeLogChanges=0_ParameterConstraints=e30
930,0
638,1
804,0
1217,0
900,
901,
902,
938,0
937,
936,
935,
934,
932,0
933,0
903,
906,
929,
907,
908,
904,0
905,0
909,0
911,
912,
913,
914,
915,
916,
917,0
918,1
919,0
920,50000
921,""
922,""
923,0
924,""
925,""
926,""
927,""