Perform a LDAP add request. :param attributes: the attributes to add. We support two formats: - a list of LDAP_Attribute (or LDAP_PartialAttribute) - a dict following {attribute: [list of values]} :returns:
(
self,
entry: str,
attributes: Union[Dict[str, List[Any]], List[ASN1_Packet]],
controls: List[LDAP_Control] = [],
)
| 2368 | ) |
| 2369 | |
| 2370 | def add( |
| 2371 | self, |
| 2372 | entry: str, |
| 2373 | attributes: Union[Dict[str, List[Any]], List[ASN1_Packet]], |
| 2374 | controls: List[LDAP_Control] = [], |
| 2375 | ): |
| 2376 | """ |
| 2377 | Perform a LDAP add request. |
| 2378 | |
| 2379 | :param attributes: the attributes to add. We support two formats: |
| 2380 | - a list of LDAP_Attribute (or LDAP_PartialAttribute) |
| 2381 | - a dict following {attribute: [list of values]} |
| 2382 | |
| 2383 | :returns: |
| 2384 | """ |
| 2385 | # We handle the two cases in the type of attributes |
| 2386 | if isinstance(attributes, dict): |
| 2387 | attributes = [ |
| 2388 | LDAP_Attribute( |
| 2389 | type=ASN1_STRING(k), |
| 2390 | values=[ |
| 2391 | LDAP_AttributeValue( |
| 2392 | value=ASN1_STRING(x), |
| 2393 | ) |
| 2394 | for x in v |
| 2395 | ], |
| 2396 | ) |
| 2397 | for k, v in attributes.items() |
| 2398 | ] |
| 2399 | |
| 2400 | resp = self.sr1( |
| 2401 | LDAP_AddRequest( |
| 2402 | entry=ASN1_STRING(entry), |
| 2403 | attributes=attributes, |
| 2404 | ), |
| 2405 | controls=controls, |
| 2406 | timeout=self.timeout, |
| 2407 | ) |
| 2408 | if LDAP_AddResponse not in resp.protocolOp or resp.protocolOp.resultCode != 0: |
| 2409 | raise LDAP_Exception( |
| 2410 | "LDAP add failed !", |
| 2411 | resp=resp, |
| 2412 | ) |
| 2413 | |
| 2414 | def modifydn( |
| 2415 | self, |
no test coverage detected