Fix code formatting and linting issues
- Updated GitHub Actions workflow to use correct flake8 configuration - Fixed line length issues by using 88 characters as configured - Removed unused imports and trailing whitespace - Fixed f-string placeholders and unused variables - All linting checks now pass with project configuration 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,12 +5,12 @@ providing a consistent interface for different authentication methods.
|
||||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Dict, Optional
|
||||
from typing import Dict
|
||||
|
||||
|
||||
class AuthHandler(ABC):
|
||||
"""Abstract base class for Wiki.js authentication handlers.
|
||||
|
||||
|
||||
This class defines the interface that all authentication implementations
|
||||
must follow, ensuring consistent behavior across different auth methods.
|
||||
"""
|
||||
@@ -18,56 +18,54 @@ class AuthHandler(ABC):
|
||||
@abstractmethod
|
||||
def get_headers(self) -> Dict[str, str]:
|
||||
"""Get authentication headers for HTTP requests.
|
||||
|
||||
|
||||
Returns:
|
||||
Dict[str, str]: Dictionary of headers to include in requests.
|
||||
|
||||
|
||||
Raises:
|
||||
AuthenticationError: If authentication is invalid or expired.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def is_valid(self) -> bool:
|
||||
"""Check if the current authentication is valid.
|
||||
|
||||
|
||||
Returns:
|
||||
bool: True if authentication is valid, False otherwise.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def refresh(self) -> None:
|
||||
"""Refresh the authentication if possible.
|
||||
|
||||
|
||||
For token-based authentication, this should refresh the token.
|
||||
For API key authentication, this is typically a no-op.
|
||||
|
||||
|
||||
Raises:
|
||||
AuthenticationError: If refresh fails.
|
||||
"""
|
||||
pass
|
||||
|
||||
def validate_credentials(self) -> None:
|
||||
"""Validate credentials and refresh if necessary.
|
||||
|
||||
|
||||
This is a convenience method that checks validity and refreshes
|
||||
if needed. Subclasses can override for custom behavior.
|
||||
|
||||
|
||||
Raises:
|
||||
AuthenticationError: If credentials are invalid or refresh fails.
|
||||
"""
|
||||
if not self.is_valid():
|
||||
self.refresh()
|
||||
|
||||
|
||||
if not self.is_valid():
|
||||
from ..exceptions import AuthenticationError
|
||||
|
||||
raise AuthenticationError("Authentication credentials are invalid")
|
||||
|
||||
|
||||
class NoAuth(AuthHandler):
|
||||
"""No-authentication handler for testing or public instances.
|
||||
|
||||
|
||||
This handler provides an empty authentication implementation,
|
||||
useful for testing or when accessing public Wiki.js instances
|
||||
that don't require authentication.
|
||||
@@ -75,7 +73,7 @@ class NoAuth(AuthHandler):
|
||||
|
||||
def get_headers(self) -> Dict[str, str]:
|
||||
"""Return empty headers dict.
|
||||
|
||||
|
||||
Returns:
|
||||
Dict[str, str]: Empty dictionary.
|
||||
"""
|
||||
@@ -83,7 +81,7 @@ class NoAuth(AuthHandler):
|
||||
|
||||
def is_valid(self) -> bool:
|
||||
"""Always return True for no-auth.
|
||||
|
||||
|
||||
Returns:
|
||||
bool: Always True.
|
||||
"""
|
||||
@@ -91,7 +89,6 @@ class NoAuth(AuthHandler):
|
||||
|
||||
def refresh(self) -> None:
|
||||
"""No-op for no-auth.
|
||||
|
||||
|
||||
This method does nothing since there's no authentication to refresh.
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user