Skip to content

Commit

Permalink
Merge pull request #10 from GuilleGF/feat/remove-basic-auth
Browse files Browse the repository at this point in the history
feat: remove basic auth
  • Loading branch information
GuilleGF authored Apr 25, 2022
2 parents 6d18a18 + 12fb6bd commit c6fb195
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions custom_components/ovh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging

import aiohttp
from aiohttp import BasicAuth
import async_timeout
import voluptuous as vol

Expand All @@ -14,18 +13,20 @@
CONF_USERNAME,
CONF_SCAN_INTERVAL
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.typing import ConfigType

_LOGGER = logging.getLogger(__name__)

DOMAIN = "ovh"

DEFAULT_INTERVAL = timedelta(minutes=10)
DEFAULT_INTERVAL = timedelta(minutes=15)

TIMEOUT = 30
UPDATE_URL = "https://www.ovh.com/nic/update"
HOST = "www.ovh.com/nic/update"

OVH_ERRORS = {
"nohost": "Hostname supplied does not exist under specified account",
Expand All @@ -51,38 +52,37 @@
extra=vol.ALLOW_EXTRA,
)

async def async_setup(hass, config):

async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Initialize the OVH component."""
conf = config[DOMAIN]
domain = conf.get(CONF_DOMAIN)
user = conf.get(CONF_USERNAME)
password = conf.get(CONF_PASSWORD)
domain = conf.get(CONF_DOMAIN).strip()
user = conf.get(CONF_USERNAME).strip()
password = conf.get(CONF_PASSWORD).strip()
interval = conf.get(CONF_SCAN_INTERVAL)

session = async_get_clientsession(hass)

result = await _update_ovh(hass, session, domain, user, password)
result = await _update_ovh(session, domain, user, password)

if not result:
return False

async def update_domain_interval(now):
"""Update the OVH entry."""
await _update_ovh(hass, session, domain, user, password)
await _update_ovh(session, domain, user, password)

async_track_time_interval(hass, update_domain_interval, interval)

return True


async def _update_ovh(hass, session, domain, user, password):
async def _update_ovh(session, domain, user, password):
"""Update OVH."""
params = {"system": "dyndns", "hostname": domain}
authentication = BasicAuth(user, password)

try:
url = f"https://{user}:{password}@{HOST}?system=dyndns&hostname={domain}"
async with async_timeout.timeout(TIMEOUT):
resp = await session.get(UPDATE_URL, params=params, auth=authentication)
resp = await session.get(url)
body = await resp.text()

if body.startswith("good") or body.startswith("nochg"):
Expand Down

0 comments on commit c6fb195

Please sign in to comment.