from __future__ import annotations
import base64
from dataclasses import dataclass
from lxml import objectify # type: ignore
from q2_sdk.tools.utils import to_bool
from .base import BaseAuthRequest, BaseAuthResponse
[docs]
@dataclass
class Request(BaseAuthRequest):
"""
Invoked in the sandbox with ``q2 db add_access_code_target``
.. code-block:: xml
<HQ request="TacTargetChange" messageID="{0}">
<UserId>2</UserId>
<CSRLogin>MyLoginName</CSRLogin>
<UserPrimaryCIF>MDcyMTIwMTA=</UserPrimaryCIF>
<CustomerPrimaryCIF>MDcyMTIwMTA=</CustomerPrimaryCIF>
<isLogon>True</isLogon>
<IsPrelogonSession>False</IsPrelogonSession>
<SessionId>shb3cnukdl32c54nodvyxcsj</SessionId>
</HQ>
"""
raw: objectify.Element
user_id: int
user_primary_cif: str
customer_primary_cif: str
is_logon: bool
is_prelogon_session: bool
session_id: str
@staticmethod
def from_xml(xml: objectify.Element) -> Request:
user_id = int(xml.UserId.text)
user_primary_cif = base64.b64decode(xml.UserPrimaryCIF.text).decode()
customer_primary_cif = base64.b64decode(xml.CustomerPrimaryCIF.text).decode()
is_logon = to_bool(xml.isLogon.text)
is_prelogon_session = to_bool(xml.IsPrelogonSession.text)
session_id = xml.SessionId.text
return Request(
xml,
user_id,
user_primary_cif,
customer_primary_cif,
is_logon,
is_prelogon_session,
session_id,
)
[docs]
@dataclass
class Response(BaseAuthResponse): ...