# -*- coding: utf-8 -*-
"""API for performing initial signup."""
from ...exceptions import ApiError
from ...tools import token_parse
from .. import json_api
from ..api_endpoints import ApiEndpoints
from ..mixins import ModelMixins
[docs]class Signup(ModelMixins):
"""API for performing initial signup and other unauthenticated endpoints.
Examples:
* Check if initial signup has been done: :meth:`is_signed_up`
* Perform initial signup: :meth:`signup`
"""
@property
def is_signed_up(self) -> bool:
"""Check if initial signup has been done.
Examples:
>>> import axonius_api_client as axonapi
>>> url: str = "10.0.3.2"
>>> client: axonapi.Connect = axonapi.Connect(url=url, key="", secret="")
>>> client.signup.is_signed_up
True
"""
return self._get().value
@property
def system_status(self) -> json_api.signup.SystemStatus:
"""Pass."""
return self._status()
[docs] def signup(self, password: str, company_name: str, contact_email: str) -> dict:
"""Perform the initial signup and get the API key and API secret of admin user.
Examples:
>>> import axonius_api_client as axonapi
>>> url: str = "10.0.3.2"
>>> client: axonapi.Connect = axonapi.Connect(url=url, key="", secret="")
>>> data = client.signup.signup(
... password="demo", company_name="Axonius", contact_email="jim@axonius.com"
... )
>>> data
{'api_key': 'xxxx', 'api_secret': 'xxxx'}
Args:
password: password for admin user
company_name: name of company
contact_email: email address of company contact
"""
return self._perform(
password=password, company_name=company_name, contact_email=contact_email
).to_dict()
[docs] def validate_password_reset_token(self, token: str) -> bool:
"""Validate that a password reset token is legit."""
token = token_parse(token)
data = self._token_validate(token=token)
return data.value
[docs] def use_password_reset_token(
self, token: str, password: str
) -> json_api.password_reset.UseResponse:
"""Use a password token reset link to change a users password.
Args:
token: password reset token
password: password to set
Notes:
token can be generated by
:meth:`axonius_api_client.api.system.system_users.SystemUsers.get_password_reset_link`
or
:meth:`axonius_api_client.api.system.system_users.SystemUsers.email_password_reset_link`
Returns:
name of user whose password was reset
"""
token = token_parse(token)
if not self.validate_password_reset_token(token=token):
raise ApiError(f"Password reset token is not valid: {token}")
data = self._token_use(token=token, password=password)
return data
@property
def is_expired(self) -> bool:
"""Check if the system has expired."""
return self._expired().value
@property
def is_licensed(self) -> bool:
"""Check if the system is licensed."""
return self._license_status().value
@property
def indication_color(self) -> str:
"""Get the indication color."""
return self._get_indication_color().value
@property
def login_options(self) -> dict:
"""Get the login options."""
return self._get_login_options().document_meta
[docs] def _get_login_options(self) -> json_api.generic.Metadata:
"""Direct API method to get the login options."""
api_endpoint = ApiEndpoints.signup.get_login_options
return api_endpoint.perform_request(http=self.http)
[docs] def _get_indication_color(self) -> json_api.generic.StrValue:
"""Direct API method to get the indication color."""
api_endpoint = ApiEndpoints.signup.get_indication_color
return api_endpoint.perform_request(http=self.http)
[docs] def _license_status(self) -> json_api.generic.BoolValue:
"""Direct API method to get the license status."""
api_endpoint = ApiEndpoints.signup.license_status
return api_endpoint.perform_request(http=self.http)
[docs] def _expired(self) -> json_api.generic.BoolValue:
"""Direct API method to get the expiry status."""
api_endpoint = ApiEndpoints.signup.expired
return api_endpoint.perform_request(http=self.http)
[docs] def _status(self) -> json_api.signup.SystemStatus:
"""Direct API method to get the status of the overall system."""
api_endpoint = ApiEndpoints.signup.status
return api_endpoint.perform_request(http=self.http)
[docs] def _get(self) -> json_api.generic.BoolValue:
"""Direct API method to get the status of initial signup."""
api_endpoint = ApiEndpoints.signup.get
return api_endpoint.perform_request(http=self.http)
[docs] def _token_validate(self, token: str) -> json_api.password_reset.ValidateResponse:
"""Pass."""
api_endpoint = ApiEndpoints.password_reset.validate
request_obj = api_endpoint.load_request(token=token)
return api_endpoint.perform_request(http=self.http, request_obj=request_obj)
[docs] def _token_use(self, token: str, password: str) -> json_api.password_reset.UseResponse:
"""Direct API method to use a reset token to change a password.
Args:
token: password reset token
password: password to set
"""
api_endpoint = ApiEndpoints.password_reset.use
request_obj = api_endpoint.load_request(token=token, password=password)
return api_endpoint.perform_request(http=self.http, request_obj=request_obj)