Complete package renaming and platform migration: Package Name Changes: - Rename package from 'wikijs-python-sdk' to 'py-wikijs' - Update setup.py package name - Update pyproject.toml package name - Users can now install with: pip install py-wikijs URL Migration (Gitea → GitHub): - Replace all Gitea URLs with GitHub URLs - Update repository: github.com/l3ocho/py-wikijs - Update issue tracker: github.com/l3ocho/py-wikijs/issues - Update documentation links - Fix URL path format (/src/branch/main/ → /blob/main/) Documentation Updates: - Update README.md badges (PyPI, GitHub) - Update installation instructions (pip install py-wikijs) - Update all doc references to new package name - Update all examples with GitHub URLs - Update DEPLOYMENT_READY.md with new package name - Update deployment.md with new package name Testing: - Successfully built py_wikijs-0.1.0.tar.gz (138 KB) - Successfully built py_wikijs-0.1.0-py3-none-any.whl (66 KB) - Package installs correctly: pip install py-wikijs - Imports work: from wikijs import WikiJSClient - Package metadata correct (Home-page: github.com/l3ocho/py-wikijs) Breaking Changes: - Package name changed from wikijs-python-sdk to py-wikijs - Repository migrated from Gitea to GitHub - All URLs updated to GitHub Users should now: pip install py-wikijs # Instead of wikijs-python-sdk 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
"""API key authentication for py-wikijs.
|
|
|
|
This module implements API key authentication for Wiki.js instances.
|
|
API keys are typically used for server-to-server authentication.
|
|
"""
|
|
|
|
from typing import Dict
|
|
|
|
from .base import AuthHandler
|
|
|
|
|
|
class APIKeyAuth(AuthHandler):
|
|
"""API key authentication handler for Wiki.js.
|
|
|
|
This handler implements authentication using an API key, which is
|
|
included in the Authorization header as a Bearer token.
|
|
|
|
Args:
|
|
api_key: The API key string from Wiki.js admin panel.
|
|
|
|
Example:
|
|
>>> auth = APIKeyAuth("your-api-key-here")
|
|
>>> client = WikiJSClient("https://wiki.example.com", auth=auth)
|
|
"""
|
|
|
|
def __init__(self, api_key: str) -> None:
|
|
"""Initialize API key authentication.
|
|
|
|
Args:
|
|
api_key: The API key from Wiki.js admin panel.
|
|
|
|
Raises:
|
|
ValueError: If api_key is empty or None.
|
|
"""
|
|
if not api_key or not api_key.strip():
|
|
raise ValueError("API key cannot be empty")
|
|
|
|
self._api_key = api_key.strip()
|
|
|
|
def get_headers(self) -> Dict[str, str]:
|
|
"""Get authentication headers with API key.
|
|
|
|
Returns:
|
|
Dict[str, str]: Headers containing the Authorization header.
|
|
"""
|
|
return {
|
|
"Authorization": f"Bearer {self._api_key}",
|
|
"Content-Type": "application/json",
|
|
}
|
|
|
|
def is_valid(self) -> bool:
|
|
"""Check if API key is valid.
|
|
|
|
For API keys, we assume they're valid if they're not empty.
|
|
Actual validation happens on the server side.
|
|
|
|
Returns:
|
|
bool: True if API key exists, False otherwise.
|
|
"""
|
|
return bool(self._api_key and self._api_key.strip())
|
|
|
|
def refresh(self) -> None:
|
|
"""Refresh authentication credentials.
|
|
|
|
API keys don't typically need refreshing, so this is a no-op.
|
|
If the API key becomes invalid, a new one must be provided.
|
|
"""
|
|
# API keys don't refresh - they're static until manually replaced
|
|
|
|
@property
|
|
def api_key(self) -> str:
|
|
"""Get the masked API key for logging/debugging.
|
|
|
|
Returns:
|
|
str: Masked API key showing only first 4 and last 4 characters.
|
|
"""
|
|
if len(self._api_key) <= 8:
|
|
return "*" * len(self._api_key)
|
|
|
|
return (
|
|
f"{self._api_key[:4]}{'*' * (len(self._api_key) - 8)}{self._api_key[-4:]}"
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
"""String representation of the auth handler.
|
|
|
|
Returns:
|
|
str: Safe representation with masked API key.
|
|
"""
|
|
return f"APIKeyAuth(api_key='{self.api_key}')"
|