# This is an autogenerated file from the command "q2 generate_hq_api" and will be overwritten if run again
"""
DataSet models for SetPasswordPolicy.
These typed dataclass models represent the tables and columns within the
DataSet parameters for the SetPasswordPolicy HQ operation.
IMPORTANT: Update operations require a GET first to populate the original_record
field. HQ uses the unchanged row for optimistic concurrency checking.
Usage::
from q2_sdk.hq.hq_api.backoffice import SetPasswordPolicy
q2_password_policy_by_ui_source_id = SetPasswordPolicy.Q2PasswordPolicyByUISourceId(
ui_source_id=1,
password_policy_id=1,
password_history_number=1,
max_password_age=1,
min_password_age=1,
max_password_length=1,
min_password_length=1,
numbers_required=1,
upper_case_required=1,
lower_case_required=1,
special_char_required=1,
invalid_attempts=1,
invalid_action=1,
limit_repeating=1,
limit_adjacent=1,
exclude_char_list="...",
auto_reset_hours=1,
new_pwd_expiration_hours=1,
cqr_count=1,
cqr_invalid_attempts=1,
case_sensitive_answer=1,
question_min_length=1,
answer_min_length=1,
tac_required_lost_pwd=1,
tacttl_minutes=1,
tac_delivery_via_voice=1,
tac_delivery_via_email=1,
tac_length=1,
description="...",
login_min_length=1,
login_max_length=1,
dormant_days=1,
mla_min_length=1,
mla_max_length=1,
mla_require_alpha=True,
mla_require_numeric=True,
tac_delivery_via_sms=True,
oob_invalid_attempts=1,
oob_invalid_action=1,
exclude_login_char_list="...",
login_numeric_required=True,
login_alpha_required=True,
login_special_char_required=True,
)
"""
from __future__ import annotations
import copy
from dataclasses import dataclass, field
from typing import Any, ClassVar, Optional
from q2_sdk.hq.models.dataset_builder import DataSetBuilder, DataSetTable, RowState
[docs]
@dataclass
class Q2PasswordPolicyByUISourceId:
"""
Represents a row in the Q2_PasswordPolicyByUISourceId table.
"""
ui_source_id: int = 0
password_policy_id: int = 0
password_history_number: int = 0
max_password_age: int = 0
min_password_age: int = 0
max_password_length: int = 0
min_password_length: int = 0
numbers_required: int = 0
upper_case_required: int = 0
lower_case_required: int = 0
special_char_required: int = 0
invalid_attempts: int = 0
invalid_action: int = 0
limit_repeating: int = 0
limit_adjacent: int = 0
exclude_char_list: str = ""
auto_reset_hours: int = 0
new_pwd_expiration_hours: int = 0
cqr_count: int = 0
cqr_invalid_attempts: int = 0
case_sensitive_answer: int = 0
question_min_length: int = 0
answer_min_length: int = 0
tac_required_lost_pwd: int = 0
tacttl_minutes: int = 0
tac_delivery_via_voice: int = 0
tac_delivery_via_email: int = 0
tac_length: int = 0
description: str = ""
login_min_length: int = 0
login_max_length: int = 0
dormant_days: int = 0
mla_min_length: int = 0
mla_max_length: int = 0
mla_require_alpha: bool = False
mla_require_numeric: bool = False
tac_delivery_via_sms: bool = False
oob_invalid_attempts: int = 0
oob_invalid_action: int = 0
exclude_login_char_list: str = ""
login_numeric_required: bool = False
login_alpha_required: bool = False
login_special_char_required: bool = False
original_record: Optional["Q2PasswordPolicyByUISourceId"] = field(
default=None, repr=False
)
[docs]
@staticmethod
def get_columns() -> list[list[str]]:
"""Returns [[HqColumnName, pythonAttrName], ...] mapping."""
return [
["UISourceID", "ui_source_id"],
["PasswordPolicyID", "password_policy_id"],
["PasswordHistoryNumber", "password_history_number"],
["MaxPasswordAge", "max_password_age"],
["MinPasswordAge", "min_password_age"],
["MaxPasswordLength", "max_password_length"],
["MinPasswordLength", "min_password_length"],
["NumbersRequired", "numbers_required"],
["UpperCaseRequired", "upper_case_required"],
["LowerCaseRequired", "lower_case_required"],
["SpecialCharRequired", "special_char_required"],
["InvalidAttempts", "invalid_attempts"],
["InvalidAction", "invalid_action"],
["LimitRepeating", "limit_repeating"],
["LimitAdjacent", "limit_adjacent"],
["ExcludeCharList", "exclude_char_list"],
["AutoResetHours", "auto_reset_hours"],
["NewPwdExpirationHours", "new_pwd_expiration_hours"],
["CQRCount", "cqr_count"],
["CQRInvalidAttempts", "cqr_invalid_attempts"],
["CaseSensitiveAnswer", "case_sensitive_answer"],
["QuestionMinLength", "question_min_length"],
["AnswerMinLength", "answer_min_length"],
["TACRequiredLostPwd", "tac_required_lost_pwd"],
["TACTTLMinutes", "tacttl_minutes"],
["TACDeliveryViaVoice", "tac_delivery_via_voice"],
["TACDeliveryViaEmail", "tac_delivery_via_email"],
["TACLength", "tac_length"],
["Description", "description"],
["LoginMinLength", "login_min_length"],
["LoginMaxLength", "login_max_length"],
["DormantDays", "dormant_days"],
["MlaMinLength", "mla_min_length"],
["MlaMaxLength", "mla_max_length"],
["MlaRequireAlpha", "mla_require_alpha"],
["MlaRequireNumeric", "mla_require_numeric"],
["TACDeliveryViaSMS", "tac_delivery_via_sms"],
["OobInvalidAttempts", "oob_invalid_attempts"],
["OobInvalidAction", "oob_invalid_action"],
["ExcludeLoginCharList", "exclude_login_char_list"],
["LoginNumericRequired", "login_numeric_required"],
["LoginAlphaRequired", "login_alpha_required"],
["LoginSpecialCharRequired", "login_special_char_required"],
]
[docs]
def to_row_values(self) -> list[Any]:
"""Returns column values in get_columns() order."""
return [
self.ui_source_id,
self.password_policy_id,
self.password_history_number,
self.max_password_age,
self.min_password_age,
self.max_password_length,
self.min_password_length,
self.numbers_required,
self.upper_case_required,
self.lower_case_required,
self.special_char_required,
self.invalid_attempts,
self.invalid_action,
self.limit_repeating,
self.limit_adjacent,
self.exclude_char_list,
self.auto_reset_hours,
self.new_pwd_expiration_hours,
self.cqr_count,
self.cqr_invalid_attempts,
self.case_sensitive_answer,
self.question_min_length,
self.answer_min_length,
self.tac_required_lost_pwd,
self.tacttl_minutes,
self.tac_delivery_via_voice,
self.tac_delivery_via_email,
self.tac_length,
self.description,
self.login_min_length,
self.login_max_length,
self.dormant_days,
self.mla_min_length,
self.mla_max_length,
self.mla_require_alpha,
self.mla_require_numeric,
self.tac_delivery_via_sms,
self.oob_invalid_attempts,
self.oob_invalid_action,
self.exclude_login_char_list,
self.login_numeric_required,
self.login_alpha_required,
self.login_special_char_required,
]
_COLUMN_TYPES: ClassVar[dict[str, type]] = {
"ui_source_id": int,
"password_policy_id": int,
"password_history_number": int,
"max_password_age": int,
"min_password_age": int,
"max_password_length": int,
"min_password_length": int,
"numbers_required": int,
"upper_case_required": int,
"lower_case_required": int,
"special_char_required": int,
"invalid_attempts": int,
"invalid_action": int,
"limit_repeating": int,
"limit_adjacent": int,
"exclude_char_list": str,
"auto_reset_hours": int,
"new_pwd_expiration_hours": int,
"cqr_count": int,
"cqr_invalid_attempts": int,
"case_sensitive_answer": int,
"question_min_length": int,
"answer_min_length": int,
"tac_required_lost_pwd": int,
"tacttl_minutes": int,
"tac_delivery_via_voice": int,
"tac_delivery_via_email": int,
"tac_length": int,
"description": str,
"login_min_length": int,
"login_max_length": int,
"dormant_days": int,
"mla_min_length": int,
"mla_max_length": int,
"mla_require_alpha": bool,
"mla_require_numeric": bool,
"tac_delivery_via_sms": bool,
"oob_invalid_attempts": int,
"oob_invalid_action": int,
"exclude_login_char_list": str,
"login_numeric_required": bool,
"login_alpha_required": bool,
"login_special_char_required": bool,
}
[docs]
@classmethod
def from_hq_response(cls, row_elem) -> "Q2PasswordPolicyByUISourceId":
"""Parse an lxml row element into this model with original_record set."""
kwargs: dict[str, Any] = {}
for hq_name, python_name in cls.get_columns():
child = row_elem.find(hq_name)
if child is not None and child.text is not None:
target_type = cls._COLUMN_TYPES.get(python_name, str)
if target_type is bool:
kwargs[python_name] = child.text.lower() in ("true", "1")
elif target_type in (int, float):
try:
kwargs[python_name] = target_type(child.text)
except (ValueError, TypeError):
kwargs[python_name] = child.text
else:
kwargs[python_name] = child.text
instance = cls(**kwargs)
instance.original_record = copy.deepcopy(instance)
return instance
[docs]
def build_password_policy_dataset(
q2_password_policy_by_ui_source_id: Optional[
Q2PasswordPolicyByUISourceId | list[Q2PasswordPolicyByUISourceId]
] = None,
) -> DataSetBuilder:
"""
Build the password_policy DataSet parameter for SetPasswordPolicy.
For update operations, each model instance should have its original_record
set to the pre-modification state (from a prior GET call).
For add operations, set auto-increment ID fields to negative values.
:returns: DataSetBuilder ready to pass as the 'password_policy' parameter
"""
dataset = DataSetBuilder("DalPasswordPolicyByUISourceId")
# Q2_PasswordPolicyByUISourceId
q2_password_policy_by_ui_source_id_cols = [
col[0] for col in Q2PasswordPolicyByUISourceId.get_columns()
]
q2_password_policy_by_ui_source_id_table = dataset.add_table(
"Q2_PasswordPolicyByUISourceId", q2_password_policy_by_ui_source_id_cols
)
_add_rows_to_table(
q2_password_policy_by_ui_source_id_table, q2_password_policy_by_ui_source_id
)
return dataset
def _add_rows_to_table(
table: DataSetTable,
records: Optional[Any | list],
) -> None:
"""
Add rows to a DataSetTable from one or more model instances.
Handles Modified+Unchanged pairs (for updates), Added rows (for inserts),
and Deleted rows automatically based on each record's original_record field.
"""
if records is None:
return
if not isinstance(records, list):
records = [records]
for record in records:
values = record.to_row_values()
if record.original_record is not None:
# Update: emit Modified row (new values) + Unchanged row (original)
table.add_row(RowState.MODIFIED, values)
table.add_row(RowState.UNCHANGED, record.original_record.to_row_values())
else:
# Add: emit Added row (new record)
table.add_row(RowState.ADDED, values)