Author: Adrian Johnson [email protected]
Version: 1.0
Date: October 22, 2025
All scripts provide identical functionality - they validate devices against multiple sources (CSV, Database, Azure, Kubernetes, ServiceNow) and return authorization status.
| Script | Language | Best For | Build Required | Dependencies |
|---|---|---|---|---|
| validate-device.py | Python 3.7+ | Cross-platform, rapid development | No | Python runtime, libraries |
| validate-device.ps1 | PowerShell 7+ | Windows environments, Azure-heavy | No | PowerShell runtime |
| validate-device.go | Go 1.19+ | Performance, containers, single binary | Yes | None (static binary) |
| validate-device.sh | Bash 4+ | Linux-only, minimal dependencies | No | Standard Unix tools |
Pros:
- ✅ Cross-platform (Windows, Linux, macOS)
- ✅ Easy to read and maintain
- ✅ Rich library ecosystem (requests, psycopg2, azure-identity)
- ✅ No compilation needed
- ✅ Great for prototyping and iteration
Cons:
- ❌ Requires Python runtime (2.7 or 3.x)
- ❌ Dependencies need to be installed (pip)
- ❌ Slower than compiled languages
- ❌ ~100ms startup overhead
Installation:
# Install Python dependencies
pip3 install psycopg2-binary requests azure-identity azure-mgmt-resourcegraph
# Make executable
chmod +x validate-device.py
# Test
./validate-device.py webapp01.contoso.comSee INSTALLATION.md for complete setup instructions.
When to Use: Default choice for most environments. Great for teams familiar with Python.
Pros:
- ✅ Native Windows integration
- ✅ Excellent Azure support (Az modules)
- ✅ Active Directory queries built-in
- ✅ No compilation needed
- ✅ Cross-platform with PowerShell Core 7+
- ✅ Native JSON/XML/CSV handling
Cons:
- ❌ Slower than Go (~200ms overhead)
- ❌ Requires PowerShell runtime
- ❌ Module dependencies (Az.ResourceGraph, Npgsql)
- ❌ Verbose syntax
Installation:
# Install PowerShell modules
Install-Module -Name Az.ResourceGraph -Scope CurrentUser -Force
Install-Module -Name Npgsql -Scope CurrentUser -Force # For PostgreSQL
# Set execution policy (if needed)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Test
.\validate-device.ps1 -Hostname webapp01.contoso.com -VerboseWhen to Use:
- Windows-heavy environments
- Teams primarily using PowerShell
- Need native Azure/AD integration
- IIS/Windows Server management
Pros:
- ✅ Fastest (~5ms startup, <50ms total)
- ✅ Single static binary (no dependencies)
- ✅ Cross-platform compilation
- ✅ Excellent for containers (small image size)
- ✅ Concurrent operations (goroutines)
- ✅ Type-safe
Cons:
- ❌ Requires compilation
- ❌ More verbose than Python/PowerShell
- ❌ Learning curve for non-Go teams
- ❌ Separate builds for Windows/Linux
Installation:
# Install Go dependencies
go mod init validate-device
go get github.com/lib/pq # PostgreSQL driver
# Build for current platform
go build -o validate-device validate-device.go
# Build for other platforms
GOOS=linux GOARCH=amd64 go build -o validate-device-linux validate-device.go
GOOS=windows GOARCH=amd64 go build -o validate-device.exe validate-device.go
# Make executable (Linux/Mac)
chmod +x validate-device
# Test
./validate-device webapp01.contoso.comWhen to Use:
- Performance-critical paths (high-volume validation)
- Container/Kubernetes environments
- Need single binary deployment
- Minimal dependencies required
- Multi-platform distribution
Pros:
- ✅ Native on all Linux systems
- ✅ No additional dependencies (uses standard tools)
- ✅ Fast (~50ms)
- ✅ Easy to understand for sysadmins
- ✅ Can be embedded in other scripts
Cons:
- ❌ Linux/Unix only (not Windows native)
- ❌ Limited error handling
- ❌ String manipulation is clunky
- ❌ Requires external tools (psql, az, kubectl, curl, jq)
Installation:
# Install required tools (most are standard)
# Ubuntu/Debian
sudo apt-get install postgresql-client curl jq
# RHEL/CentOS
sudo yum install postgresql curl jq
# Make executable
chmod +x validate-device.sh
# Test
./validate-device.sh webapp01.contoso.comWhen to Use:
- Pure Linux environments
- Simple scripting needs
- Team familiar with bash
- Need to embed in existing shell scripts
Test: Validate 100 hostnames from CSV (cached)
| Language | Time (avg) | Memory | Binary Size | Startup Overhead |
|---|---|---|---|---|
| Go | 0.8 sec | 8 MB | 6 MB | ~5ms |
| Bash | 2.1 sec | 2 MB | N/A (script) | ~10ms |
| Python | 3.5 sec | 25 MB | N/A (script) | ~100ms |
| PowerShell | 4.2 sec | 45 MB | N/A (script) | ~200ms |
Conclusion:
- Go: Best for high-volume/production
- Bash: Good balance for Linux
- Python: Best developer experience
- PowerShell: Best for Windows/Azure
| Feature | Python | PowerShell | Go | Bash |
|---|---|---|---|---|
| CSV validation | ✅ | ✅ | ✅ | ✅ |
| PostgreSQL query | ✅ | ✅ | ✅ | ✅ |
| Azure Resource Graph | ✅ | ✅ | ||
| AWS query | ✅ | ✅ | ||
| Kubernetes | ✅ | ✅ | ✅ | ✅ |
| ServiceNow API | ✅ | ✅ | ✅ | ✅ |
| Caching | ✅ | ✅ | ✅ | ✅ |
| Error handling | Excellent | Excellent | Excellent | Basic |
| Debugging | Easy | Easy | Moderate | Easy |
| Unit testing | Excellent | Good | Excellent | Difficult |
All scripts use the same command-line interface:
# Basic usage
<script> <hostname>
# With requester (future use)
<script> <hostname> <requester_email>
# Examples
./validate-device.py webapp01.contoso.com
./validate-device.ps1 -Hostname webapp01.contoso.com
./validate-device webapp01.contoso.com # Go binary
./validate-device.sh webapp01.contoso.comOutput Format (all scripts):
# Success
AUTHORIZED|team-web-apps|production|12345
Exit code: 0
# Failure
DENIED|Device 'nonexistent.contoso.com' not found in any inventory source
Exit code: 1
All scripts respect the same environment variables:
| Variable | Purpose | Default |
|---|---|---|
ASSET_CSV_PATH |
Path to CSV file | /opt/keyfactor/asset-inventory/asset-inventory.csv |
ASSET_CACHE_PATH |
Cache file location | /tmp/asset-inventory-cache.* |
ASSET_DB_HOST |
PostgreSQL host | asset-db.contoso.com |
ASSET_DB_USER |
Database username | keyfactor_reader |
ASSET_DB_PASSWORD |
Database password | (required if using DB) |
SNOW_INSTANCE |
ServiceNow instance | contoso.service-now.com |
SNOW_USER |
ServiceNow username | keyfactor-api |
SNOW_PASSWORD |
ServiceNow password | (required if using SNOW) |
AZURE_SUBSCRIPTION_ID |
Azure subscription | (auto-detected) |
- ✅ Team is familiar with Python
- ✅ Need cross-platform support
- ✅ Rapid development/iteration needed
- ✅ Comfortable with pip/virtualenv
- ✅ Want rich library ecosystem
- ✅ Windows-heavy environment
- ✅ Team primarily uses PowerShell
- ✅ Heavy Azure/AD integration needed
- ✅ Managing IIS/Windows servers
- ✅ Want native Microsoft tooling
- ✅ Performance is critical (>1000 requests/day)
- ✅ Deploy in containers
- ✅ Want single static binary
- ✅ No dependencies allowed
- ✅ Multi-platform distribution needed
- ✅ Pure Linux environment
- ✅ Team familiar with shell scripting
- ✅ Need minimal dependencies
- ✅ Embedding in existing bash workflows
- ✅ Simple, straightforward needs
| Environment Type | Recommended | Alternative |
|---|---|---|
| Windows + Azure | PowerShell | Python |
| Linux + AWS | Python | Go |
| Kubernetes | Go | Python |
| Hybrid (Windows + Linux) | Python | Go |
| High-volume (>10k/day) | Go | Python |
| Rapid prototyping | Python | Bash |
| Enterprise (existing Python team) | Python | PowerShell |
| Enterprise (existing .NET/PowerShell team) | PowerShell | Python |
| Containers/microservices | Go | Python |
# Test suite (works with any script)
for script in validate-device.py validate-device.ps1 validate-device validate-device.sh; do
echo "Testing $script..."
# Test valid device
$script webapp01.contoso.com && echo "✅ Valid test passed" || echo "❌ Valid test failed"
# Test invalid device
! $script nonexistent.contoso.com 2>/dev/null && echo "✅ Invalid test passed" || echo "❌ Invalid test failed"
echo ""
doneYou can use different languages for different tasks:
# Windows servers: PowerShell (native)
.\validate-device.ps1 -Hostname $hostname
# Linux servers: Go (performance)
./validate-device $hostname
# Development/testing: Python (ease of use)
python3 validate-device.py $hostname
# CI/CD pipelines: Go (containers)
docker run --rm keyfactor/validator:latest $hostnameGo is best for containers (smallest image):
# Dockerfile for Go validator
FROM golang:1.19-alpine AS builder
WORKDIR /build
COPY validate-device.go go.mod go.sum ./
RUN go build -o validate-device -ldflags="-s -w" validate-device.go
FROM alpine:latest
RUN apk add --no-cache ca-certificates
COPY --from=builder /build/validate-device /usr/local/bin/
ENTRYPOINT ["validate-device"]
# Image size: ~15 MB# Dockerfile for Python validator
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY validate-device.py .
ENTRYPOINT ["python3", "validate-device.py"]
# Image size: ~150 MBAll scripts work identically with Keyfactor:
# Keyfactor webhook handler (any language)
webhook_validation:
command: "/opt/keyfactor/scripts/validate-device.{py|ps1|sh|go}"
arguments: ["${hostname}", "${requester}"]
timeout: 5s
expected_exit_codes: [0]
parse_output: "AUTHORIZED\\|(.*)\\|(.*)\\|(.*)"Main Guide: ASSET-INVENTORY-INTEGRATION-GUIDE.md
Questions:
- Language choice: Contact Adrian Johnson [email protected]
- Python issues: #python-support
- PowerShell issues: #powershell-support
- Go issues: #go-support
Version: 1.0
Last Updated: October 22, 2025
Maintained by: Adrian Johnson [email protected]