def setUp(self):
        config = dict()
        config[CONFIG.CREDENTIALS_METHOD] = 'secrets'
        config[CONFIG.WLS_CREDENTIALS_NAME] = '__weblogic-credentials__'
        self.target_with_cred_name = TargetConfiguration(config)

        config2 = dict()
        config2[CONFIG.CREDENTIALS_METHOD] = 'secrets'
        self.target_without_cred_name = TargetConfiguration(config2)
Exemplo n.º 2
0
    def _validate_target_arg(self, value):
        method_name = 'validate_kubernetes_script_file_switch'

        # Check if the target configuration file exists
        target_configuration_file = path_utils.find_config_path(os.path.join('targets', value, 'target.json'))
        if not os.path.exists(target_configuration_file):
            ex = exception_helper.create_cla_exception('WLSDPLY-01643', value, target_configuration_file)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
            raise ex
        else:
            try:
                # verify the file is in proper format
                file_handle = open(target_configuration_file)
                config_dictionary = eval(file_handle.read())
                target_configuration = TargetConfiguration(config_dictionary)
                validation_method = target_configuration.get_validation_method()
                if (validation_method is not None) and (validation_method not in ['strict', 'lax']):
                    ex = exception_helper.create_cla_exception('WLSDPLY-01645', target_configuration_file)
                    ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
                    self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
                    raise ex

                credentials_method = target_configuration.get_credentials_method()
                if (credentials_method is not None) and (credentials_method not in CREDENTIALS_METHODS):
                    ex = exception_helper.create_cla_exception('WLSDPLY-01648', target_configuration_file,
                                                               credentials_method, CREDENTIALS_METHOD,
                                                               ', '.join(CREDENTIALS_METHODS))
                    ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
                    self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
                    raise ex

            except SyntaxError, se:
                ex = exception_helper.create_cla_exception('WLSDPLY-01644', target_configuration_file, se)
                ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
                self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
                raise ex
    def get_target_configuration(self):
        """
        Return the target configuration object, based on the target name.
        Lazy-load this the first time it is requested.
        Return a default target configuration if none was specified.
        :return: target configuration object
        """
        if self._target_configuration is None:
            configuration_dict = {}

            if self._target:
                target_path = os.path.join('targets', self._target, 'target.json')
                target_configuration_file = path_utils.find_config_path(target_path)
                if os.path.exists(target_configuration_file):
                    file_handle = open(target_configuration_file)
                    configuration_dict = eval(file_handle.read())

            self._target_configuration = TargetConfiguration(configuration_dict)

        return self._target_configuration