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 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686
|
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import typing as t
from elastic_transport import ObjectApiResponse
from ._base import NamespacedClient
from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters
class SecurityClient(NamespacedClient):
@_rewrite_parameters(
body_fields=("grant_type", "access_token", "password", "username"),
)
def activate_user_profile(
self,
*,
grant_type: t.Optional[
t.Union[str, t.Literal["access_token", "password"]]
] = None,
access_token: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
password: t.Optional[str] = None,
pretty: t.Optional[bool] = None,
username: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Activate a user profile.</p>
<p>Create or update a user profile on behalf of another user.</p>
<p>NOTE: The user profile feature is designed only for use by Kibana and Elastic's Observability, Enterprise Search, and Elastic Security solutions.
Individual users and external applications should not call this API directly.
The calling application must have either an <code>access_token</code> or a combination of <code>username</code> and <code>password</code> for the user that the profile document is intended for.
Elastic reserves the right to change or remove this feature in future releases without prior notice.</p>
<p>This API creates or updates a profile document for end users with information that is extracted from the user's authentication object including <code>username</code>, <code>full_name,</code> <code>roles</code>, and the authentication realm.
For example, in the JWT <code>access_token</code> case, the profile user's <code>username</code> is extracted from the JWT token claim pointed to by the <code>claims.principal</code> setting of the JWT realm that authenticated the token.</p>
<p>When updating a profile document, the API enables the document if it was disabled.
Any updates do not change existing content for either the <code>labels</code> or <code>data</code> fields.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-activate-user-profile>`_
:param grant_type: The type of grant.
:param access_token: The user's Elasticsearch access token or JWT. Both `access`
and `id` JWT token types are supported and they depend on the underlying
JWT realm configuration. If you specify the `access_token` grant type, this
parameter is required. It is not valid with other grant types.
:param password: The user's password. If you specify the `password` grant type,
this parameter is required. It is not valid with other grant types.
:param username: The username that identifies the user. If you specify the `password`
grant type, this parameter is required. It is not valid with other grant
types.
"""
if grant_type is None and body is None:
raise ValueError("Empty value passed for parameter 'grant_type'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/profile/_activate"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if grant_type is not None:
__body["grant_type"] = grant_type
if access_token is not None:
__body["access_token"] = access_token
if password is not None:
__body["password"] = password
if username is not None:
__body["username"] = username
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.activate_user_profile",
path_parts=__path_parts,
)
@_rewrite_parameters()
def authenticate(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Authenticate a user.</p>
<p>Authenticates a user and returns information about the authenticated user.
Include the user information in a <a href="https://en.wikipedia.org/wiki/Basic_access_authentication">basic auth header</a>.
A successful call returns a JSON structure that shows user information such as their username, the roles that are assigned to the user, any assigned metadata, and information about the realms that authenticated and authorized the user.
If the user cannot be authenticated, this API returns a 401 status code.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-authenticate>`_
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/_authenticate"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.authenticate",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("names",),
)
def bulk_delete_role(
self,
*,
names: t.Optional[t.Sequence[str]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Bulk delete roles.</p>
<p>The role management APIs are generally the preferred way to manage roles, rather than using file-based role management.
The bulk delete roles API cannot delete roles that are defined in roles files.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-bulk-delete-role>`_
:param names: An array of role names to delete
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if names is None and body is None:
raise ValueError("Empty value passed for parameter 'names'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/role"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
if not __body:
if names is not None:
__body["names"] = names
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.bulk_delete_role",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("roles",),
)
def bulk_put_role(
self,
*,
roles: t.Optional[t.Mapping[str, t.Mapping[str, t.Any]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Bulk create or update roles.</p>
<p>The role management APIs are generally the preferred way to manage roles, rather than using file-based role management.
The bulk create or update roles API cannot update roles that are defined in roles files.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-bulk-put-role>`_
:param roles: A dictionary of role name to RoleDescriptor objects to add or update
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if roles is None and body is None:
raise ValueError("Empty value passed for parameter 'roles'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/role"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
if not __body:
if roles is not None:
__body["roles"] = roles
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.bulk_put_role",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("ids", "expiration", "metadata", "role_descriptors"),
)
def bulk_update_api_keys(
self,
*,
ids: t.Optional[t.Union[str, t.Sequence[str]]] = None,
error_trace: t.Optional[bool] = None,
expiration: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
metadata: t.Optional[t.Mapping[str, t.Any]] = None,
pretty: t.Optional[bool] = None,
role_descriptors: t.Optional[t.Mapping[str, t.Mapping[str, t.Any]]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Bulk update API keys.
Update the attributes for multiple API keys.</p>
<p>IMPORTANT: It is not possible to use an API key as the authentication credential for this API. To update API keys, the owner user's credentials are required.</p>
<p>This API is similar to the update API key API but enables you to apply the same update to multiple API keys in one API call. This operation can greatly improve performance over making individual updates.</p>
<p>It is not possible to update expired or invalidated API keys.</p>
<p>This API supports updates to API key access scope, metadata and expiration.
The access scope of each API key is derived from the <code>role_descriptors</code> you specify in the request and a snapshot of the owner user's permissions at the time of the request.
The snapshot of the owner's permissions is updated automatically on every call.</p>
<p>IMPORTANT: If you don't specify <code>role_descriptors</code> in the request, a call to this API might still change an API key's access scope. This change can occur if the owner user's permissions have changed since the API key was created or last modified.</p>
<p>A successful request returns a JSON structure that contains the IDs of all updated API keys, the IDs of API keys that already had the requested changes and did not require an update, and error details for any failed update.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-bulk-update-api-keys>`_
:param ids: The API key identifiers.
:param expiration: Expiration time for the API keys. By default, API keys never
expire. This property can be omitted to leave the value unchanged.
:param metadata: Arbitrary nested metadata to associate with the API keys. Within
the `metadata` object, top-level keys beginning with an underscore (`_`)
are reserved for system usage. Any information specified with this parameter
fully replaces metadata previously associated with the API key.
:param role_descriptors: The role descriptors to assign to the API keys. An API
key's effective permissions are an intersection of its assigned privileges
and the point-in-time snapshot of permissions of the owner user. You can
assign new privileges by specifying them in this parameter. To remove assigned
privileges, supply the `role_descriptors` parameter as an empty object `{}`.
If an API key has no assigned privileges, it inherits the owner user's full
permissions. The snapshot of the owner's permissions is always updated, whether
you supply the `role_descriptors` parameter. The structure of a role descriptor
is the same as the request for the create API keys API.
"""
if ids is None and body is None:
raise ValueError("Empty value passed for parameter 'ids'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/api_key/_bulk_update"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if ids is not None:
__body["ids"] = ids
if expiration is not None:
__body["expiration"] = expiration
if metadata is not None:
__body["metadata"] = metadata
if role_descriptors is not None:
__body["role_descriptors"] = role_descriptors
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.bulk_update_api_keys",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("password", "password_hash"),
)
def change_password(
self,
*,
username: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
password: t.Optional[str] = None,
password_hash: t.Optional[str] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Change passwords.</p>
<p>Change the passwords of users in the native realm and built-in users.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-change-password>`_
:param username: The user whose password you want to change. If you do not specify
this parameter, the password is changed for the current user.
:param password: The new password value. Passwords must be at least 6 characters
long.
:param password_hash: A hash of the new password value. This must be produced
using the same hashing algorithm as has been configured for password storage.
For more details, see the explanation of the `xpack.security.authc.password_hashing.algorithm`
setting.
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
__path_parts: t.Dict[str, str]
if username not in SKIP_IN_PATH:
__path_parts = {"username": _quote(username)}
__path = f'/_security/user/{__path_parts["username"]}/_password'
else:
__path_parts = {}
__path = "/_security/user/_password"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
if not __body:
if password is not None:
__body["password"] = password
if password_hash is not None:
__body["password_hash"] = password_hash
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.change_password",
path_parts=__path_parts,
)
@_rewrite_parameters()
def clear_api_key_cache(
self,
*,
ids: t.Union[str, t.Sequence[str]],
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Clear the API key cache.</p>
<p>Evict a subset of all entries from the API key cache.
The cache is also automatically cleared on state changes of the security index.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-clear-api-key-cache>`_
:param ids: Comma-separated list of API key IDs to evict from the API key cache.
To evict all API keys, use `*`. Does not support other wildcard patterns.
"""
if ids in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'ids'")
__path_parts: t.Dict[str, str] = {"ids": _quote(ids)}
__path = f'/_security/api_key/{__path_parts["ids"]}/_clear_cache'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
endpoint_id="security.clear_api_key_cache",
path_parts=__path_parts,
)
@_rewrite_parameters()
def clear_cached_privileges(
self,
*,
application: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Clear the privileges cache.</p>
<p>Evict privileges from the native application privilege cache.
The cache is also automatically cleared for applications that have their privileges updated.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-clear-cached-privileges>`_
:param application: A comma-separated list of applications. To clear all applications,
use an asterism (`*`). It does not support other wildcard patterns.
"""
if application in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'application'")
__path_parts: t.Dict[str, str] = {"application": _quote(application)}
__path = f'/_security/privilege/{__path_parts["application"]}/_clear_cache'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
endpoint_id="security.clear_cached_privileges",
path_parts=__path_parts,
)
@_rewrite_parameters()
def clear_cached_realms(
self,
*,
realms: t.Union[str, t.Sequence[str]],
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
usernames: t.Optional[t.Sequence[str]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Clear the user cache.</p>
<p>Evict users from the user cache.
You can completely clear the cache or evict specific users.</p>
<p>User credentials are cached in memory on each node to avoid connecting to a remote authentication service or hitting the disk for every incoming request.
There are realm settings that you can use to configure the user cache.
For more information, refer to the documentation about controlling the user cache.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-clear-cached-realms>`_
:param realms: A comma-separated list of realms. To clear all realms, use an
asterisk (`*`). It does not support other wildcard patterns.
:param usernames: A comma-separated list of the users to clear from the cache.
If you do not specify this parameter, the API evicts all users from the user
cache.
"""
if realms in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'realms'")
__path_parts: t.Dict[str, str] = {"realms": _quote(realms)}
__path = f'/_security/realm/{__path_parts["realms"]}/_clear_cache'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if usernames is not None:
__query["usernames"] = usernames
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
endpoint_id="security.clear_cached_realms",
path_parts=__path_parts,
)
@_rewrite_parameters()
def clear_cached_roles(
self,
*,
name: t.Union[str, t.Sequence[str]],
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Clear the roles cache.</p>
<p>Evict roles from the native role cache.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-clear-cached-roles>`_
:param name: A comma-separated list of roles to evict from the role cache. To
evict all roles, use an asterisk (`*`). It does not support other wildcard
patterns.
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_security/role/{__path_parts["name"]}/_clear_cache'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
endpoint_id="security.clear_cached_roles",
path_parts=__path_parts,
)
@_rewrite_parameters()
def clear_cached_service_tokens(
self,
*,
namespace: str,
service: str,
name: t.Union[str, t.Sequence[str]],
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Clear service account token caches.</p>
<p>Evict a subset of all entries from the service account token caches.
Two separate caches exist for service account tokens: one cache for tokens backed by the <code>service_tokens</code> file, and another for tokens backed by the <code>.security</code> index.
This API clears matching entries from both caches.</p>
<p>The cache for service account tokens backed by the <code>.security</code> index is cleared automatically on state changes of the security index.
The cache for tokens backed by the <code>service_tokens</code> file is cleared automatically on file changes.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-clear-cached-service-tokens>`_
:param namespace: The namespace, which is a top-level grouping of service accounts.
:param service: The name of the service, which must be unique within its namespace.
:param name: A comma-separated list of token names to evict from the service
account token caches. Use a wildcard (`*`) to evict all tokens that belong
to a service account. It does not support other wildcard patterns.
"""
if namespace in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'namespace'")
if service in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'service'")
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {
"namespace": _quote(namespace),
"service": _quote(service),
"name": _quote(name),
}
__path = f'/_security/service/{__path_parts["namespace"]}/{__path_parts["service"]}/credential/token/{__path_parts["name"]}/_clear_cache'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
endpoint_id="security.clear_cached_service_tokens",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("expiration", "metadata", "name", "role_descriptors"),
)
def create_api_key(
self,
*,
error_trace: t.Optional[bool] = None,
expiration: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
metadata: t.Optional[t.Mapping[str, t.Any]] = None,
name: t.Optional[str] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
role_descriptors: t.Optional[t.Mapping[str, t.Mapping[str, t.Any]]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create an API key.</p>
<p>Create an API key for access without requiring basic authentication.</p>
<p>IMPORTANT: If the credential that is used to authenticate this request is an API key, the derived API key cannot have any privileges.
If you specify privileges, the API returns an error.</p>
<p>A successful request returns a JSON structure that contains the API key, its unique id, and its name.
If applicable, it also returns expiration information for the API key in milliseconds.</p>
<p>NOTE: By default, API keys never expire. You can specify expiration information when you create the API keys.</p>
<p>The API keys are created by the Elasticsearch API key service, which is automatically enabled.
To configure or turn off the API key service, refer to API key service setting documentation.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-create-api-key>`_
:param expiration: The expiration time for the API key. By default, API keys
never expire.
:param metadata: Arbitrary metadata that you want to associate with the API key.
It supports nested data structure. Within the metadata object, keys beginning
with `_` are reserved for system usage.
:param name: A name for the API key.
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
:param role_descriptors: An array of role descriptors for this API key. When
it is not specified or it is an empty array, the API key will have a point
in time snapshot of permissions of the authenticated user. If you supply
role descriptors, the resultant permissions are an intersection of API keys
permissions and the authenticated user's permissions thereby limiting the
access scope for API keys. The structure of role descriptor is the same as
the request for the create role API. For more details, refer to the create
or update roles API. NOTE: Due to the way in which this permission intersection
is calculated, it is not possible to create an API key that is a child of
another API key, unless the derived key is created without any privileges.
In this case, you must explicitly specify a role descriptor with no privileges.
The derived API key can be used for authentication; it will not have authority
to call Elasticsearch APIs.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/api_key"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
if not __body:
if expiration is not None:
__body["expiration"] = expiration
if metadata is not None:
__body["metadata"] = metadata
if name is not None:
__body["name"] = name
if role_descriptors is not None:
__body["role_descriptors"] = role_descriptors
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.create_api_key",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("access", "name", "expiration", "metadata"),
)
def create_cross_cluster_api_key(
self,
*,
access: t.Optional[t.Mapping[str, t.Any]] = None,
name: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
expiration: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
metadata: t.Optional[t.Mapping[str, t.Any]] = None,
pretty: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create a cross-cluster API key.</p>
<p>Create an API key of the <code>cross_cluster</code> type for the API key based remote cluster access.
A <code>cross_cluster</code> API key cannot be used to authenticate through the REST interface.</p>
<p>IMPORTANT: To authenticate this request you must use a credential that is not an API key. Even if you use an API key that has the required privilege, the API returns an error.</p>
<p>Cross-cluster API keys are created by the Elasticsearch API key service, which is automatically enabled.</p>
<p>NOTE: Unlike REST API keys, a cross-cluster API key does not capture permissions of the authenticated user. The API key’s effective permission is exactly as specified with the <code>access</code> property.</p>
<p>A successful request returns a JSON structure that contains the API key, its unique ID, and its name. If applicable, it also returns expiration information for the API key in milliseconds.</p>
<p>By default, API keys never expire. You can specify expiration information when you create the API keys.</p>
<p>Cross-cluster API keys can only be updated with the update cross-cluster API key API.
Attempting to update them with the update REST API key API or the bulk update REST API keys API will result in an error.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-create-cross-cluster-api-key>`_
:param access: The access to be granted to this API key. The access is composed
of permissions for cross-cluster search and cross-cluster replication. At
least one of them must be specified. NOTE: No explicit privileges should
be specified for either search or replication access. The creation process
automatically converts the access specification to a role descriptor which
has relevant privileges assigned accordingly.
:param name: Specifies the name for this API key.
:param expiration: Expiration time for the API key. By default, API keys never
expire.
:param metadata: Arbitrary metadata that you want to associate with the API key.
It supports nested data structure. Within the metadata object, keys beginning
with `_` are reserved for system usage.
"""
if access is None and body is None:
raise ValueError("Empty value passed for parameter 'access'")
if name is None and body is None:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/cross_cluster/api_key"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if access is not None:
__body["access"] = access
if name is not None:
__body["name"] = name
if expiration is not None:
__body["expiration"] = expiration
if metadata is not None:
__body["metadata"] = metadata
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.create_cross_cluster_api_key",
path_parts=__path_parts,
)
@_rewrite_parameters()
def create_service_token(
self,
*,
namespace: str,
service: str,
name: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create a service account token.</p>
<p>Create a service accounts token for access without requiring basic authentication.</p>
<p>NOTE: Service account tokens never expire.
You must actively delete them if they are no longer needed.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-create-service-token>`_
:param namespace: The name of the namespace, which is a top-level grouping of
service accounts.
:param service: The name of the service.
:param name: The name for the service account token. If omitted, a random name
will be generated. Token names must be at least one and no more than 256
characters. They can contain alphanumeric characters (a-z, A-Z, 0-9), dashes
(`-`), and underscores (`_`), but cannot begin with an underscore. NOTE:
Token names must be unique in the context of the associated service account.
They must also be globally unique with their fully qualified names, which
are comprised of the service account principal and token name, such as `<namespace>/<service>/<token-name>`.
:param refresh: If `true` then refresh the affected shards to make this operation
visible to search, if `wait_for` (the default) then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if namespace in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'namespace'")
if service in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'service'")
__path_parts: t.Dict[str, str]
if (
namespace not in SKIP_IN_PATH
and service not in SKIP_IN_PATH
and name not in SKIP_IN_PATH
):
__path_parts = {
"namespace": _quote(namespace),
"service": _quote(service),
"name": _quote(name),
}
__path = f'/_security/service/{__path_parts["namespace"]}/{__path_parts["service"]}/credential/token/{__path_parts["name"]}'
__method = "PUT"
elif namespace not in SKIP_IN_PATH and service not in SKIP_IN_PATH:
__path_parts = {"namespace": _quote(namespace), "service": _quote(service)}
__path = f'/_security/service/{__path_parts["namespace"]}/{__path_parts["service"]}/credential/token'
__method = "POST"
else:
raise ValueError("Couldn't find a path for the given parameters")
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
__method,
__path,
params=__query,
headers=__headers,
endpoint_id="security.create_service_token",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("x509_certificate_chain",),
)
def delegate_pki(
self,
*,
x509_certificate_chain: t.Optional[t.Sequence[str]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Delegate PKI authentication.</p>
<p>This API implements the exchange of an X509Certificate chain for an Elasticsearch access token.
The certificate chain is validated, according to RFC 5280, by sequentially considering the trust configuration of every installed PKI realm that has <code>delegation.enabled</code> set to <code>true</code>.
A successfully trusted client certificate is also subject to the validation of the subject distinguished name according to thw <code>username_pattern</code> of the respective realm.</p>
<p>This API is called by smart and trusted proxies, such as Kibana, which terminate the user's TLS session but still want to authenticate the user by using a PKI realm—-as if the user connected directly to Elasticsearch.</p>
<p>IMPORTANT: The association between the subject public key in the target certificate and the corresponding private key is not validated.
This is part of the TLS authentication process and it is delegated to the proxy that calls this API.
The proxy is trusted to have performed the TLS authentication and this API translates that authentication into an Elasticsearch access token.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-delegate-pki>`_
:param x509_certificate_chain: The X509Certificate chain, which is represented
as an ordered string array. Each string in the array is a base64-encoded
(Section 4 of RFC4648 - not base64url-encoded) of the certificate's DER encoding.
The first element is the target certificate that contains the subject distinguished
name that is requesting access. This may be followed by additional certificates;
each subsequent certificate is used to certify the previous one.
"""
if x509_certificate_chain is None and body is None:
raise ValueError(
"Empty value passed for parameter 'x509_certificate_chain'"
)
__path_parts: t.Dict[str, str] = {}
__path = "/_security/delegate_pki"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if x509_certificate_chain is not None:
__body["x509_certificate_chain"] = x509_certificate_chain
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.delegate_pki",
path_parts=__path_parts,
)
@_rewrite_parameters()
def delete_privileges(
self,
*,
application: str,
name: t.Union[str, t.Sequence[str]],
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Delete application privileges.</p>
<p>To use this API, you must have one of the following privileges:</p>
<ul>
<li>The <code>manage_security</code> cluster privilege (or a greater privilege such as <code>all</code>).</li>
<li>The "Manage Application Privileges" global privilege for the application being referenced in the request.</li>
</ul>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-delete-privileges>`_
:param application: The name of the application. Application privileges are always
associated with exactly one application.
:param name: The name of the privilege.
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if application in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'application'")
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {
"application": _quote(application),
"name": _quote(name),
}
__path = (
f'/_security/privilege/{__path_parts["application"]}/{__path_parts["name"]}'
)
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="security.delete_privileges",
path_parts=__path_parts,
)
@_rewrite_parameters()
def delete_role(
self,
*,
name: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Delete roles.</p>
<p>Delete roles in the native realm.
The role management APIs are generally the preferred way to manage roles, rather than using file-based role management.
The delete roles API cannot remove roles that are defined in roles files.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-delete-role>`_
:param name: The name of the role.
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_security/role/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="security.delete_role",
path_parts=__path_parts,
)
@_rewrite_parameters()
def delete_role_mapping(
self,
*,
name: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Delete role mappings.</p>
<p>Role mappings define which roles are assigned to each user.
The role mapping APIs are generally the preferred way to manage role mappings rather than using role mapping files.
The delete role mappings API cannot remove role mappings that are defined in role mapping files.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-delete-role-mapping>`_
:param name: The distinct name that identifies the role mapping. The name is
used solely as an identifier to facilitate interaction via the API; it does
not affect the behavior of the mapping in any way.
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_security/role_mapping/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="security.delete_role_mapping",
path_parts=__path_parts,
)
@_rewrite_parameters()
def delete_service_token(
self,
*,
namespace: str,
service: str,
name: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Delete service account tokens.</p>
<p>Delete service account tokens for a service in a specified namespace.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-delete-service-token>`_
:param namespace: The namespace, which is a top-level grouping of service accounts.
:param service: The service name.
:param name: The name of the service account token.
:param refresh: If `true` then refresh the affected shards to make this operation
visible to search, if `wait_for` (the default) then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if namespace in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'namespace'")
if service in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'service'")
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {
"namespace": _quote(namespace),
"service": _quote(service),
"name": _quote(name),
}
__path = f'/_security/service/{__path_parts["namespace"]}/{__path_parts["service"]}/credential/token/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="security.delete_service_token",
path_parts=__path_parts,
)
@_rewrite_parameters()
def delete_user(
self,
*,
username: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Delete users.</p>
<p>Delete users from the native realm.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-delete-user>`_
:param username: An identifier for the user.
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if username in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'username'")
__path_parts: t.Dict[str, str] = {"username": _quote(username)}
__path = f'/_security/user/{__path_parts["username"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="security.delete_user",
path_parts=__path_parts,
)
@_rewrite_parameters()
def disable_user(
self,
*,
username: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Disable users.</p>
<p>Disable users in the native realm.
By default, when you create users, they are enabled.
You can use this API to revoke a user's access to Elasticsearch.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-disable-user>`_
:param username: An identifier for the user.
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if username in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'username'")
__path_parts: t.Dict[str, str] = {"username": _quote(username)}
__path = f'/_security/user/{__path_parts["username"]}/_disable'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
endpoint_id="security.disable_user",
path_parts=__path_parts,
)
@_rewrite_parameters()
def disable_user_profile(
self,
*,
uid: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Disable a user profile.</p>
<p>Disable user profiles so that they are not visible in user profile searches.</p>
<p>NOTE: The user profile feature is designed only for use by Kibana and Elastic's Observability, Enterprise Search, and Elastic Security solutions.
Individual users and external applications should not call this API directly.
Elastic reserves the right to change or remove this feature in future releases without prior notice.</p>
<p>When you activate a user profile, its automatically enabled and visible in user profile searches. You can use the disable user profile API to disable a user profile so it’s not visible in these searches.
To re-enable a disabled user profile, use the enable user profile API .</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-disable-user-profile>`_
:param uid: Unique identifier for the user profile.
:param refresh: If 'true', Elasticsearch refreshes the affected shards to make
this operation visible to search. If 'wait_for', it waits for a refresh to
make this operation visible to search. If 'false', it does nothing with refreshes.
"""
if uid in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'uid'")
__path_parts: t.Dict[str, str] = {"uid": _quote(uid)}
__path = f'/_security/profile/{__path_parts["uid"]}/_disable'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
endpoint_id="security.disable_user_profile",
path_parts=__path_parts,
)
@_rewrite_parameters()
def enable_user(
self,
*,
username: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Enable users.</p>
<p>Enable users in the native realm.
By default, when you create users, they are enabled.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-enable-user>`_
:param username: An identifier for the user.
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if username in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'username'")
__path_parts: t.Dict[str, str] = {"username": _quote(username)}
__path = f'/_security/user/{__path_parts["username"]}/_enable'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
endpoint_id="security.enable_user",
path_parts=__path_parts,
)
@_rewrite_parameters()
def enable_user_profile(
self,
*,
uid: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Enable a user profile.</p>
<p>Enable user profiles to make them visible in user profile searches.</p>
<p>NOTE: The user profile feature is designed only for use by Kibana and Elastic's Observability, Enterprise Search, and Elastic Security solutions.
Individual users and external applications should not call this API directly.
Elastic reserves the right to change or remove this feature in future releases without prior notice.</p>
<p>When you activate a user profile, it's automatically enabled and visible in user profile searches.
If you later disable the user profile, you can use the enable user profile API to make the profile visible in these searches again.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-enable-user-profile>`_
:param uid: A unique identifier for the user profile.
:param refresh: If 'true', Elasticsearch refreshes the affected shards to make
this operation visible to search. If 'wait_for', it waits for a refresh to
make this operation visible to search. If 'false', nothing is done with refreshes.
"""
if uid in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'uid'")
__path_parts: t.Dict[str, str] = {"uid": _quote(uid)}
__path = f'/_security/profile/{__path_parts["uid"]}/_enable'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
endpoint_id="security.enable_user_profile",
path_parts=__path_parts,
)
@_rewrite_parameters()
def enroll_kibana(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Enroll Kibana.</p>
<p>Enable a Kibana instance to configure itself for communication with a secured Elasticsearch cluster.</p>
<p>NOTE: This API is currently intended for internal use only by Kibana.
Kibana uses this API internally to configure itself for communications with an Elasticsearch cluster that already has security features enabled.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-enroll-kibana>`_
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/enroll/kibana"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.enroll_kibana",
path_parts=__path_parts,
)
@_rewrite_parameters()
def enroll_node(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Enroll a node.</p>
<p>Enroll a new node to allow it to join an existing cluster with security features enabled.</p>
<p>The response contains all the necessary information for the joining node to bootstrap discovery and security related settings so that it can successfully join the cluster.
The response contains key and certificate material that allows the caller to generate valid signed certificates for the HTTP layer of all nodes in the cluster.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-enroll-node>`_
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/enroll/node"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.enroll_node",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_api_key(
self,
*,
active_only: t.Optional[bool] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
id: t.Optional[str] = None,
name: t.Optional[str] = None,
owner: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
realm_name: t.Optional[str] = None,
username: t.Optional[str] = None,
with_limited_by: t.Optional[bool] = None,
with_profile_uid: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get API key information.</p>
<p>Retrieves information for one or more API keys.
NOTE: If you have only the <code>manage_own_api_key</code> privilege, this API returns only the API keys that you own.
If you have <code>read_security</code>, <code>manage_api_key</code> or greater privileges (including <code>manage_security</code>), this API returns all API keys regardless of ownership.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-api-key>`_
:param active_only: A boolean flag that can be used to query API keys that are
currently active. An API key is considered active if it is neither invalidated,
nor expired at query time. You can specify this together with other parameters
such as `owner` or `name`. If `active_only` is false, the response will include
both active and inactive (expired or invalidated) keys.
:param id: An API key id. This parameter cannot be used with any of `name`, `realm_name`
or `username`.
:param name: An API key name. This parameter cannot be used with any of `id`,
`realm_name` or `username`. It supports prefix search with wildcard.
:param owner: A boolean flag that can be used to query API keys owned by the
currently authenticated user. The `realm_name` or `username` parameters cannot
be specified when this parameter is set to `true` as they are assumed to
be the currently authenticated ones.
:param realm_name: The name of an authentication realm. This parameter cannot
be used with either `id` or `name` or when `owner` flag is set to `true`.
:param username: The username of a user. This parameter cannot be used with either
`id` or `name` or when `owner` flag is set to `true`.
:param with_limited_by: Return the snapshot of the owner user's role descriptors
associated with the API key. An API key's actual permission is the intersection
of its assigned role descriptors and the owner user's role descriptors.
:param with_profile_uid: Determines whether to also retrieve the profile uid,
for the API key owner principal, if it exists.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/api_key"
__query: t.Dict[str, t.Any] = {}
if active_only is not None:
__query["active_only"] = active_only
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if id is not None:
__query["id"] = id
if name is not None:
__query["name"] = name
if owner is not None:
__query["owner"] = owner
if pretty is not None:
__query["pretty"] = pretty
if realm_name is not None:
__query["realm_name"] = realm_name
if username is not None:
__query["username"] = username
if with_limited_by is not None:
__query["with_limited_by"] = with_limited_by
if with_profile_uid is not None:
__query["with_profile_uid"] = with_profile_uid
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_api_key",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_builtin_privileges(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get builtin privileges.</p>
<p>Get the list of cluster privileges and index privileges that are available in this version of Elasticsearch.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-builtin-privileges>`_
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/privilege/_builtin"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_builtin_privileges",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_privileges(
self,
*,
application: t.Optional[str] = None,
name: t.Optional[t.Union[str, t.Sequence[str]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get application privileges.</p>
<p>To use this API, you must have one of the following privileges:</p>
<ul>
<li>The <code>read_security</code> cluster privilege (or a greater privilege such as <code>manage_security</code> or <code>all</code>).</li>
<li>The "Manage Application Privileges" global privilege for the application being referenced in the request.</li>
</ul>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-privileges>`_
:param application: The name of the application. Application privileges are always
associated with exactly one application. If you do not specify this parameter,
the API returns information about all privileges for all applications.
:param name: The name of the privilege. If you do not specify this parameter,
the API returns information about all privileges for the requested application.
"""
__path_parts: t.Dict[str, str]
if application not in SKIP_IN_PATH and name not in SKIP_IN_PATH:
__path_parts = {"application": _quote(application), "name": _quote(name)}
__path = f'/_security/privilege/{__path_parts["application"]}/{__path_parts["name"]}'
elif application not in SKIP_IN_PATH:
__path_parts = {"application": _quote(application)}
__path = f'/_security/privilege/{__path_parts["application"]}'
else:
__path_parts = {}
__path = "/_security/privilege"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_privileges",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_role(
self,
*,
name: t.Optional[t.Union[str, t.Sequence[str]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get roles.</p>
<p>Get roles in the native realm.
The role management APIs are generally the preferred way to manage roles, rather than using file-based role management.
The get roles API cannot retrieve roles that are defined in roles files.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-role>`_
:param name: The name of the role. You can specify multiple roles as a comma-separated
list. If you do not specify this parameter, the API returns information about
all roles.
"""
__path_parts: t.Dict[str, str]
if name not in SKIP_IN_PATH:
__path_parts = {"name": _quote(name)}
__path = f'/_security/role/{__path_parts["name"]}'
else:
__path_parts = {}
__path = "/_security/role"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_role",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_role_mapping(
self,
*,
name: t.Optional[t.Union[str, t.Sequence[str]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get role mappings.</p>
<p>Role mappings define which roles are assigned to each user.
The role mapping APIs are generally the preferred way to manage role mappings rather than using role mapping files.
The get role mappings API cannot retrieve role mappings that are defined in role mapping files.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-role-mapping>`_
:param name: The distinct name that identifies the role mapping. The name is
used solely as an identifier to facilitate interaction via the API; it does
not affect the behavior of the mapping in any way. You can specify multiple
mapping names as a comma-separated list. If you do not specify this parameter,
the API returns information about all role mappings.
"""
__path_parts: t.Dict[str, str]
if name not in SKIP_IN_PATH:
__path_parts = {"name": _quote(name)}
__path = f'/_security/role_mapping/{__path_parts["name"]}'
else:
__path_parts = {}
__path = "/_security/role_mapping"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_role_mapping",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_service_accounts(
self,
*,
namespace: t.Optional[str] = None,
service: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get service accounts.</p>
<p>Get a list of service accounts that match the provided path parameters.</p>
<p>NOTE: Currently, only the <code>elastic/fleet-server</code> service account is available.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-service-accounts>`_
:param namespace: The name of the namespace. Omit this parameter to retrieve
information about all service accounts. If you omit this parameter, you must
also omit the `service` parameter.
:param service: The service name. Omit this parameter to retrieve information
about all service accounts that belong to the specified `namespace`.
"""
__path_parts: t.Dict[str, str]
if namespace not in SKIP_IN_PATH and service not in SKIP_IN_PATH:
__path_parts = {"namespace": _quote(namespace), "service": _quote(service)}
__path = f'/_security/service/{__path_parts["namespace"]}/{__path_parts["service"]}'
elif namespace not in SKIP_IN_PATH:
__path_parts = {"namespace": _quote(namespace)}
__path = f'/_security/service/{__path_parts["namespace"]}'
else:
__path_parts = {}
__path = "/_security/service"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_service_accounts",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_service_credentials(
self,
*,
namespace: str,
service: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get service account credentials.</p>
<p>To use this API, you must have at least the <code>read_security</code> cluster privilege (or a greater privilege such as <code>manage_service_account</code> or <code>manage_security</code>).</p>
<p>The response includes service account tokens that were created with the create service account tokens API as well as file-backed tokens from all nodes of the cluster.</p>
<p>NOTE: For tokens backed by the <code>service_tokens</code> file, the API collects them from all nodes of the cluster.
Tokens with the same name from different nodes are assumed to be the same token and are only counted once towards the total number of service tokens.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-service-credentials>`_
:param namespace: The name of the namespace.
:param service: The service name.
"""
if namespace in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'namespace'")
if service in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'service'")
__path_parts: t.Dict[str, str] = {
"namespace": _quote(namespace),
"service": _quote(service),
}
__path = f'/_security/service/{__path_parts["namespace"]}/{__path_parts["service"]}/credential'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_service_credentials",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_settings(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get security index settings.</p>
<p>Get the user-configurable settings for the security internal index (<code>.security</code> and associated indices).
Only a subset of the index settings — those that are user-configurable—will be shown.
This includes:</p>
<ul>
<li><code>index.auto_expand_replicas</code></li>
<li><code>index.number_of_replicas</code></li>
</ul>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-settings>`_
:param master_timeout: Period to wait for a connection to the master node. If
no response is received before the timeout expires, the request fails and
returns an error.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/settings"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_settings",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"grant_type",
"kerberos_ticket",
"password",
"refresh_token",
"scope",
"username",
),
)
def get_token(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
grant_type: t.Optional[
t.Union[
str,
t.Literal[
"_kerberos", "client_credentials", "password", "refresh_token"
],
]
] = None,
human: t.Optional[bool] = None,
kerberos_ticket: t.Optional[str] = None,
password: t.Optional[str] = None,
pretty: t.Optional[bool] = None,
refresh_token: t.Optional[str] = None,
scope: t.Optional[str] = None,
username: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get a token.</p>
<p>Create a bearer token for access without requiring basic authentication.
The tokens are created by the Elasticsearch Token Service, which is automatically enabled when you configure TLS on the HTTP interface.
Alternatively, you can explicitly enable the <code>xpack.security.authc.token.enabled</code> setting.
When you are running in production mode, a bootstrap check prevents you from enabling the token service unless you also enable TLS on the HTTP interface.</p>
<p>The get token API takes the same parameters as a typical OAuth 2.0 token API except for the use of a JSON request body.</p>
<p>A successful get token API call returns a JSON structure that contains the access token, the amount of time (seconds) that the token expires in, the type, and the scope if available.</p>
<p>The tokens returned by the get token API have a finite period of time for which they are valid and after that time period, they can no longer be used.
That time period is defined by the <code>xpack.security.authc.token.timeout</code> setting.
If you want to invalidate a token immediately, you can do so by using the invalidate token API.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-token>`_
:param grant_type: The type of grant. Supported grant types are: `password`,
`_kerberos`, `client_credentials`, and `refresh_token`.
:param kerberos_ticket: The base64 encoded kerberos ticket. If you specify the
`_kerberos` grant type, this parameter is required. This parameter is not
valid with any other supported grant type.
:param password: The user's password. If you specify the `password` grant type,
this parameter is required. This parameter is not valid with any other supported
grant type.
:param refresh_token: The string that was returned when you created the token,
which enables you to extend its life. If you specify the `refresh_token`
grant type, this parameter is required. This parameter is not valid with
any other supported grant type.
:param scope: The scope of the token. Currently tokens are only issued for a
scope of FULL regardless of the value sent with the request.
:param username: The username that identifies the user. If you specify the `password`
grant type, this parameter is required. This parameter is not valid with
any other supported grant type.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/oauth2/token"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if grant_type is not None:
__body["grant_type"] = grant_type
if kerberos_ticket is not None:
__body["kerberos_ticket"] = kerberos_ticket
if password is not None:
__body["password"] = password
if refresh_token is not None:
__body["refresh_token"] = refresh_token
if scope is not None:
__body["scope"] = scope
if username is not None:
__body["username"] = username
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.get_token",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_user(
self,
*,
username: t.Optional[t.Union[str, t.Sequence[str]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
with_profile_uid: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get users.</p>
<p>Get information about users in the native realm and built-in users.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-user>`_
:param username: An identifier for the user. You can specify multiple usernames
as a comma-separated list. If you omit this parameter, the API retrieves
information about all users.
:param with_profile_uid: Determines whether to retrieve the user profile UID,
if it exists, for the users.
"""
__path_parts: t.Dict[str, str]
if username not in SKIP_IN_PATH:
__path_parts = {"username": _quote(username)}
__path = f'/_security/user/{__path_parts["username"]}'
else:
__path_parts = {}
__path = "/_security/user"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if with_profile_uid is not None:
__query["with_profile_uid"] = with_profile_uid
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_user",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_user_privileges(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get user privileges.</p>
<p>Get the security privileges for the logged in user.
All users can use this API, but only to determine their own privileges.
To check the privileges of other users, you must use the run as feature.
To check whether a user has a specific list of privileges, use the has privileges API.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-user-privileges>`_
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/user/_privileges"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_user_privileges",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_user_profile(
self,
*,
uid: t.Union[str, t.Sequence[str]],
data: t.Optional[t.Union[str, t.Sequence[str]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get a user profile.</p>
<p>Get a user's profile using the unique profile ID.</p>
<p>NOTE: The user profile feature is designed only for use by Kibana and Elastic's Observability, Enterprise Search, and Elastic Security solutions.
Individual users and external applications should not call this API directly.
Elastic reserves the right to change or remove this feature in future releases without prior notice.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-user-profile>`_
:param uid: A unique identifier for the user profile.
:param data: A comma-separated list of filters for the `data` field of the profile
document. To return all content use `data=*`. To return a subset of content
use `data=<key>` to retrieve content nested under the specified `<key>`.
By default returns no `data` content.
"""
if uid in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'uid'")
__path_parts: t.Dict[str, str] = {"uid": _quote(uid)}
__path = f'/_security/profile/{__path_parts["uid"]}'
__query: t.Dict[str, t.Any] = {}
if data is not None:
__query["data"] = data
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.get_user_profile",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"api_key",
"grant_type",
"access_token",
"password",
"run_as",
"username",
),
ignore_deprecated_options={"api_key"},
)
def grant_api_key(
self,
*,
api_key: t.Optional[t.Mapping[str, t.Any]] = None,
grant_type: t.Optional[
t.Union[str, t.Literal["access_token", "password"]]
] = None,
access_token: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
password: t.Optional[str] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
run_as: t.Optional[str] = None,
username: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Grant an API key.</p>
<p>Create an API key on behalf of another user.
This API is similar to the create API keys API, however it creates the API key for a user that is different than the user that runs the API.
The caller must have authentication credentials for the user on whose behalf the API key will be created.
It is not possible to use this API to create an API key without that user's credentials.
The supported user authentication credential types are:</p>
<ul>
<li>username and password</li>
<li>Elasticsearch access tokens</li>
<li>JWTs</li>
</ul>
<p>The user, for whom the authentication credentials is provided, can optionally "run as" (impersonate) another user.
In this case, the API key will be created on behalf of the impersonated user.</p>
<p>This API is intended be used by applications that need to create and manage API keys for end users, but cannot guarantee that those users have permission to create API keys on their own behalf.
The API keys are created by the Elasticsearch API key service, which is automatically enabled.</p>
<p>A successful grant API key API call returns a JSON structure that contains the API key, its unique id, and its name.
If applicable, it also returns expiration information for the API key in milliseconds.</p>
<p>By default, API keys never expire. You can specify expiration information when you create the API keys.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-grant-api-key>`_
:param api_key: The API key.
:param grant_type: The type of grant. Supported grant types are: `access_token`,
`password`.
:param access_token: The user's access token. If you specify the `access_token`
grant type, this parameter is required. It is not valid with other grant
types.
:param password: The user's password. If you specify the `password` grant type,
this parameter is required. It is not valid with other grant types.
:param refresh: If 'true', Elasticsearch refreshes the affected shards to make
this operation visible to search. If 'wait_for', it waits for a refresh to
make this operation visible to search. If 'false', nothing is done with refreshes.
:param run_as: The name of the user to be impersonated.
:param username: The user name that identifies the user. If you specify the `password`
grant type, this parameter is required. It is not valid with other grant
types.
"""
if api_key is None and body is None:
raise ValueError("Empty value passed for parameter 'api_key'")
if grant_type is None and body is None:
raise ValueError("Empty value passed for parameter 'grant_type'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/api_key/grant"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
if not __body:
if api_key is not None:
__body["api_key"] = api_key
if grant_type is not None:
__body["grant_type"] = grant_type
if access_token is not None:
__body["access_token"] = access_token
if password is not None:
__body["password"] = password
if run_as is not None:
__body["run_as"] = run_as
if username is not None:
__body["username"] = username
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.grant_api_key",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("application", "cluster", "index"),
)
def has_privileges(
self,
*,
user: t.Optional[str] = None,
application: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
cluster: t.Optional[
t.Sequence[
t.Union[
str,
t.Literal[
"all",
"cancel_task",
"create_snapshot",
"cross_cluster_replication",
"cross_cluster_search",
"delegate_pki",
"grant_api_key",
"manage",
"manage_api_key",
"manage_autoscaling",
"manage_behavioral_analytics",
"manage_ccr",
"manage_data_frame_transforms",
"manage_data_stream_global_retention",
"manage_enrich",
"manage_esql",
"manage_ilm",
"manage_index_templates",
"manage_inference",
"manage_ingest_pipelines",
"manage_logstash_pipelines",
"manage_ml",
"manage_oidc",
"manage_own_api_key",
"manage_pipeline",
"manage_rollup",
"manage_saml",
"manage_search_application",
"manage_search_query_rules",
"manage_search_synonyms",
"manage_security",
"manage_service_account",
"manage_slm",
"manage_token",
"manage_transform",
"manage_user_profile",
"manage_watcher",
"monitor",
"monitor_data_frame_transforms",
"monitor_data_stream_global_retention",
"monitor_enrich",
"monitor_esql",
"monitor_inference",
"monitor_ml",
"monitor_rollup",
"monitor_snapshot",
"monitor_stats",
"monitor_text_structure",
"monitor_transform",
"monitor_watcher",
"none",
"post_behavioral_analytics_event",
"read_ccr",
"read_fleet_secrets",
"read_ilm",
"read_pipeline",
"read_security",
"read_slm",
"transport_client",
"write_connector_secrets",
"write_fleet_secrets",
],
]
]
] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
index: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
pretty: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Check user privileges.</p>
<p>Determine whether the specified user has a specified list of privileges.
All users can use this API, but only to determine their own privileges.
To check the privileges of other users, you must use the run as feature.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-has-privileges>`_
:param user: Username
:param application:
:param cluster: A list of the cluster privileges that you want to check.
:param index:
"""
__path_parts: t.Dict[str, str]
if user not in SKIP_IN_PATH:
__path_parts = {"user": _quote(user)}
__path = f'/_security/user/{__path_parts["user"]}/_has_privileges'
else:
__path_parts = {}
__path = "/_security/user/_has_privileges"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if application is not None:
__body["application"] = application
if cluster is not None:
__body["cluster"] = cluster
if index is not None:
__body["index"] = index
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.has_privileges",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("privileges", "uids"),
)
def has_privileges_user_profile(
self,
*,
privileges: t.Optional[t.Mapping[str, t.Any]] = None,
uids: t.Optional[t.Sequence[str]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Check user profile privileges.</p>
<p>Determine whether the users associated with the specified user profile IDs have all the requested privileges.</p>
<p>NOTE: The user profile feature is designed only for use by Kibana and Elastic's Observability, Enterprise Search, and Elastic Security solutions. Individual users and external applications should not call this API directly.
Elastic reserves the right to change or remove this feature in future releases without prior notice.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-has-privileges-user-profile>`_
:param privileges: An object containing all the privileges to be checked.
:param uids: A list of profile IDs. The privileges are checked for associated
users of the profiles.
"""
if privileges is None and body is None:
raise ValueError("Empty value passed for parameter 'privileges'")
if uids is None and body is None:
raise ValueError("Empty value passed for parameter 'uids'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/profile/_has_privileges"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if privileges is not None:
__body["privileges"] = privileges
if uids is not None:
__body["uids"] = uids
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.has_privileges_user_profile",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("id", "ids", "name", "owner", "realm_name", "username"),
)
def invalidate_api_key(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
id: t.Optional[str] = None,
ids: t.Optional[t.Sequence[str]] = None,
name: t.Optional[str] = None,
owner: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
realm_name: t.Optional[str] = None,
username: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Invalidate API keys.</p>
<p>This API invalidates API keys created by the create API key or grant API key APIs.
Invalidated API keys fail authentication, but they can still be viewed using the get API key information and query API key information APIs, for at least the configured retention period, until they are automatically deleted.</p>
<p>To use this API, you must have at least the <code>manage_security</code>, <code>manage_api_key</code>, or <code>manage_own_api_key</code> cluster privileges.
The <code>manage_security</code> privilege allows deleting any API key, including both REST and cross cluster API keys.
The <code>manage_api_key</code> privilege allows deleting any REST API key, but not cross cluster API keys.
The <code>manage_own_api_key</code> only allows deleting REST API keys that are owned by the user.
In addition, with the <code>manage_own_api_key</code> privilege, an invalidation request must be issued in one of the three formats:</p>
<ul>
<li>Set the parameter <code>owner=true</code>.</li>
<li>Or, set both <code>username</code> and <code>realm_name</code> to match the user's identity.</li>
<li>Or, if the request is issued by an API key, that is to say an API key invalidates itself, specify its ID in the <code>ids</code> field.</li>
</ul>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-invalidate-api-key>`_
:param id:
:param ids: A list of API key ids. This parameter cannot be used with any of
`name`, `realm_name`, or `username`.
:param name: An API key name. This parameter cannot be used with any of `ids`,
`realm_name` or `username`.
:param owner: Query API keys owned by the currently authenticated user. The `realm_name`
or `username` parameters cannot be specified when this parameter is set to
`true` as they are assumed to be the currently authenticated ones. NOTE:
At least one of `ids`, `name`, `username`, and `realm_name` must be specified
if `owner` is `false`.
:param realm_name: The name of an authentication realm. This parameter cannot
be used with either `ids` or `name`, or when `owner` flag is set to `true`.
:param username: The username of a user. This parameter cannot be used with either
`ids` or `name` or when `owner` flag is set to `true`.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/api_key"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if id is not None:
__body["id"] = id
if ids is not None:
__body["ids"] = ids
if name is not None:
__body["name"] = name
if owner is not None:
__body["owner"] = owner
if realm_name is not None:
__body["realm_name"] = realm_name
if username is not None:
__body["username"] = username
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.invalidate_api_key",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("realm_name", "refresh_token", "token", "username"),
)
def invalidate_token(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
realm_name: t.Optional[str] = None,
refresh_token: t.Optional[str] = None,
token: t.Optional[str] = None,
username: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Invalidate a token.</p>
<p>The access tokens returned by the get token API have a finite period of time for which they are valid.
After that time period, they can no longer be used.
The time period is defined by the <code>xpack.security.authc.token.timeout</code> setting.</p>
<p>The refresh tokens returned by the get token API are only valid for 24 hours.
They can also be used exactly once.
If you want to invalidate one or more access or refresh tokens immediately, use this invalidate token API.</p>
<p>NOTE: While all parameters are optional, at least one of them is required.
More specifically, either one of <code>token</code> or <code>refresh_token</code> parameters is required.
If none of these two are specified, then <code>realm_name</code> and/or <code>username</code> need to be specified.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-invalidate-token>`_
:param realm_name: The name of an authentication realm. This parameter cannot
be used with either `refresh_token` or `token`.
:param refresh_token: A refresh token. This parameter cannot be used if any of
`refresh_token`, `realm_name`, or `username` are used.
:param token: An access token. This parameter cannot be used if any of `refresh_token`,
`realm_name`, or `username` are used.
:param username: The username of a user. This parameter cannot be used with either
`refresh_token` or `token`.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/oauth2/token"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if realm_name is not None:
__body["realm_name"] = realm_name
if refresh_token is not None:
__body["refresh_token"] = refresh_token
if token is not None:
__body["token"] = token
if username is not None:
__body["username"] = username
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.invalidate_token",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("nonce", "redirect_uri", "state", "realm"),
)
def oidc_authenticate(
self,
*,
nonce: t.Optional[str] = None,
redirect_uri: t.Optional[str] = None,
state: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
realm: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Authenticate OpenID Connect.</p>
<p>Exchange an OpenID Connect authentication response message for an Elasticsearch internal access token and refresh token that can be subsequently used for authentication.</p>
<p>Elasticsearch exposes all the necessary OpenID Connect related functionality with the OpenID Connect APIs.
These APIs are used internally by Kibana in order to provide OpenID Connect based authentication, but can also be used by other, custom web applications or other clients.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-oidc-authenticate>`_
:param nonce: Associate a client session with an ID token and mitigate replay
attacks. This value needs to be the same as the one that was provided to
the `/_security/oidc/prepare` API or the one that was generated by Elasticsearch
and included in the response to that call.
:param redirect_uri: The URL to which the OpenID Connect Provider redirected
the User Agent in response to an authentication request after a successful
authentication. This URL must be provided as-is (URL encoded), taken from
the body of the response or as the value of a location header in the response
from the OpenID Connect Provider.
:param state: Maintain state between the authentication request and the response.
This value needs to be the same as the one that was provided to the `/_security/oidc/prepare`
API or the one that was generated by Elasticsearch and included in the response
to that call.
:param realm: The name of the OpenID Connect realm. This property is useful in
cases where multiple realms are defined.
"""
if nonce is None and body is None:
raise ValueError("Empty value passed for parameter 'nonce'")
if redirect_uri is None and body is None:
raise ValueError("Empty value passed for parameter 'redirect_uri'")
if state is None and body is None:
raise ValueError("Empty value passed for parameter 'state'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/oidc/authenticate"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if nonce is not None:
__body["nonce"] = nonce
if redirect_uri is not None:
__body["redirect_uri"] = redirect_uri
if state is not None:
__body["state"] = state
if realm is not None:
__body["realm"] = realm
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.oidc_authenticate",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("token", "refresh_token"),
)
def oidc_logout(
self,
*,
token: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh_token: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Logout of OpenID Connect.</p>
<p>Invalidate an access token and a refresh token that were generated as a response to the <code>/_security/oidc/authenticate</code> API.</p>
<p>If the OpenID Connect authentication realm in Elasticsearch is accordingly configured, the response to this call will contain a URI pointing to the end session endpoint of the OpenID Connect Provider in order to perform single logout.</p>
<p>Elasticsearch exposes all the necessary OpenID Connect related functionality with the OpenID Connect APIs.
These APIs are used internally by Kibana in order to provide OpenID Connect based authentication, but can also be used by other, custom web applications or other clients.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-oidc-logout>`_
:param token: The access token to be invalidated.
:param refresh_token: The refresh token to be invalidated.
"""
if token is None and body is None:
raise ValueError("Empty value passed for parameter 'token'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/oidc/logout"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if token is not None:
__body["token"] = token
if refresh_token is not None:
__body["refresh_token"] = refresh_token
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.oidc_logout",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("iss", "login_hint", "nonce", "realm", "state"),
)
def oidc_prepare_authentication(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
iss: t.Optional[str] = None,
login_hint: t.Optional[str] = None,
nonce: t.Optional[str] = None,
pretty: t.Optional[bool] = None,
realm: t.Optional[str] = None,
state: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Prepare OpenID connect authentication.</p>
<p>Create an oAuth 2.0 authentication request as a URL string based on the configuration of the OpenID Connect authentication realm in Elasticsearch.</p>
<p>The response of this API is a URL pointing to the Authorization Endpoint of the configured OpenID Connect Provider, which can be used to redirect the browser of the user in order to continue the authentication process.</p>
<p>Elasticsearch exposes all the necessary OpenID Connect related functionality with the OpenID Connect APIs.
These APIs are used internally by Kibana in order to provide OpenID Connect based authentication, but can also be used by other, custom web applications or other clients.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-oidc-prepare-authentication>`_
:param iss: In the case of a third party initiated single sign on, this is the
issuer identifier for the OP that the RP is to send the authentication request
to. It cannot be specified when *realm* is specified. One of *realm* or *iss*
is required.
:param login_hint: In the case of a third party initiated single sign on, it
is a string value that is included in the authentication request as the *login_hint*
parameter. This parameter is not valid when *realm* is specified.
:param nonce: The value used to associate a client session with an ID token and
to mitigate replay attacks. If the caller of the API does not provide a value,
Elasticsearch will generate one with sufficient entropy and return it in
the response.
:param realm: The name of the OpenID Connect realm in Elasticsearch the configuration
of which should be used in order to generate the authentication request.
It cannot be specified when *iss* is specified. One of *realm* or *iss* is
required.
:param state: The value used to maintain state between the authentication request
and the response, typically used as a Cross-Site Request Forgery mitigation.
If the caller of the API does not provide a value, Elasticsearch will generate
one with sufficient entropy and return it in the response.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/oidc/prepare"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if iss is not None:
__body["iss"] = iss
if login_hint is not None:
__body["login_hint"] = login_hint
if nonce is not None:
__body["nonce"] = nonce
if realm is not None:
__body["realm"] = realm
if state is not None:
__body["state"] = state
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.oidc_prepare_authentication",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_name="privileges",
)
def put_privileges(
self,
*,
privileges: t.Optional[
t.Mapping[str, t.Mapping[str, t.Mapping[str, t.Any]]]
] = None,
body: t.Optional[t.Mapping[str, t.Mapping[str, t.Mapping[str, t.Any]]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create or update application privileges.</p>
<p>To use this API, you must have one of the following privileges:</p>
<ul>
<li>The <code>manage_security</code> cluster privilege (or a greater privilege such as <code>all</code>).</li>
<li>The "Manage Application Privileges" global privilege for the application being referenced in the request.</li>
</ul>
<p>Application names are formed from a prefix, with an optional suffix that conform to the following rules:</p>
<ul>
<li>The prefix must begin with a lowercase ASCII letter.</li>
<li>The prefix must contain only ASCII letters or digits.</li>
<li>The prefix must be at least 3 characters long.</li>
<li>If the suffix exists, it must begin with either a dash <code>-</code> or <code>_</code>.</li>
<li>The suffix cannot contain any of the following characters: <code>\\</code>, <code>/</code>, <code>*</code>, <code>?</code>, <code>"</code>, <code><</code>, <code>></code>, <code>|</code>, <code>,</code>, <code>*</code>.</li>
<li>No part of the name can contain whitespace.</li>
</ul>
<p>Privilege names must begin with a lowercase ASCII letter and must contain only ASCII letters and digits along with the characters <code>_</code>, <code>-</code>, and <code>.</code>.</p>
<p>Action names can contain any number of printable ASCII characters and must contain at least one of the following characters: <code>/</code>, <code>*</code>, <code>:</code>.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-put-privileges>`_
:param privileges:
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
"""
if privileges is None and body is None:
raise ValueError(
"Empty value passed for parameters 'privileges' and 'body', one of them should be set."
)
elif privileges is not None and body is not None:
raise ValueError("Cannot set both 'privileges' and 'body'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/privilege"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
__body = privileges if privileges is not None else body
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.put_privileges",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"applications",
"cluster",
"description",
"global_",
"indices",
"metadata",
"remote_cluster",
"remote_indices",
"run_as",
"transient_metadata",
),
parameter_aliases={"global": "global_"},
)
def put_role(
self,
*,
name: str,
applications: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
cluster: t.Optional[
t.Sequence[
t.Union[
str,
t.Literal[
"all",
"cancel_task",
"create_snapshot",
"cross_cluster_replication",
"cross_cluster_search",
"delegate_pki",
"grant_api_key",
"manage",
"manage_api_key",
"manage_autoscaling",
"manage_behavioral_analytics",
"manage_ccr",
"manage_data_frame_transforms",
"manage_data_stream_global_retention",
"manage_enrich",
"manage_esql",
"manage_ilm",
"manage_index_templates",
"manage_inference",
"manage_ingest_pipelines",
"manage_logstash_pipelines",
"manage_ml",
"manage_oidc",
"manage_own_api_key",
"manage_pipeline",
"manage_rollup",
"manage_saml",
"manage_search_application",
"manage_search_query_rules",
"manage_search_synonyms",
"manage_security",
"manage_service_account",
"manage_slm",
"manage_token",
"manage_transform",
"manage_user_profile",
"manage_watcher",
"monitor",
"monitor_data_frame_transforms",
"monitor_data_stream_global_retention",
"monitor_enrich",
"monitor_esql",
"monitor_inference",
"monitor_ml",
"monitor_rollup",
"monitor_snapshot",
"monitor_stats",
"monitor_text_structure",
"monitor_transform",
"monitor_watcher",
"none",
"post_behavioral_analytics_event",
"read_ccr",
"read_fleet_secrets",
"read_ilm",
"read_pipeline",
"read_security",
"read_slm",
"transport_client",
"write_connector_secrets",
"write_fleet_secrets",
],
]
]
] = None,
description: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
global_: t.Optional[t.Mapping[str, t.Any]] = None,
human: t.Optional[bool] = None,
indices: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
metadata: t.Optional[t.Mapping[str, t.Any]] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
remote_cluster: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
remote_indices: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
run_as: t.Optional[t.Sequence[str]] = None,
transient_metadata: t.Optional[t.Mapping[str, t.Any]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create or update roles.</p>
<p>The role management APIs are generally the preferred way to manage roles in the native realm, rather than using file-based role management.
The create or update roles API cannot update roles that are defined in roles files.
File-based role management is not available in Elastic Serverless.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-put-role>`_
:param name: The name of the role that is being created or updated. On Elasticsearch
Serverless, the role name must begin with a letter or digit and can only
contain letters, digits and the characters '_', '-', and '.'. Each role must
have a unique name, as this will serve as the identifier for that role.
:param applications: A list of application privilege entries.
:param cluster: A list of cluster privileges. These privileges define the cluster-level
actions for users with this role.
:param description: Optional description of the role descriptor
:param global_: An object defining global privileges. A global privilege is a
form of cluster privilege that is request-aware. Support for global privileges
is currently limited to the management of application privileges.
:param indices: A list of indices permissions entries.
:param metadata: Optional metadata. Within the metadata object, keys that begin
with an underscore (`_`) are reserved for system use.
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
:param remote_cluster: A list of remote cluster permissions entries.
:param remote_indices: A list of remote indices permissions entries. NOTE: Remote
indices are effective for remote clusters configured with the API key based
model. They have no effect for remote clusters configured with the certificate
based model.
:param run_as: A list of users that the owners of this role can impersonate.
*Note*: in Serverless, the run-as feature is disabled. For API compatibility,
you can still specify an empty `run_as` field, but a non-empty list will
be rejected.
:param transient_metadata: Indicates roles that might be incompatible with the
current cluster license, specifically roles with document and field level
security. When the cluster license doesn’t allow certain features for a given
role, this parameter is updated dynamically to list the incompatible features.
If `enabled` is `false`, the role is ignored, but is still listed in the
response from the authenticate API.
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_security/role/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
if not __body:
if applications is not None:
__body["applications"] = applications
if cluster is not None:
__body["cluster"] = cluster
if description is not None:
__body["description"] = description
if global_ is not None:
__body["global"] = global_
if indices is not None:
__body["indices"] = indices
if metadata is not None:
__body["metadata"] = metadata
if remote_cluster is not None:
__body["remote_cluster"] = remote_cluster
if remote_indices is not None:
__body["remote_indices"] = remote_indices
if run_as is not None:
__body["run_as"] = run_as
if transient_metadata is not None:
__body["transient_metadata"] = transient_metadata
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.put_role",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"enabled",
"metadata",
"role_templates",
"roles",
"rules",
"run_as",
),
)
def put_role_mapping(
self,
*,
name: str,
enabled: t.Optional[bool] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
metadata: t.Optional[t.Mapping[str, t.Any]] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
role_templates: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
roles: t.Optional[t.Sequence[str]] = None,
rules: t.Optional[t.Mapping[str, t.Any]] = None,
run_as: t.Optional[t.Sequence[str]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create or update role mappings.</p>
<p>Role mappings define which roles are assigned to each user.
Each mapping has rules that identify users and a list of roles that are granted to those users.
The role mapping APIs are generally the preferred way to manage role mappings rather than using role mapping files. The create or update role mappings API cannot update role mappings that are defined in role mapping files.</p>
<p>NOTE: This API does not create roles. Rather, it maps users to existing roles.
Roles can be created by using the create or update roles API or roles files.</p>
<p><strong>Role templates</strong></p>
<p>The most common use for role mappings is to create a mapping from a known value on the user to a fixed role name.
For example, all users in the <code>cn=admin,dc=example,dc=com</code> LDAP group should be given the superuser role in Elasticsearch.
The <code>roles</code> field is used for this purpose.</p>
<p>For more complex needs, it is possible to use Mustache templates to dynamically determine the names of the roles that should be granted to the user.
The <code>role_templates</code> field is used for this purpose.</p>
<p>NOTE: To use role templates successfully, the relevant scripting feature must be enabled.
Otherwise, all attempts to create a role mapping with role templates fail.</p>
<p>All of the user fields that are available in the role mapping rules are also available in the role templates.
Thus it is possible to assign a user to a role that reflects their username, their groups, or the name of the realm to which they authenticated.</p>
<p>By default a template is evaluated to produce a single string that is the name of the role which should be assigned to the user.
If the format of the template is set to "json" then the template is expected to produce a JSON string or an array of JSON strings for the role names.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-put-role-mapping>`_
:param name: The distinct name that identifies the role mapping. The name is
used solely as an identifier to facilitate interaction via the API; it does
not affect the behavior of the mapping in any way.
:param enabled: Mappings that have `enabled` set to `false` are ignored when
role mapping is performed.
:param metadata: Additional metadata that helps define which roles are assigned
to each user. Within the metadata object, keys beginning with `_` are reserved
for system usage.
:param refresh: If `true` (the default) then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh to
make this operation visible to search, if `false` then do nothing with refreshes.
:param role_templates: A list of Mustache templates that will be evaluated to
determine the roles names that should granted to the users that match the
role mapping rules. Exactly one of `roles` or `role_templates` must be specified.
:param roles: A list of role names that are granted to the users that match the
role mapping rules. Exactly one of `roles` or `role_templates` must be specified.
:param rules: The rules that determine which users should be matched by the mapping.
A rule is a logical condition that is expressed by using a JSON DSL.
:param run_as:
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_security/role_mapping/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
if not __body:
if enabled is not None:
__body["enabled"] = enabled
if metadata is not None:
__body["metadata"] = metadata
if role_templates is not None:
__body["role_templates"] = role_templates
if roles is not None:
__body["roles"] = roles
if rules is not None:
__body["rules"] = rules
if run_as is not None:
__body["run_as"] = run_as
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.put_role_mapping",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"email",
"enabled",
"full_name",
"metadata",
"password",
"password_hash",
"roles",
),
)
def put_user(
self,
*,
username: str,
email: t.Optional[t.Union[None, str]] = None,
enabled: t.Optional[bool] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
full_name: t.Optional[t.Union[None, str]] = None,
human: t.Optional[bool] = None,
metadata: t.Optional[t.Mapping[str, t.Any]] = None,
password: t.Optional[str] = None,
password_hash: t.Optional[str] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
roles: t.Optional[t.Sequence[str]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create or update users.</p>
<p>Add and update users in the native realm.
A password is required for adding a new user but is optional when updating an existing user.
To change a user's password without updating any other fields, use the change password API.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-put-user>`_
:param username: An identifier for the user. NOTE: Usernames must be at least
1 and no more than 507 characters. They can contain alphanumeric characters
(a-z, A-Z, 0-9), spaces, punctuation, and printable symbols in the Basic
Latin (ASCII) block. Leading or trailing whitespace is not allowed.
:param email: The email of the user.
:param enabled: Specifies whether the user is enabled.
:param full_name: The full name of the user.
:param metadata: Arbitrary metadata that you want to associate with the user.
:param password: The user's password. Passwords must be at least 6 characters
long. When adding a user, one of `password` or `password_hash` is required.
When updating an existing user, the password is optional, so that other fields
on the user (such as their roles) may be updated without modifying the user's
password
:param password_hash: A hash of the user's password. This must be produced using
the same hashing algorithm as has been configured for password storage. For
more details, see the explanation of the `xpack.security.authc.password_hashing.algorithm`
setting in the user cache and password hash algorithm documentation. Using
this parameter allows the client to pre-hash the password for performance
and/or confidentiality reasons. The `password` parameter and the `password_hash`
parameter cannot be used in the same request.
:param refresh: Valid values are `true`, `false`, and `wait_for`. These values
have the same meaning as in the index API, but the default value for this
API is true.
:param roles: A set of roles the user has. The roles determine the user's access
permissions. To create a user without any roles, specify an empty list (`[]`).
"""
if username in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'username'")
__path_parts: t.Dict[str, str] = {"username": _quote(username)}
__path = f'/_security/user/{__path_parts["username"]}'
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
if not __body:
if email is not None:
__body["email"] = email
if enabled is not None:
__body["enabled"] = enabled
if full_name is not None:
__body["full_name"] = full_name
if metadata is not None:
__body["metadata"] = metadata
if password is not None:
__body["password"] = password
if password_hash is not None:
__body["password_hash"] = password_hash
if roles is not None:
__body["roles"] = roles
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.put_user",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"aggregations",
"aggs",
"from_",
"query",
"search_after",
"size",
"sort",
),
parameter_aliases={"from": "from_"},
)
def query_api_keys(
self,
*,
aggregations: t.Optional[t.Mapping[str, t.Mapping[str, t.Any]]] = None,
aggs: t.Optional[t.Mapping[str, t.Mapping[str, t.Any]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
from_: t.Optional[int] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
query: t.Optional[t.Mapping[str, t.Any]] = None,
search_after: t.Optional[
t.Sequence[t.Union[None, bool, float, int, str]]
] = None,
size: t.Optional[int] = None,
sort: t.Optional[
t.Union[
t.Sequence[t.Union[str, t.Mapping[str, t.Any]]],
t.Union[str, t.Mapping[str, t.Any]],
]
] = None,
typed_keys: t.Optional[bool] = None,
with_limited_by: t.Optional[bool] = None,
with_profile_uid: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Find API keys with a query.</p>
<p>Get a paginated list of API keys and their information.
You can optionally filter the results with a query.</p>
<p>To use this API, you must have at least the <code>manage_own_api_key</code> or the <code>read_security</code> cluster privileges.
If you have only the <code>manage_own_api_key</code> privilege, this API returns only the API keys that you own.
If you have the <code>read_security</code>, <code>manage_api_key</code>, or greater privileges (including <code>manage_security</code>), this API returns all API keys regardless of ownership.
Refer to the linked documentation for examples of how to find API keys:</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-query-api-keys>`_
:param aggregations: Any aggregations to run over the corpus of returned API
keys. Aggregations and queries work together. Aggregations are computed only
on the API keys that match the query. This supports only a subset of aggregation
types, namely: `terms`, `range`, `date_range`, `missing`, `cardinality`,
`value_count`, `composite`, `filter`, and `filters`. Additionally, aggregations
only run over the same subset of fields that query works with.
:param aggs: Any aggregations to run over the corpus of returned API keys. Aggregations
and queries work together. Aggregations are computed only on the API keys
that match the query. This supports only a subset of aggregation types, namely:
`terms`, `range`, `date_range`, `missing`, `cardinality`, `value_count`,
`composite`, `filter`, and `filters`. Additionally, aggregations only run
over the same subset of fields that query works with.
:param from_: The starting document offset. It must not be negative. By default,
you cannot page through more than 10,000 hits using the `from` and `size`
parameters. To page through more hits, use the `search_after` parameter.
:param query: A query to filter which API keys to return. If the query parameter
is missing, it is equivalent to a `match_all` query. The query supports a
subset of query types, including `match_all`, `bool`, `term`, `terms`, `match`,
`ids`, `prefix`, `wildcard`, `exists`, `range`, and `simple_query_string`.
You can query the following public information associated with an API key:
`id`, `type`, `name`, `creation`, `expiration`, `invalidated`, `invalidation`,
`username`, `realm`, and `metadata`. NOTE: The queryable string values associated
with API keys are internally mapped as keywords. Consequently, if no `analyzer`
parameter is specified for a `match` query, then the provided match query
string is interpreted as a single keyword value. Such a match query is hence
equivalent to a `term` query.
:param search_after: The search after definition.
:param size: The number of hits to return. It must not be negative. The `size`
parameter can be set to `0`, in which case no API key matches are returned,
only the aggregation results. By default, you cannot page through more than
10,000 hits using the `from` and `size` parameters. To page through more
hits, use the `search_after` parameter.
:param sort: The sort definition. Other than `id`, all public fields of an API
key are eligible for sorting. In addition, sort can also be applied to the
`_doc` field to sort by index order.
:param typed_keys: Determines whether aggregation names are prefixed by their
respective types in the response.
:param with_limited_by: Return the snapshot of the owner user's role descriptors
associated with the API key. An API key's actual permission is the intersection
of its assigned role descriptors and the owner user's role descriptors (effectively
limited by it). An API key cannot retrieve any API key’s limited-by role
descriptors (including itself) unless it has `manage_api_key` or higher privileges.
:param with_profile_uid: Determines whether to also retrieve the profile UID
for the API key owner principal. If it exists, the profile UID is returned
under the `profile_uid` response field for each API key.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/_query/api_key"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
# The 'sort' parameter with a colon can't be encoded to the body.
if sort is not None and (
(isinstance(sort, str) and ":" in sort)
or (
isinstance(sort, (list, tuple))
and all(isinstance(_x, str) for _x in sort)
and any(":" in _x for _x in sort)
)
):
__query["sort"] = sort
sort = None
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if typed_keys is not None:
__query["typed_keys"] = typed_keys
if with_limited_by is not None:
__query["with_limited_by"] = with_limited_by
if with_profile_uid is not None:
__query["with_profile_uid"] = with_profile_uid
if not __body:
if aggregations is not None:
__body["aggregations"] = aggregations
if aggs is not None:
__body["aggs"] = aggs
if from_ is not None:
__body["from"] = from_
if query is not None:
__body["query"] = query
if search_after is not None:
__body["search_after"] = search_after
if size is not None:
__body["size"] = size
if sort is not None:
__body["sort"] = sort
if not __body:
__body = None # type: ignore[assignment]
__headers = {"accept": "application/json"}
if __body is not None:
__headers["content-type"] = "application/json"
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.query_api_keys",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("from_", "query", "search_after", "size", "sort"),
parameter_aliases={"from": "from_"},
)
def query_role(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
from_: t.Optional[int] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
query: t.Optional[t.Mapping[str, t.Any]] = None,
search_after: t.Optional[
t.Sequence[t.Union[None, bool, float, int, str]]
] = None,
size: t.Optional[int] = None,
sort: t.Optional[
t.Union[
t.Sequence[t.Union[str, t.Mapping[str, t.Any]]],
t.Union[str, t.Mapping[str, t.Any]],
]
] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Find roles with a query.</p>
<p>Get roles in a paginated manner.
The role management APIs are generally the preferred way to manage roles, rather than using file-based role management.
The query roles API does not retrieve roles that are defined in roles files, nor built-in ones.
You can optionally filter the results with a query.
Also, the results can be paginated and sorted.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-query-role>`_
:param from_: The starting document offset. It must not be negative. By default,
you cannot page through more than 10,000 hits using the `from` and `size`
parameters. To page through more hits, use the `search_after` parameter.
:param query: A query to filter which roles to return. If the query parameter
is missing, it is equivalent to a `match_all` query. The query supports a
subset of query types, including `match_all`, `bool`, `term`, `terms`, `match`,
`ids`, `prefix`, `wildcard`, `exists`, `range`, and `simple_query_string`.
You can query the following information associated with roles: `name`, `description`,
`metadata`, `applications.application`, `applications.privileges`, and `applications.resources`.
:param search_after: The search after definition.
:param size: The number of hits to return. It must not be negative. By default,
you cannot page through more than 10,000 hits using the `from` and `size`
parameters. To page through more hits, use the `search_after` parameter.
:param sort: The sort definition. You can sort on `username`, `roles`, or `enabled`.
In addition, sort can also be applied to the `_doc` field to sort by index
order.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/_query/role"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if from_ is not None:
__body["from"] = from_
if query is not None:
__body["query"] = query
if search_after is not None:
__body["search_after"] = search_after
if size is not None:
__body["size"] = size
if sort is not None:
__body["sort"] = sort
if not __body:
__body = None # type: ignore[assignment]
__headers = {"accept": "application/json"}
if __body is not None:
__headers["content-type"] = "application/json"
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.query_role",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("from_", "query", "search_after", "size", "sort"),
parameter_aliases={"from": "from_"},
)
def query_user(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
from_: t.Optional[int] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
query: t.Optional[t.Mapping[str, t.Any]] = None,
search_after: t.Optional[
t.Sequence[t.Union[None, bool, float, int, str]]
] = None,
size: t.Optional[int] = None,
sort: t.Optional[
t.Union[
t.Sequence[t.Union[str, t.Mapping[str, t.Any]]],
t.Union[str, t.Mapping[str, t.Any]],
]
] = None,
with_profile_uid: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Find users with a query.</p>
<p>Get information for users in a paginated manner.
You can optionally filter the results with a query.</p>
<p>NOTE: As opposed to the get user API, built-in users are excluded from the result.
This API is only for native users.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-query-user>`_
:param from_: The starting document offset. It must not be negative. By default,
you cannot page through more than 10,000 hits using the `from` and `size`
parameters. To page through more hits, use the `search_after` parameter.
:param query: A query to filter which users to return. If the query parameter
is missing, it is equivalent to a `match_all` query. The query supports a
subset of query types, including `match_all`, `bool`, `term`, `terms`, `match`,
`ids`, `prefix`, `wildcard`, `exists`, `range`, and `simple_query_string`.
You can query the following information associated with user: `username`,
`roles`, `enabled`, `full_name`, and `email`.
:param search_after: The search after definition
:param size: The number of hits to return. It must not be negative. By default,
you cannot page through more than 10,000 hits using the `from` and `size`
parameters. To page through more hits, use the `search_after` parameter.
:param sort: The sort definition. Fields eligible for sorting are: `username`,
`roles`, `enabled`. In addition, sort can also be applied to the `_doc` field
to sort by index order.
:param with_profile_uid: Determines whether to retrieve the user profile UID,
if it exists, for the users.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/_query/user"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if with_profile_uid is not None:
__query["with_profile_uid"] = with_profile_uid
if not __body:
if from_ is not None:
__body["from"] = from_
if query is not None:
__body["query"] = query
if search_after is not None:
__body["search_after"] = search_after
if size is not None:
__body["size"] = size
if sort is not None:
__body["sort"] = sort
if not __body:
__body = None # type: ignore[assignment]
__headers = {"accept": "application/json"}
if __body is not None:
__headers["content-type"] = "application/json"
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.query_user",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("content", "ids", "realm"),
)
def saml_authenticate(
self,
*,
content: t.Optional[str] = None,
ids: t.Optional[t.Union[str, t.Sequence[str]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
realm: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Authenticate SAML.</p>
<p>Submit a SAML response message to Elasticsearch for consumption.</p>
<p>NOTE: This API is intended for use by custom web applications other than Kibana.
If you are using Kibana, refer to the documentation for configuring SAML single-sign-on on the Elastic Stack.</p>
<p>The SAML message that is submitted can be:</p>
<ul>
<li>A response to a SAML authentication request that was previously created using the SAML prepare authentication API.</li>
<li>An unsolicited SAML message in the case of an IdP-initiated single sign-on (SSO) flow.</li>
</ul>
<p>In either case, the SAML message needs to be a base64 encoded XML document with a root element of <code><Response></code>.</p>
<p>After successful validation, Elasticsearch responds with an Elasticsearch internal access token and refresh token that can be subsequently used for authentication.
This API endpoint essentially exchanges SAML responses that indicate successful authentication in the IdP for Elasticsearch access and refresh tokens, which can be used for authentication against Elasticsearch.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-saml-authenticate>`_
:param content: The SAML response as it was sent by the user's browser, usually
a Base64 encoded XML document.
:param ids: A JSON array with all the valid SAML Request Ids that the caller
of the API has for the current user.
:param realm: The name of the realm that should authenticate the SAML response.
Useful in cases where many SAML realms are defined.
"""
if content is None and body is None:
raise ValueError("Empty value passed for parameter 'content'")
if ids is None and body is None:
raise ValueError("Empty value passed for parameter 'ids'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/saml/authenticate"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if content is not None:
__body["content"] = content
if ids is not None:
__body["ids"] = ids
if realm is not None:
__body["realm"] = realm
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.saml_authenticate",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("ids", "realm", "content", "query_string"),
)
def saml_complete_logout(
self,
*,
ids: t.Optional[t.Union[str, t.Sequence[str]]] = None,
realm: t.Optional[str] = None,
content: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
query_string: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Logout of SAML completely.</p>
<p>Verifies the logout response sent from the SAML IdP.</p>
<p>NOTE: This API is intended for use by custom web applications other than Kibana.
If you are using Kibana, refer to the documentation for configuring SAML single-sign-on on the Elastic Stack.</p>
<p>The SAML IdP may send a logout response back to the SP after handling the SP-initiated SAML Single Logout.
This API verifies the response by ensuring the content is relevant and validating its signature.
An empty response is returned if the verification process is successful.
The response can be sent by the IdP with either the HTTP-Redirect or the HTTP-Post binding.
The caller of this API must prepare the request accordingly so that this API can handle either of them.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-saml-complete-logout>`_
:param ids: A JSON array with all the valid SAML Request Ids that the caller
of the API has for the current user.
:param realm: The name of the SAML realm in Elasticsearch for which the configuration
is used to verify the logout response.
:param content: If the SAML IdP sends the logout response with the HTTP-Post
binding, this field must be set to the value of the SAMLResponse form parameter
from the logout response.
:param query_string: If the SAML IdP sends the logout response with the HTTP-Redirect
binding, this field must be set to the query string of the redirect URI.
"""
if ids is None and body is None:
raise ValueError("Empty value passed for parameter 'ids'")
if realm is None and body is None:
raise ValueError("Empty value passed for parameter 'realm'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/saml/complete_logout"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if ids is not None:
__body["ids"] = ids
if realm is not None:
__body["realm"] = realm
if content is not None:
__body["content"] = content
if query_string is not None:
__body["query_string"] = query_string
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.saml_complete_logout",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("query_string", "acs", "realm"),
)
def saml_invalidate(
self,
*,
query_string: t.Optional[str] = None,
acs: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
realm: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Invalidate SAML.</p>
<p>Submit a SAML LogoutRequest message to Elasticsearch for consumption.</p>
<p>NOTE: This API is intended for use by custom web applications other than Kibana.
If you are using Kibana, refer to the documentation for configuring SAML single-sign-on on the Elastic Stack.</p>
<p>The logout request comes from the SAML IdP during an IdP initiated Single Logout.
The custom web application can use this API to have Elasticsearch process the <code>LogoutRequest</code>.
After successful validation of the request, Elasticsearch invalidates the access token and refresh token that corresponds to that specific SAML principal and provides a URL that contains a SAML LogoutResponse message.
Thus the user can be redirected back to their IdP.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-saml-invalidate>`_
:param query_string: The query part of the URL that the user was redirected to
by the SAML IdP to initiate the Single Logout. This query should include
a single parameter named `SAMLRequest` that contains a SAML logout request
that is deflated and Base64 encoded. If the SAML IdP has signed the logout
request, the URL should include two extra parameters named `SigAlg` and `Signature`
that contain the algorithm used for the signature and the signature value
itself. In order for Elasticsearch to be able to verify the IdP's signature,
the value of the `query_string` field must be an exact match to the string
provided by the browser. The client application must not attempt to parse
or process the string in any way.
:param acs: The Assertion Consumer Service URL that matches the one of the SAML
realm in Elasticsearch that should be used. You must specify either this
parameter or the `realm` parameter.
:param realm: The name of the SAML realm in Elasticsearch the configuration.
You must specify either this parameter or the `acs` parameter.
"""
if query_string is None and body is None:
raise ValueError("Empty value passed for parameter 'query_string'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/saml/invalidate"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if query_string is not None:
__body["query_string"] = query_string
if acs is not None:
__body["acs"] = acs
if realm is not None:
__body["realm"] = realm
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.saml_invalidate",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("token", "refresh_token"),
)
def saml_logout(
self,
*,
token: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
refresh_token: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Logout of SAML.</p>
<p>Submits a request to invalidate an access token and refresh token.</p>
<p>NOTE: This API is intended for use by custom web applications other than Kibana.
If you are using Kibana, refer to the documentation for configuring SAML single-sign-on on the Elastic Stack.</p>
<p>This API invalidates the tokens that were generated for a user by the SAML authenticate API.
If the SAML realm in Elasticsearch is configured accordingly and the SAML IdP supports this, the Elasticsearch response contains a URL to redirect the user to the IdP that contains a SAML logout request (starting an SP-initiated SAML Single Logout).</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-saml-logout>`_
:param token: The access token that was returned as a response to calling the
SAML authenticate API. Alternatively, the most recent token that was received
after refreshing the original one by using a `refresh_token`.
:param refresh_token: The refresh token that was returned as a response to calling
the SAML authenticate API. Alternatively, the most recent refresh token that
was received after refreshing the original access token.
"""
if token is None and body is None:
raise ValueError("Empty value passed for parameter 'token'")
__path_parts: t.Dict[str, str] = {}
__path = "/_security/saml/logout"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if token is not None:
__body["token"] = token
if refresh_token is not None:
__body["refresh_token"] = refresh_token
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.saml_logout",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("acs", "realm", "relay_state"),
)
def saml_prepare_authentication(
self,
*,
acs: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
realm: t.Optional[str] = None,
relay_state: t.Optional[str] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Prepare SAML authentication.</p>
<p>Create a SAML authentication request (<code><AuthnRequest></code>) as a URL string based on the configuration of the respective SAML realm in Elasticsearch.</p>
<p>NOTE: This API is intended for use by custom web applications other than Kibana.
If you are using Kibana, refer to the documentation for configuring SAML single-sign-on on the Elastic Stack.</p>
<p>This API returns a URL pointing to the SAML Identity Provider.
You can use the URL to redirect the browser of the user in order to continue the authentication process.
The URL includes a single parameter named <code>SAMLRequest</code>, which contains a SAML Authentication request that is deflated and Base64 encoded.
If the configuration dictates that SAML authentication requests should be signed, the URL has two extra parameters named <code>SigAlg</code> and <code>Signature</code>.
These parameters contain the algorithm used for the signature and the signature value itself.
It also returns a random string that uniquely identifies this SAML Authentication request.
The caller of this API needs to store this identifier as it needs to be used in a following step of the authentication process.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-saml-prepare-authentication>`_
:param acs: The Assertion Consumer Service URL that matches the one of the SAML
realms in Elasticsearch. The realm is used to generate the authentication
request. You must specify either this parameter or the `realm` parameter.
:param realm: The name of the SAML realm in Elasticsearch for which the configuration
is used to generate the authentication request. You must specify either this
parameter or the `acs` parameter.
:param relay_state: A string that will be included in the redirect URL that this
API returns as the `RelayState` query parameter. If the Authentication Request
is signed, this value is used as part of the signature computation.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/saml/prepare"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if acs is not None:
__body["acs"] = acs
if realm is not None:
__body["realm"] = realm
if relay_state is not None:
__body["relay_state"] = relay_state
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.saml_prepare_authentication",
path_parts=__path_parts,
)
@_rewrite_parameters()
def saml_service_provider_metadata(
self,
*,
realm_name: str,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create SAML service provider metadata.</p>
<p>Generate SAML metadata for a SAML 2.0 Service Provider.</p>
<p>The SAML 2.0 specification provides a mechanism for Service Providers to describe their capabilities and configuration using a metadata file.
This API generates Service Provider metadata based on the configuration of a SAML realm in Elasticsearch.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-saml-service-provider-metadata>`_
:param realm_name: The name of the SAML realm in Elasticsearch.
"""
if realm_name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'realm_name'")
__path_parts: t.Dict[str, str] = {"realm_name": _quote(realm_name)}
__path = f'/_security/saml/metadata/{__path_parts["realm_name"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="security.saml_service_provider_metadata",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("data", "hint", "name", "size"),
)
def suggest_user_profiles(
self,
*,
data: t.Optional[t.Union[str, t.Sequence[str]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
hint: t.Optional[t.Mapping[str, t.Any]] = None,
human: t.Optional[bool] = None,
name: t.Optional[str] = None,
pretty: t.Optional[bool] = None,
size: t.Optional[int] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Suggest a user profile.</p>
<p>Get suggestions for user profiles that match specified search criteria.</p>
<p>NOTE: The user profile feature is designed only for use by Kibana and Elastic's Observability, Enterprise Search, and Elastic Security solutions.
Individual users and external applications should not call this API directly.
Elastic reserves the right to change or remove this feature in future releases without prior notice.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-suggest-user-profiles>`_
:param data: A comma-separated list of filters for the `data` field of the profile
document. To return all content use `data=*`. To return a subset of content,
use `data=<key>` to retrieve content nested under the specified `<key>`.
By default, the API returns no `data` content. It is an error to specify
`data` as both the query parameter and the request body field.
:param hint: Extra search criteria to improve relevance of the suggestion result.
Profiles matching the spcified hint are ranked higher in the response. Profiles
not matching the hint aren't excluded from the response as long as the profile
matches the `name` field query.
:param name: A query string used to match name-related fields in user profile
documents. Name-related fields are the user's `username`, `full_name`, and
`email`.
:param size: The number of profiles to return.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/profile/_suggest"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if data is not None:
__body["data"] = data
if hint is not None:
__body["hint"] = hint
if name is not None:
__body["name"] = name
if size is not None:
__body["size"] = size
if not __body:
__body = None # type: ignore[assignment]
__headers = {"accept": "application/json"}
if __body is not None:
__headers["content-type"] = "application/json"
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.suggest_user_profiles",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("expiration", "metadata", "role_descriptors"),
)
def update_api_key(
self,
*,
id: str,
error_trace: t.Optional[bool] = None,
expiration: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
metadata: t.Optional[t.Mapping[str, t.Any]] = None,
pretty: t.Optional[bool] = None,
role_descriptors: t.Optional[t.Mapping[str, t.Mapping[str, t.Any]]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Update an API key.</p>
<p>Update attributes of an existing API key.
This API supports updates to an API key's access scope, expiration, and metadata.</p>
<p>To use this API, you must have at least the <code>manage_own_api_key</code> cluster privilege.
Users can only update API keys that they created or that were granted to them.
To update another user’s API key, use the <code>run_as</code> feature to submit a request on behalf of another user.</p>
<p>IMPORTANT: It's not possible to use an API key as the authentication credential for this API. The owner user’s credentials are required.</p>
<p>Use this API to update API keys created by the create API key or grant API Key APIs.
If you need to apply the same update to many API keys, you can use the bulk update API keys API to reduce overhead.
It's not possible to update expired API keys or API keys that have been invalidated by the invalidate API key API.</p>
<p>The access scope of an API key is derived from the <code>role_descriptors</code> you specify in the request and a snapshot of the owner user's permissions at the time of the request.
The snapshot of the owner's permissions is updated automatically on every call.</p>
<p>IMPORTANT: If you don't specify <code>role_descriptors</code> in the request, a call to this API might still change the API key's access scope.
This change can occur if the owner user's permissions have changed since the API key was created or last modified.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-update-api-key>`_
:param id: The ID of the API key to update.
:param expiration: The expiration time for the API key. By default, API keys
never expire. This property can be omitted to leave the expiration unchanged.
:param metadata: Arbitrary metadata that you want to associate with the API key.
It supports a nested data structure. Within the metadata object, keys beginning
with `_` are reserved for system usage. When specified, this value fully
replaces the metadata previously associated with the API key.
:param role_descriptors: The role descriptors to assign to this API key. The
API key's effective permissions are an intersection of its assigned privileges
and the point in time snapshot of permissions of the owner user. You can
assign new privileges by specifying them in this parameter. To remove assigned
privileges, you can supply an empty `role_descriptors` parameter, that is
to say, an empty object `{}`. If an API key has no assigned privileges, it
inherits the owner user's full permissions. The snapshot of the owner's permissions
is always updated, whether you supply the `role_descriptors` parameter or
not. The structure of a role descriptor is the same as the request for the
create API keys API.
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'id'")
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
__path = f'/_security/api_key/{__path_parts["id"]}'
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if expiration is not None:
__body["expiration"] = expiration
if metadata is not None:
__body["metadata"] = metadata
if role_descriptors is not None:
__body["role_descriptors"] = role_descriptors
if not __body:
__body = None # type: ignore[assignment]
__headers = {"accept": "application/json"}
if __body is not None:
__headers["content-type"] = "application/json"
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.update_api_key",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("access", "expiration", "metadata"),
)
def update_cross_cluster_api_key(
self,
*,
id: str,
access: t.Optional[t.Mapping[str, t.Any]] = None,
error_trace: t.Optional[bool] = None,
expiration: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
metadata: t.Optional[t.Mapping[str, t.Any]] = None,
pretty: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Update a cross-cluster API key.</p>
<p>Update the attributes of an existing cross-cluster API key, which is used for API key based remote cluster access.</p>
<p>To use this API, you must have at least the <code>manage_security</code> cluster privilege.
Users can only update API keys that they created.
To update another user's API key, use the <code>run_as</code> feature to submit a request on behalf of another user.</p>
<p>IMPORTANT: It's not possible to use an API key as the authentication credential for this API.
To update an API key, the owner user's credentials are required.</p>
<p>It's not possible to update expired API keys, or API keys that have been invalidated by the invalidate API key API.</p>
<p>This API supports updates to an API key's access scope, metadata, and expiration.
The owner user's information, such as the <code>username</code> and <code>realm</code>, is also updated automatically on every call.</p>
<p>NOTE: This API cannot update REST API keys, which should be updated by either the update API key or bulk update API keys API.</p>
<p>To learn more about how to use this API, refer to the <a href="https://www.elastic.co/docs/reference/elasticsearch/rest-apis/update-cc-api-key-examples">Update cross cluter API key API examples page</a>.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-update-cross-cluster-api-key>`_
:param id: The ID of the cross-cluster API key to update.
:param access: The access to be granted to this API key. The access is composed
of permissions for cross cluster search and cross cluster replication. At
least one of them must be specified. When specified, the new access assignment
fully replaces the previously assigned access.
:param expiration: The expiration time for the API key. By default, API keys
never expire. This property can be omitted to leave the value unchanged.
:param metadata: Arbitrary metadata that you want to associate with the API key.
It supports nested data structure. Within the metadata object, keys beginning
with `_` are reserved for system usage. When specified, this information
fully replaces metadata previously associated with the API key.
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'id'")
if access is None and body is None:
raise ValueError("Empty value passed for parameter 'access'")
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
__path = f'/_security/cross_cluster/api_key/{__path_parts["id"]}'
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if access is not None:
__body["access"] = access
if expiration is not None:
__body["expiration"] = expiration
if metadata is not None:
__body["metadata"] = metadata
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.update_cross_cluster_api_key",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("security", "security_profile", "security_tokens"),
parameter_aliases={
"security-profile": "security_profile",
"security-tokens": "security_tokens",
},
)
def update_settings(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
pretty: t.Optional[bool] = None,
security: t.Optional[t.Mapping[str, t.Any]] = None,
security_profile: t.Optional[t.Mapping[str, t.Any]] = None,
security_tokens: t.Optional[t.Mapping[str, t.Any]] = None,
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Update security index settings.</p>
<p>Update the user-configurable settings for the security internal index (<code>.security</code> and associated indices). Only a subset of settings are allowed to be modified. This includes <code>index.auto_expand_replicas</code> and <code>index.number_of_replicas</code>.</p>
<p>NOTE: If <code>index.auto_expand_replicas</code> is set, <code>index.number_of_replicas</code> will be ignored during updates.</p>
<p>If a specific index is not in use on the system and settings are provided for it, the request will be rejected.
This API does not yet support configuring the settings for indices before they are in use.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-update-settings>`_
:param master_timeout: The period to wait for a connection to the master node.
If no response is received before the timeout expires, the request fails
and returns an error.
:param security: Settings for the index used for most security configuration,
including native realm users and roles configured with the API.
:param security_profile: Settings for the index used to store profile information.
:param security_tokens: Settings for the index used to store tokens.
:param timeout: The period to wait for a response. If no response is received
before the timeout expires, the request fails and returns an error.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_security/settings"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
if timeout is not None:
__query["timeout"] = timeout
if not __body:
if security is not None:
__body["security"] = security
if security_profile is not None:
__body["security-profile"] = security_profile
if security_tokens is not None:
__body["security-tokens"] = security_tokens
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.update_settings",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("data", "labels"),
)
def update_user_profile_data(
self,
*,
uid: str,
data: t.Optional[t.Mapping[str, t.Any]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
if_primary_term: t.Optional[int] = None,
if_seq_no: t.Optional[int] = None,
labels: t.Optional[t.Mapping[str, t.Any]] = None,
pretty: t.Optional[bool] = None,
refresh: t.Optional[
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Update user profile data.</p>
<p>Update specific data for the user profile that is associated with a unique ID.</p>
<p>NOTE: The user profile feature is designed only for use by Kibana and Elastic's Observability, Enterprise Search, and Elastic Security solutions.
Individual users and external applications should not call this API directly.
Elastic reserves the right to change or remove this feature in future releases without prior notice.</p>
<p>To use this API, you must have one of the following privileges:</p>
<ul>
<li>The <code>manage_user_profile</code> cluster privilege.</li>
<li>The <code>update_profile_data</code> global privilege for the namespaces that are referenced in the request.</li>
</ul>
<p>This API updates the <code>labels</code> and <code>data</code> fields of an existing user profile document with JSON objects.
New keys and their values are added to the profile document and conflicting keys are replaced by data that's included in the request.</p>
<p>For both labels and data, content is namespaced by the top-level fields.
The <code>update_profile_data</code> global privilege grants privileges for updating only the allowed namespaces.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-update-user-profile-data>`_
:param uid: A unique identifier for the user profile.
:param data: Non-searchable data that you want to associate with the user profile.
This field supports a nested data structure. Within the `data` object, top-level
keys cannot begin with an underscore (`_`) or contain a period (`.`). The
data object is not searchable, but can be retrieved with the get user profile
API.
:param if_primary_term: Only perform the operation if the document has this primary
term.
:param if_seq_no: Only perform the operation if the document has this sequence
number.
:param labels: Searchable data that you want to associate with the user profile.
This field supports a nested data structure. Within the labels object, top-level
keys cannot begin with an underscore (`_`) or contain a period (`.`).
:param refresh: If 'true', Elasticsearch refreshes the affected shards to make
this operation visible to search. If 'wait_for', it waits for a refresh to
make this operation visible to search. If 'false', nothing is done with refreshes.
"""
if uid in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'uid'")
__path_parts: t.Dict[str, str] = {"uid": _quote(uid)}
__path = f'/_security/profile/{__path_parts["uid"]}/_data'
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if if_primary_term is not None:
__query["if_primary_term"] = if_primary_term
if if_seq_no is not None:
__query["if_seq_no"] = if_seq_no
if pretty is not None:
__query["pretty"] = pretty
if refresh is not None:
__query["refresh"] = refresh
if not __body:
if data is not None:
__body["data"] = data
if labels is not None:
__body["labels"] = labels
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="security.update_user_profile_data",
path_parts=__path_parts,
)
|