Skip to content
Merged
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
18 changes: 7 additions & 11 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,30 @@ def run(self):
@click.option(
"--entraid-identity-type",
type=click.Choice(["system_assigned", "user_assigned"]),
default="system_assigned",
help="Managed identity type",
help="Managed identity type (env: REDIS_ENTRAID_IDENTITY_TYPE, default system_assigned)",
)
@click.option(
"--entraid-scopes",
default="https://redis.azure.com/.default",
help="Entra ID scopes (comma-separated)",
help="Entra ID scopes (comma-separated) (env: REDIS_ENTRAID_SCOPES, default https://redis.azure.com/.default)",
)
@click.option(
"--entraid-resource", default="https://redis.azure.com/", help="Entra ID resource"
"--entraid-resource",
help="Entra ID resource (env: REDIS_ENTRAID_RESOURCE, default https://redis.azure.com/)",
)
@click.option(
"--entraid-token-refresh-ratio",
type=float,
default=0.9,
help="Token expiration refresh ratio",
help="Token expiration refresh ratio (env: REDIS_ENTRAID_TOKEN_EXPIRATION_REFRESH_RATIO, default 0.9)",
)
@click.option(
"--entraid-retry-max-attempts",
type=int,
default=3,
help="Maximum retry attempts for token requests",
help="Maximum retry attempts for token requests (env: REDIS_ENTRAID_RETRY_MAX_ATTEMPTS, default 3)",
)
@click.option(
"--entraid-retry-delay-ms",
type=int,
default=100,
help="Retry delay in milliseconds",
help="Retry delay in milliseconds (env: REDIS_ENTRAID_RETRY_DELAY_MS, default 100)",
)
def cli(
url,
Expand Down
36 changes: 36 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,39 @@ def test_env_values_survive_cli_without_flags(
assert cfg.REDIS_CFG["host"] == "redis.example.com"
assert cfg.REDIS_CFG["port"] == 6380
assert cfg.REDIS_CFG["ssl"] is True


class TestCLIDefaultsDoNotOverrideEntraIDEnv:
"""Unset --entraid-* options must not override REDIS_ENTRAID_* config (#207)."""

def setup_method(self):
self.runner = CliRunner()

@patch("src.main.set_entraid_config_from_cli")
@patch("src.main.RedisMCPServer")
def test_unset_options_are_not_forwarded(self, mock_server_class, mock_set_config):
result = self.runner.invoke(cli, [])

assert result.exit_code == 0
mock_set_config.assert_not_called()

@patch("src.main.RedisMCPServer")
def test_env_values_survive_cli_without_flags(self, mock_server_class, monkeypatch):
from src.common import config as cfg

env_values = {
"identity_type": "user_assigned",
"scopes": "custom-scope",
"resource": "https://custom/",
"token_expiration_refresh_ratio": 0.5,
"retry_max_attempts": 9,
"retry_delay_ms": 500,
}
for key, value in env_values.items():
monkeypatch.setitem(cfg.ENTRAID_CFG, key, value)

result = self.runner.invoke(cli, [])

assert result.exit_code == 0
for key, value in env_values.items():
assert cfg.ENTRAID_CFG[key] == value
Loading