def ReadConfigData(args):
  """Read configuration data from the parsed arguments.

  See command_lib.iot.flags for the flag definitions.

  Args:
    args: a parsed argparse Namespace object containing config_data and
      config_file.

  Returns:
    str, the binary configuration data

  Raises:
    ValueError: unless exactly one of --config-data, --config-file given
  """
  if args.IsSpecified('config_data') and args.IsSpecified('config_file'):
    raise ValueError('Both --config-data and --config-file given.')
  if args.IsSpecified('config_data'):
    return args.config_data
  elif args.IsSpecified('config_file'):
    # Note: use 'rb' for Windows
    with open(args.config_file, 'rb') as f:
      return f.read()
  else:
    raise ValueError('Neither --config-data nor --config-file given.')