def _authenticate(self): auth_token = self._get_provider_option("auth_token") response = requests.get(API_BASE_URL + "/login", params={"api-key": auth_token}) result = _process_response(response) self._session_id = result.headers["Auth-Sid"] response = self._get( "/query-domain-list", query_params={"pattern": self.domain, "showstatus": 1} ) if not response.data: raise AuthenticationError( f"Domain {self.domain} is not registered with this account." ) data = response.data[0] items = data.split(" ") if items[2] not in ["production", "lock"]: raise AuthenticationError( f"Current status for domain {self.domain} is: {items[2]}" ) self.domain_id = self.domain
def _authenticate(self): # Getting required cookie "ORGID" payload = { "action": "logmein", "login": self._get_provider_option("auth_username"), "password": self._get_provider_option("auth_password"), } # Cannot allow redirects, as we miss the cookie then response = requests.post(self.api_endpoint, data=payload, allow_redirects=False) response.raise_for_status() if "ORGID" not in response.cookies: raise AuthenticationError("Unexpected auth response") self.cookies["ORGID"] = response.cookies["ORGID"] # Make sure domain exists # domain is stored in self.domain from BaseProvider domains = self._list_domains() for domain in domains: if domain == self.domain: # Domain name is the ID self.domain_id = domain break else: raise AuthenticationError(f"Domain {self.domain} not found")
def _authenticate(self): self._auth_token = self._get_provider_option("auth_token") if not self._auth_token: auth_response = self._auth_request( "POST", "/tokens", { "auth": { "RAX-KSKEY:apiKeyCredentials": { "username": self._get_provider_option("auth_username"), "apiKey": self._get_provider_option("auth_api_key"), } } }, ) self._auth_token = auth_response["access"]["token"]["id"] self._auth_account = auth_response["access"]["token"]["tenant"][ "id"] payload = self._get("/domains", {"name": self.domain}) if not payload["domains"]: raise AuthenticationError("No domain found") if len(payload["domains"]) > 1: raise AuthenticationError( "Too many domains found. This should not happen") self.domain_id = payload["domains"][0]["id"]
def _authenticate(self): self.auth_token = self._get_provider_option("auth_token") if not self.auth_token: if not (self._get_provider_option("auth_username") and self._get_provider_option("auth_password")): raise Exception( "auth_username and auth_password or auth_token must be specified." ) auth_response = self._send_request( "POST", f"{self.auth_api_endpoint}/tokens", { "auth": { "passwordCredentials": { "username": self._get_provider_option("auth_username"), "password": self._get_provider_option("auth_password"), }, "tenantId": self._get_provider_option("auth_tenant_id"), } }, ) self.auth_token = auth_response["access"]["token"]["id"] payload = self._get("/domains", {"name": self._fqdn_name(self.domain)}) if not payload["domains"]: raise AuthenticationError("No domain found") if len(payload["domains"]) > 1: raise AuthenticationError( "Too many domains found. This should not happen") self.domain_id = payload["domains"][0]["id"]
def _authenticate(self): payload = self._get("/accounts") if not payload[0]["id"]: raise AuthenticationError("No account id found") for account in payload: if account["plan_identifier"] is None: logging.warning( "Skipping unconfigured account %s (%d). " "To use this account, you must select a plan.", account["email"], account["id"], ) continue dompayload = self._get(f"/{account['id']}/domains", query_params={"name_like": self.domain}) if dompayload and dompayload[0]["id"]: self.account_id = account["id"] self.domain_id = dompayload[0]["id"] break else: raise AuthenticationError(f"No domain found like {self.domain}")
def _authenticate(self): if not (self._get_provider_option("auth_username") and self._get_provider_option("auth_password")): raise ValueError( "username and password must be specified, add --help for details" ) # Get a session ID first. LOGGER.info("Getting Session ID...") response = self._get() self.session_id = response["result"]["sess_id"]["value"] LOGGER.info("Logging in...") auth_response = self._get( query_params={ "subaction": "login", "email": self._get_provider_option("auth_username"), "password": self._get_provider_option("auth_password"), }) # Find the contract number of the given domain orders = auth_response["result"]["orders"] for order in orders: if int(order["pg_id"]["value"]) == PRODUCT_ID_DOMAIN: # The description contains the description of the product itself # and in a second line the domain name order_description = order["ord_description"]["value"].split( "\n") if order_description[1] == self.domain: self.order_id = order["ord_no"]["value"] break else: raise AuthenticationError("Order for domain not found") # Select the order for the given domain so we can use the DNS actions LOGGER.info("Choosing order %s", self.order_id) self._get(query_params={ "subaction": "choose_order", "ord_no": self.order_id }) # Retrieve domain ID LOGGER.info("Retrieving DNS records to find domain id for %s...", self.domain) domains = self._get( query_params={"subaction": "kc2_domain_dns_get_records"}) for domain in domains["result"]["domains"]: if domain["dom_domain"]["value"] == self.domain: self.domain_id = domain["dom_id"]["value"] break else: raise AuthenticationError("Domain not found in DNS records")
def _authenticate(self): params = {"domain": self.domain} try: result = self._api_call("get-domain", params) except Exception as e: raise AuthenticationError(str(e)) if result["name"] != self.domain: raise AuthenticationError("Domain not found") self.domain_id = self.domain
def _authenticate(self): payload = self._get("/Domain/List", {"searchTermFilter": self.domain}) LOGGER.debug("authenticate debug: %s", payload) if not payload["status"]: raise AuthenticationError("Internal error. This should not happen") if payload["status"] != "SUCCESS": raise AuthenticationError(f"Api error: {payload['message']}") if self.domain not in payload["domain"]: raise AuthenticationError("Domain not found") self.domain_id = self.domain
def _authenticate(self): self.domain_id = None payload = self._get("domain-list_domains") data = payload.get("data", None) if data is None: raise AuthenticationError("Domain not found") for domain in data: if domain.get("domain", "") == self.domain: self.domain_id = self.domain if self.domain_id is None: raise AuthenticationError("Domain not found")
def _authenticate(self): domain = self.domain payload = self.sl_dns.resolve_ids(domain) if not payload: raise AuthenticationError("No domain found") if len(payload) > 1: raise AuthenticationError( "Too many domains found. This should not happen") LOGGER.debug("domain id: %s", payload[0]) self.domain_id = payload[0]
def _authenticate(self): data = {"command": "Services_GetDomains"} payload = self._post("", data) if not payload["data"]: raise AuthenticationError("No domain found") for data in payload["data"]: if data["domain"] == self.domain: break else: raise AuthenticationError("Requested domain is not among the owned domains") self.domain_id = self.domain
def _authenticate(self): # Create the session GET the login page to retrieve a session cookie self.session = Session() self.session.get("https://dns.he.net/") # Hit the login page with authentication info to login the session login_response = self.session.post( "https://dns.he.net", data={ "email": self._get_provider_option("auth_username") or "", "pass": self._get_provider_option("auth_password") or "", }, ) # Parse in the HTML, if the div containing the error message is found, error html = BeautifulSoup(login_response.content, "html.parser") if html.find("div", {"id": "dns_err"}) is not None: LOGGER.warning("HE login failed, check HE_USER and HE_PASS") return False # Make an authenticated GET to the DNS management page zones_response = self.session.get("https://dns.he.net") html = BeautifulSoup(zones_response.content, "html.parser") zone_img = html.find("img", {"name": self.domain, "alt": "delete"}) # If the tag couldn't be found, error, otherwise, return the value of the tag if zone_img is None: LOGGER.warning("Domain %s not found in account", self.domain) raise AuthenticationError(f"Domain {self.domain} not found in account") self.domain_id = zone_img["value"] LOGGER.debug("HENET domain ID: %s", self.domain_id) return True
def _authenticate(self): # Getting required cookies "hover_session" and "hoverauth" response = requests.get("https://www.hover.com/signin") self.cookies["hover_session"] = response.cookies["hover_session"] payload = { "username": self._get_provider_option("auth_username"), "password": self._get_provider_option("auth_password"), } response = requests.post("https://www.hover.com/api/login/", json=payload, cookies=self.cookies) response.raise_for_status() if "hoverauth" not in response.cookies: raise Exception("Unexpected auth response") self.cookies["hoverauth"] = response.cookies["hoverauth"] # Make sure domain exists # domain is stored in self.domain from BaseProvider domains = self._list_domains() for domain in domains: if domain["name"] == self.domain: self.domain_id = domain["id"] break else: raise AuthenticationError(f"Domain {self.domain} not found")
def _authenticate(self): result = self._get(f"/{self.domain}") if not result["uid"]: raise AuthenticationError(f"Error, domain {self.domain} not found") self.domain_id = result["uid"]
def _authenticate(self): payload = self._post("/Domain.Info", {"domain": self.domain}) if payload["status"]["code"] != "1": raise AuthenticationError(payload["status"]["message"]) self.domain_id = payload["domain"]["id"]
def _authenticate(self): payload = self._get(f"/dns/{self.domain}") if not payload["additional"]["domain_id"]: raise AuthenticationError("No domain found") self.domain_id = payload["additional"]["domain_id"]
def _authenticate(self): payload = self._get(f"/domain/{self.domain}") if payload["data"]["exists"] == "N": raise AuthenticationError("No domain found") self.domain_id = payload["data"]["id"]
def _authenticate(self): try: self._get(f"/zones/{self.domain}") self.domain_id = self.domain except requests.exceptions.HTTPError as err: if err.response.status_code == 404: raise AuthenticationError("No domain found") raise err
def _authenticate(self): payload = self._get("/getdomainbyname/", {"name": self.domain}) if not payload["id"]: raise AuthenticationError("No domain found") self.domain_id = payload["id"]
def authenticate(self): """Determine the current domain and zone IDs for the domain.""" try: payload = self._api.domain.info(self._api_key, self._domain) self._zone_id = payload["zone_id"] return payload["id"] except xmlrpclib.Fault as err: raise AuthenticationError(f"Failed to authenticate: '{err}'")
def _authenticate(self): payload = self._get(f"/zones/{self.domain}") if not payload["id"]: raise AuthenticationError("No domain found") self.domain_id = self.domain
def _authenticate(self): payload = self._get("/zones") domains = [item for item in payload if item["name"] == self.domain] if not domains: raise AuthenticationError("No domain found") self.domain_id = domains[0]["id"] self.version_id = domains[0]["current_version_id"]
def _authenticate(self): payload = self._get("/domain") for record in payload["data"]: if record["domain"] == self.domain + ".": self.domain_id = record["id"] break else: raise AuthenticationError("No domain found")
def _authenticate(self): payload = self._get("/zones") for item in payload: if item["name"] == self.domain: self.domain_id = item["id"] break else: raise AuthenticationError("No domain found")
def _authenticate(self): result = self._get(f"/v5/domains/{self.domain}") identifier = result.get("domain", {}).get("id") if not identifier: raise AuthenticationError(f"Error, domain {self.domain} not found") self.domain_id = identifier
def _authenticate(self): self.domain_id = None payload = self._get("domain.list") for domain in payload["DATA"]: if domain["DOMAIN"].lower() == self.domain.lower(): self.domain_id = domain["DOMAINID"] break else: raise AuthenticationError("Domain not found")
def _authenticate(self): # may need to get auth token if self.auth_token is None and self._get_provider_option( "auth_token") is None: auth_request = requests.request( "POST", "https://auth.mythic-beasts.com/login", data={"grant_type": "client_credentials"}, auth=( self._get_provider_option("auth_username"), self._get_provider_option("auth_password"), ), ) auth_request.raise_for_status() post_result = auth_request.json() if not post_result["access_token"]: raise AuthenticationError( "Error, could not get access token " f"for Mythic Beasts API for user: {self._get_provider_option('auth_username')}" ) self.auth_token = post_result["access_token"] elif self.auth_token is None: self.auth_token = self._get_provider_option("auth_token") payload = self._get("/zones") if self.domain is None: if not payload["zones"]: raise AuthenticationError("No domain found") if len(payload["zones"]) > 1: raise AuthenticationError( "Too many domains found. This should not happen") else: self.domain = payload["zones"][0] else: if not payload["zones"]: raise AuthenticationError("No domain found") if self.domain not in payload["zones"]: raise AuthenticationError("Requested domain not found") self.domain_id = self.domain
def _authenticate(self): response = self._request_aliyun("DescribeDomainInfo") if "DomainId" not in response: raise AuthenticationError( f"failed to fetch basic domain info for {self.domain}") self.domain_id = response["DomainId"] return self
def _authenticate(self): # This request will fail when the domain does not exist, # allowing us to check for existence try: self.client.get_info(self.domain) except BaseException: raise AuthenticationError( f"Could not retrieve information about {self.domain}, is this domain yours?" ) self.domain_id = self.domain
def _authenticate(self): self.domain_id = None payload = self._get( "domains", query_params={"filter": { "domain": self.domain.lower() }}) if payload["data"]: self.domain_id = payload["data"][0]["id"] else: raise AuthenticationError("Domain not found")