-
Notifications
You must be signed in to change notification settings - Fork 3
/
migrate_v1_to_v2.py
1664 lines (1512 loc) · 86.1 KB
/
migrate_v1_to_v2.py
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/python3
"""
Migrate field configuration from CloudV1 to CloudV2.
To be used on a CloudV2 source having the same schema version as CloudV1.
TODO: Move filtering of mytype date and sort=false sooner in the process
"""
import json
import itertools
import re
from client.cloud_v1 import *
from client.cloud_v2 import *
from client.fields import Fields
import argparse
import jiphy
import jsbeautifier
import os
# v1 -> v2
FIELDS_KEYS_V1_V2 = {'fieldQueries': 'includeInQuery',
'freeTextQueries': 'mergeWithLexicon',
'facet': 'facet',
'multivalueFacet': 'multiValueFacet',
'sort': 'sort',
'displayField': 'includeInResults'}
KEY_V1_CONFIGNAME = 'v1ConfigName'
KEY_V2_CONFIGNAME = 'v2ConfigName'
KEY_V1_FIELD = 'v1Field'
KEY_V2_FIELD = 'v2Field'
KEY_V1_VALUE = 'v1Value'
KEY_V2_VALUE = 'v2Value'
KEY_CONFIG_DIFF = 'configDiff'
def v1_get_source_id(sources, source_name):
""" Get a source id from a source name (CloudV1)
>>> v1_get_source_id([{'id': '0', 'name': 'FOO'}, {'id': '1', 'name': 'BAR'}], 'bar')
'1'
>>> v1_get_source_id([{'id': '0', 'name': 'FOO'}, {'id': '1', 'name': 'BAR'}], 'new')
Traceback (most recent call last):
...
ValueError: Source new does not exist
>>> v1_get_source_id([{'id': '0', 'name': 'FOO'}, {'id': '1', 'name': 'FOO'}], 'foo')
Traceback (most recent call last):
...
ValueError: More than one source foo found. This should not happen.
"""
source_ids = [source['id'] for source in sources
if source['name'].lower() == source_name.lower()]
if not source_ids:
raise ValueError(f'Source {source_name} does not exist')
if len(source_ids) > 1:
raise ValueError(f'More than one source {source_name} found. This should not happen.')
return source_ids[0]
def v1_get_fields_by_name(fields):
""" Get a dictionary of fields by name (field name -> field) (CloudV1)
>>> v1_get_fields_by_name(( \
{'id': '0', 'name': 'FOO'}, \
{'id': '1', 'name': 'bAr'}, \
{'id': '2', 'name': 'foobar'}))
{'foo': {'id': '0', 'name': 'FOO'}, 'bar': {'id': '1', 'name': 'bAr'}, 'foobar': {'id': '2', 'name': 'foobar'}}
"""
return dict([(f['name'].lower(), f) for f in fields])
def v2_get_fields_in_use(fields, mappings):
""" Get a dictionary of fields that are used in the mappings provided (field name -> field) (CloudV2)
>>> v2_get_fields_in_use(({'items': ({'name': 'FOO'}, {'name': 'bar'}, {'name': 'foobar'})}), ('foo', 'BAR'))
{'foo': {'name': 'FOO'}, 'bar': {'name': 'bar'}}
"""
return dict((field['name'].lower(), field) for field in
fields['items'] if field['name'].lower() in
[mapping.lower() for mapping in mappings])
def v2_get_mappings_fieldname(mappings):
""" Get a dictionary of mappings (field name -> field) (CloudV2)
>>> v2_get_mappings_fieldname({'common': {'rules': []}})
[]
>>> v2_get_mappings_fieldname({'common': {'rules': [{'field': 'FOO'}, {'field': 'bAr'}]}})
['foo', 'bar']
>>> v2_get_mappings_fieldname({'types': []})
[]
>>> v2_get_mappings_fieldname({'types': [{'rules': []}]})
[]
>>> v2_get_mappings_fieldname({'types': [ \
{'rules': [{'field': 'foo0'}, {'field': 'fOO1'}]}, \
{'rules': [{'field': 'bar0'}]}]})
['foo0', 'foo1', 'bar0']
>>> v2_get_mappings_fieldname({'common': {'rules': [{'field': 'FOO'}, {'field': 'bAr'}]}, \
'types': [ \
{'rules': [{'field': 'foo0'}, {'field': 'fOO1'}]}, \
{'rules': [{'field': 'bar0'}]}]})
['foo', 'bar', 'foo0', 'foo1', 'bar0']
"""
# get common mappings
common_mappings = mappings['common']['rules'] if 'common' in mappings and 'rules' in mappings['common'] else []
# get mytype specifc mappings
type_mappings = list()
type_rules = [rule['rules'] if 'rules' in rule else [] for rule in mappings['types']] if 'types' in mappings else []
[[type_mappings.append(field) for field in type_rule] for type_rule in type_rules]
# all v2 mappings
v2_all_mappings = common_mappings + type_mappings
return [mapping['field'].lower() for mapping in v2_all_mappings]
def get_fields_difference(v1_field, v2_field):
""" Get the differences between 2 fields
>>> get_fields_difference({}, {})
[]
>>> v1_field = {'sort': True}
>>> v2_field = {'sort': True}
>>> get_fields_difference(v1_field, v2_field)
[]
>>> v1_field = {'fieldQueries': True}
>>> v2_field = {'includeInQuery': False}
>>> get_fields_difference(v1_field, v2_field)
[{'v1ConfigName': 'fieldQueries', 'v2ConfigName': 'includeInQuery', 'v1Value': True, 'v2Value': False}]
>>> v1_field = {'fieldQueries': True, 'sort': False}
>>> v2_field = {'includeInQuery': False, 'sort': True}
>>> get_fields_difference(v1_field, v2_field)
[{'v1ConfigName': 'fieldQueries', 'v2ConfigName': 'includeInQuery', 'v1Value': True, 'v2Value': False}, {'v1ConfigName': 'sort', 'v2ConfigName': 'sort', 'v1Value': False, 'v2Value': True}]
"""
field_diff = [{KEY_V1_CONFIGNAME: diff,
KEY_V2_CONFIGNAME: FIELDS_KEYS_V1_V2[diff],
KEY_V1_VALUE: v1_field[diff],
KEY_V2_VALUE: v2_field[FIELDS_KEYS_V1_V2[diff]]}
for diff in FIELDS_KEYS_V1_V2
if diff in v1_field and FIELDS_KEYS_V1_V2[diff] in v2_field and v1_field[diff] != v2_field[FIELDS_KEYS_V1_V2[diff]]]
return field_diff
def get_fields_differences(v1_fields, v2_fields):
""" Get a list of differences between 2 fields list
>>> get_fields_differences({}, {})
[]
>>> v1_fields = {'field0': {'sort': True, 'fieldType':'STRING', 'facet': False, 'multivalueFacet': False}, 'field1': {'sort': True, 'fieldType':'STRING', 'facet': True, 'multivalueFacet': False}}
>>> v2_fields = {'field1': {'sort': False, 'facet': False, 'type':'STRING', 'multiValueFacet': False}, 'field2': {'sort': True, 'facet': True, 'type':'STRING', 'multiValueFacet': False }}
>>> get_fields_differences(v1_fields, v2_fields)
[('field1', {'v1Field': {'sort': True, 'fieldType': 'STRING', 'facet': True, 'multivalueFacet': False}, 'v2Field': {'sort': False, 'facet': False, 'type': 'STRING', 'multiValueFacet': False}, 'configDiff': [{'v1ConfigName': 'facet', 'v2ConfigName': 'facet', 'v1Value': True, 'v2Value': False}, {'v1ConfigName': 'sort', 'v2ConfigName': 'sort', 'v1Value': True, 'v2Value': False}]})]
"""
v1_field_names = v1_fields.keys()
v2_field_names = v2_fields.keys()
diffs = list()
for v1_field_name in v1_field_names:
if v1_field_name in v2_field_names:
v1_field = v1_fields[v1_field_name]
#Fix v1_field facet and Multifacet
if v1_field['facet'] and v1_field['multivalueFacet']:
v1_field['facet'] = False
#Fix sorting
mysort = v1_field['sort']
if v1_field['fieldType']=='DATE' or v1_field['fieldType']=='INTEGER' or v1_field['fieldType']=='DOUBLE' or v1_field['fieldType']=='LONG_64':
mysort = True
v1_field['sort']=mysort
myfieldtype = v1_field['fieldType']
#fix field types
if myfieldtype=='INTEGER':
myfieldtype='LONG'
v1_field['fieldType']=myfieldtype
v2_field = v2_fields[v1_field_name]
diff = get_fields_difference(v1_field, v2_fields[v1_field_name])
if diff:
diffs.append((v1_field_name, {KEY_V1_FIELD: v1_field, KEY_V2_FIELD: v2_field, KEY_CONFIG_DIFF: diff}))
return diffs
def v2_get_updated_field(field_difference):
global finalreport
""" Get a modified field according to the differences provided (CloudV2)
>>> diffs = ('field1', {'v1Field': {'sort': True, 'facet': True}, 'v2Field': {'name': 'field1', 'sort': False, 'facet': False, 'type': 'SOMEtype'}, 'configDiff': [{'v1ConfigName': 'facet', 'v2ConfigName': 'facet', 'v1Value': True, 'v2Value': False}, {'v1ConfigName': 'sort', 'v2ConfigName': 'sort', 'v1Value': True, 'v2Value': False}]})
>>> v2_get_updated_field(diffs)
{'name': 'field1', 'sort': True, 'facet': True, 'type': 'SOMEtype'}
"""
for diff in field_difference[1][KEY_CONFIG_DIFF]:
if field_difference[1][KEY_V2_FIELD]['type'].lower() == 'date' and \
diff[KEY_V2_CONFIGNAME].lower() == 'sort' and \
diff[KEY_V1_VALUE] == False:
print(f'\t-> Field "{field_difference[1][KEY_V2_FIELD]["name"]}" is of type date and cannot be set to sort = false. Skipping this change.')
finalreport += f'\n\t-> Field "{field_difference[1][KEY_V2_FIELD]["name"]}" is of type date and cannot be set to sort = false. Skipping this change.'
else:
field_difference[1][KEY_V2_FIELD][diff[KEY_V2_CONFIGNAME]] = diff[KEY_V1_VALUE]
return field_difference[1][KEY_V2_FIELD]
def v2_get_updated_fields(field_differences):
""" Get a list of modified fields according to the differences provided (CloudV2)
"""
return [v2_get_updated_field(diff) for diff in field_differences]
def get_unused_fields(fields):
global finalreport
unused_fields = []
for item in fields['items']:
if not item['sources'] and not item['system']:
unused_fields.append(item['name'])
print(f'\t-> Field "{item["name"]}" is unused')
finalreport += f'\n\t-> Field "{item["name"]}" is unused'
return ",".join(unused_fields)
def v1_get_unique_fields(fields: list) -> list:
"""
# >>> fields = [{'name': 'f0', 'fieldType': 'STRING', 'contentType': 'METADATA', 'sort': True, 'facet': False}, \
# {'name': 'f0', 'fieldType': 'STRING', 'contentType': 'METADATA', 'sort': False, 'facet': True}, \
# {'name': 'f1', 'fieldType': 'STRING', 'contentType': 'METADATA'}]
# >>> v1_get_unique_fields(fields)
# [('f0', [{'name': 'f0', 'fieldType': 'STRING', 'contentType': 'METADATA', 'sort': True, 'facet': False}, {'name': 'f0', 'fieldType': 'STRING', 'contentType': 'METADATA', 'sort': False, 'facet': True}]), ('f1', [{'name': 'f1', 'fieldType': 'STRING', 'contentType': 'METADATA'}])]
"""
def get_fields_by_name() -> dict:
fields_by_name = dict()
for field in fields:
name = field['name']
if name in fields_by_name:
fields_by_name[name].append(field)
else:
fields_by_name[name] = [field]
return fields_by_name
def merge_fields_config(fields: list) -> dict:
new_field = {'fieldQueries': False, 'freeTextQueries': False, 'facet': False, 'multivalueFacet': False, 'sort': False, 'displayField': False}
mappings = list()
for field in fields:
#print (field)
if (field['contentType']=='SCRIPT'):
mapping = {'name': field['name'], 'contentType':field['contentType'], 'metadataName': field['scriptParams'], 'sourceId': field['sourceId']}
else:
mapping = {'name': field['name'], 'contentType':field['contentType'], 'metadataName': field['metadataName'], 'sourceId': field['sourceId']}
for flag in new_field:
new_field[flag] |= field[flag]
mappings.append(mapping)
new_field['mappings'] = mappings
return new_field
def validate_field_config(fields: list) -> bool:
expected_length = len(fields)
field_type = fields[0]['fieldType']
content_type = fields[0]['contentType']
if expected_length != len(list(filter(lambda f: f['fieldType'] == field_type and
f['contentType'] == content_type, fields))):
return False
return True
fields_by_name = get_fields_by_name()
unique_fields_by_name = list()
for field_name in fields_by_name:
field = fields_by_name[field_name]
if validate_field_config(field):
merged = merge_fields_config(field)
merged['name'] = field_name
merged['fieldType'] = field[0]['fieldType']
merged['contentType'] = field[0]['contentType']
unique_fields_by_name.append((field_name, merged))
return unique_fields_by_name
def v1_field_is_user(field: dict) -> bool:
return field['fieldOrigin'] == 'CUSTOM' and not field['contentType'] == 'CUSTOM_SCRIPT'
#return field['contentType'] == 'CUSTOM'
def copy_user_fields(v1_fields: list, v2_client: CloudV2, dry_run: bool):
global finalreport
v2_unique_fields = [Fields.v1_to_v2(field[1]) for field in v1_fields]
v2_fields = [f['name'] for f in v2_client.fields_get()['items']]
v2_fields_to_create = list()
for field in v2_unique_fields:
if field['name'] in v2_fields:
print(f'SKIPPING FIELD \'{field["name"]}\' because it already exists in org: {field}')
finalreport += f'\n\tSKIPPING FIELD \'{field["name"]}\' because it already exists in org: {field}'
else:
print(f'ADDING FIELD \'{field["name"]}\': {field}')
finalreport += f'\n\tADDING FIELD \'{field["name"]}\': {field}'
v2_fields_to_create.append(field)
if not dry_run and len(v2_fields_to_create) > 0:
v2_client.fields_create_batch(v2_fields_to_create)
def v2_create_mapping_from_v1_fields(v2_client: CloudV2, v1_sources: object, v1_fields: list, v2_sources: list, dry_run: bool):
def v2_get_mappings_by_source_id_by_field_name(sources: dict) -> dict:
# we can't have the same mapping on the same field in CloudV1
return dict([(sources[source]['v2_id'],
dict([(x['field'].lower(), x) for x in
v2_client.mappings_get(sources[source]['v2_id'])['common']['rules']]))
for source in sources])
def v2_get_sources_by_name() -> dict:
v1_sources_by_name = dict([(source['name'].lower(), source) for source in v1_sources['sources']])
v2_sources_by_name = dict([(source['name'].lower(), source) for source in v2_sources])
return dict([(v2_source_key,
{'v1_id': v1_sources_by_name[v2_source_key]['id'],
'v2_id': v2_sources_by_name[v2_source_key]['id']})
for v2_source_key in v2_sources_by_name.keys()
if v2_source_key in v1_sources_by_name])
def v2_get_source_used_field(field: dict, common_sources: dict) -> dict:
# v1 source id -> v1 source name == v2 source name -> v2 source id
v1_source_id = field['sourceId']
v1_source_name = v1_sources_by_id[v1_source_id]['name']
v2_source_id = None
if v1_source_name.lower() in common_sources:
v2_source_id = common_sources[v1_source_name.lower()]['v2_id']
return {'id': v2_source_id, 'name': v1_source_name}
def v2_create_mapping(field: dict, mappings: dict, source_id: str, source_name: str) -> None:
global finalreport
#print (field)
if (field['contentType']=='SCRIPT'):
#get content from scriptparams
scriptcontent=field["metadataName"]
new_mapping = {'content': [f'{scriptcontent["Content"]}'], 'field': f'{field["name"]}'}
else:
new_mapping = {'content': [f'%[{field["metadataName"]}]'], 'field': f'{field["name"]}'}
new_mapping_exists = new_mapping['field'].lower() in mappings
if new_mapping_exists:
print(f'SKIPPING MAPPING {new_mapping} because it\'s already present in source \'{source_name}\'')
finalreport += f'\n\tSKIPPING MAPPING {new_mapping} because it\'s already present in source \'{source_name}\''
elif not dry_run:
print(f'ADD MAPPING: {new_mapping}')
finalreport += f'\n\tADD MAPPING: {new_mapping}'
v2_client.mappings_common_add(source_id, False, new_mapping)
global finalreport
common_sources = v2_get_sources_by_name()
if len(common_sources) == 0:
print(f'No common source names between CloudV1 and CloudV2. Cannot copy mappings.')
finalreport += f'\n\tNo common source names between CloudV1 and CloudV2. Cannot copy mappings.'
else:
print ("Common source names found.")
#print(f'Common source names ({len(common_sources)}): {json.dumps(common_sources)}')
mappings_by_source_id = v2_get_mappings_by_source_id_by_field_name(common_sources)
v1_sources_by_id = dict([(source['id'].lower(), source) for source in v1_sources['sources']])
for field in v1_fields:
v2_source = v2_get_source_used_field(field, common_sources)
v2_source_id = v2_source['id']
v2_source_name = v2_source['name']
if v2_source_id is None:
print(f'SKIPPING MAPPING for \'{field["name"]}\' because source \'{v2_source_name}\' does not exist in CloudV2')
finalreport += f'\n\tSKIPPING MAPPING for \'{field["name"]}\' because source \'{v2_source_name}\' does not exist in CloudV2'
else:
v2_create_mapping(field, mappings_by_source_id[v2_source_id], v2_source_id, v2_source_name)
def addLine():
return " --------------------------------------------------\n"
def translatetype(mytype):
fromRepo = { "WEB":"WEB2", "EXCHANGE_ENTERPRISE":"EXCHANGE",
"JIRA":"JIRA2_HOSTED", "JIRA_CLOUD":"JIRA2", "JIVE":"JIVE_HOSTED", "JIVE_CLOUD":"JIVE",
"CONFLUENCE2":"CONFLUENCE2_HOSTED","CONFLUENCE2_CLOUD":"CONFLUENCE2","SHAREPOINT":"SHAREPOINT",
"GMAIL":"GMAIL_SINGLE_USER",
"SHAREPOINT_ONLINE":"SHAREPOINT_ONLINE2","TWITTER":"TWITTER2",
"YAMMER":"BAD","ORACLE_KNOWLEDGE":"BAD","CONFLUENCE":"BAD",
"WEBSCRAPER": "MAN",
#Must be done manual, you need an valid OAUTH token
"SALESFORCE":"SALESFORCE", "KNOWLEDGEBASE":"SALESFORCE","SALESFORCE_CONTENT":"SALESFORCE",
}
for repo in fromRepo:
if repo == mytype:
return fromRepo[repo]
return mytype
def addAddressPattern(mytype):
mytype["configuration"]["addressPatterns"]=[]
mytype["configuration"]["addressPatterns"].append({})
mytype["configuration"]["addressPatterns"][0]["expression"]="*"
mytype["configuration"]["addressPatterns"][0]["patterntype"]="Wildcard"
mytype["configuration"]["addressPatterns"][0]["allowed"]=True
return mytype
def addSecurityEverybody(mytype):
mytype["configuration"]["permissions"]=[{"permissionSets": [{"allowedPermissions": [{"identitytype": "Group","securityProvider": "Email Security Provider","identity": "*@*"}],"name": "Shared"}],"name": "Source Specified Permissions"} ]
return mytype
def addSecurityUser(mytype,email):
mytype["configuration"]["permissions"]=[{"permissionSets": [{"allowedPermissions": [{"identitytype": "User","securityProvider": "Email Security Provider","identity": email}],"name": "Private"}],"name": "Source Specified Permissions"} ]
return mytype
def addParam(mytype,key,sensitive, value):
mytype["configuration"]["parameters"][key]={}
mytype["configuration"]["parameters"][key]["sensitive"]=sensitive
mytype["configuration"]["parameters"][key]["value"]=value
return mytype
def getCloudSetting(config, value, default):
if value in config["cloudSourceConfiguration"]:
return config["cloudSourceConfiguration"][value]
else:
return default
def fix(mytype, config):
global v1_org_id
global actionlist
mytype["MethodToUse"]="SIMPLE"
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="GOOGLE_DRIVE_SINGLE_USER":
actionlist += "\n\tAdd password"
actionlist += "\n\tRefresh Token"
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.GoogleDriveSingleUser"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"ClientSecret", True, "UPDATEIT")
mytype=addParam(mytype,"ClientId", False, "UPDATEIT")
mytype=addParam(mytype,"ClientRefreshToken", True, "UPDATEIT")
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
email = getCloudSetting(config,"name","").replace('Drive - ','')
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Specified"
mytype=addSecurityUser(mytype,getCloudSetting(config,"owner","*@*"))
if email:
mytype["emailAddress"]=email
mytype["additionalInfos"]={"emailAddress": email }
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="GMAIL":
actionlist += "\n\tAdd password"
actionlist += "\n\tRefresh Token"
#Must be done manual, you need an valid OAUTH token
#Must be done using RAW
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.GmailSingleUser"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"ClientSecret", True, "UPDATEIT")
mytype=addParam(mytype,"ClientId", False, "UPDATEIT")
mytype=addParam(mytype,"ClientRefreshToken", True, "UPDATEIT")
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Specified"
mytype=addSecurityUser(mytype,getCloudSetting(config,"emailAddress","*@*"))
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["emailAddress"]=config["cloudSourceConfiguration"]["emailAddress"]
mytype["additionalInfos"]={"emailAddress": config["cloudSourceConfiguration"]["emailAddress"] }
mytype["configuration"]["startingAddresses"]=["https://www.gmail.com"]
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="EXCHANGE":
actionlist += "\n\tAdd password"
actionlist += "\n\tRefresh Token"
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["email"]=config["cloudSourceConfiguration"]["emailAddress"]
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.Exchange"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"ClientSecret", True, "UPDATEIT")
mytype=addParam(mytype,"ClientId", False, "UPDATEIT")
mytype=addParam(mytype,"ClientRefreshToken", True, "UPDATEIT")
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Specified"
mytype=addSecurityUser(mytype,getCloudSetting(config,"emailAddress","*@*"))
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["emailAddress"]=config["cloudSourceConfiguration"]["emailAddress"]
mytype["additionalInfos"]={"emailAddress": config["cloudSourceConfiguration"]["emailAddress"] }
mytype["configuration"]["startingAddresses"]=[ "https://outlook.office365.com/exchange/"+config["cloudSourceConfiguration"]["emailAddress"] ]
mytype["configuration"]["userIdentities"]= { "UserIdentity": { "name": "token", "userName": config["cloudSourceConfiguration"]["emailAddress"], "password": "UPDATEIT" }}
mytype["password"]="TOCHANGE"
#mytype["sourceVisibility"] = "SHARED"
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="DROPBOX":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tAdd password"
actionlist += "\n\tRefresh Token"
email = getCloudSetting(config,"name","").replace('Dropbox - ','')
if email:
mytype["emailAddress"]=email
mytype["additionalInfos"]={"emailAddress": email }
mytype["accessToken"]="UPDATEIT"
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="TWITTER":
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="LITHIUM":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tAdd password"
if "serverAddress" in config["cloudSourceConfiguration"]:
mytype["serverAddress"]=config["cloudSourceConfiguration"]["serverAddress"]
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="SHAREPOINT":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tAdd password"
if "url" in config["cloudSourceConfiguration"]:
mytype["urls"]=[config["cloudSourceConfiguration"]["url"]]
mytype["crawlScope"]="SiteCollection"
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="SHAREPOINT_ONLINE":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tRefresh Token"
actionlist += "\n\tAdd Tennant name"
mytype["RefreshToken"]="UPDATEIT"
mytype["tenantname"]="UPDATEIT"
mytype["crawlScope"]="SiteCollection"
if "url" in config["cloudSourceConfiguration"]:
mytype["urls"]=[config["cloudSourceConfiguration"]["url"]]
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="SHAREPOINT_LEGACY":
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="YAMMER":
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="WEBSCRAPER":
actionlist += "\n\tAdjust webscraper configuration"
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="GOOGLE_DRIVE_DOMAIN_WIDE":
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="RSS":
if "uri" in config["cloudSourceConfiguration"]:
mytype["urls"]=[config["cloudSourceConfiguration"]["uri"]]
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="WEB":
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="CONFLUENCE":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tAdd password"
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="CONFLUENCE2":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tAdd password"
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["email"]=config["cloudSourceConfiguration"]["emailAddress"]
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.Confluence2"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"IndexComments", False, getCloudSetting(config,"indexComments",True))
mypersonal = getCloudSetting(config,"indexOnlyPersonalSpaces",False)
myglobal = getCloudSetting(config, "indexOnlyGlobalSpaces", False)
#Current/Archived is not present in V1
mycurrent = getCloudSetting(config,"indexCurrentSpaces",True)
myarchived = getCloudSetting(config, "indexArchivedSpaces", False)
if mypersonal and myglobal:
myglobal = False
mypersonal = True
mytype=addParam(mytype,"IndexOnlyPersonalSpaces", False, getCloudSetting(config,"indexOnlyPersonalSpaces",mypersonal))
mytype=addParam(mytype,"IndexArchivedSpaces", False, getCloudSetting(config, "indexArchivedSpaces", myarchived))
mytype=addParam(mytype,"IndexOnlyGlobalSpaces", False, getCloudSetting(config, "indexOnlyGlobalSpaces", myglobal))
mytype=addParam(mytype,"IndexAttachments", False, getCloudSetting(config, "indexAttachments", True))
mytype=addParam(mytype,"IndexCurrentSpaces", False, getCloudSetting(config, "indexCurrentSpaces", mycurrent))
mytype=addParam(mytype,"FilterSpaceRegex", False, getCloudSetting(config,"spaceFilter",""))
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Specified"
mytype=addSecurityUser(mytype,getCloudSetting(config,"username","*@*"))
if "username" in config["cloudSourceConfiguration"]:
mytype["emailAddress"]=config["cloudSourceConfiguration"]["username"]
mytype["configuration"]["userIdentities"]= { "UserIdentity": { "name": "token", "userName": config["cloudSourceConfiguration"]["username"], "password": "UPDATEIT" }}
mytype["additionalInfos"]={"emailAddress": config["cloudSourceConfiguration"]["username"] }
if "urls" in config["cloudSourceConfiguration"]:
mytype["configuration"]["startingAddresses"]= config["cloudSourceConfiguration"]["urls"]
mytype["password"]="TOCHANGE"
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="CONFLUENCE2_CLOUD":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tAdd password"
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["email"]=config["cloudSourceConfiguration"]["emailAddress"]
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.Confluence2"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"IndexComments", False, getCloudSetting(config,"indexComments",True))
mypersonal = getCloudSetting(config,"indexOnlyPersonalSpaces",False)
myglobal = getCloudSetting(config, "indexOnlyGlobalSpaces", False)
#Current/Archived is not present in V1
mycurrent = getCloudSetting(config,"indexCurrentSpaces",True)
myarchived = getCloudSetting(config, "indexArchivedSpaces", False)
if mypersonal and myglobal:
myglobal = False
mypersonal = True
mytype=addParam(mytype,"IndexOnlyPersonalSpaces", False, getCloudSetting(config,"indexOnlyPersonalSpaces",mypersonal))
mytype=addParam(mytype,"IndexArchivedSpaces", False, getCloudSetting(config, "indexArchivedSpaces", myarchived))
mytype=addParam(mytype,"IndexOnlyGlobalSpaces", False, getCloudSetting(config, "indexOnlyGlobalSpaces", myglobal))
mytype=addParam(mytype,"IndexAttachments", False, getCloudSetting(config, "indexAttachments", True))
mytype=addParam(mytype,"IndexCurrentSpaces", False, getCloudSetting(config, "indexCurrentSpaces", mycurrent))
mytype=addParam(mytype,"FilterSpaceRegex", False, getCloudSetting(config,"spaceFilter",""))
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Specified"
mytype=addSecurityUser(mytype,getCloudSetting(config,"username","*@*"))
if "username" in config["cloudSourceConfiguration"]:
mytype["emailAddress"]=config["cloudSourceConfiguration"]["username"]
mytype["configuration"]["userIdentities"]= { "UserIdentity": { "name": "token", "userName": config["cloudSourceConfiguration"]["username"], "password": "UPDATEIT" }}
mytype["additionalInfos"]={"emailAddress": config["cloudSourceConfiguration"]["username"] }
if "urls" in config["cloudSourceConfiguration"]:
mytype["configuration"]["startingAddresses"]= config["cloudSourceConfiguration"]["urls"]
mytype["password"]="TOCHANGE"
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="ORACLE_KNOWLEDGE":
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="YOUTUBE":
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="SITEMAP":
actionlist += "\n\tAdjust webscraper configuration"
if (getCloudSetting(config,"urlReplacementPattern","")):
actionlist += "\n\tUrl replacement is obsolete, add your extension script to solve it."
if (getCloudSetting(config,"oAuthProviderType","")):
actionlist += "\n\toAuthProviderType is obsolete, set form authentication in the source."
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="JIRA":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tAdd password"
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["email"]=config["cloudSourceConfiguration"]["emailAddress"]
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.Jira2"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"ShallIndexWorkLogs", False, getCloudSetting(config,"indexWorkLogs",True))
mytype=addParam(mytype,"ShallIndexComments", False, getCloudSetting(config,"indexComments",False))
mytype=addParam(mytype,"ShallIndexAttachments", False, getCloudSetting(config, "indexAttachments", False))
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Specified"
mytype=addSecurityUser(mytype,getCloudSetting(config,"username","*@*"))
if "username" in config["cloudSourceConfiguration"]:
mytype["emailAddress"]=config["cloudSourceConfiguration"]["username"]
mytype["configuration"]["userIdentities"]= { "UserIdentity": { "name": "token", "userName": config["cloudSourceConfiguration"]["username"], "password": "UPDATEIT" }}
mytype["additionalInfos"]={"emailAddress": config["cloudSourceConfiguration"]["username"] }
if "startingAddress" in config["cloudSourceConfiguration"]:
mytype["configuration"]["startingAddresses"]= [ config["cloudSourceConfiguration"]["startingAddress"] ]
mytype["password"]="TOCHANGE"
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="JIRA_CLOUD":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tAdd password"
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["email"]=config["cloudSourceConfiguration"]["emailAddress"]
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.Jira2"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"ShallIndexWorkLogs", False, getCloudSetting(config,"indexWorkLogs",True))
mytype=addParam(mytype,"ShallIndexComments", False, getCloudSetting(config,"indexComments",False))
mytype=addParam(mytype,"ShallIndexAttachments", False, getCloudSetting(config, "indexAttachments", False))
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Specified"
mytype=addSecurityUser(mytype,getCloudSetting(config,"username","*@*"))
if "username" in config["cloudSourceConfiguration"]:
mytype["emailAddress"]=config["cloudSourceConfiguration"]["username"]
mytype["configuration"]["userIdentities"]= { "UserIdentity": { "name": "token", "userName": config["cloudSourceConfiguration"]["username"], "password": "UPDATEIT" }}
mytype["additionalInfos"]={"emailAddress": config["cloudSourceConfiguration"]["username"] }
if "startingAddress" in config["cloudSourceConfiguration"]:
mytype["configuration"]["startingAddresses"]= [ config["cloudSourceConfiguration"]["startingAddress"] ]
mytype["password"]="TOCHANGE"
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="JIVE":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tAdd password"
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["email"]=config["cloudSourceConfiguration"]["emailAddress"]
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.Jive"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"OnlyIndexPublishedContent", False, getCloudSetting(config,"indexOnlyPublishedItems",False))
mytype=addParam(mytype,"ShallIndexGroups", False, getCloudSetting(config,"indexSocialGroups",True))
mytype=addParam(mytype,"ShallIndexSystemBlogs", False, getCloudSetting(config, "indexSystemBlogs", True))
mytype=addParam(mytype,"ShallIndexSpaces", False, getCloudSetting(config,"indexCommunities",True))
mytype=addParam(mytype,"ShallIndexProjects", False, getCloudSetting(config,"indexProjects",True))
mytype=addParam(mytype,"ShallIndexPeople", False, getCloudSetting(config, "indexUsers", False))
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
mytype["additionalInfos"] = { "JiveInstanceAllowsAnonymousAccess": getCloudSetting(config, "allowsAnonymousAccess", True) }
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Specified"
mytype=addSecurityUser(mytype,getCloudSetting(config,"username","*@*"))
if "username" in config["cloudSourceConfiguration"]:
mytype["configuration"]["userIdentities"]= { "UserIdentity": { "name": "token", "userName": config["cloudSourceConfiguration"]["username"], "password": "UPDATEIT" }}
mytype["emailAddress"]=config["cloudSourceConfiguration"]["username"]
mytype["additionalInfos"]={"emailAddress": config["cloudSourceConfiguration"]["username"] }
if "url" in config["cloudSourceConfiguration"]:
mytype["configuration"]["startingAddresses"]= [ config["cloudSourceConfiguration"]["url"] ]
mytype["password"]="TOCHANGE"
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="JIVE_CLOUD":
if "publicVisibility" in config["cloudSourceConfiguration"]:
if not config["cloudSourceConfiguration"]["publicVisibility"]:
actionlist += "\n\tWARNING: V1 has public Visibility set to false, check security in V2!!!"
actionlist += "\n\tAdd password"
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["email"]=config["cloudSourceConfiguration"]["emailAddress"]
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.Jive"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"OnlyIndexPublishedContent", False, getCloudSetting(config,"indexOnlyPublishedItems",False))
mytype=addParam(mytype,"ShallIndexGroups", False, getCloudSetting(config,"indexSocialGroups",True))
mytype=addParam(mytype,"ShallIndexSystemBlogs", False, getCloudSetting(config, "indexSystemBlogs", True))
mytype=addParam(mytype,"ShallIndexSpaces", False, getCloudSetting(config,"indexCommunities",True))
mytype=addParam(mytype,"ShallIndexProjects", False, getCloudSetting(config,"indexProjects",True))
mytype=addParam(mytype,"ShallIndexPeople", False, getCloudSetting(config, "indexUsers", False))
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
mytype["additionalInfos"] = { "JiveInstanceAllowsAnonymousAccess": getCloudSetting(config, "allowsAnonymousAccess", True) }
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Specified"
mytype=addSecurityUser(mytype,getCloudSetting(config,"username","*@*"))
if "username" in config["cloudSourceConfiguration"]:
mytype["configuration"]["userIdentities"]= { "UserIdentity": { "name": "token", "userName": config["cloudSourceConfiguration"]["username"], "password": "UPDATEIT" }}
mytype["emailAddress"]=config["cloudSourceConfiguration"]["username"]
mytype["additionalInfos"]={"emailAddress": config["cloudSourceConfiguration"]["username"] }
if "url" in config["cloudSourceConfiguration"]:
mytype["configuration"]["startingAddresses"]= [ config["cloudSourceConfiguration"]["url"] ]
mytype["password"]="TOCHANGE"
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="SALESFORCE":
actionlist += "\n\tAdd password"
actionlist += "\n\tRefresh Token"
actionlist += "\n\tImport field configuration"
#Must be done using RAW
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.Salesforce2"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
#remove objectsSchema
mytype["objectsSchema"]=[]
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"ClientSecret", True, "UPDATEIT")
mytype=addParam(mytype,"ClientId", False, "UPDATEIT")
mytype=addParam(mytype,"ClientRefreshToken", True, "UPDATEIT")
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
mytype=addParam(mytype,"SchemaVersion", False, "LEGACY")
mytype=addParam(mytype,"IsSandbox", False, getCloudSetting(config,"sandbox", False))
mytype=addParam(mytype,"UseRefreshToken", False, getCloudSetting(config,"useRefreshToken", True))
mytype=addParam(mytype,"OAuthRefreshToken", True, "UPDATEIT")
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Merge"
#Weird token is in password of a useridentity
mytype["configuration"]["userIdentities"]= { "UserIdentity": { "name": "token", "userName": "unused", "password": "UPDATEIT" }}
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["emailAddress"]=config["cloudSourceConfiguration"]["emailAddress"]
if "username" in config["cloudSourceConfiguration"]:
mytype["additionalInfos"]={"salesforceOrg": "UPDATEIT", "schemaVersion": "LEGACY", "salesforceOrgName": "UPDATEIT", "salesforceUser":config["cloudSourceConfiguration"]["username"] }
mytype["configuration"]["startingAddresses"]=["http://www.salesforce.com"]
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="KNOWLEDGEBASE":
actionlist += "\n\tAdd password"
actionlist += "\n\tRefresh Token"
actionlist += "\n\tImport field configuration"
#Must be done using RAW
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.Salesforce2"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
#remove objectsSchema
mytype["objectsSchema"]=[]
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"ClientSecret", True, "UPDATEIT")
mytype=addParam(mytype,"ClientId", False, "UPDATEIT")
mytype=addParam(mytype,"ClientRefreshToken", True, "UPDATEIT")
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
mytype=addParam(mytype,"SchemaVersion", False, "LEGACY")
mytype=addParam(mytype,"IsSandbox", False, getCloudSetting(config,"sandbox", False))
mytype=addParam(mytype,"UseRefreshToken", False, getCloudSetting(config,"useRefreshToken", True))
mytype=addParam(mytype,"OAuthRefreshToken", True, "UPDATEIT")
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Merge"
#Weird token is in password of a useridentity
mytype["configuration"]["userIdentities"]= { "UserIdentity": { "name": "token", "userName": "unused", "password": "UPDATEIT" }}
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["emailAddress"]=config["cloudSourceConfiguration"]["emailAddress"]
if "username" in config["cloudSourceConfiguration"]:
mytype["additionalInfos"]={"salesforceOrg": "UPDATEIT", "schemaVersion": "LEGACY", "salesforceOrgName": "UPDATEIT", "salesforceUser":config["cloudSourceConfiguration"]["username"] }
mytype["configuration"]["startingAddresses"]=["http://www.salesforce.com"]
a=0
#-----------------------------------------------------------------------------------------------------------------
if config["type"]=="SALESFORCE_CONTENT":
actionlist += "\n\tAdd password"
actionlist += "\n\tRefresh Token"
actionlist += "\n\tImport field configuration"
#Must be done using RAW
mytype["MethodToUse"]="RAW"
mytype["crawlerInstancetype"] = "Connector.Salesforce2"
mytype["configuration"]={}
mytype = addAddressPattern(mytype)
#remove objectsSchema
mytype["objectsSchema"]=[]
mytype["configuration"]["parameters"]={}
mytype=addParam(mytype,"PauseOnError", False, "true")
mytype=addParam(mytype,"ClientSecret", True, "UPDATEIT")
mytype=addParam(mytype,"ClientId", False, "UPDATEIT")
mytype=addParam(mytype,"ClientRefreshToken", True, "UPDATEIT")
mytype=addParam(mytype,"OrganizationId", False, v1_org_id)
mytype=addParam(mytype,"SchemaVersion", False, "LEGACY")
mytype=addParam(mytype,"IsSandbox", False, getCloudSetting(config,"sandbox", False))
mytype=addParam(mytype,"UseRefreshToken", False, getCloudSetting(config,"useRefreshToken", True))
mytype=addParam(mytype,"OAuthRefreshToken", True, "UPDATEIT")
if config["cloudSourceConfiguration"]["publicVisibility"]:
mytype=addSecurityEverybody(mytype)
mytype["configuration"]["sourceSecurityOption"] = "Specified"
else:
mytype["configuration"]["sourceSecurityOption"] = "Merge"
#Weird token is in password of a useridentity
mytype["configuration"]["userIdentities"]= { "UserIdentity": { "name": "token", "userName": "unused", "password": "UPDATEIT" }}
if "emailAddress" in config["cloudSourceConfiguration"]:
mytype["emailAddress"]=config["cloudSourceConfiguration"]["emailAddress"]
if "username" in config["cloudSourceConfiguration"]:
mytype["additionalInfos"]={"salesforceOrg": "UPDATEIT", "schemaVersion": "LEGACY", "salesforceOrgName": "UPDATEIT", "salesforceUser":config["cloudSourceConfiguration"]["username"] }
mytype["configuration"]["startingAddresses"]=["http://www.salesforce.com"]
a=0
return mytype
def translateVisibility(mytype):
fromRepo = { "PUBLIC":"SHARED","PRIVATE":"SECURED"}
for repo in fromRepo:
if repo == mytype:
return fromRepo[repo]
return mytype
def transformV1ToV2(myconfig):
#Transform V1 source to V2 RAW format
#Check for problems in SFDC configs
restrictedfields = { "name","notifyOnRebuildCompleted","objectsSchema","owner","publicVisibility","rebuildRequired", "sourceType","sourceVisibility", "titleSelectionSequence","type","urls", "urlFilters"}
report = {}
#print (myconfig["cloudSourceConfiguration"])
report["id"]=myconfig["id"]
report["information"]={}
report["information"]["sourceId"] = myconfig["id"]
sourcename=""
if 'name' in myconfig["cloudSourceConfiguration"]:
sourcename = myconfig["cloudSourceConfiguration"]["name"]
else:
sourcename = myconfig["id"]
report["information"]["sourceName"] = sourcename
report["name"] = sourcename
if 'owner' in myconfig["cloudSourceConfiguration"]:
report["owner"] = myconfig["cloudSourceConfiguration"]["owner"]
report["sourceType"] = translatetype(myconfig["type"])
report["sourceVisibility"] = translateVisibility(myconfig["visibility"])
if 'urls' in myconfig["cloudSourceConfiguration"]:
report["urls"] = myconfig["cloudSourceConfiguration"]["urls"]
if 'urlFilters' in myconfig["cloudSourceConfiguration"]:
report["urlFilters"] = myconfig["cloudSourceConfiguration"]["urlFilters"]
report["customParameters"] = {}
for field in myconfig["cloudSourceConfiguration"]:
if not field in restrictedfields:
report["customParameters"][field]=myconfig["cloudSourceConfiguration"][field]
report[field]=myconfig["cloudSourceConfiguration"][field]
report = fix(report,myconfig)
return report
def inspectSFDC(myconfig):
#Inspects SFDC custom settings
#Check for problems in SFDC configs
report = ""
if myconfig['cloudSourceConfiguration']:
if 'objectsSchema' in myconfig['cloudSourceConfiguration']:
for objects in myconfig['cloudSourceConfiguration']['objectsSchema']:
if objects['custom']==True:
body = ""
if 'body' in objects:
body = objects['body']
report += "\n\tSFDC SCHEMA FOR OBJECT: "+objects['name']+", different body:\n\t"+body+"\n\t==================================================\n"
for fields in objects['fields']:
if fields['custom']==True:
report += "\n\tSFDC SCHEMA FOR OBJECT: "+objects['name']+""
#facet, fieldName, freeText, label, multi, name, parentObjectName, mytype
report += "\n\tSFDC SCHEMA FOR FIELD : "+fields["name"]+"\n"+addLine()
report += "\tfieldName : "+fields["fieldName"]+"\n"+addLine()
report += "\tlabel : "+fields["label"]+"\n"+addLine()
report += "\ttype : "+fields["type"]+"\n"+addLine()
report += "\tparentObjectName : "+fields["parentObjectName"]+"\n"+addLine()
report += "\tfacet : "+str(fields["facet"])+"\n"+addLine()
report += "\tfreeText : "+str(fields["freeText"])+"\n"+addLine()
report += "\tmulti facet : "+str(fields["multi"])+"\n"
report += "\n\t==================================================\n"
return report
def removeComments(string):
string = re.sub(re.compile("/\*.*?\*/",re.RegexFlag.MULTILINE|re.RegexFlag.DOTALL ) ,"" ,string) # remove all occurance streamed comments (/*COMMENT */) from string
string = re.sub(re.compile("//.*?\n" ,re.RegexFlag.MULTILINE|re.RegexFlag.DOTALL ) ,"" ,string) # remove all occurance singleline comments (//COMMENT\n ) from string
return string