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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
|
# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
# This software is distributed under the terms and conditions of the 'Apache-2.0'
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
from uuid import uuid4
import os
import json
import copy
import re
import six
import time
from keystone.common import manager
from keystone import config
from oslo_log import log
from keystone.common import dependency
from keystone import exception
from oslo_config import cfg
from keystone.i18n import _
from keystone.contrib.moon.exception import *
from keystone.contrib.moon.algorithms import *
CONF = config.CONF
LOG = log.getLogger(__name__)
_OPTS = [
cfg.StrOpt('authz_driver',
default='keystone.contrib.moon.backends.flat.SuperExtensionConnector',
help='Authorisation backend driver.'),
cfg.StrOpt('log_driver',
default='keystone.contrib.moon.backends.flat.LogConnector',
help='Logs backend driver.'),
cfg.StrOpt('superextension_driver',
default='keystone.contrib.moon.backends.flat.SuperExtensionConnector',
help='SuperExtension backend driver.'),
cfg.StrOpt('intraextension_driver',
default='keystone.contrib.moon.backends.sql.IntraExtensionConnector',
help='IntraExtension backend driver.'),
cfg.StrOpt('tenant_driver',
default='keystone.contrib.moon.backends.sql.TenantConnector',
help='Tenant backend driver.'),
cfg.StrOpt('interextension_driver',
default='keystone.contrib.moon.backends.sql.InterExtensionConnector',
help='InterExtension backend driver.'),
cfg.StrOpt('policy_directory',
default='/etc/keystone/policies',
help='Local directory where all policies are stored.'),
cfg.StrOpt('super_extension_directory',
default='/etc/keystone/super_extension',
help='Local directory where SuperExtension configuration is stored.'),
]
CONF.register_opts(_OPTS, group='moon')
def filter_args(func):
def wrapped(*args, **kwargs):
_args = []
for arg in args:
if type(arg) in (unicode, str):
arg = "".join(re.findall("[\w\-+]*", arg))
_args.append(arg)
for arg in kwargs:
if type(kwargs[arg]) in (unicode, str):
kwargs[arg] = "".join(re.findall("[\w\-+]*", kwargs[arg]))
return func(*_args, **kwargs)
return wrapped
def enforce(actions, object, **extra):
_actions = actions
def wrap(func):
def wrapped(*args):
# global actions
self = args[0]
user_name = args[1]
intra_extension_uuid = args[2]
_admin_extension_uuid = self.tenant_api.get_admin_extension_uuid(args[2])
# func.func_globals["_admin_extension_uuid"] = _admin_extension_uuid
if not _admin_extension_uuid:
args[0].moonlog_api.warning("No admin IntraExtension found, authorization granted by default.")
return func(*args)
else:
_authz = False
if type(_actions) in (str, unicode):
actions = (_actions, )
else:
actions = _actions
for action in actions:
if self.admin_api.authz(
_admin_extension_uuid,
user_name,
object,
action):
_authz = True
else:
_authz = False
break
if _authz:
return func(*args)
return wrapped
return wrap
def filter_input(data):
if type(data) not in (str, unicode):
return data
try:
return "".join(re.findall("[\w\-+*]", data))
except TypeError:
LOG.error("Error in filtering input data: {}".format(data))
@dependency.provider('moonlog_api')
class LogManager(manager.Manager):
def __init__(self):
driver = CONF.moon.log_driver
super(LogManager, self).__init__(driver)
def get_logs(self, logger="authz", options="", event_number=None, time_from=None, time_to=None, filter_str=None):
if len(options) > 0:
options = options.split(",")
event_number = None
time_from = None
time_to = None
filter_str = None
for opt in options:
if "event_number" in opt:
event_number = "".join(re.findall("\d*", opt.split("=")[-1]))
try:
event_number = int(event_number)
except ValueError:
event_number = None
elif "from" in opt:
time_from = "".join(re.findall("[\w\-:]*", opt.split("=")[-1]))
try:
time_from = time.strptime(time_from, self.TIME_FORMAT)
except ValueError:
time_from = None
elif "to" in opt:
time_to = "".join(re.findall("[\w\-:] *", opt.split("=")[-1]))
try:
time_to = time.strptime(time_to, self.TIME_FORMAT)
except ValueError:
time_to = None
elif "filter" in opt:
filter_str = "".join(re.findall("\w*", opt.split("=")[-1]))
return self.driver.get_logs(logger, event_number, time_from, time_to, filter_str)
def get_authz_logs(self, options="", event_number=None, time_from=None, time_to=None, filter_str=None):
return self.get_logs(
logger="authz",
options="",
event_number=None,
time_from=None,
time_to=None,
filter_str=None)
def get_sys_logs(self, options="", event_number=None, time_from=None, time_to=None, filter_str=None):
return self.get_logs(
logger="sys",
options="",
event_number=None,
time_from=None,
time_to=None,
filter_str=None)
def authz(self, message):
return self.driver.authz(message)
def debug(self, message):
return self.driver.debug(message)
def info(self, message):
return self.driver.info(message)
def warning(self, message):
return self.driver.warning(message)
def error(self, message):
return self.driver.error(message)
def critical(self, message):
return self.driver.critical(message)
@dependency.provider('tenant_api')
@dependency.requires('moonlog_api')
class TenantManager(manager.Manager):
def __init__(self):
super(TenantManager, self).__init__(CONF.moon.tenant_driver)
def get_tenant_dict(self):
"""
Return a dictionnary with all tenants
:return: dict
"""
try:
return self.driver.get_tenant_dict()
except TenantListEmpty:
self.moonlog_api.error(_("Tenant Mapping list is empty."))
return {}
def get_tenant_name(self, tenant_uuid):
_tenant_dict = self.get_tenant_dict()
if tenant_uuid not in _tenant_dict:
raise TenantNotFound(_("Tenant UUID ({}) was not found.".format(tenant_uuid)))
return _tenant_dict[tenant_uuid]["name"]
def set_tenant_name(self, tenant_uuid, tenant_name):
_tenant_dict = self.get_tenant_dict()
if tenant_uuid not in _tenant_dict:
raise TenantNotFound(_("Tenant UUID ({}) was not found.".format(tenant_uuid)))
_tenant_dict[tenant_uuid]['name'] = tenant_name
return self.driver.set_tenant_dict(_tenant_dict)
def get_extension_uuid(self, tenant_uuid, scope="authz"):
"""
Return the UUID of the scoped extension for a particular tenant.
:param tenant_uuid: UUID of the tenant
:param scope: "admin" or "authz"
:return (str): the UUID of the scoped extension
"""
# 1 tenant only with 1 authz extension and 1 admin extension
_tenant_dict = self.get_tenant_dict()
if tenant_uuid not in _tenant_dict:
raise TenantNotFound(_("Tenant UUID ({}) was not found.".format(tenant_uuid)))
if not _tenant_dict[tenant_uuid][scope]:
raise IntraExtensionNotFound(_("No IntraExtension found for Tenant {}.".format(tenant_uuid)))
return _tenant_dict[tenant_uuid][scope]
def get_tenant_uuid(self, extension_uuid):
for _tenant_uuid, _tenant_value in six.iteritems(self.get_tenant_dict()):
if extension_uuid == _tenant_value["authz"] or extension_uuid == _tenant_value["admin"]:
return _tenant_uuid
raise TenantNotFound()
def get_admin_extension_uuid(self, authz_extension_uuid):
_tenants = self.get_tenant_dict()
for _tenant_uuid in _tenants:
if authz_extension_uuid == _tenants[_tenant_uuid]['authz'] and _tenants[_tenant_uuid]['admin']:
return _tenants[_tenant_uuid]['admin']
self.moonlog_api.error(_("No IntraExtension found mapping this Authz IntraExtension: {}.".format(
authz_extension_uuid)))
# FIXME (dthom): if AdminIntraExtensionNotFound, maybe we can add an option in configuration file
# to allow or not the fact that Admin IntraExtension can be None
# raise AdminIntraExtensionNotFound()
def delete(self, authz_extension_uuid):
_tenants = self.get_tenant_dict()
for _tenant_uuid in _tenants:
if authz_extension_uuid == _tenants[_tenant_uuid]['authz']:
return self.set_tenant_dict(_tenant_uuid, "", "", "")
raise AuthzIntraExtensionNotFound(_("No IntraExtension found mapping this Authz IntraExtension: {}.".format(
authz_extension_uuid)))
def set_tenant_dict(self, tenant_uuid, name, authz_extension_uuid, admin_extension_uuid):
tenant = {
tenant_uuid: {
"name": name,
"authz": authz_extension_uuid,
"admin": admin_extension_uuid
}
}
# TODO (dthom): Tenant must be checked against Keystone database.
return self.driver.set_tenant_dict(tenant)
class TenantDriver:
def get_tenant_dict(self):
raise exception.NotImplemented() # pragma: no cover
def set_tenant_dict(self, tenant):
raise exception.NotImplemented() # pragma: no cover
@dependency.requires('identity_api', 'moonlog_api', 'tenant_api', 'authz_api', 'admin_api')
class IntraExtensionManager(manager.Manager):
__genre__ = None
def __init__(self):
driver = CONF.moon.intraextension_driver
super(IntraExtensionManager, self).__init__(driver)
def __get_authz_buffer(self, intra_extension_uuid, subject_uuid, object_uuid, action_uuid):
"""
:param intra_extension_uuid:
:param subject_uuid:
:param object_uuid:
:param action_uuid:
:return: authz_buffer = {
'subject_uuid': xxx,
'object_uuid': yyy,
'action_uuid': zzz,
'subject_attributes': {
'subject_category1': [],
'subject_category2': [],
...
'subject_categoryn': []
},
'object_attributes': {},
'action_attributes': {},
}
"""
if not self.driver.get_intra_extension(intra_extension_uuid):
raise IntraExtensionNotFound()
_authz_buffer = dict()
_authz_buffer['subject_uuid'] = subject_uuid
_authz_buffer['object_uuid'] = object_uuid
_authz_buffer['action_uuid'] = action_uuid
_meta_data_dict = {}
_meta_data_dict["subject_categories"] = self.driver.get_subject_category_dict(intra_extension_uuid)["subject_categories"]
_meta_data_dict["object_categories"] = self.driver.get_object_category_dict(intra_extension_uuid)["object_categories"]
_meta_data_dict["action_categories"] = self.driver.get_action_category_dict(intra_extension_uuid)["action_categories"]
_subject_assignment_dict = dict()
for category in _meta_data_dict["subject_categories"]:
_subject_assignment_dict[category] = self.driver.get_subject_category_assignment_dict(
intra_extension_uuid, category)["subject_category_assignments"]
_object_assignment_dict = dict()
for category in _meta_data_dict["object_categories"]:
_object_assignment_dict[category] = self.driver.get_object_category_assignment_dict(
intra_extension_uuid, category)["object_category_assignments"]
_action_assignment_dict = dict()
for category in _meta_data_dict["action_categories"]:
_action_assignment_dict[category] = self.driver.get_action_category_assignment_dict(
intra_extension_uuid, category)["action_category_assignments"]
_authz_buffer['subject_attributes'] = dict()
_authz_buffer['object_attributes'] = dict()
_authz_buffer['action_attributes'] = dict()
for _subject_category in _meta_data_dict['subject_categories']:
_authz_buffer['subject_attributes'][_subject_category] = _subject_assignment_dict[_subject_category]
for _object_category in _meta_data_dict['object_categories']:
_authz_buffer['object_attributes'][_object_category] = _object_assignment_dict[_object_category]
for _action_category in _meta_data_dict['action_categories']:
_authz_buffer['action_attributes'][_action_category] = _action_assignment_dict[_action_category]
return _authz_buffer
def authz(self, intra_extension_uuid, subject_uuid, object_uuid, action_uuid):
"""Check authorization for a particular action.
:param intra_extension_uuid: UUID of an IntraExtension
:param subject_uuid: subject UUID of the request
:param object_uuid: object UUID of the request
:param action_uuid: action UUID of the request
:return: True or False or raise an exception
:raises: (in that order)
IntraExtensionNotFound
SubjectUnknown
ObjectUnknown
ActionUnknown
SubjectCategoryAssignmentUnknown
ObjectCategoryAssignmentUnknown
ActionCategoryAssignmentUnknown
"""
_authz_buffer = self.__get_authz_buffer(intra_extension_uuid, subject_uuid, object_uuid, action_uuid)
_decision_buffer = dict()
_meta_rule_dict = self.driver.get_meta_rule_dict(intra_extension_uuid)
_rule_dict = self.driver.get_rule_dict(intra_extension_uuid)
for _rule in _meta_rule_dict['sub_meta_rules']:
if _meta_rule_dict['sub_meta_rules'][_rule]['algorithm'] == 'inclusion':
_decision_buffer[_rule] = algo_inclusion(
_authz_buffer,
_meta_rule_dict['sub_meta_rules'][_rule],
_rule_dict['rules'][_rule])
elif _meta_rule_dict['sub_meta_rules'][_rule]['algorithm'] == 'comparison':
_decision_buffer[_rule] = algo_comparison(
_authz_buffer,
_meta_rule_dict['sub_meta_rules'][_rule],
_rule_dict['rules'][_rule])
if _meta_rule_dict['aggregation'] == 'all_true':
return aggr_all_true(_decision_buffer)
return False
def get_intra_extension_list(self):
# TODO: check will be done through super_extension later
return self.driver.get_intra_extension_list()
def get_intra_extension_id_for_tenant(self, tenant_id):
for intra_extension_id in self.driver.get_intra_extension_list():
if self.driver.get_intra_extension(intra_extension_id)["tenant"] == tenant_id:
return intra_extension_id
LOG.error("IntraExtension not found for tenant {}".format(tenant_id))
raise exception.NotFound
def get_intra_extension(self, uuid):
return self.driver.get_intra_extension(uuid)
def set_perimeter_values(self, ie, policy_dir):
perimeter_path = os.path.join(policy_dir, 'perimeter.json')
f = open(perimeter_path)
json_perimeter = json.load(f)
subject_dict = dict()
# We suppose that all subjects can be mapped to a true user in Keystone
for _subject in json_perimeter['subjects']:
user = self.identity_api.get_user_by_name(_subject, "default")
subject_dict[user["id"]] = user
self.driver.set_subject_dict(ie["id"], subject_dict)
ie["subjects"] = subject_dict
# Copy all values for objects and subjects
object_dict = dict()
for _object in json_perimeter['objects']:
object_dict[uuid4().hex] = {"name": _object}
self.driver.set_object_dict(ie["id"], object_dict)
ie["objects"] = object_dict
action_dict = dict()
for _action in json_perimeter['actions']:
action_dict[uuid4().hex] = {"name": _action}
self.driver.set_action_dict(ie["id"], action_dict)
ie["ations"] = action_dict
def set_metadata_values(self, ie, policy_dir):
metadata_path = os.path.join(policy_dir, 'metadata.json')
f = open(metadata_path)
json_perimeter = json.load(f)
subject_categories_dict = dict()
for _cat in json_perimeter['subject_categories']:
subject_categories_dict[uuid4().hex] = {"name": _cat}
self.driver.set_subject_category_dict(ie["id"], subject_categories_dict)
# Initialize scope categories
for _cat in subject_categories_dict.keys():
self.driver.set_subject_category_scope_dict(ie["id"], _cat, {})
ie['subject_categories'] = subject_categories_dict
object_categories_dict = dict()
for _cat in json_perimeter['object_categories']:
object_categories_dict[uuid4().hex] = {"name": _cat}
self.driver.set_object_category_dict(ie["id"], object_categories_dict)
# Initialize scope categories
for _cat in object_categories_dict.keys():
self.driver.set_object_category_scope_dict(ie["id"], _cat, {})
ie['object_categories'] = object_categories_dict
action_categories_dict = dict()
for _cat in json_perimeter['action_categories']:
action_categories_dict[uuid4().hex] = {"name": _cat}
self.driver.set_action_category_dict(ie["id"], action_categories_dict)
# Initialize scope categories
for _cat in action_categories_dict.keys():
self.driver.set_action_category_scope_dict(ie["id"], _cat, {})
ie['action_categories'] = action_categories_dict
def set_scope_values(self, ie, policy_dir):
metadata_path = os.path.join(policy_dir, 'scope.json')
f = open(metadata_path)
json_perimeter = json.load(f)
ie['subject_category_scope'] = dict()
for category, scope in json_perimeter["subject_category_scope"].iteritems():
category = self.driver.get_uuid_from_name(ie["id"], category, self.driver.SUBJECT_CATEGORY)
_scope_dict = dict()
for _scope in scope:
_scope_dict[uuid4().hex] = {"name": _scope}
self.driver.set_subject_category_scope_dict(ie["id"], category, _scope_dict)
ie['subject_category_scope'][category] = _scope_dict
ie['object_category_scope'] = dict()
for category, scope in json_perimeter["object_category_scope"].iteritems():
category = self.driver.get_uuid_from_name(ie["id"], category, self.driver.OBJECT_CATEGORY)
_scope_dict = dict()
for _scope in scope:
_scope_dict[uuid4().hex] = {"name": _scope}
self.driver.set_object_category_scope_dict(ie["id"], category, _scope_dict)
ie['object_category_scope'][category] = _scope_dict
ie['action_category_scope'] = dict()
for category, scope in json_perimeter["action_category_scope"].iteritems():
category = self.driver.get_uuid_from_name(ie["id"], category, self.driver.ACTION_CATEGORY)
_scope_dict = dict()
for _scope in scope:
_scope_dict[uuid4().hex] = {"name": _scope}
self.driver.set_action_category_scope_dict(ie["id"], category, _scope_dict)
ie['action_category_scope'][category] = _scope_dict
def set_assignments_values(self, ie, policy_dir):
f = open(os.path.join(policy_dir, 'assignment.json'))
json_assignments = json.load(f)
subject_assignments = dict()
for category_name, value in json_assignments['subject_assignments'].iteritems():
category = self.driver.get_uuid_from_name(ie["id"], category_name, self.driver.SUBJECT_CATEGORY)
for user_name in value:
user_uuid = self.driver.get_uuid_from_name(ie["id"], user_name, self.driver.SUBJECT)
if user_uuid not in subject_assignments:
subject_assignments[user_uuid] = dict()
if category not in subject_assignments[user_uuid]:
subject_assignments[user_uuid][category] = \
map(lambda x: self.driver.get_uuid_from_name(ie["id"], x, self.driver.SUBJECT_SCOPE, category_name),
value[user_name])
else:
subject_assignments[user_uuid][category].extend(
map(lambda x: self.driver.get_uuid_from_name(ie["id"], x, self.driver.SUBJECT_SCOPE, category_name),
value[user_name])
)
# Note (dthom): subject_category_assignment must be initialized because when there is no data in json
# we will not go through the for loop
self.driver.set_subject_category_assignment_dict(ie["id"])
for subject in subject_assignments:
self.driver.set_subject_category_assignment_dict(ie["id"], subject, subject_assignments[subject])
object_assignments = dict()
for category_name, value in json_assignments["object_assignments"].iteritems():
category = self.driver.get_uuid_from_name(ie["id"], category_name, self.driver.OBJECT_CATEGORY)
for object_name in value:
if object_name not in object_assignments:
object_assignments[object_name] = dict()
if category not in object_assignments[object_name]:
object_assignments[object_name][category] = \
map(lambda x: self.driver.get_uuid_from_name(ie["id"], x, self.driver.OBJECT_SCOPE, category_name),
value[object_name])
else:
object_assignments[object_name][category].extend(
map(lambda x: self.driver.get_uuid_from_name(ie["id"], x, self.driver.OBJECT_SCOPE, category_name),
value[object_name])
)
# Note (dthom): object_category_assignment must be initialized because when there is no data in json
# we will not go through the for loop
self.driver.set_object_category_assignment_dict(ie["id"])
for object in object_assignments:
self.driver.set_object_category_assignment_dict(ie["id"], object, object_assignments[object])
action_assignments = dict()
for category_name, value in json_assignments["action_assignments"].iteritems():
category = self.driver.get_uuid_from_name(ie["id"], category_name, self.driver.ACTION_CATEGORY)
for action_name in value:
if action_name not in action_assignments:
action_assignments[action_name] = dict()
if category not in action_assignments[action_name]:
action_assignments[action_name][category] = \
map(lambda x: self.driver.get_uuid_from_name(ie["id"], x, self.driver.ACTION_SCOPE, category_name),
value[action_name])
else:
action_assignments[action_name][category].extend(
map(lambda x: self.driver.get_uuid_from_name(ie["id"], x, self.driver.ACTION_SCOPE, category_name),
value[action_name])
)
# Note (dthom): action_category_assignment must be initialized because when there is no data in json
# we will not go through the for loop
self.driver.set_action_category_assignment_dict(ie["id"])
for action in action_assignments:
self.driver.set_action_category_assignment_dict(ie["id"], action, action_assignments[action])
def set_metarule_values(self, ie, policy_dir):
metadata_path = os.path.join(policy_dir, 'metarule.json')
f = open(metadata_path)
json_metarule = json.load(f)
# ie["meta_rules"] = copy.deepcopy(json_metarule)
metarule = dict()
categories = {
"subject_categories": self.driver.SUBJECT_CATEGORY,
"object_categories": self.driver.OBJECT_CATEGORY,
"action_categories": self.driver.ACTION_CATEGORY
}
# Translate value from JSON file to UUID for Database
for relation in json_metarule["sub_meta_rules"]:
metarule[relation] = dict()
for item in ("subject_categories", "object_categories", "action_categories"):
metarule[relation][item] = list()
for element in json_metarule["sub_meta_rules"][relation][item]:
metarule[relation][item].append(self.driver.get_uuid_from_name(ie["id"], element, categories[item]))
metarule[relation]["algorithm"] = json_metarule["sub_meta_rules"][relation]["algorithm"]
submetarules = {
"aggregation": json_metarule["aggregation"],
"sub_meta_rules": metarule
}
self.driver.set_meta_rule_dict(ie["id"], submetarules)
def set_subrules_values(self, ie, policy_dir):
metadata_path = os.path.join(policy_dir, 'rules.json')
f = open(metadata_path)
json_rules = json.load(f)
ie["sub_rules"] = {"rules": copy.deepcopy(json_rules)}
# Translate value from JSON file to UUID for Database
rules = dict()
sub_meta_rules = self.driver.get_meta_rule_dict(ie["id"])
for relation in json_rules:
# print(relation)
# print(self.get_sub_meta_rule_relations("admin", ie["id"]))
# if relation not in self.get_sub_meta_rule_relations("admin", ie["id"])["sub_meta_rule_relations"]:
# raise IntraExtensionException("Bad relation name {} in rules".format(relation))
rules[relation] = list()
for rule in json_rules[relation]:
subrule = list()
_rule = list(rule)
for category_uuid in sub_meta_rules["sub_meta_rules"][relation]["subject_categories"]:
scope_name = _rule.pop(0)
scope_uuid = self.driver.get_uuid_from_name(ie["id"],
scope_name,
self.driver.SUBJECT_SCOPE,
category_uuid=category_uuid)
subrule.append(scope_uuid)
for category_uuid in sub_meta_rules["sub_meta_rules"][relation]["action_categories"]:
scope_name = _rule.pop(0)
scope_uuid = self.driver.get_uuid_from_name(ie["id"],
scope_name,
self.driver.ACTION_SCOPE,
category_uuid=category_uuid)
subrule.append(scope_uuid)
for category_uuid in sub_meta_rules["sub_meta_rules"][relation]["object_categories"]:
scope_name = _rule.pop(0)
scope_uuid = self.driver.get_uuid_from_name(ie["id"],
scope_name,
self.driver.OBJECT_SCOPE,
category_uuid=category_uuid)
subrule.append(scope_uuid)
# for cat, cat_func, cat_func_cat in (
# ("subject_categories", self.driver.get_uuid_from_name, self.driver.SUBJECT_SCOPE),
# ("action_categories", self.driver.ACTION_SCOPE),
# ("object_categories", self.driver.OBJECT_SCOPE),
# ):
# for cat_value in sub_meta_rules["sub_meta_rules"][relation][cat]:
# scope = cat_func(
# ie["id"],
# cat_value,
# cat_func_cat
# )[cat_func.__name__.replace("get_", "").replace("_dict", "")]
#
# _ = rule.pop(0)
# a_scope = self.driver.get_uuid_from_name(ie["id"], _, scope[cat_value])
# subrule.append(a_scope)
# if a positive/negative value exists, all item of rule have not be consumed
if len(rule) >= 1 and type(rule[0]) is bool:
subrule.append(rule[0])
else:
# if value doesn't exist add a default value
subrule.append(True)
rules[relation].append(subrule)
self.driver.set_rule_dict(ie["id"], rules)
def load_intra_extension(self, intra_extension):
ie = dict()
# TODO: clean some values
ie['id'] = uuid4().hex
ie["name"] = filter_input(intra_extension["name"])
ie["model"] = filter_input(intra_extension["policymodel"])
ie["description"] = filter_input(intra_extension["description"])
ref = self.driver.set_intra_extension(ie['id'], ie)
self.moonlog_api.debug("Creation of IE: {}".format(ref))
# read the profile given by "policymodel" and populate default variables
policy_dir = os.path.join(CONF.moon.policy_directory, ie["model"])
self.set_perimeter_values(ie, policy_dir)
self.set_metadata_values(ie, policy_dir)
self.set_scope_values(ie, policy_dir)
self.set_assignments_values(ie, policy_dir)
self.set_metarule_values(ie, policy_dir)
self.set_subrules_values(ie, policy_dir)
return ref
def delete_intra_extension(self, intra_extension_id):
ref = self.driver.delete_intra_extension(intra_extension_id)
return ref
# Perimeter functions
@filter_args
@enforce("read", "subjects")
def get_subject_dict(self, user_uuid, intra_extension_uuid):
return self.driver.get_subject_dict(intra_extension_uuid)
@filter_args
@enforce(("read", "write"), "subjects")
def set_subject_dict(self, user_uuid, intra_extension_uuid, subject_list):
subject_dict = {}
for _user in subject_list:
# Next line will raise an error if user is not present in Keystone database
user = self.identity_api.get_user_by_name(_user["name"], "default")
subject_dict[user["id"]] = dict()
for key in user.keys():
subject_dict[user["id"]][key] = user[key]
return self.driver.set_subject_dict(intra_extension_uuid, subject_dict)
@filter_args
@enforce(("read", "write"), "subjects")
def add_subject_dict(self, user_uuid, intra_extension_uuid, subject_name):
# Next line will raise an error if user is not present in Keystone database
user = self.identity_api.get_user_by_name(subject_name, "default")
subjects = self.driver.add_subject(intra_extension_uuid, user["id"], user)
return subjects
@filter_args
@enforce("read", "subjects")
@enforce("write", "subjects")
def del_subject(self, user_uuid, intra_extension_uuid, subject_uuid):
self.driver.remove_subject(intra_extension_uuid, subject_uuid)
@filter_args
@enforce("read", "objects")
def get_object_dict(self, user_uuid, intra_extension_uuid):
return self.driver.get_object_dict(intra_extension_uuid)
@filter_args
@enforce(("read", "write"), "objects")
def set_object_dict(self, user_uuid, intra_extension_uuid, object_list):
# TODO (asteroide): we must check input here.
object_dict = {uuid4().hex: item for item in object_list}
return self.driver.set_object_dict(intra_extension_uuid, object_dict)
@filter_args
@enforce(("read", "write"), "objects")
def add_object_dict(self, user_uuid, intra_extension_uuid, object_dict):
# TODO (asteroide): we must check input here.
object_uuid = uuid4().hex
return self.driver.add_object(intra_extension_uuid, object_uuid, object_dict)
@filter_args
@enforce("read", "objects")
@enforce("write", "objects")
def del_object(self, user_uuid, intra_extension_uuid, object_uuid):
self.driver.remove_object(intra_extension_uuid, object_uuid)
@filter_args
@enforce("read", "actions")
def get_action_dict(self, user_uuid, intra_extension_uuid):
return self.driver.get_action_dict(intra_extension_uuid)
@filter_args
@enforce(("read", "write"), "actions")
def set_action_dict(self, user_uuid, intra_extension_uuid, action_list):
# TODO (asteroide): we must check input here.
action_dict = {uuid4().hex: item for item in action_list}
return self.driver.set_action_dict(intra_extension_uuid, action_dict)
@filter_args
@enforce(("read", "write"), "actions")
def add_action_dict(self, user_uuid, intra_extension_uuid, action_dict):
# TODO (asteroide): we must check input here.
action_uuid = uuid4().hex
return self.driver.add_action(intra_extension_uuid, action_uuid, action_dict)
@filter_args
@enforce("read", "actions")
@enforce("write", "actions")
def del_action(self, user_uuid, intra_extension_uuid, action_uuid):
self.driver.remove_action(intra_extension_uuid, action_uuid)
# Metadata functions
@filter_args
@enforce("read", "subject_categories")
def get_subject_category_dict(self, user_uuid, intra_extension_uuid):
return self.driver.get_subject_category_dict(intra_extension_uuid)
@filter_args
@enforce("read", "subject_categories")
@enforce("read", "subject_category_scope")
@enforce("write", "subject_category_scope")
def set_subject_category_dict(self, user_uuid, intra_extension_uuid, subject_category_list):
subject_category = {uuid4().hex: item for item in subject_category_list}
subject_category_dict = self.driver.set_subject_category_dict(intra_extension_uuid, subject_category)
# if we add a new category, we must add it to the subject_category_scope
for _cat in subject_category.keys():
try:
_ = self.driver.get_subject_category_scope_dict(intra_extension_uuid, _cat)
except SubjectScopeUnknown:
self.driver.set_subject_category_scope_dict(intra_extension_uuid, _cat, {})
return subject_category_dict
@filter_args
@enforce("read", "subject_categories")
@enforce("write", "subject_categories")
def add_subject_category_dict(self, user_uuid, intra_extension_uuid, subject_category_dict):
# TODO (asteroide): we must check input here.
subject_category_uuid = uuid4().hex
subject_categories = self.driver.add_subject_category_dict(
intra_extension_uuid, subject_category_uuid, subject_category_dict)
return subject_categories
@filter_args
@enforce("write", "subject_categories")
def del_subject_category(self, user_uuid, intra_extension_uuid, subject_uuid):
return self.driver.remove_subject_category(intra_extension_uuid, subject_uuid)
@filter_args
@enforce("read", "object_categories")
def get_object_category_dict(self, user_uuid, intra_extension_uuid):
return self.driver.get_object_category_dict(intra_extension_uuid)
@filter_args
@enforce("read", "object_categories")
@enforce("read", "object_category_scope")
@enforce("write", "object_category_scope")
def set_object_category_dict(self, user_uuid, intra_extension_uuid, object_category_list):
# TODO (asteroide): we must check input here.
object_category = {uuid4().hex: item for item in object_category_list}
object_category_dict = self.driver.set_object_category_dict(intra_extension_uuid, object_category)
# if we add a new category, we must add it to the object_category_scope
for _cat in object_category.keys():
try:
_ = self.driver.get_object_category_scope_dict(intra_extension_uuid, _cat)
except ObjectScopeUnknown:
self.driver.set_object_category_scope_dict(intra_extension_uuid, _cat, {})
return object_category_dict
@filter_args
@enforce("read", "object_categories")
@enforce("write", "object_categories")
def add_object_category_dict(self, user_uuid, intra_extension_uuid, object_category_dict):
# TODO (asteroide): we must check input here.
object_category_uuid = uuid4().hex
object_categories = self.driver.add_object_category_dict(
intra_extension_uuid, object_category_uuid, object_category_dict)
return object_categories
@filter_args
@enforce("write", "object_categories")
def del_object_category(self, user_uuid, intra_extension_uuid, object_uuid):
return self.driver.remove_object_category(intra_extension_uuid, object_uuid)
@filter_args
@enforce("read", "action_categories")
def get_action_category_dict(self, user_uuid, intra_extension_uuid):
return self.driver.get_action_category_dict(intra_extension_uuid)
@filter_args
@enforce("read", "action_categories")
@enforce("read", "action_category_scope")
@enforce("write", "action_category_scope")
def set_action_category_dict(self, user_uuid, intra_extension_uuid, action_category_list):
# TODO (asteroide): we must check input here.
action_category = {uuid4().hex: item for item in action_category_list}
action_category_dict = self.driver.set_action_category_dict(intra_extension_uuid, action_category)
# if we add a new category, we must add it to the action_category_scope
for _cat in action_category.keys():
try:
_ = self.driver.get_action_category_scope_dict(intra_extension_uuid, _cat)
except ActionScopeUnknown:
self.driver.set_action_category_scope_dict(intra_extension_uuid, _cat, {})
return action_category_dict
@filter_args
@enforce("read", "action_categories")
@enforce("write", "action_categories")
def add_action_category_dict(self, user_uuid, intra_extension_uuid, action_category_dict):
# TODO (asteroide): we must check input here.
action_category_uuid = uuid4().hex
action_categories = self.driver.add_action_category_dict(
intra_extension_uuid, action_category_uuid, action_category_dict)
return action_categories
@filter_args
@enforce("write", "action_categories")
def del_action_category(self, user_uuid, intra_extension_uuid, action_uuid):
return self.driver.remove_action_category(intra_extension_uuid, action_uuid)
# Scope functions
@filter_args
@enforce("read", "subject_category_scope")
@enforce("read", "subject_category")
def get_subject_category_scope_dict(self, user_uuid, intra_extension_uuid, category):
if category not in self.get_subject_category_dict(user_uuid, intra_extension_uuid)["subject_categories"]:
raise SubjectCategoryUnknown()
return self.driver.get_subject_category_scope_dict(intra_extension_uuid, category)
@filter_args
@enforce("read", "subject_category_scope")
@enforce("read", "subject_category")
def set_subject_category_scope_dict(self, user_uuid, intra_extension_uuid, category_uuid, scope_list):
# TODO (asteroide): we must check input here.
scope_dict = {uuid4().hex: item for item in scope_list}
return self.driver.set_subject_category_scope_dict(intra_extension_uuid, category_uuid, scope_dict)
@filter_args
@enforce(("read", "write"), "subject_category_scope")
@enforce("read", "subject_category")
def add_subject_category_scope_dict(self, user_uuid, intra_extension_uuid, category_uuid, scope_dict):
# TODO (asteroide): we must check input here.
scope_uuid = uuid4().hex
return self.driver.add_subject_category_scope_dict(
intra_extension_uuid,
category_uuid,
scope_uuid,
scope_dict)
@filter_args
@enforce("write", "subject_category_scope")
@enforce("read", "subject_category")
def del_subject_category_scope(self, user_uuid, intra_extension_uuid, category_uuid, scope_uuid):
self.driver.remove_subject_category_scope_dict(
intra_extension_uuid,
category_uuid,
scope_uuid)
@filter_args
@enforce("read", "object_category_scope")
@enforce("read", "object_category")
def get_object_category_scope_dict(self, user_uuid, intra_extension_uuid, category_uuid):
return self.driver.get_object_category_scope_dict(intra_extension_uuid, category_uuid)
@filter_args
@enforce("read", "object_category_scope")
@enforce("read", "object_category")
def set_object_category_scope_dict(self, user_uuid, intra_extension_uuid, category_uuid, scope_list):
# TODO (asteroide): we must check input here.
scope_dict = {uuid4().hex: item for item in scope_list}
return self.driver.set_object_category_scope_dict(intra_extension_uuid, category_uuid, scope_dict)
@filter_args
@enforce(("read", "write"), "object_category_scope")
@enforce("read", "object_category")
def add_object_category_scope_dict(self, user_uuid, intra_extension_uuid, category_uuid, scope_dict):
# TODO (asteroide): we must check input here.
scope_uuid = uuid4().hex
return self.driver.add_subject_category_scope_dict(
intra_extension_uuid,
category_uuid,
scope_uuid,
scope_dict)
@filter_args
@enforce("write", "object_category_scope")
@enforce("read", "object_category")
def del_object_category_scope(self, user_uuid, intra_extension_uuid, category_uuid, scope_uuid):
self.driver.remove_object_category_scope_dict(
intra_extension_uuid,
category_uuid,
scope_uuid)
@filter_args
@enforce("read", "action_category_scope")
@enforce("read", "action_category")
def get_action_category_scope_dict(self, user_uuid, intra_extension_uuid, category_uuid):
return self.driver.get_action_category_scope_dict(intra_extension_uuid, category_uuid)
@filter_args
@enforce(("read", "write"), "action_category_scope")
@enforce("read", "action_category")
def set_action_category_scope_dict(self, user_uuid, intra_extension_uuid, category_uuid, scope_list):
# TODO (asteroide): we must check input here.
scope_dict = {uuid4().hex: item for item in scope_list}
return self.driver.set_action_category_scope_dict(intra_extension_uuid, category_uuid, scope_dict)
@filter_args
@enforce(("read", "write"), "action_category_scope")
@enforce("read", "action_category")
def add_action_category_scope_dict(self, user_uuid, intra_extension_uuid, category_uuid, scope_dict):
# TODO (asteroide): we must check input here.
scope_uuid = uuid4().hex
return self.driver.add_action_category_scope_dict(
intra_extension_uuid,
category_uuid,
scope_uuid,
scope_dict)
@filter_args
@enforce("write", "action_category_scope")
@enforce("read", "action_category")
def del_action_category_scope(self, user_uuid, intra_extension_uuid, category_uuid, scope_uuid):
self.driver.remove_action_category_scope_dict(
intra_extension_uuid,
category_uuid,
scope_uuid)
# Assignment functions
@filter_args
@enforce("read", "subject_category_assignment")
@enforce("read", "subjects")
def get_subject_category_assignment_dict(self, user_uuid, intra_extension_uuid, subject_uuid):
return self.driver.get_subject_category_assignment_dict(intra_extension_uuid, subject_uuid)
@filter_args
@enforce("read", "subject_category_assignment")
@enforce("write", "subject_category_assignment")
@enforce("read", "subjects")
def set_subject_category_assignment_dict(self, user_uuid, intra_extension_uuid, subject_uuid, assignment_dict):
# TODO (asteroide): we must check input here.
return self.driver.set_subject_category_assignment_dict(intra_extension_uuid, subject_uuid, assignment_dict)
@filter_args
@enforce("read", "subject_category_assignment")
@enforce("write", "subject_category_assignment")
@enforce("read", "subjects")
@enforce("read", "subject_category")
@enforce("read", "subject_scope")
def del_subject_category_assignment(self, user_uuid, intra_extension_uuid, subject_uuid, category_uuid, scope_uuid):
self.driver.remove_subject_category_assignment(intra_extension_uuid, subject_uuid, category_uuid, scope_uuid)
@filter_args
@enforce("write", "subject_category_assignment")
@enforce("read", "subjects")
@enforce("read", "subject_category")
def add_subject_category_assignment_dict(self,
user_uuid,
intra_extension_uuid,
subject_uuid,
category_uuid,
scope_uuid):
return self.driver.add_subject_category_assignment_dict(
intra_extension_uuid, subject_uuid, category_uuid, scope_uuid)
@filter_args
@enforce("read", "object_category_assignment")
@enforce("read", "objects")
def get_object_category_assignment_dict(self, user_uuid, intra_extension_uuid, object_uuid):
return self.driver.get_object_category_assignment_dict(intra_extension_uuid, object_uuid)
@filter_args
@enforce("read", "object_category_assignment")
@enforce("write", "object_category_assignment")
@enforce("read", "objects")
def set_object_category_assignment_dict(self, user_uuid, intra_extension_uuid, object_uuid, assignment_dict):
# TODO (asteroide): we must check input here.
return self.driver.set_object_category_assignment_dict(intra_extension_uuid, object_uuid, assignment_dict)
@filter_args
@enforce("read", "object_category_assignment")
@enforce("write", "object_category_assignment")
@enforce("read", "objects")
@enforce("read", "object_category")
def del_object_category_assignment(self, user_uuid, intra_extension_uuid, object_uuid, category_uuid, scope_uuid):
self.driver.remove_object_category_assignment(intra_extension_uuid, object_uuid, category_uuid, scope_uuid)
@filter_args
@enforce("write", "object_category_assignment")
@enforce("read", "objects")
@enforce("read", "object_category")
def add_object_category_assignment_dict(self,
user_uuid,
intra_extension_uuid,
object_uuid,
category_uuid,
scope_uuid):
return self.driver.add_object_category_assignment_dict(
intra_extension_uuid, object_uuid, category_uuid, scope_uuid)
@filter_args
@enforce("read", "action_category_assignment")
@enforce("read", "actions")
def get_action_category_assignment_dict(self, user_uuid, intra_extension_uuid, action_uuid):
return self.driver.get_action_category_assignment_dict(intra_extension_uuid, action_uuid)
@filter_args
@enforce("read", "action_category_assignment")
@enforce("write", "action_category_assignment")
@enforce("read", "actions")
def set_action_category_assignment_dict(self, user_uuid, intra_extension_uuid, action_uuid, assignment_dict):
# TODO (asteroide): we must check input here.
return self.driver.set_action_category_assignment_dict(intra_extension_uuid, action_uuid, assignment_dict)
@filter_args
@enforce("read", "action_category_assignment")
@enforce("write", "action_category_assignment")
@enforce("read", "actions")
@enforce("read", "action_category")
def del_action_category_assignment(self, user_uuid, intra_extension_uuid, action_uuid, category_uuid, scope_uuid):
self.driver.remove_action_category_assignment(intra_extension_uuid, action_uuid, category_uuid, scope_uuid)
@filter_args
@enforce("write", "action_category_assignment")
@enforce("read", "actions")
@enforce("read", "action_category")
def add_action_category_assignment_dict(self,
user_uuid,
intra_extension_uuid,
action_uuid,
category_uuid,
scope_uuid):
return self.driver.add_action_category_assignment_dict(
intra_extension_uuid,
action_uuid,
category_uuid,
scope_uuid
)
# Metarule functions
@filter_args
def get_aggregation_algorithms(self, user_uuid, intra_extension_uuid):
# TODO: check which algorithms are really usable
return {"aggregation_algorithms": ["and_true_aggregation", "test_aggregation", "all_true"]}
@filter_args
@enforce("read", "aggregation_algorithms")
def get_aggregation_algorithm(self, user_uuid, intra_extension_uuid):
return self.driver.get_meta_rule_dict(intra_extension_uuid)
@filter_args
@enforce("read", "aggregation_algorithms")
@enforce("write", "aggregation_algorithms")
def set_aggregation_algorithm(self, user_uuid, intra_extension_uuid, aggregation_algorithm):
if aggregation_algorithm not in self.get_aggregation_algorithms(
user_uuid, intra_extension_uuid)["aggregation_algorithms"]:
raise IntraExtensionError("Unknown aggregation_algorithm: {}".format(aggregation_algorithm))
meta_rule = self.driver.get_meta_rule_dict(intra_extension_uuid)
meta_rule["aggregation"] = aggregation_algorithm
return self.driver.set_meta_rule_dict(intra_extension_uuid, meta_rule)
@filter_args
@enforce("read", "sub_meta_rule")
def get_sub_meta_rule(self, user_uuid, intra_extension_uuid):
return self.driver.get_meta_rule_dict(intra_extension_uuid)
@filter_args
@enforce("read", "sub_meta_rule")
@enforce("write", "sub_meta_rule")
def set_sub_meta_rule(self, user_uuid, intra_extension_uuid, sub_meta_rules):
# TODO: check which algorithms are really usable
# TODO (dthom): When sub_meta_rule is set, all rules must be dropped
# because the previous rules cannot be mapped to the new sub_meta_rule.
for relation in sub_meta_rules.keys():
if relation not in self.get_sub_meta_rule_relations(user_uuid, intra_extension_uuid)["sub_meta_rule_relations"]:
raise IntraExtensionError("set_sub_meta_rule unknown MetaRule relation {}".format(relation))
for cat in ("subject_categories", "object_categories", "action_categories"):
if cat not in sub_meta_rules[relation]:
raise IntraExtensionError("set_sub_meta_rule category {} missed".format(cat))
if type(sub_meta_rules[relation][cat]) is not list:
raise IntraExtensionError("set_sub_meta_rule category {} is not a list".format(cat))
subject_categories = self.get_subject_category_dict(user_uuid, intra_extension_uuid)["subject_categories"]
for data in list(sub_meta_rules[relation]["subject_categories"]):
if data not in subject_categories:
raise IntraExtensionError("set_sub_meta_rule category {} is not part of subject_categories {}".format(
data, subject_categories))
object_categories = self.get_object_category_dict(user_uuid, intra_extension_uuid)["object_categories"]
for data in sub_meta_rules[relation]["object_categories"]:
if data not in object_categories:
raise IntraExtensionError("set_sub_meta_rule category {} is not part of object_categories {}".format(
data, object_categories))
action_categories = self.get_action_category_dict(user_uuid, intra_extension_uuid)["actions_categories"]
for data in sub_meta_rules[relation]["action_categories"]:
if data not in action_categories:
raise IntraExtensionError("set_sub_meta_rule category {} is not part of action_categories {}".format(
data, action_categories))
aggregation = self.driver.get_meta_rule_dict(intra_extension_uuid)["aggregation"]
return self.driver.set_meta_rule_dict(
intra_extension_uuid,
{
"aggregation": aggregation,
"sub_meta_rules": sub_meta_rules
})
# Sub-rules functions
@filter_args
@enforce("read", "sub_rules")
def get_rules(self, user_uuid, intra_extension_uuid):
return self.driver.get_rules(intra_extension_uuid)
@filter_args
@enforce("read", "sub_rules")
@enforce("write", "sub_rules")
def set_rule(self, user_uuid, intra_extension_uuid, relation, sub_rule):
for item in sub_rule:
if type(item) not in (str, unicode, bool):
raise IntraExtensionError("Bad input data (sub_rule).")
ref_rules = self.driver.get_rules(intra_extension_uuid)
_sub_rule = list(sub_rule)
if relation not in self.get_sub_meta_rule_relations(user_uuid, intra_extension_uuid)["sub_meta_rule_relations"]:
raise IntraExtensionError("Bad input data (rules).")
# filter strings in sub_rule
sub_rule = [filter_input(x) for x in sub_rule]
# check if length of sub_rule is correct from metadata_sub_rule
metadata_sub_rule = self.get_sub_meta_rule(user_uuid, intra_extension_uuid)
metadata_sub_rule_length = len(metadata_sub_rule['sub_meta_rules'][relation]["subject_categories"]) + \
len(metadata_sub_rule['sub_meta_rules'][relation]["action_categories"]) + \
len(metadata_sub_rule['sub_meta_rules'][relation]["object_categories"]) + 1
if metadata_sub_rule_length != len(sub_rule):
raise IntraExtensionError("Bad number of argument in sub_rule {}/{}".format(sub_rule,
metadata_sub_rule_length))
# check if each item in sub_rule match a corresponding scope value
for category in metadata_sub_rule['sub_meta_rules'][relation]["subject_categories"]:
item = _sub_rule.pop(0)
if item not in self.get_subject_category_scope_dict(
user_uuid,
intra_extension_uuid, category)["subject_category_scope"][category].keys():
raise IntraExtensionError("Bad subject value in sub_rule {}/{}".format(category, item))
for category in metadata_sub_rule['sub_meta_rules'][relation]["action_categories"]:
action_categories = self.get_action_category_scope_dict(
user_uuid,
intra_extension_uuid, category)["action_category_scope"][category]
item = _sub_rule.pop(0)
if item not in action_categories.keys():
self.moonlog_api.warning("set_sub_rule bad action value in sub_rule {}/{}".format(category, item))
raise IntraExtensionError("Bad input data.")
for category in metadata_sub_rule['sub_meta_rules'][relation]["object_categories"]:
item = _sub_rule.pop(0)
if item not in self.get_object_category_scope_dict(
user_uuid,
intra_extension_uuid, category)["object_category_scope"][category].keys():
raise IntraExtensionError("Bad object value in sub_rule {}/{}".format(category, item))
# check if relation is already there
if relation not in ref_rules["rules"]:
ref_rules["rules"][relation] = list()
# add sub_rule
ref_rules["rules"][relation].append(sub_rule)
return self.driver.set_rules(intra_extension_uuid, ref_rules["rules"])
@filter_args
@enforce("read", "sub_rules")
@enforce("write", "sub_rules")
def del_rule(self, user_uuid, intra_extension_uuid, relation_name, sub_rule):
ref_rules = self.driver.get_rules(intra_extension_uuid)
sub_rule = sub_rule.split("+")
for index, _item in enumerate(sub_rule):
if "True" in _item:
sub_rule[index] = True
if "False" in _item:
sub_rule[index] = False
if relation_name in ref_rules["rules"]:
if sub_rule in ref_rules["rules"][relation_name]:
ref_rules["rules"][relation_name].remove(sub_rule)
else:
raise RuleUnknown()
else:
raise IntraExtensionError("Unknown relation name for rules: {}".format(relation_name))
self.driver.set_rules(intra_extension_uuid, ref_rules["rules"])
@dependency.provider('authz_api')
@dependency.requires('identity_api', 'moonlog_api', 'tenant_api')
class IntraExtensionAuthzManager(IntraExtensionManager):
__genre__ = "authz"
def authz(self, tenant_uuid, sub, obj, act):
"""Check authorization for a particular action.
:param tenant_uuid: UUID of a tenant
:param sub: subject of the request
:param obj: object of the request
:param act: action of the request
:return: True or False or raise an exception
"""
_intra_authz_extention_uuid = self.tenant_api.get_extension_uuid(tenant_uuid, "authz")
return super(IntraExtensionAuthzManager, self).authz(_intra_authz_extention_uuid, sub, obj, act)
def delete_intra_extension(self, intra_extension_id):
raise AdminException()
def set_subject_dict(self, user_uuid, intra_extension_uuid, subject_dict):
raise SubjectAddNotAuthorized()
def add_subject_dict(self, user_uuid, intra_extension_uuid, subject_name):
raise SubjectAddNotAuthorized()
def del_subject(self, user_uuid, intra_extension_uuid, subject_name):
raise SubjectDelNotAuthorized()
def set_object_dict(self, user_uuid, intra_extension_uuid, object_dict):
raise ObjectAddNotAuthorized()
def add_object_dict(self, user_uuid, intra_extension_uuid, object_name):
raise ObjectAddNotAuthorized()
def del_object(self, user_uuid, intra_extension_uuid, object_uuid):
raise ObjectDelNotAuthorized()
def set_action_dict(self, user_uuid, intra_extension_uuid, action_dict):
raise ActionAddNotAuthorized()
def add_action_dict(self, user_uuid, intra_extension_uuid, action_dict):
raise ActionAddNotAuthorized()
def del_action(self, user_uuid, intra_extension_uuid, action_uuid):
raise ActionDelNotAuthorized()
def set_subject_category_dict(self, user_uuid, intra_extension_uuid, subject_category):
raise SubjectCategoryAddNotAuthorized()
def add_subject_category_dict(self, user_uuid, intra_extension_uuid, subject_category_name):
raise SubjectCategoryAddNotAuthorized()
def del_subject_category(self, user_uuid, intra_extension_uuid, subject_uuid):
raise SubjectCategoryDelNotAuthorized()
def set_object_category_dict(self, user_uuid, intra_extension_uuid, object_category):
raise ObjectCategoryAddNotAuthorized()
def add_object_category_dict(self, user_uuid, intra_extension_uuid, object_category_name):
raise ObjectCategoryAddNotAuthorized()
def del_object_category(self, user_uuid, intra_extension_uuid, object_uuid):
raise ObjectCategoryDelNotAuthorized()
def set_action_category_dict(self, user_uuid, intra_extension_uuid, action_category):
raise ActionCategoryAddNotAuthorized()
def add_action_category_dict(self, user_uuid, intra_extension_uuid, action_category_name):
raise ActionCategoryAddNotAuthorized()
def del_action_category(self, user_uuid, intra_extension_uuid, action_uuid):
raise ActionCategoryDelNotAuthorized()
def set_subject_category_scope_dict(self, user_uuid, intra_extension_uuid, category, scope):
raise SubjectCategoryScopeAddNotAuthorized()
def add_subject_category_scope_dict(self, user_uuid, intra_extension_uuid, subject_category, scope_name):
raise SubjectCategoryScopeAddNotAuthorized()
def del_subject_category_scope(self, user_uuid, intra_extension_uuid, subject_category, subject_category_scope):
raise SubjectCategoryScopeDelNotAuthorized()
def set_object_category_scope_dict(self, user_uuid, intra_extension_uuid, category, scope):
raise ObjectCategoryScopeAddNotAuthorized()
def add_object_category_scope_dict(self, user_uuid, intra_extension_uuid, object_category, scope_name):
raise ObjectCategoryScopeAddNotAuthorized()
def del_object_category_scope(self, user_uuid, intra_extension_uuid, object_category, object_category_scope):
raise ObjectCategoryScopeDelNotAuthorized()
def set_action_category_scope_dict(self, user_uuid, intra_extension_uuid, category, scope):
raise ActionCategoryScopeAddNotAuthorized()
def add_action_category_scope_dict(self, user_uuid, intra_extension_uuid, action_category, scope_name):
raise ActionCategoryScopeAddNotAuthorized()
def del_action_category_scope(self, user_uuid, intra_extension_uuid, action_category, action_category_scope):
raise ActionCategoryScopeDelNotAuthorized()
def set_subject_category_assignment_dict(self, user_uuid, intra_extension_uuid, subject_uuid, assignment_dict):
raise SubjectCategoryAssignmentAddNotAuthorized()
def del_subject_category_assignment(self, user_uuid, intra_extension_uuid, subject_uuid, category_uuid, scope_uuid):
raise SubjectCategoryAssignmentAddNotAuthorized()
def add_subject_category_assignment_dict(self, user_uuid, intra_extension_uuid, subject_uuid, category_uuid, scope_uuid):
raise SubjectCategoryAssignmentDelNotAuthorized()
def set_object_category_assignment_dict(self, user_uuid, intra_extension_uuid, object_uuid, assignment_dict):
raise ObjectCategoryAssignmentAddNotAuthorized()
def del_object_category_assignment(self, user_uuid, intra_extension_uuid, object_uuid, category_uuid, scope_uuid):
raise ObjectCategoryAssignmentAddNotAuthorized()
def add_object_category_assignment_dict(self, user_uuid, intra_extension_uuid, object_uuid, category_uuid, scope_uuid):
raise ObjectCategoryAssignmentDelNotAuthorized()
def set_action_category_assignment_dict(self, user_uuid, intra_extension_uuid, action_uuid, assignment_dict):
raise ActionCategoryAssignmentAddNotAuthorized()
def del_action_category_assignment(self, user_uuid, intra_extension_uuid, action_uuid, category_uuid, scope_uuid):
raise ActionCategoryAssignmentAddNotAuthorized()
def add_action_category_assignment_dict(self, user_uuid, intra_extension_uuid, action_uuid, category_uuid, scope_uuid):
raise ActionCategoryAssignmentDelNotAuthorized()
def set_aggregation_algorithm(self, user_uuid, intra_extension_uuid, aggregation_algorithm):
raise MetaRuleAddNotAuthorized()
def set_sub_meta_rule(self, user_uuid, intra_extension_uuid, sub_meta_rules):
raise MetaRuleAddNotAuthorized()
def set_sub_rule(self, user_uuid, intra_extension_uuid, relation, sub_rule):
raise RuleAddNotAuthorized()
def del_sub_rule(self, user_uuid, intra_extension_uuid, relation_name, rule):
raise RuleAddNotAuthorized()
@dependency.provider('admin_api')
@dependency.requires('identity_api', 'moonlog_api', 'tenant_api')
class IntraExtensionAdminManager(IntraExtensionManager):
__genre__ = "admin"
# def set_perimeter_values(self, ie, policy_dir):
#
# # Check if object like "subjects", "objects", "actions" exist...
# perimeter_path = os.path.join(policy_dir, 'perimeter.json')
# f = open(perimeter_path)
# json_perimeter = json.load(f)
# for item in ("subjects", "objects", "actions"):
# if item not in json_perimeter["objects"]:
# raise AdminIntraExtensionCreationError()
#
# super(IntraExtensionAdminManager, self).set_perimeter_values(ie, policy_dir)
#
# @filter_args
# def add_subject_dict(self, user_name, uuid, subject_uuid):
# raise AdminIntraExtensionModificationNotAuthorized()
#
# @filter_args
# def del_subject(self, user_name, uuid, subject_uuid):
# raise AdminIntraExtensionModificationNotAuthorized()
class AuthzDriver(object):
def get_subject_category_list(self, extension_uuid):
raise exception.NotImplemented() # pragma: no cover
def get_object_category_list(self, extension_uuid):
raise exception.NotImplemented() # pragma: no cover
def get_action_category_list(self, extension_uuid):
raise exception.NotImplemented() # pragma: no cover
def get_subject_category_value_dict(self, extension_uuid, subject_uuid):
raise exception.NotImplemented() # pragma: no cover
def get_object_category_value_dict(self, extension_uuid, object_uuid):
raise exception.NotImplemented() # pragma: no cover
def get_action_category_value_dict(self, extension_uuid, action_uuid):
raise exception.NotImplemented() # pragma: no cover
def get_meta_rule(self, extension_uuid):
raise exception.NotImplemented() # pragma: no cover
def get_rules(self, extension_uuid):
raise exception.NotImplemented() # pragma: no cover
class UpdateDriver(object):
def get_intra_extensions(self):
raise exception.NotImplemented() # pragma: no cover
def get_intra_extension(self, extension_uuid):
raise exception.NotImplemented() # pragma: no cover
def create_intra_extensions(self, extension_uuid, intra_extension):
raise exception.NotImplemented() # pragma: no cover
def delete_intra_extensions(self, extension_uuid):
raise exception.NotImplemented() # pragma: no cover
# Getter and setter for tenant
def get_tenant(self, uuid):
raise exception.NotImplemented() # pragma: no cover
def set_tenant(self, uuid, tenant_id):
raise exception.NotImplemented() # pragma: no cover
# Getter and setter for name
def get_name(self, uuid):
raise exception.NotImplemented() # pragma: no cover
def set_name(self, uuid, name):
raise exception.NotImplemented() # pragma: no cover
# Getter and setter for model
def get_model(self, uuid):
raise exception.NotImplemented() # pragma: no cover
def set_model(self, uuid, model):
raise exception.NotImplemented() # pragma: no cover
# Getter and setter for genre
def get_genre(self, uuid):
raise exception.NotImplemented() # pragma: no cover
def set_genre(self, uuid, genre):
raise exception.NotImplemented() # pragma: no cover
# Getter and setter for description
def get_description(self, uuid):
raise exception.NotImplemented() # pragma: no cover
def set_description(self, uuid, args):
raise exception.NotImplemented() # pragma: no cover
class IntraExtensionDriver(object):
SUBJECT = 'subject'
OBJECT = 'object'
ACTION = 'action'
SUBJECT_CATEGORY = 'subject_category'
OBJECT_CATEGORY = 'object_category'
ACTION_CATEGORY = 'action_category'
SUBJECT_SCOPE = 'subject_scope'
OBJECT_SCOPE = 'object_scope'
ACTION_SCOPE = 'action_scope'
def __get_data_from_type(self,
intra_extension_uuid,
name=None,
uuid=None,
data_name=None,
category_name=None,
category_uuid=None):
def extract_name(data_dict):
for key in data_dict:
try:
yield data_dict[key]["name"]
except KeyError:
for key2 in data_dict[key]:
yield data_dict[key][key2]["name"]
data_values = list()
if data_name == self.SUBJECT:
data_values = self.get_subject_dict(intra_extension_uuid)["subjects"]
if (name and name not in extract_name(data_values)) or \
(uuid and uuid not in data_values.keys()):
raise SubjectUnknown()
elif data_name == self.OBJECT:
data_values = self.get_object_dict(intra_extension_uuid)["objects"]
if (name and name not in extract_name(data_values)) or \
(uuid and uuid not in data_values.keys()):
raise ObjectUnknown()
elif data_name == self.ACTION:
data_values = self.get_action_dict(intra_extension_uuid)["actions"]
if (name and name not in extract_name(data_values)) or \
(uuid and uuid not in data_values.keys()):
raise ActionUnknown()
elif data_name == self.SUBJECT_CATEGORY:
data_values = self.get_subject_category_dict(intra_extension_uuid)["subject_categories"]
if (name and name not in extract_name(data_values)) or \
(uuid and uuid not in data_values.keys()):
raise SubjectCategoryUnknown()
elif data_name == self.OBJECT_CATEGORY:
data_values = self.get_object_category_dict(intra_extension_uuid)["object_categories"]
if (name and name not in extract_name(data_values)) or \
(uuid and uuid not in data_values.keys()):
raise ObjectCategoryUnknown()
elif data_name == self.ACTION_CATEGORY:
data_values = self.get_action_category_dict(intra_extension_uuid)["action_categories"]
if (name and name not in extract_name(data_values)) or \
(uuid and uuid not in data_values.keys()):
raise ActionCategoryUnknown()
elif data_name == self.SUBJECT_SCOPE:
if not category_uuid:
category_uuid = self.get_uuid_from_name(intra_extension_uuid, category_name, self.SUBJECT_CATEGORY)
data_values = self.get_subject_category_scope_dict(intra_extension_uuid,
category_uuid)["subject_category_scope"]
if (name and name not in extract_name(data_values)) or \
(uuid and uuid not in data_values.keys()):
raise SubjectScopeUnknown()
elif data_name == self.OBJECT_SCOPE:
if not category_uuid:
category_uuid = self.get_uuid_from_name(intra_extension_uuid, category_name, self.OBJECT_CATEGORY)
data_values = self.get_object_category_scope_dict(intra_extension_uuid,
category_uuid)["object_category_scope"]
if (name and name not in extract_name(data_values)) or \
(uuid and uuid not in data_values.keys()):
raise ObjectScopeUnknown()
elif data_name == self.ACTION_SCOPE:
if not category_uuid:
category_uuid = self.get_uuid_from_name(intra_extension_uuid, category_name, self.ACTION_CATEGORY)
data_values = self.get_action_category_scope_dict(intra_extension_uuid,
category_uuid)["action_category_scope"]
if (name and name not in extract_name(data_values)) or \
(uuid and uuid not in data_values.keys()):
raise ActionScopeUnknown()
if category_uuid:
return data_values[category_uuid]
return data_values
def get_uuid_from_name(self, intra_extension_uuid, name, data_name, category_name=None, category_uuid=None):
data_values = self.__get_data_from_type(
intra_extension_uuid=intra_extension_uuid,
name=name,
data_name=data_name,
category_name=category_name,
category_uuid=category_uuid,
)
return filter(lambda v: v[1]["name"] == name, data_values.iteritems())[0][0]
def get_name_from_uuid(self, intra_extension_uuid, uuid, data_name, category_name=None, category_uuid=None):
data_values = self.__get_data_from_type(
intra_extension_uuid=intra_extension_uuid,
uuid=uuid,
data_name=data_name,
category_name=category_name,
category_uuid=category_uuid,
)
return data_values[uuid]
# Getter ad Setter for subjects
def get_subject_dict(self, extension_uuid):
"""Get the list of subject for that IntraExtension
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:return: a dictionary containing all subjects for that IntraExtension, eg. {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def set_subject_dict(self, extension_uuid, subject_dict):
"""Set the list of subject for that IntraExtension
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_dict: dict of subject: {"uuid1": "name1", "uuid2": "name2"}
:type subject_dict: dict
:return: a dictionary containing all subjects for that IntraExtension, eg. {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def add_subject(self, extension_uuid, subject_uuid, subject_name):
"""Add a subject
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_uuid: Subject UUID
:type subject_uuid: string
:param subject_name: Subject name
:type subject_name: string
:return: the added subject {"uuid1": "name1"}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_subject(self, extension_uuid, subject_uuid):
"""Remove a subject
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_uuid: Subject UUID
:type subject_uuid: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
# Getter ad Setter for objects
def get_object_dict(self, extension_uuid):
"""Get the list of object for that IntraExtension
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:return: a dictionary containing all objects for that IntraExtension, eg. {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def set_object_dict(self, extension_uuid, object_dict):
"""Set the list of object for that IntraExtension
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_dict: dict of object: {"uuid1": "name1", "uuid2": "name2"}
:type object_dict: dict
:return: a dictionary containing all objects for that IntraExtension, eg. {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def add_object(self, extension_uuid, object_uuid, object_name):
"""Ad an object
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_uuid: Object UUID
:type object_uuid: string
:param object_name: Object name
:type object_name: string
:return: the added object {"uuid1": "name1"}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_object(self, extension_uuid, object_uuid):
"""Remove an object
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_uuid: Object UUID
:type object_uuid: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
# Getter ad Setter for actions
def get_action_dict(self, extension_uuid):
""" Get the list of action for that IntraExtension
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:return: a dictionary containing all actions for that IntraExtension, eg. {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def set_action_dict(self, extension_uuid, action_dict):
""" Set the list of action for that IntraExtension
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_dict: dict of actions: {"uuid1": "name1", "uuid2": "name2"}
:type action_dict: dict
:return: a dictionary containing all actions for that IntraExtension, eg. {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def add_action(self, extension_uuid, action_uuid, action_name):
"""Ad an action
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_uuid: Action UUID
:type action_uuid: string
:param action_name: Action name
:type action_name: string
:return: the added action {"uuid1": "name1"}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_action(self, extension_uuid, action_uuid):
"""Remove an action
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_uuid: Action UUID
:type action_uuid: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
# Getter ad Setter for subject_category
def get_subject_category_dict(self, extension_uuid):
"""Get a list of all subject categories
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:return: a dictionary containing all subject categories {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def set_subject_category_dict(self, extension_uuid, subject_categories):
"""Set the list of all subject categories
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_categories: dict of subject categories {"uuid1": "name1", "uuid2": "name2"}
:type subject_categories: dict
:return: a dictionary containing all subject categories {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def add_subject_category_dict(self, extension_uuid, subject_category_uuid, subject_category_name):
"""Add a subject category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_category_uuid: the UUID of the subject category
:type subject_category_uuid: string
:param subject_category_name: the name of the subject category
:type subject_category_name: string
:return: a dictionnary with the subject catgory added {"uuid1": "name1"}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_subject_category(self, extension_uuid, subject_category_uuid):
"""Remove one subject category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_category_uuid: the UUID of subject category to remove
:type subject_category_uuid: string
:return: a dictionary containing all subject categories {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
# Getter ad Setter for object_category
def get_object_category_dict(self, extension_uuid):
"""Get a list of all object categories
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:return: a dictionary containing all object categories {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def set_object_category_dict(self, extension_uuid, object_categories):
"""Set the list of all object categories
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_categories: dict of object categories {"uuid1": "name1", "uuid2": "name2"}
:type object_categories: dict
:return: a dictionary containing all object categories {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def add_object_category_dict(self, extension_uuid, object_category_uuid, object_category_name):
"""Add a object category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_category_uuid: the UUID of the object category
:type object_category_uuid: string
:param object_category_name: the name of the object category
:type object_category_name: string
:return: a dictionnary with the object catgory added {"uuid1": "name1"}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_object_category(self, extension_uuid, object_category_uuid):
"""Remove one object category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_category_uuid: the UUID of object category to remove
:type object_category_uuid: string
:return: a dictionary containing all object categories {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
# Getter ad Setter for action_category
def get_action_category_dict(self, extension_uuid):
"""Get a list of all action categories
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:return: a dictionary containing all action categories {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def set_action_category_dict(self, extension_uuid, action_categories):
"""Set the list of all action categories
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_categories: dict of action categories {"uuid1": "name1", "uuid2": "name2"}
:type action_categories: dict
:return: a dictionary containing all action categories {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
def add_action_category_dict(self, extension_uuid, action_category_uuid, action_category_name):
"""Add a action category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_category_uuid: the UUID of the action category
:type action_category_uuid: string
:param action_category_name: the name of the action category
:type action_category_name: string
:return: a dictionnary with the action catgory added {"uuid1": "name1"}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_action_category(self, extension_uuid, action_category_uuid):
"""Remove one action category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_category_uuid: the UUID of action category to remove
:type action_category_uuid: string
:return: a dictionary containing all action categories {"uuid1": "name1", "uuid2": "name2"}
"""
raise exception.NotImplemented() # pragma: no cover
# Getter and Setter for subject_category_value_scope
def get_subject_category_scope_dict(self, extension_uuid, category):
"""Get a list of all subject category scope
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param category: the category UUID where the scope values are
:type category: string
:return: a dictionary containing all subject category scope {"category1": {"scope_uuid1": "scope_name1}}
"""
raise exception.NotImplemented() # pragma: no cover
def set_subject_category_scope_dict(self, extension_uuid, subject_category, scope):
"""Set the list of all scope for that subject category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_category: the UUID of the subject category where this scope will be set
:type subject_category: string
:return: a dictionary containing all scope {"scope_uuid1": "scope_name1, "scope_uuid2": "scope_name2}
"""
raise exception.NotImplemented() # pragma: no cover
def add_subject_category_scope_dict(self, extension_uuid, subject_category, scope_uuid, scope_name):
"""Add a subject category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_category: the subject category UUID where the scope will be added
:type subject_category: string
:param scope_uuid: the UUID of the subject category
:type scope_uuid: string
:param scope_name: the name of the subject category
:type scope_name: string
:return: a dictionary containing the subject category scope added {"category1": {"scope_uuid1": "scope_name1}}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_subject_category_scope_dict(self, extension_uuid, subject_category, scope_uuid):
"""Remove one scope belonging to a subject category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_category: the UUID of subject categorywhere we can find the scope to remove
:type subject_category: string
:param scope_uuid: the UUID of the scope to remove
:type scope_uuid: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
# Getter and Setter for object_category_scope
def get_object_category_scope_dict(self, extension_uuid, category):
"""Get a list of all object category scope
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param category: the category UUID where the scope values are
:type category: string
:return: a dictionary containing all object category scope {"category1": {"scope_uuid1": "scope_name1}}
"""
raise exception.NotImplemented() # pragma: no cover
def set_object_category_scope_dict(self, extension_uuid, object_category, scope):
"""Set the list of all scope for that object category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_category: the UUID of the object category where this scope will be set
:type object_category: string
:return: a dictionary containing all scope {"scope_uuid1": "scope_name1, "scope_uuid2": "scope_name2}
"""
raise exception.NotImplemented() # pragma: no cover
def add_object_category_scope_dict(self, extension_uuid, object_category, scope_uuid, scope_name):
"""Add a object category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_category: the object category UUID where the scope will be added
:type object_category: string
:param scope_uuid: the UUID of the object category
:type scope_uuid: string
:param scope_name: the name of the object category
:type scope_name: string
:return: a dictionary containing the object category scope added {"category1": {"scope_uuid1": "scope_name1}}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_object_category_scope_dict(self, extension_uuid, object_category, scope_uuid):
"""Remove one scope belonging to a object category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_category: the UUID of object categorywhere we can find the scope to remove
:type object_category: string
:param scope_uuid: the UUID of the scope to remove
:type scope_uuid: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
# Getter and Setter for action_category_scope
def get_action_category_scope_dict(self, extension_uuid, category):
"""Get a list of all action category scope
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param category: the category UUID where the scope values are
:type category: string
:return: a dictionary containing all action category scope {"category1": {"scope_uuid1": "scope_name1}}
"""
raise exception.NotImplemented() # pragma: no cover
def set_action_category_scope_dict(self, extension_uuid, action_category, scope):
"""Set the list of all scope for that action category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_category: the UUID of the action category where this scope will be set
:type action_category: string
:return: a dictionary containing all scope {"scope_uuid1": "scope_name1, "scope_uuid2": "scope_name2}
"""
raise exception.NotImplemented() # pragma: no cover
def add_action_category_scope_dict(self, extension_uuid, action_category, scope_uuid, scope_name):
"""Add a action category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_category: the action category UUID where the scope will be added
:type action_category: string
:param scope_uuid: the UUID of the action category
:type scope_uuid: string
:param scope_name: the name of the action category
:type scope_name: string
:return: a dictionary containing the action category scope added {"category1": {"scope_uuid1": "scope_name1}}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_action_category_scope_dict(self, extension_uuid, action_category, scope_uuid):
"""Remove one scope belonging to a action category
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_category: the UUID of action categorywhere we can find the scope to remove
:type action_category: string
:param scope_uuid: the UUID of the scope to remove
:type scope_uuid: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
# Getter and Setter for subject_category_assignment
def get_subject_category_assignment_dict(self, extension_uuid, subject_uuid):
"""Get the assignment for a given subject_uuid
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_uuid: subject UUID
:type subject_uuid: string
:return: a dictionary of assignment for the given subject {"cat1": ["scope_uuid1", "scope_uuid2"]}
:raises: IntraExtensionNotFound, SubjectUnknown, SubjectCategoryAssignmentUnknown, SubjectCategoryAssignmentOutOfScope
"""
raise exception.NotImplemented() # pragma: no cover
def set_subject_category_assignment_dict(self, extension_uuid, subject_uuid, assignment_dict):
"""Set the assignment for a given subject_uuid
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_uuid: subject UUID
:type subject_uuid: string
:param assignment_dict: the assignment dictionary {"cat1": ["scope_uuid1", "scope_uuid2"]}
:type assignment_dict: dict
:return: a dictionary of assignment for the given subject {"cat1": ["scope_uuid1", "scope_uuid2"]}
"""
raise exception.NotImplemented() # pragma: no cover
def add_subject_category_assignment_dict(self, extension_uuid, subject_uuid, category_uuid, scope_uuid):
"""Add a scope to a category and to a subject
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_uuid: the subject UUID
:type subject_uuid: string
:param category_uuid: the category UUID
:type category_uuid: string
:param scope_uuid: the scope UUID
:type scope_uuid: string
:return: a dictionary of assignment for the given subject {"cat1": ["scope_uuid1", "scope_uuid2"]}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_subject_category_assignment(self, extension_uuid, subject_uuid, category_uuid, scope_uuid):
"""Remove a scope from a category and from a subject
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param subject_uuid: the subject UUID
:type subject_uuid: string
:param category_uuid: the category UUID
:type category_uuid: string
:param scope_uuid: the scope UUID
:type scope_uuid: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
# Getter and Setter for object_category_assignment
def get_object_category_assignment_dict(self, extension_uuid, object_uuid):
"""Get the assignment for a given object_uuid
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_uuid: object UUID
:type object_uuid: string
:return: a dictionary of assignment for the given object {"cat1": ["scope_uuid1", "scope_uuid2"]}
:raises: IntraExtensionNotFound, ObjectUnknown, ObjectCategoryAssignmentUnknown, ObjectCategoryAssignmentOutOfScope
"""
raise exception.NotImplemented() # pragma: no cover
def set_object_category_assignment_dict(self, extension_uuid, object_uuid, assignment_dict):
"""Set the assignment for a given object_uuid
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_uuid: object UUID
:type object_uuid: string
:param assignment_dict: the assignment dictionary {"cat1": ["scope_uuid1", "scope_uuid2"]}
:type assignment_dict: dict
:return: a dictionary of assignment for the given object {"cat1": ["scope_uuid1", "scope_uuid2"]}
"""
raise exception.NotImplemented() # pragma: no cover
def add_object_category_assignment_dict(self, extension_uuid, object_uuid, category_uuid, scope_uuid):
"""Add a scope to a category and to a object
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_uuid: the object UUID
:type object_uuid: string
:param category_uuid: the category UUID
:type category_uuid: string
:param scope_uuid: the scope UUID
:type scope_uuid: string
:return: a dictionary of assignment for the given object {"cat1": ["scope_uuid1", "scope_uuid2"]}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_object_category_assignment(self, extension_uuid, object_uuid, category_uuid, scope_uuid):
"""Remove a scope from a category and from a object
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param object_uuid: the object UUID
:type object_uuid: string
:param category_uuid: the category UUID
:type category_uuid: string
:param scope_uuid: the scope UUID
:type scope_uuid: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
# Getter and Setter for action_category_assignment
def get_action_category_assignment_dict(self, extension_uuid, action_uuid):
"""Get the assignment for a given action_uuid
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_uuid: action UUID
:type action_uuid: string
:return: a dictionary of assignment for the given action {"cat1": ["scope_uuid1", "scope_uuid2"]}
:raises: IntraExtensionNotFound, ActionUnknown, ActionCategoryAssignmentUnknown, ActionCategoryAssignmentOutOfScope
"""
raise exception.NotImplemented() # pragma: no cover
def set_action_category_assignment_dict(self, extension_uuid, action_uuid, assignment_dict):
"""Set the assignment for a given action_uuid
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_uuid: action UUID
:type action_uuid: string
:param assignment_dict: the assignment dictionary {"cat1": ["scope_uuid1", "scope_uuid2"]}
:type assignment_dict: dict
:return: a dictionary of assignment for the given action {"cat1": ["scope_uuid1", "scope_uuid2"]}
"""
raise exception.NotImplemented() # pragma: no cover
def add_action_category_assignment_dict(self, extension_uuid, action_uuid, category_uuid, scope_uuid):
"""Add a scope to a category and to a action
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_uuid: the action UUID
:type action_uuid: string
:param category_uuid: the category UUID
:type category_uuid: string
:param scope_uuid: the scope UUID
:type scope_uuid: string
:return: a dictionary of assignment for the given action {"cat1": ["scope_uuid1", "scope_uuid2"]}
"""
raise exception.NotImplemented() # pragma: no cover
def remove_action_category_assignment(self, extension_uuid, action_uuid, category_uuid, scope_uuid):
"""Remove a scope from a category and from a action
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param action_uuid: the action UUID
:type action_uuid: string
:param category_uuid: the category UUID
:type category_uuid: string
:param scope_uuid: the scope UUID
:type scope_uuid: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
# Getter and Setter for meta_rule
def get_meta_rule_dict(self, extension_uuid):
"""Get the Meta rule
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:return: a dictionary containing the meta_rule
Here is an example of a meta_rule:
{
"sub_meta_rules": {
"relation_super": {
"subject_categories": ["role"],
"action_categories": ["computing_action"],
"object_categories": ["id"],
"relation": "relation_super"
}
},
"aggregation": "and_true_aggregation"
}
"""
raise exception.NotImplemented() # pragma: no cover
def set_meta_rule_dict(self, extension_uuid, meta_rule_dict):
"""Set the Meta rule
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param meta_rule: a dictionary representing the meta_rule (see below)
:return:a dictionary containing the meta_rule
Here is an example of a meta_rule:
{
"sub_meta_rules": {
"relation_super": {
"subject_categories": ["role"],
"action_categories": ["computing_action"],
"object_categories": ["id"],
"relation": "relation_super"
}
},
"aggregation": "and_true_aggregation"
}
"""
raise exception.NotImplemented() # pragma: no cover
# Getter and Setter for rules
def get_rule_dict(self, extension_uuid):
"""Get all rules
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:return: a dictionary containing rules ie.
{
"relation_super":[
["admin", "vm_admin", "servers", True],
["admin", "vm_access", "servers", True]
]
}
All items will be UUID.
The last boolean item is the positive/negative value. If True, request that conforms to that rule
will be authorized, if false, request will be rejected.
"""
raise exception.NotImplemented() # pragma: no cover
def set_rule_dict(self, extension_uuid, rule_dict):
"""Set all rules
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param rules: a dictionary containing rules (see below)
:type rules: dict
:return: a dictionary containing rules ie.
{
"relation_super":[
["admin", "vm_admin", "servers", True],
["admin", "vm_access", "servers", True]
]
}
All items will be UUID.
The last boolean item is the positive/negative value. If True, request that conforms to that rule
will be authorized, if false, request will be rejected.
"""
raise exception.NotImplemented() # pragma: no cover
# Getter and Setter for intra_extension
def get_intra_extension_list(self):
"""Get a list of IntraExtension UUIDs
:return: a list of IntraExtension UUIDs ["uuid1", "uuid2"]
"""
raise exception.NotImplemented() # pragma: no cover
def get_intra_extension_dict(self, extension_uuid):
"""Get a description of an IntraExtension
:param extension_uuid: the UUID of the IntraExtension
:type extension_uuid: string
:return:
"""
raise exception.NotImplemented() # pragma: no cover
def set_intra_extension(self, extension_uuid, extension_dict):
"""Set a new IntraExtension
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:param extension_dict: a dictionary withe the description of the IntraExtension (see below)
:type extension_dict: dict
:return: the IntraExtension dictionary, example:
{
"id": "uuid1",
"name": "Name of the intra_extension",
"model": "Model of te intra_extension (admin or authz)"
"description": "a description of the intra_extension"
}
"""
raise exception.NotImplemented() # pragma: no cover
def delete_intra_extension(self, extension_uuid):
"""Delete an IntraExtension
:param extension_uuid: IntraExtension UUID
:type extension_uuid: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
def get_sub_meta_rule_relations(self, username, uuid):
# TODO: check which relations are really usable
return {"sub_meta_rule_relations": ["relation_super", "relation_test"]}
class LogDriver(object):
def authz(self, message):
"""Log authorization message
:param message: the message to log
:type message: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
def debug(self, message):
"""Log debug message
:param message: the message to log
:type message: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
def info(self, message):
"""Log informational message
:param message: the message to log
:type message: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
def warning(self, message):
"""Log warning message
:param message: the message to log
:type message: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
def error(self, message):
"""Log error message
:param message: the message to log
:type message: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
def critical(self, message):
"""Log critical message
:param message: the message to log
:type message: string
:return: None
"""
raise exception.NotImplemented() # pragma: no cover
def get_logs(self, options):
"""Get logs
:param options: options to filter log events
:type options: string eg: "event_number=10,from=2014-01-01-10:10:10,to=2014-01-01-12:10:10,filter=expression"
:return: a list of log events
TIME_FORMAT is '%Y-%m-%d-%H:%M:%S'
"""
raise exception.NotImplemented() # pragma: no cover
# @dependency.provider('superextension_api')
# class SuperExtensionManager(manager.Manager):
#
# def __init__(self):
# driver = CONF.moon.superextension_driver
# super(SuperExtensionManager, self).__init__(driver)
#
# def authz(self, sub, obj, act):
# #return self.driver.admin(sub, obj, act)
# return True
# @dependency.provider('interextension_api')
# @dependency.requires('identity_api')
# class InterExtensionManager(manager.Manager):
#
# def __init__(self):
# driver = CONF.moon.interextension_driver
# super(InterExtensionManager, self).__init__(driver)
#
# def check_inter_extension(self, uuid):
# if uuid not in self.get_inter_extensions():
# LOG.error("Unknown InterExtension {}".format(uuid))
# raise exception.NotFound("InterExtension not found.")
#
# def get_inter_extensions(self):
# return self.driver.get_inter_extensions()
#
# def get_inter_extension(self, uuid):
# return self.driver.get_inter_extension(uuid)
#
# def create_inter_extension(self, inter_extension):
# ie = dict()
# ie['id'] = uuid4().hex
# ie["requesting_intra_extension_uuid"] = filter_input(inter_extension["requesting_intra_extension_uuid"])
# ie["requested_intra_extension_uuid"] = filter_input(inter_extension["requested_intra_extension_uuid"])
# ie["description"] = filter_input(inter_extension["description"])
# ie["virtual_entity_uuid"] = filter_input(inter_extension["virtual_entity_uuid"])
# ie["genre"] = filter_input(inter_extension["genre"])
#
# ref = self.driver.create_inter_extensions(ie['id'], ie)
# return ref
#
# def delete_inter_extension(self, inter_extension_id):
# LOG.error("Deleting {}".format(inter_extension_id))
# ref = self.driver.delete_inter_extensions(inter_extension_id)
# return ref
#
#
# class SuperExtensionDriver(object):
#
# def __init__(self):
# self.__super_extension = None
#
# def admin(self, sub, obj, act):
# return self.__super_extension.authz(sub, obj, act)
#
# def delegate(self, delegating_uuid, delegated_uuid, privilege): # TODO later
# pass
#
# # Getter and Setter for SuperExtensions
#
# def get_super_extensions(self):
# raise exception.NotImplemented() # pragma: no cover
#
# def create_super_extensions(self, super_id, super_extension):
# raise exception.NotImplemented() # pragma: no cover
#
#
# class InterExtensionDriver(object):
#
# # Getter and Setter for InterExtensions
#
# def get_inter_extensions(self):
# raise exception.NotImplemented() # pragma: no cover
#
# def get_inter_extension(self, uuid):
# raise exception.NotImplemented() # pragma: no cover
#
# def create_inter_extensions(self, intra_id, intra_extension):
# raise exception.NotImplemented() # pragma: no cover
#
# def delete_inter_extensions(self, intra_extension_id):
# raise exception.NotImplemented() # pragma: no cover
#
#
# class VirtualEntityDriver(object):
#
# # Getter and Setter for InterExtensions
#
# def get_virtual_entities(self):
# raise exception.NotImplemented() # pragma: no cover
#
# def create_virtual_entities(self, ve_id, virtual_entity):
# raise exception.NotImplemented() # pragma: no cover
|