def _run_step(self): """Runs the step implemented by this StepImplementer. Returns ------- StepResult Object containing the dictionary results of this step. """ step_result = StepResult.from_step_implementer(self) # configlint-yml-path is required configlint_yml_path = self.get_value('configlint-yml-path') if not os.path.exists(configlint_yml_path): step_result.success = False step_result.message = 'File specified in ' \ f'configlint-yml-path not found: {configlint_yml_path}' return step_result # Required: rules and exists rules_file = self.get_value('rules') if not os.path.exists(rules_file): step_result.success = False step_result.message = f'File specified in rules not found: {rules_file}' return step_result configlint_results_file_path = self.write_working_file('configlint_results_file.txt') try: # run config-lint writing stdout and stderr to the standard streams # as well as to a results file. with open(configlint_results_file_path, 'w') as configlint_results_file: out_callback = create_sh_redirect_to_multiple_streams_fn_callback([ sys.stdout, configlint_results_file ]) err_callback = create_sh_redirect_to_multiple_streams_fn_callback([ sys.stderr, configlint_results_file ]) sh.config_lint( # pylint: disable=no-member "-verbose", "-debug", "-rules", rules_file, configlint_yml_path, _encoding='UTF-8', _out=out_callback, _err=err_callback, _tee='err' ) except sh.ErrorReturnCode_255: # pylint: disable=no-member # NOTE: expected failure condition, # aka, the config lint run, but found an issue # stderr/stdout is captured in configlint_results_file_path step_result.success = False step_result.message = 'Failed config-lint scan.' except sh.ErrorReturnCode: # NOTE: un-expected failure condition # aka, the config lint failed to run for some reason # stderr/stdout is captured in configlint_results_file_path step_result.success = False step_result.message = 'Unexpected Error invoking config-lint.' step_result.add_artifact( name='configlint-result-set', value=configlint_results_file_path ) step_result.add_artifact( name='configlint-yml-path', value=configlint_yml_path ) return step_result
def _run_step(self): """ Runs the TSSC step implemented by this StepImplementer. Parameters ---------- runtime_step_config : dict Step configuration to use when the StepImplementer runs the step with all of the various static, runtime, defaults, and environment configuration munged together. Returns ------- dict Results of running this step. """ # yml_path is required yml_path = self.get_config_value('yml_path') if yml_path is None: current_step_results = self.current_step_results() if 'options' in current_step_results: if 'yml_path' in current_step_results['options']: yml_path = current_step_results['options'].get('yml_path') if yml_path is None: raise ValueError( 'yml_path not specified in runtime args or in options') if not os.path.exists(yml_path): raise ValueError( f'Specified file in yml_path not found: {yml_path}') # Required: rules and exists rules_file = self.get_config_value('rules') if not os.path.exists(rules_file): raise ValueError( f'Rules file specified in tssc config not found: {rules_file}') configlint_results_file_path = self.write_working_file( 'configlint_results_file.txt') try: # run config-lint writing stdout and stderr to the standard streams # as well as to a results file. with open(configlint_results_file_path, 'w') as configlint_results_file: out_callback = create_sh_redirect_to_multiple_streams_fn_callback( [sys.stdout, configlint_results_file]) err_callback = create_sh_redirect_to_multiple_streams_fn_callback( [sys.stderr, configlint_results_file]) sh.config_lint( # pylint: disable=no-member "-verbose", "-debug", "-rules", rules_file, yml_path, _encoding='UTF-8', _out=out_callback, _err=err_callback, _tee='err') except sh.ErrorReturnCode_255 as error: # pylint: disable=no-member # NOTE: expected failure condition, # aka, the config lint run, but found an issue raise TSSCException( 'Failed config-lint scan. See standard out and standard error.' ) from error except sh.ErrorReturnCode as error: # NOTE: un-expected failure condition # aka, the config lint failed to run for some reason raise RuntimeError( f'Unexpected Error invoking config-lint: {error}') from error results = { 'result': { 'success': True, 'message': 'configlint step completed', }, 'report-artifacts': [{ 'name': 'configlint-result-set', 'path': f'file://{configlint_results_file_path}' }], 'options': { 'yml_path': yml_path } } return results
def _run_step(self): """ Runs the TSSC step implemented by this StepImplementer. Parameters ---------- runtime_step_config : dict Step configuration to use when the StepImplementer runs the step with all of the various static, runtime, defaults, and environment configuration munged together. Returns ------- dict Results of running this step. """ # yml_path is required yml_path = self.get_config_value('yml_path') if yml_path is None: current_step_results = self.current_step_results() if 'options' in current_step_results: if 'yml_path' in current_step_results['options']: yml_path = current_step_results['options'].get('yml_path') if yml_path is None: raise ValueError('yml_path not specified in runtime args or in options') if not os.path.exists(yml_path): raise ValueError(f'Specified file in yml_path not found: {yml_path}') # Required: rules and exists rules_file = self.get_config_value('rules') if not os.path.exists(rules_file): raise ValueError(f'Rules file specified in tssc config not found: {rules_file}') try: configlint_results_file = self.write_working_file( 'configlint_results_file.txt', b'' ) # Hint: Call config-lint with sh.config_lint sh.config_lint( # pylint: disable=no-member "-verbose", "-debug", "-rules", rules_file, yml_path, _out=configlint_results_file, _err_to_out=True ) except sh.ErrorReturnCode as error: # pylint: disable=undefined-variable raise RuntimeError(f'Error invoking config-lint: {error}') from error results = { 'result': { 'success': True, 'message': 'configlint step completed', }, 'report-artifacts': [ { 'name' : 'configlint-result-set', 'path': f'file://{configlint_results_file}' } ], 'options': { 'yml_path': yml_path } } return results