# Copyright 2022-2025 Ping Identity Corporation. All Rights Reserved
#
# This code is to be used exclusively in connection with Ping Identity
# Corporation software or services. Ping Identity Corporation only offers
# such software or services to legal entities who have entered into a
# binding license agreement with Ping Identity Corporation.

# -*- coding: utf-8 -*-

from pyrock.tasks.idm.recon import TestIdmConnector, TestRCSConnection, ReconTask, ReconResultTask
from pyrock.tasks.idm.general import DumpIDMIDWithAPITask, GenerateUserGroups
from pyrock.tasks.deployment.datainit import MakeUsersTask
from pyrock.tasks.scenario.ds_sdk import DSLdapModifyTask
from pyrock.tasks.scenario.gatling import GatlingTask
from pyrock.lib.report.json.tasks.ReportSimulation import ReportSimulation
from pyrock.tasks.deployment.validation import ValidationNumUsers
from shared.lib.cloud_utils import kubectl
from shared.lib.components.am import AM
from shared.lib.components.idm import IDM
from pyrock.lib.scheduler.tasks.StepTask import StepTask
from pyrock.lib.PyRockRun import get_pyrock_run
from shared.lib.platform_utils import PlatformUtils
from shared.lib.utils.exception import FailException


pyrock_run = get_pyrock_run()


class UpdateRcsClientSecretTask(StepTask):
    def pre(self):
        if self.source != "controller":
            raise FailException("Task must be executed on controller")
        if not isinstance(self.target, AM):
            raise ValueError(f"Target {self.target} must be an AM component")

    @staticmethod
    def step1():
        pyrock_run.log("Reset RCSClient password")
        PlatformUtils(components=pyrock_run.get_components()).set_rcs_client_secret()

    def post(self):
        """Post method"""
        self.set_result_pass()
