|
19 | 19 | from ..misc import ( |
20 | 20 | attrs_include_value, |
21 | 21 | attrs_parse, |
| 22 | + delimiter_parse, |
22 | 23 | get_attr, |
23 | 24 | ip_version, |
24 | 25 | to_list, |
@@ -1192,6 +1193,20 @@ def test_example(client: Client, ipa: IPA): |
1192 | 1193 | """ |
1193 | 1194 | return IDUserOverride(self) |
1194 | 1195 |
|
| 1196 | + def subid(self) -> IPASubID: |
| 1197 | + """ |
| 1198 | + IPA subid management. |
| 1199 | +
|
| 1200 | + .. code-block:: python |
| 1201 | + :caption: Example usage |
| 1202 | +
|
| 1203 | + @pytest.mark.topology(KnownTopology.IPA) |
| 1204 | + def test_ipa__subids_configured(ipa: IPA): |
| 1205 | + user = ipa.user("user1").add() |
| 1206 | + user.subid().generate() |
| 1207 | + """ |
| 1208 | + return IPASubID(self) |
| 1209 | + |
1195 | 1210 |
|
1196 | 1211 | class IDUserOverride(IPAUser): |
1197 | 1212 | """ |
@@ -1400,6 +1415,50 @@ def show_override(self, idview_name: str) -> dict[str, list[str]]: |
1400 | 1415 | return attrs_parse(lines) |
1401 | 1416 |
|
1402 | 1417 |
|
| 1418 | +class IPASubID(IPAUser): |
| 1419 | + """ |
| 1420 | + IPA sub id management. |
| 1421 | + """ |
| 1422 | + |
| 1423 | + def __init__(self, user: IPAUser) -> None: |
| 1424 | + """ |
| 1425 | + :param user: IPA user object. |
| 1426 | + :type user: IPAUser |
| 1427 | + """ |
| 1428 | + super().__init__(user.role, user.name) |
| 1429 | + |
| 1430 | + self.name = user.name |
| 1431 | + """ Owner name.""" |
| 1432 | + |
| 1433 | + self.uid_start: int | None = None |
| 1434 | + """ SubUID range start""" |
| 1435 | + |
| 1436 | + self.uid_size: int | None = None |
| 1437 | + """ SubUID range size.""" |
| 1438 | + |
| 1439 | + self.gid_start: int | None = None |
| 1440 | + """ SubGID range start.""" |
| 1441 | + |
| 1442 | + self.gid_size: int | None = None |
| 1443 | + """ SubGID range size.""" |
| 1444 | + |
| 1445 | + def generate(self) -> IPASubID: |
| 1446 | + """ |
| 1447 | + Generate subordinate id. |
| 1448 | + """ |
| 1449 | + self.host.conn.run(f"ipa subid-generate --owner {self.name}") |
| 1450 | + result = self.host.conn.run(f"ipa subid-find --owner {self.name}").stdout_lines |
| 1451 | + result = [item for item in result if ":" in item] |
| 1452 | + subids = {k: v for k, v in delimiter_parse(result).items()} |
| 1453 | + |
| 1454 | + self.uid_start = int(subids["SubUID range start"]) if subids.get("SubUID range start") else None |
| 1455 | + self.uid_size = int(subids["SubUID range size"]) if subids.get("SubUID range size") else None |
| 1456 | + self.gid_start = int(subids["SubGID range start"]) if subids.get("SubGID range start") else None |
| 1457 | + self.gid_size = int(subids["SubGID range size"]) if subids.get("SubGID range size") else None |
| 1458 | + |
| 1459 | + return self |
| 1460 | + |
| 1461 | + |
1403 | 1462 | class IPAGroup(IPAObject): |
1404 | 1463 | """ |
1405 | 1464 | IPA group management. |
|
0 commit comments