Skip to content

cloudflare-auth package has broken imports (src.config.settings does not exist) #2

@williaby

Description

@williaby

Summary

The cloudflare-auth package cannot be installed and used as a standalone package because it imports from a non-existent module src.config.settings.

Problem

Three files have broken imports:

# In validators.py, middleware.py, middleware_enhanced.py
from src.config.settings import CloudflareSettings, get_cloudflare_settings

The CloudflareSettings class and get_cloudflare_settings() function do not exist anywhere in the cloudflare-auth package. These were external application configuration that was never included when the package was extracted.

Error When Installing

ModuleNotFoundError: No module named 'src.config'

Impact

  • Cannot use cloudflare-auth as a Git URL dependency
  • Cannot use cloudflare-auth from Artifact Registry
  • homelab-infra must maintain a local copy with modified imports

Proposed Solutions

Option 1: Include settings module in package (Recommended)

Create cloudflare_auth/config.py with:

  • CloudflareSettings - Pydantic settings class for Cloudflare configuration
  • get_cloudflare_settings() - Factory function with caching

Update the three files to import from cloudflare_auth.config instead of src.config.settings.

Option 2: Constructor-only configuration

Remove settings imports entirely and require all configuration to be passed via constructor parameters. This makes the package more flexible but requires more setup code.

Option 3: Environment variables directly

Use os.environ.get() directly instead of a settings class. Simpler but less structured.

Files to Update

  1. packages/cloudflare-auth/src/cloudflare_auth/validators.py
  2. packages/cloudflare-auth/src/cloudflare_auth/middleware.py
  3. packages/cloudflare-auth/src/cloudflare_auth/middleware_enhanced.py
  4. Create: packages/cloudflare-auth/src/cloudflare_auth/config.py (if Option 1)

Reference Implementation

The CloudflareSettings class from homelab-infra can be used as a starting point:

from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic import Field
from typing import Literal
from functools import lru_cache

class CloudflareSettings(BaseSettings):
    model_config = SettingsConfigDict(
        env_file=".env",
        env_file_encoding="utf-8",
        case_sensitive=False,
        extra="ignore",
    )

    environment: Literal["dev", "staging", "prod"] = "dev"
    cloudflare_team_domain: str = Field(default="")
    cloudflare_audience_tag: str = Field(default="")
    cloudflare_enabled: bool = True
    # ... additional fields

@lru_cache
def get_cloudflare_settings() -> CloudflareSettings:
    return CloudflareSettings()

Related

  • Blocks: ByronWilliamsCPA/homelab-infra PR #54 (remove cloudflare-auth duplication)

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions