def _GetUpdateMask(self, args):
     """Returns update mask for specified fields."""
     update_fields = [
         resource_property.ConvertToCamelCase(field)
         for field in sorted(self._FIELDS_MAP) if args.IsSpecified(field)
     ]
     update_fields.extend([
         'reverseSshConnectivity.{0}'.format(
             resource_property.ConvertToCamelCase(field))
         for field in sorted(self._REVERSE_MAP) if args.IsSpecified(field)
     ])
     if args.IsSpecified('peer_vpc'):
         update_fields.append('vpcPeeringConnectivity.vpc')
     return update_fields
Exemplo n.º 2
0
        def ToJson(self):
            """Generate JSON with camel-cased key."""

            key_camel_cased_dict = {
                resource_property.ConvertToCamelCase(key): value
                for key, value in self.__dict__.items()
            }
            return json.dumps(key_camel_cased_dict,
                              default=str,
                              sort_keys=True)
Exemplo n.º 3
0
def _extract_keys(keys, search_dict, result_dict):
    """Converts key to multiple cases and attempts to extract from search_dict."""
    for original_key in keys:
        if original_key in search_dict:
            _assign_with_error_on_duplicate(original_key,
                                            search_dict[original_key],
                                            result_dict)
        else:
            # Can error if both camel and snake case matches are present.
            # Note: The below conversion utils don't work all the time.
            # For example, they cannot handle kebab-case.
            camel_case_key = resource_property.ConvertToCamelCase(original_key)
            snake_case_key = resource_property.ConvertToSnakeCase(original_key)
            if camel_case_key in search_dict:
                _assign_with_error_on_duplicate(original_key,
                                                search_dict[camel_case_key],
                                                result_dict)
            if snake_case_key in search_dict:
                _assign_with_error_on_duplicate(original_key,
                                                search_dict[snake_case_key],
                                                result_dict)
Exemplo n.º 4
0
  def _AttachCompleter(self, arg, name, completer, positional,
                       deprecated_collection=None,
                       deprecated_list_command=None,
                       deprecated_list_command_callback=None):
    """Attaches a completer to arg if one is specified.

    Args:
      arg: The argument to attach the completer to.
      name: The arg name for messaging.
      completer: The completer Completer class or argcomplete function object.
      positional: True if argument is a positional.
      deprecated_collection: The collection name for the resource to complete.
      deprecated_list_command: The command whose Run() method returns the
        current resource list.
      deprecated_list_command_callback: A callback function that returns the
        list command to run.
    """
    if not completer:
      if not deprecated_collection:
        if deprecated_list_command or deprecated_list_command_callback:
          raise parser_errors.ArgumentException(
              'Command [{}] argument [{}] does not have completion_resource '
              'set but has one or more of the deprecated list_command_path '
              'and list_command_callback_fn attributes.'.format(
                  ' '.join(self.data.command_name), name))
        return

      class DeprecatedCompleter(
          deprecated_completers.DeprecatedListCommandCompleter):

        def __init__(self, **kwargs):
          super(DeprecatedCompleter, self).__init__(
              collection=deprecated_collection,
              list_command=deprecated_list_command,
              list_command_callback=deprecated_list_command_callback,
              **kwargs)

      DeprecatedCompleter.__name__ = (
          resource_property.ConvertToCamelCase(
              deprecated_collection.capitalize().replace('.', '_')) +
          'DeprecatedCompleter')

      completer = DeprecatedCompleter
    elif (deprecated_collection or
          deprecated_list_command or
          deprecated_list_command_callback):
      raise parser_errors.ArgumentException(
          'Command [{}] argument [{}] has a completer set with one or more '
          'of the deprecated completion_resource, list_command_path, and '
          'list_command_callback_fn attributes.'.format(
              ' '.join(self.data.command_name), name))
    if isinstance(completer, type):
      # A completer class that will be instantiated at completion time.
      if positional and issubclass(completer, completion_cache.Completer):
        # The list of positional resource completers is used to determine
        # parameters that must be present in the completions.
        self.data.positional_completers.add(completer)
      arg.completer = parser_completer.ArgumentCompleter(
          completer, argument=arg)
    else:
      arg.completer = completer