第 4 章 IdM API example scenarios
The following examples provide you with the common scenarios of using IdM API commands.
4.1. Managing users with IdM API commands 复制链接链接已复制到粘贴板!
The examples below show common scenarios of how you can manage IdM users with the IdM API commands.
- Creating an IdM user
In this example, you create an IdM user with the username
exampleuserand the supported userone-time password (OTP)authentication.api.Command.user_add("exampleuser", givenname="Example", sn="User", ipauserauthtype="otp")- Showing an IdM user information
In this example, you display all available information about the IdM user
exampleuser.api.Command.user_show("exampleuser", all=True)- Modifying an IdM user
In this example, you change the e-mail address for the IdM user
exampleuser.api.Command.user_mod("exampleuser", mail="exampleuser@example.org")- Searching for an IdM user
In this example, you search for all IdM users that match
exampleuserin the IdM groupadmins.api.Command.user_find(criteria="exampleuser", in_group="admins")- Deleting an IdM user
In this example, you delete the IdM user
exampleuser.api.Command.user_del("exampleuser")To restore the user in future, use the
preserveoption. If you use this option, you can restore the user with theuser_undelcommand.- Adding and removing a certificate for an IdM user
You can add or remove
Base64 encodedcertificate for a user with theuser_add_certanduser_remove_certcommands. In this example, you add a certificate for a userexampleuser.args = ["exampleuser"] kw = { "usercertificate": """ MIICYzCCAcygAwIBAgIBADANBgkqhkiG9w0BAQUFADAuMQswCQYDVQQGEwJVUzEMMAoGA1UEC hMDSUJNMREwDwYDVQQLEwhMb2NhbCBDQTAeFw05OTEyMjIwNTAwMDBaFw0wMDEyMjMwNDU5NT laMC4xCzAJBgNVBAYTAlVTMQwwCgYDVQQKEwNJQk0xETAPBgNVBAsTCExvY2FsIENBMIGfMA0 GCSqGSIb3DQEBATOPA4GNADCBiQKBgQD2bZEo7xGaX2/0GHkrNFZvlxBou9v1Jmt/PDiTMPve 8r9FeJAQ0QdvFST/0JPQYD20rH0bimdDLgNdNynmyRoS2S/IInfpmf69iyc2G0TPyRvmHIiOZ bdCd+YBHQi1adkj17NDcWj6S14tVurFX73zx0sNoMS79q3tuXKrDsxeuwIDAQABo4GQMIGNME sGCVUdDwGG+EIBDQQ+EzxHZW5lcmF0ZWQgYnkgdGhlIFNlY3VyZVdheSBTZWN1cml0eSBTZXJ 2ZXIgZm9yIE9TLzM5MCAoUkFDRikwDgYDVR0PAQH/BAQDAgAGMA8GA1UdEwEB/wQFMAMBAf8w HQYDVR0OBBYEFJ3+ocRyCTJw067dLSwr/nalx6YMMA0GCSqGSIb3DQEBBQUAA4GBAMaQzt+za j1GU77yzlr8iiMBXgdQrwsZZWJo5exnAucJAEYQZmOfyLiMD6oYq+ZnfvM0n8G/Y79q8nhwvu xpYOnRSAXFp6xSkrIOeZtJMY1h00LKp/JX3Ng1svZ2agE126JHsQ0bhzN5TKsYfbwfTwfjdWA Gy6Vf1nYi/rO+ryMO """ } api.Command.user_add_cert(*args, **kw)- Enabling and disabling an IdM user
You can enable or disable an IdM user with the
user_enableanduser_disablecommands. In this example, you disable the IdM userexampleuser.api.Command.user_disable("exampleuser")