Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use servicehandlers server for remote API #502

Merged
merged 1 commit into from
Sep 12, 2023
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
3 changes: 0 additions & 3 deletions hass_nabucasa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def __init__(
alexa_server: str | None = None,
cloudhook_server: str | None = None,
relayer_server: str | None = None,
remote_sni_server: str | None = None,
remotestate_server: str | None = None,
thingtalk_server: str | None = None,
servicehandlers_server: str | None = None,
Expand Down Expand Up @@ -90,7 +89,6 @@ def __init__(
self.alexa_server = alexa_server
self.cloudhook_server = cloudhook_server
self.relayer_server = relayer_server
self.remote_sni_server = remote_sni_server
self.remotestate_server = remotestate_server
self.thingtalk_server = thingtalk_server
self.servicehandlers_server = servicehandlers_server
Expand All @@ -110,7 +108,6 @@ def __init__(
self.alexa_server = _servers["alexa"]
self.cloudhook_server = _servers["cloudhook"]
self.relayer_server = _servers["relayer"]
self.remote_sni_server = _servers["remote_sni"]
self.remotestate_server = _servers["remotestate"]
self.thingtalk_server = _servers["thingtalk"]
self.servicehandlers_server = _servers["servicehandlers"]
Expand Down
8 changes: 4 additions & 4 deletions hass_nabucasa/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def async_create_cloudhook(cloud: Cloud[_ClientT]) -> ClientResponse:
@_log_response
async def async_remote_register(cloud: Cloud[_ClientT]) -> ClientResponse:
"""Create/Get a remote URL."""
url = f"https://{cloud.remote_sni_server}/register_instance"
url = f"https://{cloud.servicehandlers_server}/instance/register"
return await cloud.websession.post(url, headers={AUTHORIZATION: cloud.id_token})


Expand All @@ -79,7 +79,7 @@ async def async_remote_token(
cloud: Cloud[_ClientT], aes_key: bytes, aes_iv: bytes
) -> ClientResponse:
"""Create a remote snitun token."""
url = f"https://{cloud.remote_sni_server}/snitun_token"
url = f"https://{cloud.servicehandlers_server}/instance/snitun_token"
return await cloud.websession.post(
url,
headers={AUTHORIZATION: cloud.id_token},
Expand All @@ -93,7 +93,7 @@ async def async_remote_challenge_txt(
cloud: Cloud[_ClientT], txt: str
) -> ClientResponse:
"""Set DNS challenge."""
url = f"https://{cloud.remote_sni_server}/challenge_txt"
url = f"https://{cloud.servicehandlers_server}/instance/dns_challenge_txt"
return await cloud.websession.post(
url, headers={AUTHORIZATION: cloud.id_token}, json={"txt": txt}
)
Expand All @@ -105,7 +105,7 @@ async def async_remote_challenge_cleanup(
cloud: Cloud[_ClientT], txt: str
) -> ClientResponse:
"""Remove DNS challenge."""
url = f"https://{cloud.remote_sni_server}/challenge_cleanup"
url = f"https://{cloud.servicehandlers_server}/instance/dns_challenge_cleanup"
return await cloud.websession.post(
url, headers={AUTHORIZATION: cloud.id_token}, json={"txt": txt}
)
Expand Down
1 change: 0 additions & 1 deletion hass_nabucasa/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"alexa": "alexa-api.nabucasa.com",
"cloudhook": "webhooks-api.nabucasa.com",
"relayer": "cloud.nabucasa.com",
"remote_sni": "remote-sni-api.nabucasa.com",
"remotestate": "remotestate.nabucasa.com",
"servicehandlers": "servicehandlers.nabucasa.com",
"thingtalk": "thingtalk-api.nabucasa.com",
Expand Down
16 changes: 8 additions & 8 deletions tests/test_cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ async def test_create_cloudhook(auth_cloud_mock, aioclient_mock):
async def test_remote_register(auth_cloud_mock, aioclient_mock):
"""Test creating a cloudhook."""
aioclient_mock.post(
"https://example.com/bla/register_instance",
"https://example.com/bla/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
auth_cloud_mock.id_token = "mock-id-token"
auth_cloud_mock.remote_sni_server = "example.com/bla"
auth_cloud_mock.servicehandlers_server = "example.com/bla"

resp = await cloud_api.async_remote_register(auth_cloud_mock)
assert len(aioclient_mock.mock_calls) == 1
Expand All @@ -46,7 +46,7 @@ async def test_remote_register(auth_cloud_mock, aioclient_mock):
async def test_remote_token(auth_cloud_mock, aioclient_mock):
"""Test creating a cloudhook."""
aioclient_mock.post(
"https://example.com/snitun_token",
"https://example.com/instance/snitun_token",
json={
"token": "123456",
"server": "rest-remote.nabu.casa",
Expand All @@ -55,7 +55,7 @@ async def test_remote_token(auth_cloud_mock, aioclient_mock):
},
)
auth_cloud_mock.id_token = "mock-id-token"
auth_cloud_mock.remote_sni_server = "example.com"
auth_cloud_mock.servicehandlers_server = "example.com"

resp = await cloud_api.async_remote_token(auth_cloud_mock, b"aes", b"iv")
assert len(aioclient_mock.mock_calls) == 1
Expand All @@ -70,9 +70,9 @@ async def test_remote_token(auth_cloud_mock, aioclient_mock):

async def test_remote_challenge_txt(auth_cloud_mock, aioclient_mock):
"""Test creating a cloudhook."""
aioclient_mock.post("https://example.com/challenge_txt")
aioclient_mock.post("https://example.com/instance/dns_challenge_txt")
auth_cloud_mock.id_token = "mock-id-token"
auth_cloud_mock.remote_sni_server = "example.com"
auth_cloud_mock.servicehandlers_server = "example.com"

await cloud_api.async_remote_challenge_txt(auth_cloud_mock, "123456")
assert len(aioclient_mock.mock_calls) == 1
Expand All @@ -81,9 +81,9 @@ async def test_remote_challenge_txt(auth_cloud_mock, aioclient_mock):

async def test_remote_challenge_cleanup(auth_cloud_mock, aioclient_mock):
"""Test creating a cloudhook."""
aioclient_mock.post("https://example.com/challenge_cleanup")
aioclient_mock.post("https://example.com/instance/dns_challenge_cleanup")
auth_cloud_mock.id_token = "mock-id-token"
auth_cloud_mock.remote_sni_server = "example.com"
auth_cloud_mock.servicehandlers_server = "example.com"

await cloud_api.async_remote_challenge_cleanup(auth_cloud_mock, "123456")
assert len(aioclient_mock.mock_calls) == 1
Expand Down
2 changes: 0 additions & 2 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_constructor_loads_info_from_constant(cloud_client):
"relayer": "test-relayer",
"accounts": "test-subscription-info-url",
"cloudhook": "test-cloudhook_server",
"remote_sni": "test-remote_sni_server",
"alexa": "test-alexa-token-url",
"acme": "test-acme-directory-server",
"remotestate": "test-google-actions-report-state-url",
Expand All @@ -44,7 +43,6 @@ def test_constructor_loads_info_from_constant(cloud_client):
assert cl.relayer_server == "test-relayer"
assert cl.accounts_server == "test-subscription-info-url"
assert cl.cloudhook_server == "test-cloudhook_server"
assert cl.remote_sni_server == "test-remote_sni_server"
assert cl.alexa_server == "test-alexa-token-url"
assert cl.acme_server == "test-acme-directory-server"
assert cl.remotestate_server == "test-google-actions-report-state-url"
Expand Down
66 changes: 33 additions & 33 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ async def test_load_backend_exists_cert(
):
"""Initialize backend."""
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand Down Expand Up @@ -134,19 +134,19 @@ async def test_load_backend_not_exists_cert(
):
"""Initialize backend."""
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand Down Expand Up @@ -192,19 +192,19 @@ async def test_load_and_unload_backend(
):
"""Initialize backend."""
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand Down Expand Up @@ -251,11 +251,11 @@ async def test_load_backend_exists_wrong_cert(
):
"""Initialize backend."""
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
Expand All @@ -264,7 +264,7 @@ async def test_load_backend_exists_wrong_cert(
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand Down Expand Up @@ -308,19 +308,19 @@ async def test_call_disconnect(
):
"""Initialize backend."""
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand All @@ -346,19 +346,19 @@ async def test_load_backend_no_autostart(
):
"""Initialize backend."""
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand Down Expand Up @@ -396,21 +396,21 @@ async def test_get_certificate_details(
):
"""Initialize backend."""
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

assert remote.certificate is None

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand Down Expand Up @@ -442,19 +442,19 @@ async def test_certificate_task_no_backend(
"""Initialize backend."""
loop = event_loop
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand Down Expand Up @@ -485,19 +485,19 @@ async def test_certificate_task_renew_cert(
"""Initialize backend."""
loop = event_loop
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand Down Expand Up @@ -536,19 +536,19 @@ async def test_load_connect_insecure(
):
"""Initialize backend."""
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand Down Expand Up @@ -578,19 +578,19 @@ async def test_call_disconnect_clean_token(
):
"""Initialize backend."""
valid = utcnow() + timedelta(days=1)
auth_cloud_mock.remote_sni_server = "test.local"
auth_cloud_mock.servicehandlers_server = "test.local"
remote = RemoteUI(auth_cloud_mock)

aioclient_mock.post(
"https://test.local/register_instance",
"https://test.local/instance/register",
json={
"domain": "test.dui.nabu.casa",
"email": "[email protected]",
"server": "rest-remote.nabu.casa",
},
)
aioclient_mock.post(
"https://test.local/snitun_token",
"https://test.local/instance/snitun_token",
json={
"token": "test-token",
"server": "rest-remote.nabu.casa",
Expand Down