code: def _import_users(users_list: list[dict[str, Any]]):
      with get_application_builder() as appbuilder:
          users_created = []
          users_updated = []
  
          try:
              UserSchema(many=True).load(users_list)
          except ValidationError as e:
              msg = []
              for row_num, failure in e.normalized_messages().items():
                  msg.append(f"[Item {row_num}]")
                  for key, value in failure.items():
                      msg.append(f"\t{key}: {value}")
              raise SystemExit(
                  "Error: Input file didn't pass validation. See below:\n{}".format(
                      "\n".join(msg)
                  )
              )
  
          for user in users_list:
              roles = []
              for rolename in user["roles"]:
                  role = appbuilder.sm.find_role(rolename)
                  if not role:
                      valid_roles = appbuilder.sm.get_all_roles()
                      raise SystemExit(
                          f'Error: "{rolename}" is not a valid role. Valid roles are: {valid_roles}'
                      )
                  roles.append(role)
  
              existing_user = appbuilder.sm.find_user(
                  email=user["email"]
              )
              if existing_user:
                  print(
                      f"Found existing user with email '{user['email']}'"
                  )
                  if existing_user.username != user["username"]:
                      raise SystemExit(
                          f"Error: Changing the username is not allowed - "
                          f"please delete and recreate the user with email {user['email']!r}"
                      )
  
                  existing_user.roles = roles
                  existing_user.first_name = user["firstname"]
                  existing_user.last_name = user["lastname"]
                  appbuilder.sm.update_user(existing_user)
                  users_updated.append(user["email"])
              else:
                  print(
                      f"Creating new user with email '{user['email']}'"
                  )
                  appbuilder.sm.add_user(
                      username=user["username"],
                      first_name=user["firstname"],
                      last_name=user["lastname"],
                      email=user["email"],
                      role=roles,
                  )
  
                  users_created.append(user["email"])
  
          return users_created, users_updated
  
imports: from __future__ import annotations
  import functools
  import getpass
  import json
  import os
  import random
  import string
  from typing import Any
  import re2
  from marshmallow import Schema, fields, validate
  from marshmallow.exceptions import ValidationError
  from airflow.cli.simple_table import AirflowConsole
  from airflow.cli.utils import print_export_output
  from airflow.providers.fab.auth_manager.cli_commands.utils import get_application_builder
  from airflow.utils import cli
  from airflow.utils.cli import suppress_logs_and_warning
  from airflow.utils.providers_configuration_loader import providers_configuration_loaded
label_desc: Use image node_id 8 for calling a global function with example usage: _import_users(users_list) and returns: users_created,  users_updated