-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reposreader.py
826 lines (739 loc) · 30.1 KB
/
reposreader.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
# filereader.py
# Copyright (C) 2005-2024 the Archimedes authors and contributors
# <see AUTHORS file>
#
# This module is part of Archimedes and is released under
# the MIT License: https://www.opensource.org/licenses/mit-license.php
"""
This is a utility to read the CA Live API Creator file based repository and print a report that can be used to help migrate
to API Logic Server (a Python API open-source tool) https://apilogicserver.github.io/Docs/
"""
import os
import json
import sys
import argparse
from pathlib import Path
from rule import RuleObj
from resourceobj import ResourceObj
from role_security import Role
from util import to_camel_case, fixup
global version
global tableAlias
def main(calling_args=None):
if calling_args:
args = calling_args
else:
parser = argparse.ArgumentParser(
description="Generate a report of an existing CA Live API Creator Repository "
)
parser.add_argument(
"--repos",
help="Full path to /User/guest/caliveapicreator.repository",
type=str,
)
parser.add_argument(
"--project",
help="The name of the LAC project (teamspace/api) default: demo",
default="demo",
type=str,
)
parser.add_argument(
"--section",
help="The api directory name to process [rules, resources, functions, etc.] default: all",
default="all",
type=str,
)
parser.add_argument(
"--version", action="store_true", help="print the version number and exit"
)
args = parser.parse_args()
if args.version:
version = "1.0" # TODO
print(version)
return
if not args.repos:
print("Please supply a --repos location\n", file=sys.stderr)
parser.print_help()
return
projectName = args.project or "demo"
reposLocation = args.repos
sections = args.section or "all"
apiURL = f"/LAC/rest/default/{projectName}/v1" # this is used for building the resource URL
basepath = f"{reposLocation}/{api_root}/{projectName}"
try:
# readTranslationTable("table_to_class.json")
listDirs(basepath, sections, apiURL)
except Exception as ex:
print(f"Error running {ex}")
def printTransform():
print("def transform(style:str, key:str, result: dict) -> dict:")
print(f"\t# use this to change the output (pipeline) of the result")
# use this to change the output (pipeline) of the result
code = "\
try: \n\
j = json.loads(result)\n\
except Exception as ex:\n\
app_logger.error(f'Transform Error on style {style} using key: {key} error: {ex}')\n\
return result\n\
if style == 'LAC':\n\
if key == '':\n\
r = []\n\
r.append(j)\n\
return r\n\
else:\n\
return j[key] if key in j else j\n\
return j"
print(code)
print("")
def readTableAlias():
"""
Read a list of generated tables from ALS to use in the translation
TableName = AliasName
"""
tableAlias = dict(str, str)
def readTranslationTable(tableName):
with open(tableName) as user_file:
file_contents = user_file.read()
# print(file_contents)
return json.loads(file_contents)
def setVersion(path: Path):
# Recommend upgrade to 5.4 before starting transform
global version
version = next(
(
"5.4"
for dirpath, dirs, files in os.walk(path)
if os.path.basename(dirpath) == "pipeline_events"
),
"5.x",
)
def listDir(path: Path):
if path in [".DS_Store"]:
return
for entry in os.listdir(path):
if os.path.isdir(os.path.join(path, entry)):
print(f"DIR: {entry}")
if entry not in [".DS_Store"]:
for d in os.listdir(os.path.join(path, entry)):
if d not in [".DS_Store"]:
listFiles(f"{os.path.join(path, entry)}/{d}")
def listFiles(path: Path):
if path in [".DS_Store"]:
return
with os.scandir(path) as entries:
for entry in entries:
if entry.name in [".DS_Store", "apiversions.json"]:
continue
if entry.is_file():
if entry.name.endswith(".json"):
print(f" JSON: {entry.name}")
if entry.name.endswith(".js"):
print(f" JS: {entry.name}")
if entry.name.endswith(".sql"):
print(f" SQL: {entry.name}")
def dataSource(path: Path, no_print: bool = False):
# print("#=========================")
# print("# SQL Tables ")
# print("#=========================")
if not no_print:
print("# This is informational only of the database schema, tables, columns")
tableList = []
with os.scandir(path) as entries:
for f in entries:
if f in ["ReadMe.md", ".DS_Store"]:
continue
# print ('|', len(path)*'---', f)
fname = os.path.join(path, f)
if fname.endswith(".json"):
with open(fname) as myfile:
d = myfile.read()
j = json.loads(d)
#print("j:",j)
db = j["databaseType"]
url = j["url"] if "url" in j else "JNDI"
uname = j["username"] if "username" in j else "JNDI"
schema = j["schema"] if "schema" in j else "JNDI"
if not no_print:
print(
"------------------------------------------------------------"
)
print(f"Database: {db} ")
print(f" URL:{url} ")
print(f" User: {uname} Schema: {schema}")
ti = j["tableIncludes"]
te = j["tableExcludes"]
if ti != None:
print(f" TableIncludes: {ti}")
if te != None:
print(f" TableExcludes: {te}")
print(
"------------------------------------------------------------"
)
# ["metaHolder"] was prior to 5.4
if "schemaCache" in j:
tables = (
j["schemaCache"]["tables"]
if version == "5.4"
else j["schemaCache"]["metaHolder"]["tables"]
)
for t in tables:
if not no_print:
print(" ")
name = t["name"] if version == "5.4" else t["entity"]
tableList.append(name)
if not no_print:
print(f"create table {schema}.{name} (")
sep = ""
for c in t["columns"]:
name = c["name"]
autoIncr = ""
if "isAutoIncrement" in c:
autoIncr = (
"AUTO_INCREMENT"
if c["isAutoIncrement"] == True
else ""
)
baseType = (
c["attrTypeName"]
if version == "5.4"
else c["baseTypeName"]
)
# l = c["len"]
nullable = (
"" # 'not null' if c["nullable"] == False else ''
)
if not no_print:
print(
f" {sep}{name} {baseType} {nullable} {autoIncr}"
)
sep = ","
for k in t["keys"]:
c = k["columns"]
cols = f"{c}"
cols = cols.replace("[", "")
cols = cols.replace("]", "")
if not no_print:
print(")")
print("")
print(f"# PRIMARY KEY({cols})")
print("")
# ["metaHolder"] was prior to 5.4
if version == "5.4":
fkeys = j["schemaCache"]["foreignKeys"]
else:
fkeys = j["schemaCache"]["metaHolder"]["foreignKeys"]
for fk in fkeys:
name = fk["name"] if version == "5.4" else fk["entity"]
parent = (
fk["parent"]["name"]
if version == "5.4"
else fk["parent"]["object"]
)
child = (
fk["child"]["name"]
if version == "5.4"
else fk["child"]["object"]
)
parentCol = fk["columns"][0]["parent"]
childCol = fk["columns"][0]["child"]
if not no_print:
print("")
print(
f" ALTER TABLE ADD CONSTRAINT fk_{name} FOREIGN KEY {child}({childCol}) REFERENCES {parent}({parentCol})"
)
print("")
return tableList
def printTableAsResource(tableList):
print(
"#============================================================================================="
)
print(
"# ALS may change the name of tables (entity) - so create a endpoint with original name"
)
print("# copy to als api/customize_api.py")
print(
"#============================================================================================="
)
print("")
for name in tableList:
entity_name = to_camel_case(name)
entity_name = entity_name[:1].upper() + entity_name[1:]
print(f"@app.route('{apiurl}/{name}', methods=['GET', 'POST','PUT','OPTIONS'])")
print("@admin_required()")
print(f"def {name}():")
print(f"\troot = CustomEndpoint(model_class=models.{entity_name})")
print(f"\tresult = root.execute(request)")
print(f"\treturn root.transform('LAC', '{name.lower()}', result)")
print("")
def printTableTestCLI(tableList):
print(
"#============================================================================================="
)
print(
"# als command line tests for each table endpoint ?page[limit]=10&page[offset]=00&filter[key]=value"
)
print(
"#============================================================================================="
)
print("")
for tbl in tableList:
name = singular(tbl)
print(f"# als calling endpoint: {name}?page[limit]=1")
print(f'als get "{apiurl}/{name}?page%5Blimit%5D=1" -m json')
print("")
print("")
def singular(name: str) -> str:
# return name[:-1] if name.endswith("s") else name # singular names only
return name
def resourceType(resource: object):
print(resource)
def securityRoles(thisPath) -> list:
path = f"{thisPath}/roles"
roleList = []
print(
"============================================================================================="
)
print(" Grant and Role based Access Control for user Security")
print(" copy to security/declare_security.py")
print(
"============================================================================================="
)
print(" ")
for dirpath, dirs, files in os.walk(path):
path = dirpath.split("/")
for f in files:
if f in ["ReadMe.md", ".DS_Store"]:
continue
fname = os.path.join(dirpath, f)
if fname.endswith(".json"):
with open(fname) as myfile:
data = myfile.read()
j = json.loads(data)
name = j["name"]
role = Role(roleName=name)
role.loadEntities(j)
roleList.append(role)
return roleList
def securityUsers(thisPath) -> list:
path = f"{thisPath}/users"
userList = []
for dirpath, dirs, files in os.walk(path):
path = dirpath.split("/")
for f in files:
if f in ["ReadMe.md", ".DS_Store"]:
continue
fname = os.path.join(dirpath, f)
if fname.endswith(".json"):
with open(fname) as myfile:
d = myfile.read()
j = json.loads(d)
name = j["name"]
roles = j["roles"]
print(f"User: {name} Role: {roles}")
userList.append(name)
return userList
def printCols(jsonObj: object):
entity = "" if jsonObj["resourceType"] != "TableBased" else jsonObj["entity"]
attrs = ""
join = ""
filterStr = ""
isParent = ""
if "filter" in jsonObj:
f = jsonObj["filter"]
if f != None:
filterStr = f"Filter: ({f})"
if "join" in jsonObj:
join = jsonObj["join"]
join = join.replace("\\", "", 10)
join = f"Join: ({join})"
if "attributes" in jsonObj:
attributes = jsonObj["attributes"]
sep = ""
for a in attributes:
if "attribute" in a:
attrs += sep + a["attribute"] if a["attribute"] else ""
sep = ","
attrs = f"Attrs: ({attrs})"
if "isCollection" in jsonObj:
isParent = "" if jsonObj["isCollection"] else "isParent=True"
return f"{entity} {join} {attrs}) {filterStr} {isParent}"
def getRootResources(resourceList: object):
return [r for r in resourceList if r.parentName == "v1"]
def buildResourceList(resPath: str, no_print: bool = False):
# print("=========================")
# print(" RESOURCES ")
# print("=========================")
resources = []
thisPath = f"{resPath}{os.sep}v1"
for dirpath, dirs, files in os.walk(thisPath):
path = dirpath.split(f"{os.sep}")
parentName = path[-1] if path[-1] == "v1" else path[-2]
if not no_print:
dirName = path[len(path) - 1]
print("|", len(path) * "--", "D", dirName)
for f in files:
if f in ["ReadMe.md", ".DS_Store"]:
continue
fname = os.path.join(dirpath, f)
if fname.endswith(".json"):
with open(fname) as myfile:
data = myfile.read()
jsonObj = json.loads(data)
if "isActive" in jsonObj and jsonObj["isActive"] == False:
continue
if not no_print:
print(
"|",
len(path) * "---",
"F",
f,
"Entity:",
printCols(jsonObj),
)
drName = ",".join(path[:-1])
resObj = ResourceObj(
parentName=parentName, parentDir=drName, jsonObj=jsonObj
)
resources.append(resObj)
fn = jsonObj["name"].split(".")[0] + ".sql"
resObj.jsSQL = findInFiles(dirpath, files, fn)
resObj._getJSObj = findInFiles(dirpath, files, "get_event.js")
fn = jsonObj["name"].split(".")[0] + ".js"
resObj._jsObj = findInFiles(dirpath, files, fn)
if parentName != "v1":
parentRes = findParent(resources, path, parentName)
if parentRes != None:
parentRes.childObj.append(resObj)
elif not no_print:
print("|", len(path) * "---", "F", f)
return getRootResources(resources)
def printDir(thisPath: Path):
objList = []
for dirpath, dirs, files in os.walk(thisPath):
path = dirpath.split("/")
parent = path[len(path) - 1]
for f in files:
if f in ["ReadMe.md", ".DS_Store", "apiversions.json"]:
continue
print("|", len(path) * "---", "F", f)
fname = os.path.join(dirpath, f)
if fname.endswith(".json"):
with open(fname) as myfile:
d = myfile.read()
j = json.loads(d)
objList.append(d)
return objList
def relationships(relFile: str):
print("# This is informational only")
# print("=========================")
# print(" RELATIONSHIPS ")
# print("=========================")
with open(relFile) as myfile:
d = myfile.read()
js = json.loads(d)
for rel in js:
parent = rel["parentEntity"]
child = rel["childEntity"]
roleToParent = rel["roleToParent"]
roleToChild = rel["roleToChild"]
parentColumns = rel["parentColumns"][0]
childColumns = rel["childColumns"][0]
# primaryjoin
print(
f"{roleToParent} = relationship('{parent}, remote_side=[{childColumns}] ,cascade_backrefs=True, backref='{child}')"
)
print(
f"{roleToChild} = relationship('{child}, remote_side=[{parentColumns}] ,cascade_backrefs=True, backref='{parent}')"
)
def functionList(thisPath: str):
"""
LAC has many different JavaScript functions, libraries, pipelines (aka request_response)
Many of these cannot be converted directly since they may use utilities or functions
not available (e.g. SysUtility) or expect state information (logic_row)
Recommendation: refactor the JS to match the desired result in ALS
Args:
thisPath (str):
"""
for dirpath, dirs, files in os.walk(thisPath):
path = dirpath.split(os.sep)
for f in files:
if f in [
"ReadMe.md",
".DS_Store",
"prefixes.json",
"api.json",
"apioptions.json",
]:
continue
fname = os.path.join(dirpath, f)
if fname.endswith(".js"):
with open(fname) as myfile:
fn = myfile.read()
print("")
fn = fixup(fn)
funName = "fn_" + f.split(".")[0]
print(
f"def {funName}(row: models.TableName, old_row: models.TableName, logic_row: LogicRow):"
)
# print(" return")
print(f" {fn}")
def rules(thisPath) -> list:
# print("=========================")
# print(" RULES ")
# print("=========================")
"""
Collect all of the rules definitions and JS info and stash in a list of RuleObj objects
The object itself (rule.py) has print functions that do the transforms
"""
print("#===========================================================")
print("# Copy rules section to ALS logic/declare_logic.py")
print("#===========================================================")
print("")
rules = []
for dirpath, dirs, files in os.walk(thisPath):
for f in files:
if f in ["ReadMe.md", ".DS_Store", "prefixes.json"]:
continue
# print ('|', len(path)*'---', f)
fname = os.path.join(dirpath, f)
if fname.endswith(".json"):
with open(fname) as myfile:
data = myfile.read()
jsonData = json.loads(data)
rule = RuleObj(jsonData, None)
fn = f.split(".")[0] + ".js"
javaScriptFile = findInFiles(dirpath, files, fn)
rule.jsObj = javaScriptFile
rules.append(rule)
return rules
def entityList(rules: object):
entityList = []
for r in rules:
entity = r.entity
if entity not in entityList:
entityList.append(entity)
return entityList
def findInFiles(dirpath, files, fileName):
for f in files:
if f == fileName:
fname = os.path.join(dirpath, f)
with open(fname) as myfile:
return myfile.read()
return None
def findParent(objectList, path, parentName):
if path[-2] == "v1":
return None # Root
parentDir = ",".join(path[:-2])
return next(
(l for l in objectList if l.parentDir == parentDir and l.name == parentName),
None,
)
def findObjInPath(objectList, pathName, name):
pn = pathName.replace(f"{basepath}{os.sep}v1{os.sep}", "")
nm = name.split(".")[0]
return next((l for l in objectList if l.parentName == pn and l.name == nm), None)
def printChild(self):
if self.childObj != None:
print(
f" Name: {self.parentName} Entity: {self.entity} ChildName: {self.childObj.name} ChildPath: {self.childObj.parentName}"
)
def addChildObj(co):
self.childObj.append(co)
def __str__(self):
# switch statement for each Resource
if self.childObj == []:
return f"Name: {self.name} Entity: {self.entity} ResourceType: {self.ResourceType}"
else:
return f"Name: {self.name} Entity: {self.entity} ResourceType: {self.ResourceType} ChildName: {self.childObj[0].name}" # {print(childObj[0]) for i in childObj: print(childObj[i])}
def lac_functions(thisPath):
path = f"{thisPath}"
lac_func = []
for dirpath, dirs, files in os.walk(path):
path = dirpath.split("/")
for f in files:
if f in ["ReadMe.md", ".DS_Store"]:
continue
fname = os.path.join(dirpath, f)
if fname.endswith(".json"):
with open(fname) as myfile:
d = myfile.read()
j = json.loads(d)
isActive = j["isActive"]
if isActive:
func_type = j["functionType"]
if func_type == "rowLevel":
comments = j["comments"]
if comments != "":
print('"""')
print(f"comments: {comments}")
print('"""')
name = j["name"]
appliesTo = j["appliesTo"]
params = j["parameters"]
print(
f"#RowLevel Function: {name} appliesTo: {appliesTo} params: {params}"
)
fn = f.split(".")[0] + ".js"
javaScriptFile = findInFiles(dirpath, files, fn)
print(f"def fn_rowlevel_{name}(params: any) -> dict:")
print("'''")
print(fixup(javaScriptFile))
print("'''")
print("")
lac_func.append(name)
return lac_func
def pipeline(thisPath):
path = f"{thisPath}"
pipelines = []
for dirpath, dirs, files in os.walk(path):
path = dirpath.split("/")
for f in files:
if f in ["ReadMe.md", ".DS_Store"]:
continue
fname = os.path.join(dirpath, f)
if fname.endswith(".json"):
with open(fname) as myfile:
d = myfile.read()
j = json.loads(d)
isActive = j["isActive"]
if isActive:
name = j["name"]
_type = j["eventType"]
appliesTo = j["appliesTo"]
isRestricted = j["isRestricted"]
restrictedTo = j["restrictedTo"] if isRestricted else ""
print(
f"#Pipeline: {name} type: {_type} appliesTo: {appliesTo} restrictedTo: {restrictedTo}"
)
fn = f.split(".")[0] + ".js"
javaScriptFile = findInFiles(dirpath, files, fn)
print("def fn_pipeline_{name}(result: dict) -> dict:")
print("'''")
print(fixup(javaScriptFile))
print("'''")
print("")
pipelines.append(name)
def printTests(resObj: ResourceObj, apiURL: str):
print("")
# print("ALS Command Line TESTS")
if resObj.isActive:
name = resObj.name.lower()
entity = resObj.entity
filter_by = "?page%5Blimit%5D=1" # page[offset]=0&filter[key]=value"
print(f"# als get calling Entity {entity} using: {apiURL}/{name}{filter_by}")
print(f'als get "{apiURL}/{name}{filter_by}" -k 1 -m json')
print("")
def listDirs(path: Path, section: str = "all", apiURL: str = ""):
setVersion(path)
print(f"# LAC Version: {version}")
for entry in os.listdir(path):
# for dirpath, dirs, files in os.walk(basepath):
if section == "tests":
print("")
print("#===========================================================")
print("# ALS Command Line tests for each Resource endpoint")
print("#===========================================================")
print("als login http://localhost:5656 -u u1 -p p -a nw")
print("")
resList: ResourceObj = buildResourceList(
f"{path}{os.sep}resources", no_print=True
)
for res in resList:
printTests(res, apiURL=apiURL)
fp = f"{path}{os.sep}data_sources"
tableList = dataSource(fp, no_print=True)
printTableTestCLI(tableList=tableList)
break
if section.lower() != "all" and entry != section:
continue
if entry in [
"api.json",
"issues.json",
"apioptions.json",
"exportoptions.json",
".DS_Store",
]:
continue
filePath = f"{path}{os.sep}{entry}"
print("")
print("=========================")
print(f" {entry.upper()} ")
print("=========================")
if entry == "resources":
print("#Copy this section to ALS api/customize_api.py")
print("#from flask_cors import cross_origin")
print("#from api.system.custom_endpoint import CustomEndpoint, DotDict")
print("#from api.system.free_sql import FreeSQL")
print("")
resList: ResourceObj = buildResourceList(f"{path}{os.sep}{entry}")
for resObj in resList:
resObj.PrintResource(version, apiURL)
for resObj in resList:
resObj.PrintResourceFunctions(resObj._name, version)
print("#FreeSQL section to ALS api/customize_api.py")
for resObj in resList:
resObj.PrintFreeSQL(apiURL)
print("#JavaScript section to ALS api/customize_api.py")
for resObj in resList:
resObj.PrintJavaScript(apiURL)
continue
if entry == "rules":
rulesList = rules(filePath)
entities = entityList(rulesList)
for entity in entities:
entityName = to_camel_case(entity)
print(f"# ENTITY: {entityName}")
print("")
for rule in rulesList:
if rule.entity == entity:
RuleObj.ruleTypes(rule)
continue
if entry == "data_sources":
tableList = dataSource(filePath)
printTableAsResource(tableList)
continue
if entry in ["request_events", "pipelines", "libraries"]:
print(
f"# These are JavaScript {entry} can be called by rules and resources"
)
functionList(filePath)
continue
if entry == "relationships.json":
relationships(f"{path}{os.sep}relationships.json")
continue
if entry == "security":
roleList = securityRoles(filePath)
print("class Roles():")
for r in roleList:
r.printRole()
print("")
for r in roleList:
r.printGrants()
print("")
for r in roleList:
r.printTablePermission()
print("")
securityUsers(filePath)
continue
if entry == "pipeline_events":
pipeline(filePath)
continue
if entry == "functions":
lac_functions(filePath)
continue
printDir(f"{basepath}{os.sep}{entry}")
projectName = "gfer"
apiurl = f"/rest/default/{projectName}/v1" # this is used for building the resource URL
api_root = "teamspaces/default/apis"
running_at = Path(__file__)
reposLocation = f"{running_at.parent}/CALiveAPICreator.repository"
basepath = f"{reposLocation}/{api_root}/{projectName}"
version = "5.4"
command = "not set"
section = "all" # all is default or resources, rules, security, pipeline_events, data_sources , tests, etc.
if __name__ == "__main__":
main()
# else:
# local testing and debugging
# table_to_class = readTranslationTable("table_to_class.json")
# listDirs(basepath, section, apiurl)