def get_dev_env_configuration( configuration: Commands, human_readable: bool = False) -> utility.ExecutorResponse: """Captures the specified environment configuration. Captures the developement environment configuration including PIP version and Phython version as specifeid by configuration Args: configuration: Commands for specific information to be retrieved - PIP3LIST: captures pip3 freeze results - PYTHON3PIPLIST: captuers python3 -m pip freeze results - PIP3VERSION: captuers pip3 -V results - PYHYON3PIPVERSION: captuers python3 -m pip -V results human_readable: If true all output will be in human readable form insted of Json. Returns: A utility.ExecutorResponse with the output results for the specified command. """ command_list = _command_string[configuration].split(' ') if not human_readable and configuration not in ( Commands.PIP3_VERSION, Commands.PYHYON3_PIP_VERSION, Commands.WHICH_PYHYON3, Commands.WHICH_PIP3, ): command_list.extend(['--format', 'json']) return utility.ExecutorResponse().execute_command(command_list)
def execute_gcloud_command( gcloud_command_list: List[Text], project_id: Optional[Text] = None, human_readable: Optional[bool] = False) -> utility.ExecutorResponse: """Function for invoking gcloud command. Args: gcloud_command_list: a command string list to be past to gcloud example format is ['config', 'list', '--all'] project_id: specificies the project to run the commands against if not provided provided will use gcloud default project if one is configured otherwise will return an error message. human_readable: If false sets parameter --format json for all calls, otherwie output will be in human readable format. Returns: utility.ExecutorResponse with outputs from stdout,stderr and execution code. """ command_list = ['gcloud'] command_list.extend(gcloud_command_list) if not human_readable: command_list.extend(['--format', 'json']) if project_id is not None: command_list.extend(['--project', project_id]) return utility.ExecutorResponse().execute_command(command_list)
def test_parse_raw_input_text(self): """Testing non-json stdout is correctly parsed.""" response = utility.ExecutorResponse() response._stdout = 'non-json string' response._parse_raw_input() self.assertEqual(response._json, '"non-json string"') self.assertEqual(response._parsed_output, 'non-json string')
def test_parse_raw_input_json(self): """Testing json stdout is correctly parsed.""" response = utility.ExecutorResponse() response._stdout = '{"key":"value"}' response._parse_raw_input() self.assertEqual(response._json, '{"key":"value"}') self.assertEqual(response._parsed_output, {'key': 'value'})
def execute_kubectl_command( kubectl_command_list: List[Text], human_readable: bool = False) -> utility.ExecutorResponse: """Invokes the kubectl command. Args: kubectl_command_list: a command string list to be past to kubectl example format is ['config', 'view'] human_readable: If false sets parameter -o json for all calls, otherwie output will be in human readable format. Returns: utility.ExecutorResponse with outputs from stdout,stderr and execution code. """ command_list = ['kubectl', *kubectl_command_list] if not human_readable: command_list.extend(['-o', 'json']) return utility.ExecutorResponse().execute_command(command_list)
def execute_gsutil_command( gsutil_command_list: List[Text], project_id: Optional[Text] = None) -> utility.ExecutorResponse: """Function for invoking gsutil command. This function takes in a gsutil parameter list and returns the results as a list of dictionaries. Args: gsutil_command_list: a command string list to be past to gsutil example format is ['config', 'list', '--all'] project_id: specific project to check the QUOTASs for,if no project id is provided will use gcloud default project if one is configured otherwise will return an erro massage. Returns: utility.ExecutorResponse with outputs from stdout,stderr and execution code. """ command_list = ['gsutil', *gsutil_command_list] if project_id is not None: command_list.extend(['-p', project_id]) return utility.ExecutorResponse().execute_command(command_list)