Skip to content

Commit

Permalink
feat(agent): redacted url
Browse files Browse the repository at this point in the history
  • Loading branch information
floork committed Oct 18, 2024
1 parent 52617be commit 96bb187
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion metricq/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ def __init__(
__version__,
)

@property
def url(self) -> str:
"""
The management URL with the password replaced by '******', if user present.
"""
url = URL(self._management_url)
if url.user:
return str(url.with_password("******"))
return self._management_url

def derive_address(self, address: str) -> str:
"""Add the credentials from the management connection to the provided address
Expand Down Expand Up @@ -244,7 +254,7 @@ async def connect(self) -> None:
"""Connect to the MetricQ network"""
logger.info(
"establishing management connection to {}",
URL(self._management_url).with_password("******"),
self.url,
)

try:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ def test_agent_url_and_management_url() -> None:
url="amqps://test.invalid",
management_url="amqps://test.invalid",
)


def test_agent_redacted_url() -> None:
agent = Agent(token="test", url="amqps://user:[email protected]")
assert agent.url == "amqps://user:******@test.invalid"


def test_agent_redacted_url_no_login_info() -> None:
agent = Agent(token="test", url="amqps://test.invalid")
assert agent.url == "amqps://test.invalid"

0 comments on commit 96bb187

Please sign in to comment.