init client with credentials
This commit is contained in:
parent
bf880935ab
commit
8b1a5ac175
@ -177,6 +177,24 @@ class Client:
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _init_client(
|
||||||
|
base_url: str, email: str, password: str, verify: bool = True
|
||||||
|
) -> "Client":
|
||||||
|
cli = Client(base_url, email, password)
|
||||||
|
cli.session = Session()
|
||||||
|
cli.session.headers.update({"content-type": "application/json"})
|
||||||
|
|
||||||
|
if not verify:
|
||||||
|
urllib3.disable_warnings()
|
||||||
|
|
||||||
|
cli.session.verify = verify
|
||||||
|
|
||||||
|
cli._login()
|
||||||
|
|
||||||
|
logging.info(f"client successfully initialized for user: {cli.email}")
|
||||||
|
return cli
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_env(cls) -> "Client":
|
def from_env(cls) -> "Client":
|
||||||
"""
|
"""
|
||||||
@ -193,24 +211,17 @@ class Client:
|
|||||||
dotenv_data = dotenv_values()
|
dotenv_data = dotenv_values()
|
||||||
env_data.update(dotenv_data) # type: ignore
|
env_data.update(dotenv_data) # type: ignore
|
||||||
|
|
||||||
cli = Client(
|
return Client._init_client(
|
||||||
env_data.get("WHEREIS_API_BASE_URL", ""),
|
env_data.get("WHEREIS_API_BASE_URL", ""),
|
||||||
env_data.get("WHEREIS_API_EMAIL", ""),
|
env_data.get("WHEREIS_API_EMAIL", ""),
|
||||||
env_data.get("WHEREIS_API_PASSWORD", ""),
|
env_data.get("WHEREIS_API_PASSWORD", ""),
|
||||||
)
|
)
|
||||||
cli.session = Session()
|
|
||||||
cli.session.headers.update({"content-type": "application/json"})
|
|
||||||
|
|
||||||
is_cert_verify = env_data.get("WHEREIS_CERT_VERIFY", "") != "false"
|
@classmethod
|
||||||
if not is_cert_verify:
|
def from_creds(
|
||||||
urllib3.disable_warnings()
|
cls, base_url: str, email: str, password: str, verify: bool = False
|
||||||
|
) -> "Client":
|
||||||
cli.session.verify = is_cert_verify
|
return Client._init_client(base_url, email, password, verify)
|
||||||
|
|
||||||
cli._login()
|
|
||||||
|
|
||||||
logging.info(f"client successfully initialized for user: {cli.email}")
|
|
||||||
return cli
|
|
||||||
|
|
||||||
@refresh()
|
@refresh()
|
||||||
def _get_sessions_page(self, url: str) -> dict[str, Any] | WhereIsException:
|
def _get_sessions_page(self, url: str) -> dict[str, Any] | WhereIsException:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user