Skip to content
Open
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: 1 addition & 1 deletion src/viam/app/viam_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def create_from_dial_options(cls, dial_options: DialOptions, app_url: Opti
self._dial_options = dial_options
if app_url is None:
app_url = "app.viam.com"
self._channel = await _dial_app(app_url)
self._channel = await _dial_app(app_url, dial_options)
access_token = await _get_access_token(self._channel, dial_options.auth_entity, dial_options)
self._metadata = {"authorization": f"Bearer {access_token}"}
return self
Expand Down
4 changes: 2 additions & 2 deletions src/viam/rpc/dial.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,5 +416,5 @@ async def dial_direct(address: str, options: Optional[DialOptions] = None) -> Ch
return await _dial_direct(address, options)


async def _dial_app(app_url: str) -> Channel:
return await _dial_direct(app_url)
async def _dial_app(app_url: str, options: Optional[DialOptions] = None) -> Channel:
return await _dial_direct(app_url, options)
28 changes: 28 additions & 0 deletions tests/test_viam_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ async def test_sets_fields(self):
assert DIAL_OPTIONS.auth_entity is not None
assert client._metadata == {"authorization": f"Bearer {ACCESS_TOKEN}"}

async def test_passes_dial_options_to_dial_app(self):
async with ChannelFor([]) as channel:
with patch("viam.app.viam_client._dial_app") as patched_dial:
patched_dial.return_value = channel
with patch("viam.app.viam_client._get_access_token") as patched_auth:
patched_auth.return_value = "MY_ACCESS_TOKEN"

creds = Credentials("api-key", "SOME_API_KEY")
dial_options = DialOptions(credentials=creds, auth_entity=str(uuid4()), insecure=True)

await ViamClient.create_from_dial_options(dial_options)

patched_dial.assert_called_once_with("app.viam.com", dial_options)

async def test_passes_dial_options_with_custom_url(self):
async with ChannelFor([]) as channel:
with patch("viam.app.viam_client._dial_app") as patched_dial:
patched_dial.return_value = channel
with patch("viam.app.viam_client._get_access_token") as patched_auth:
patched_auth.return_value = "MY_ACCESS_TOKEN"

creds = Credentials("api-key", "SOME_API_KEY")
dial_options = DialOptions(credentials=creds, auth_entity=str(uuid4()), insecure=True)

await ViamClient.create_from_dial_options(dial_options, app_url="localhost:8080")

patched_dial.assert_called_once_with("localhost:8080", dial_options)

async def test_clients(self):
async with ChannelFor([]) as channel:
with patch("viam.app.viam_client._dial_app") as patched_dial:
Expand Down
Loading