Welcome to ldap2jira’s documentation!¶
LDAP to JIRA User mapping
Package looks for given user names in LDAP. Gets configurable fields for user name, email, name. Tries to search those in JIRA and find a matching JIRA account.
Optionally consumes user map from file (json, csv).
- Usage:
Configure instance
Use LDAP2JiraUserMap.find_jira_accounts method
- class ldap2jira.map.LDAP2JiraUserMap(jira_url: str, ldap_url: str, ldap_base: str, ldap_query_fields_username: List[str], ldap_fields_username: List[str], ldap_fields_mail: List[str], ldap_fields_name: List[str], ldap_fields_jira_search: List[str], email_domain: str, map_file: str | None = None, jira_user: str | None = None, jira_password: str | None = None, jira_auth_token: str | None = None, jira_extra_kwargs=None)[source]¶
Finds matching JIRA accounts for given user names
Checks whether user name has LDAP record. Gets user names and email alternatives from LDAP. Looks for matching accounts in JIRA.
- Parameters:
jira_url – JIRA server url (’https://issues.domain.org’)
jira_user – JIRA user to use for querying
jira_password – JIRA user password to use for querying
jira_auth_token – JIRA auth token to use for querying
ldap_url – LDAP server host (’ldap://ldaphost’)
ldap_base – LDAP base for queries (‘ou=users,dc=dep,dc=org’)
ldap_query_fields_username – Which LDAP fields to search given user name in
ldap_fields_username – LDAP fields to match against JIRA account user name
ldap_fields_mail – LDAP fields to match against JIRA account email
ldap_fields_name – LDAP fields to match against JIRA account name
ldap_fields_jira_search – Run JIRA search against those field values from LDAP
email_domain – JIRA user email domain to match
map_file –
json or csv file with user mapping (username -> jira_username)
csv example:
us1csv,us1jira
us2csv,us2jira
- json example:
{
“us1json”: “us1jira”,
”us2json”: “us2jira”
}
- find_jira_accounts(usernames: List[str]) dict [source]¶
Finds matching JIRA account for given user names
- Parameters:
usernames – List of user names
- Returns:
A dict with user names as keys and match results dict as values
- Possible match result keys:
- status:
found: Found good match in JIRA
missing: No match found in JIRA
ambiguous: No good match, possible matches in jira-results
not_in_ldap: User name wasn’t found in LDAP
jira-account: JIRA user name
jira-results: A list of JIRA user names that partially match
Example:
- {
‘us1’: {‘jira-results’: [‘us1’], ‘status’: ‘ambiguous’},
’us2’: {‘status’: ‘missing’},
’us3’: {‘status’: ‘not_in_ldap’},
- ’us4’: {‘jira-results’: [‘us1’, ‘us3’],
’status’: ‘ambiguous’},
’us5’: {‘jira-account’: ‘us5’, ‘status’: ‘found’}
}
- class ldap2jira.ldap_lookup.LDAPLookup(ldap_url: str, ldap_base: str, ldap_retry_max: int = 3, ldap_retry_delay: float = 5.0)[source]¶
Wraps ldap library query
- Parameters:
ldap_url – LDAP server in the form of ‘ldap://ldaphost’
ldap_base – LDAP base for search (‘ou=users,dc=department,dc=org’)
ldap_retry_max – LDAP number of reconnect attempts
ldap_retry_delay – LDAP seconds between reconnect attempts
- query(query: str, query_fields: List[str] | None = None, return_fields: List[str] | None = None, raise_exception: bool = False) List[dict] [source]¶
Perform LDAP query
- Parameters:
query – String to search
query_fields – Which LDAP fields to search in
return_fields – What LDAP fields to return
raise_exception – If True - raise exception if no results
- Returns:
List if dicts with LDAP results
Example:
- [
{‘uid’: ‘us1’, ‘cn’: ‘user 1’, ‘mail’: ‘us1@org.com’},
{‘uid’: ‘us2’, ‘cn’: ‘user 2’, ‘mail’: ‘us2@org.com’}
]
- Raises:
LDAPQueryNotFoundError – No result while raise_exception True