Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ than stored in the configuration file:
| Variable | Purpose |
|---|---|
| `VIP_CONNECT_API_KEY` | Connect admin API key |
| `VIP_WORKBENCH_API_KEY` | Workbench admin API key |
| `VIP_PM_TOKEN` | Package Manager token |
| `VIP_TEST_USERNAME` | Test user login name |
| `VIP_TEST_PASSWORD` | Test user login password |

Expand Down
7 changes: 5 additions & 2 deletions src/vip/clients/packagemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
class PackageManagerClient:
"""Minimal Package Manager HTTP wrapper."""

def __init__(self, base_url: str, *, timeout: float = 30.0) -> None:
def __init__(self, base_url: str, token: str = "", *, timeout: float = 30.0) -> None:
self.base_url = base_url.rstrip("/")
self._client = httpx.Client(base_url=self.base_url, timeout=timeout)
headers = {}
if token:
headers["Authorization"] = f"Bearer {token}"
self._client = httpx.Client(base_url=self.base_url, headers=headers, timeout=timeout)

# -- Health / status ----------------------------------------------------

Expand Down
7 changes: 5 additions & 2 deletions src/vip/clients/workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
class WorkbenchClient:
"""Minimal Workbench HTTP wrapper."""

def __init__(self, base_url: str, *, timeout: float = 30.0) -> None:
def __init__(self, base_url: str, api_key: str = "", *, timeout: float = 30.0) -> None:
self.base_url = base_url.rstrip("/")
self._client = httpx.Client(base_url=self.base_url, timeout=timeout)
headers = {}
if api_key:
headers["Authorization"] = f"Key {api_key}"
self._client = httpx.Client(base_url=self.base_url, headers=headers, timeout=timeout)

# -- Health / info ------------------------------------------------------

Expand Down
32 changes: 28 additions & 4 deletions src/vip/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ def __post_init__(self) -> None:
self.api_key = os.environ.get("VIP_CONNECT_API_KEY", "")


@dataclass
class WorkbenchConfig(ProductConfig):
"""Workbench-specific configuration."""

api_key: str = ""

def __post_init__(self) -> None:
if not self.api_key:
self.api_key = os.environ.get("VIP_WORKBENCH_API_KEY", "")


@dataclass
class PackageManagerConfig(ProductConfig):
"""Package Manager-specific configuration."""

token: str = ""

def __post_init__(self) -> None:
if not self.token:
self.token = os.environ.get("VIP_PM_TOKEN", "")


@dataclass
class AuthConfig:
"""Authentication configuration."""
Expand Down Expand Up @@ -77,8 +99,8 @@ class VIPConfig:
extension_dirs: list[str] = field(default_factory=list)

connect: ConnectConfig = field(default_factory=ConnectConfig)
workbench: ProductConfig = field(default_factory=ProductConfig)
package_manager: ProductConfig = field(default_factory=ProductConfig)
workbench: WorkbenchConfig = field(default_factory=WorkbenchConfig)
package_manager: PackageManagerConfig = field(default_factory=PackageManagerConfig)

auth: AuthConfig = field(default_factory=AuthConfig)
runtimes: RuntimesConfig = field(default_factory=RuntimesConfig)
Expand Down Expand Up @@ -153,15 +175,17 @@ def load_config(path: str | Path | None = None) -> VIPConfig:
version=connect_raw.get("version"),
api_key=connect_raw.get("api_key", ""),
),
workbench=ProductConfig(
workbench=WorkbenchConfig(
enabled=workbench_raw.get("enabled", True),
url=workbench_raw.get("url", ""),
version=workbench_raw.get("version"),
api_key=workbench_raw.get("api_key", ""),
),
package_manager=ProductConfig(
package_manager=PackageManagerConfig(
enabled=pm_raw.get("enabled", True),
url=pm_raw.get("url", ""),
version=pm_raw.get("version"),
token=pm_raw.get("token", ""),
),
auth=AuthConfig(
provider=auth_raw.get("provider", "password"),
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def connect_url(vip_config: VIPConfig) -> str:
def workbench_client(vip_config: VIPConfig) -> WorkbenchClient | None:
if not vip_config.workbench.is_configured:
return None
client = WorkbenchClient(vip_config.workbench.url)
client = WorkbenchClient(vip_config.workbench.url, vip_config.workbench.api_key)
yield client
client.close()

Expand All @@ -58,7 +58,7 @@ def workbench_url(vip_config: VIPConfig) -> str:
def pm_client(vip_config: VIPConfig) -> PackageManagerClient | None:
if not vip_config.package_manager.is_configured:
return None
client = PackageManagerClient(vip_config.package_manager.url)
client = PackageManagerClient(vip_config.package_manager.url, vip_config.package_manager.token)
yield client
client.close()

Expand Down
8 changes: 8 additions & 0 deletions vip.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ enabled = true
url = "https://workbench.example.com"
# version = "2024.09.0"

# API key for a Workbench admin user.
# Prefer setting the VIP_WORKBENCH_API_KEY environment variable.
# api_key = "..."

[package_manager]
enabled = true
url = "https://packagemanager.example.com"
# version = "2024.09.0"

# Token for a Package Manager user.
# Prefer setting the VIP_PM_TOKEN environment variable.
# token = "..."

[auth]
# Authentication provider in use: "password", "ldap", "saml", "oidc", "oauth2"
provider = "password"
Expand Down
Loading