Modern Active Directory user management tool with conflict resolution
Project description
AD User Manager
Modern Active Directory user management tool with conflict resolution, supporting both domain controller (PowerShell) and remote LDAP operations.
Features
- Dual Operation Modes: PowerShell on domain controllers for optimal performance, LDAP for remote connections
- Automatic Conflict Resolution: Intelligent username conflict detection and resolution
- Type-Safe Configuration: Pydantic-based configuration with validation
- Rich CLI Interface: Beautiful command-line interface with progress indicators
- Structured Logging: JSON and console logging with contextual information
- Modern Python: Built for Python 3.12+ with type hints and async support
Installation
pip install ad-user-manager
Quick Start
Domain Controller Mode (Recommended)
When running directly on a domain controller, the tool automatically uses PowerShell for optimal performance:
from ad_user_manager import ADConfig, DCServerConfig, create_ad_manager
# Configure for domain controller
config = ADConfig(
server=DCServerConfig(
connection_type="domain_controller",
base_dn="CN=Users,DC=example,DC=com",
use_current_credentials=True # Use current user's AD credentials
)
)
# Create user
with create_ad_manager(config) as manager:
result = manager.create_user(
username="jdoe",
first_name="John",
last_name="Doe",
email="john.doe@example.com",
resolve_conflicts=True
)
print(f"Created user: {result.username}")
LDAP Mode (Remote Connections)
For remote connections to Active Directory:
from ad_user_manager import ADConfig, LDAPServerConfig, create_ad_manager
# Configure for LDAP connection
config = ADConfig(
server=LDAPServerConfig(
connection_type="ldap",
host="dc.example.com",
port=389,
use_ssl=False,
bind_dn="CN=service-account,CN=Users,DC=example,DC=com",
bind_password="your-password",
base_dn="CN=Users,DC=example,DC=com"
)
)
# Create user
with create_ad_manager(config) as manager:
result = manager.create_user(
username="jsmith",
first_name="Jane",
last_name="Smith",
email="jane.smith@example.com"
)
CLI Usage
Create a User
# Domain controller mode
ad-user-manager create-user -u jdoe -f John -l Doe -e john.doe@example.com
# With conflict resolution
ad-user-manager create-user -u jdoe -f John -l Doe -e john.doe@example.com --resolve-conflicts
# Dry run mode
ad-user-manager create-user -u jdoe -f John -l Doe -e john.doe@example.com --dry-run
Search for a User
ad-user-manager search-user -u jdoe
Test Connection
ad-user-manager test-connection
Generate Username Suggestions
ad-user-manager suggest-usernames -f John -l Doe
Configuration
Environment Variables
# LDAP Configuration
export AD_CONNECTION_TYPE=ldap
export AD_HOST=dc.example.com
export AD_PORT=389
export AD_USE_SSL=false
export AD_BIND_DN="CN=service-account,CN=Users,DC=example,DC=com"
export AD_BIND_PASSWORD="your-password"
export AD_BASE_DN="CN=Users,DC=example,DC=com"
# Domain Controller Configuration
export AD_CONNECTION_TYPE=domain_controller
export AD_BASE_DN="CN=Users,DC=example,DC=com"
export AD_USE_CURRENT_CREDENTIALS=true
Configuration File
Create a .env file or use environment variables:
# For LDAP mode
AD_CONNECTION_TYPE=ldap
AD_HOST=dc.example.com
AD_BIND_DN=CN=service-account,CN=Users,DC=example,DC=com
AD_BIND_PASSWORD=your-password
AD_BASE_DN=CN=Users,DC=example,DC=com
# For DC mode
AD_CONNECTION_TYPE=domain_controller
AD_BASE_DN=CN=Users,DC=example,DC=com
AD_USE_CURRENT_CREDENTIALS=true
Advanced Features
Conflict Resolution
The tool automatically detects username conflicts and generates alternatives:
# Automatic conflict resolution
result = manager.create_user(
username="jdoe", # If exists, might become "jdoe1", "jdoe2", etc.
first_name="John",
last_name="Doe",
email="john.doe@example.com",
resolve_conflicts=True
)
print(f"Final username: {result.username}")
print(f"Conflicts resolved: {result.conflicts_resolved}")
Custom Attributes
result = manager.create_user(
username="jdoe",
first_name="John",
last_name="Doe",
email="john.doe@example.com",
additional_attributes={
"department": "Engineering",
"title": "Software Developer",
"telephoneNumber": "+1-555-0123"
}
)
Logging Configuration
config = ADConfig(
server=your_server_config,
log_level="DEBUG", # DEBUG, INFO, WARNING, ERROR, CRITICAL
log_format="json" # "json" or "console"
)
Development
Setup
git clone https://github.com/your-org/ad-user-manager.git
cd ad-user-manager
pip install -e ".[dev]"
Running Tests
pytest
Code Quality
# Linting
ruff check .
# Formatting
black .
# Type checking
mypy .
Architecture
The project is organized into focused modules:
models.py- Data models and configuration schemaspowershell_manager.py- PowerShell-based AD operations (DC mode)ldap_manager.py- LDAP-based AD operations (remote mode)factory.py- Manager creation and auto-detectionconfig.py- Configuration managementvalidators.py- Input validation and conflict resolutionexceptions.py- Custom exception hierarchycli.py- Command-line interfaceutils.py- Utility functions
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues, feature requests, or questions:
- Check the GitHub Issues
- Create a new issue with detailed information
- Include configuration (without sensitive data) and error messages
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ad_user_manager-0.1.0a20.tar.gz.
File metadata
- Download URL: ad_user_manager-0.1.0a20.tar.gz
- Upload date:
- Size: 45.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7152b1c9413c09dcb1a506c15eacb5a7f548e8f74f89fd7a4ab81437689de7f3
|
|
| MD5 |
c727a5d7808b92b2b7882a181011c12e
|
|
| BLAKE2b-256 |
6da7999ff24706075a64b918acba922052c915bba9756f9d7694259bac20bcc4
|
Provenance
The following attestation bundles were made for ad_user_manager-0.1.0a20.tar.gz:
Publisher:
pypi-publish.yml on VinnyVanGogh/py-ad-user-mgr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ad_user_manager-0.1.0a20.tar.gz -
Subject digest:
7152b1c9413c09dcb1a506c15eacb5a7f548e8f74f89fd7a4ab81437689de7f3 - Sigstore transparency entry: 251955909
- Sigstore integration time:
-
Permalink:
VinnyVanGogh/py-ad-user-mgr@5b6c75b98dca8bf1a21baabf34d6be4bb2a27bd1 -
Branch / Tag:
refs/tags/v0.1.0-alpha.21 - Owner: https://github.com/VinnyVanGogh
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@5b6c75b98dca8bf1a21baabf34d6be4bb2a27bd1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ad_user_manager-0.1.0a20-py3-none-any.whl.
File metadata
- Download URL: ad_user_manager-0.1.0a20-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d49553209884a51c778ff89c66651ed60bd9472123ebc91a241806de63822a6
|
|
| MD5 |
77b90e4ff3a4f8448dd7013ef7011abf
|
|
| BLAKE2b-256 |
29fab5cff77e98bf854cfed82fff34887aab2905ebda0ab5fe47829740d5be09
|
Provenance
The following attestation bundles were made for ad_user_manager-0.1.0a20-py3-none-any.whl:
Publisher:
pypi-publish.yml on VinnyVanGogh/py-ad-user-mgr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ad_user_manager-0.1.0a20-py3-none-any.whl -
Subject digest:
6d49553209884a51c778ff89c66651ed60bd9472123ebc91a241806de63822a6 - Sigstore transparency entry: 251955918
- Sigstore integration time:
-
Permalink:
VinnyVanGogh/py-ad-user-mgr@5b6c75b98dca8bf1a21baabf34d6be4bb2a27bd1 -
Branch / Tag:
refs/tags/v0.1.0-alpha.21 - Owner: https://github.com/VinnyVanGogh
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@5b6c75b98dca8bf1a21baabf34d6be4bb2a27bd1 -
Trigger Event:
push
-
Statement type: