# Copyright 2020-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 -*-

# load tasks used by configuration file
from pyrock.tasks.scenario.ds_sdk import DSAddRateTask, DSSearchRateTask, DSModRateTask, DSLdapSearchTask

# Python imports
import os

# Framework imports
from pyrock.lib.PyRockRun import get_pyrock_run
from pyrock.lib.scheduler.tasks.StepTask import StepTask
from pyrock.lib.scheduler.tasks.OverseerTask import OverseerTask
from shared.lib.utils.exception import FailException
from shared.lib.cloud_utils import kubectl

pyrock_run = get_pyrock_run()


class CopyCustomTemplate(StepTask):
    pod_name = None
    config_dir = None

    def pre(self):
        if not self.source.component_type == "overseer":
            raise FailException("source (%s) must be an overseer component" % self.source.instance_name)
        self.pod_name = self.source.pods[0].name
        self.config_dir = os.path.join(pyrock_run.get_test_path(), "config")

    def step1(self):
        print("=> Copying template(s) to overseer")
        # Just copy the whole directory which contains templates
        kubectl(f"cp {self.config_dir} {self.pod_name}:/results", component=self.source)


class DumpFRUUIDTask(OverseerTask):
    """Dump results from ldapsearch to a file that can be used by the tools."""

    @property
    def command(self):
        return f"/lodestar/pyrock/shared/scripts/ds/get_fruuid.py {self.get_option()}"
