def resolve_passed_files()

in modular_cli/service/request_processor.py [0:0]


def resolve_passed_files(command, params):
    parameters = command['parameters']
    for parameter in parameters:
        is_file = parameter.get('convert_content_to_file')
        parameter_name = parameter.get('name')
        if not is_file or parameter_name not in params:
            continue

        path_to_file = params[parameter_name]
        *_, filename = os.path.split(path_to_file)
        filename, file_extension = os.path.splitext(filename)
        allowed_extensions = parameter.get('temp_file_extension')
        if allowed_extensions and file_extension not in allowed_extensions:
            raise ModularCliBadRequestException(
                f'File must have the following extensions: '
                f'{", ".join(allowed_extensions)}')
        if not os.path.isfile(path_to_file):
            raise ModularCliBadRequestException(
                'Provided file path does not exist'
            )
        encoded_str = str(b64encode(open(path_to_file, 'rb').read()))[2:-1]

        params.update(
            {parameter_name: {'file_content': encoded_str,
                              'filename': filename,
                              'file_extension': file_extension}})
    return params