def Run(self_, args): # Check if mask is required for an update request, if required, return # the dotted path, e.g updateRequest.fieldMask. mask_path = update.GetMaskFieldPath(self.method) if mask_path: # If user sets to disable the auto-generated field mask, set the value # to the empty string instead so that custom hooks can be used. if self.spec.update and self.spec.update.disable_auto_field_mask: mask_string = '' else: mask_string = update.GetMaskString( args, self.spec, mask_path) self.spec.request.static_fields[mask_path] = mask_string # Check if the update is full-update, which requires a get request. existing_message = None if self.spec.update: if self.spec.update.read_modify_update: existing_message = self._GetExistingResource(args) ref, response = self._CommonRun(args, existing_message) if self.spec. async: request_string = None if ref: request_string = 'Request issued for: [{{{}}}]'.format( yaml_command_schema.NAME_FORMAT_KEY) response = self._HandleAsync(args, ref, response, request_string=request_string) log.UpdatedResource(self._GetDisplayName(ref, args), kind=self.display_resource_type) return self._HandleResponse(response, args)
def Run(self_, args): # Check if mask is required for an update request. mask_path = update.GetMaskFieldPath(self.method) if mask_path: mask_string = update.GetMaskString(args, self.spec, mask_path) self.spec.request.static_fields[mask_path] = mask_string # Check if the update is full-update, which requires a get request. existing_message = None if self.spec.update: if self.spec.update.read_modify_update: existing_message = self._GetExistingResource(args) ref, response = self._CommonRun(args, existing_message) if self.spec. async: request_string = None if ref: request_string = 'Request issued for: [{{{}}}]'.format( yaml_command_schema.NAME_FORMAT_KEY) response = self._HandleAsync(args, ref, response, request_string=request_string) log.UpdatedResource(self._GetDisplayName(ref, args), kind=self.resource_type) return self._HandleResponse(response, args)
def testGetInOthers(self, collection, method_name, expected_path): path = update.GetMaskFieldPath( self._MakeMethod(collection, method_name)) self.assertEqual(expected_path, path)
def CreateRequest(self, namespace, static_fields=None, resource_method_params=None, labels=None, command_type=None, use_relative_name=True, override_method=None, parse_resource_into_request=True, existing_message=None): """Generates the request object for the method call from the parsed args. Args: namespace: The argparse namespace. static_fields: {str, value}, A mapping of API field name to value to insert into the message. This is a convenient way to insert extra data while the request is being constructed for fields that don't have corresponding arguments. resource_method_params: {str: str}, A mapping of API method parameter name to resource ref attribute name when the API method uses non-standard names. labels: The labels section of the command spec. command_type: Type of the command, i.e. CREATE, UPDATE. use_relative_name: Use ref.RelativeName() if True otherwise ref.Name(). override_method: APIMethod, The method other than self.method, this is used when the command has more than one API call. parse_resource_into_request: bool, True if the resource reference should be automatically parsed into the request. existing_message: the apitools message returned from server, which is used to construct the to-be-modified message when the command follows get-modify-update pattern. Returns: The apitools message to be send to the method. """ message_type = (override_method or self.method).GetRequestType() message = message_type() # If an apitools message is provided, use the existing one by default # instead of creating an empty one. if existing_message: message = arg_utils.ParseExistingMessageIntoMessage( message, existing_message, self.method) # Add labels into message if labels: if command_type == yaml_command_schema.CommandType.CREATE: _ParseLabelsIntoCreateMessage(message, namespace, labels.api_field) elif command_type == yaml_command_schema.CommandType.UPDATE: need_update = _ParseLabelsIntoUpdateMessage(message, namespace, labels.api_field) if need_update: update_mask_path = update.GetMaskFieldPath(override_method) _AddLabelsToUpdateMask(static_fields, update_mask_path) # Insert static fields into message. arg_utils.ParseStaticFieldsIntoMessage(message, static_fields=static_fields) # Parse api Fields into message. self._ParseArguments(message, namespace) ref = self._ParseResourceArg(namespace) if not ref: return message # For each method path field, get the value from the resource reference. if parse_resource_into_request: arg_utils.ParseResourceIntoMessage( ref, self.method, message, resource_method_params=resource_method_params, request_id_field=self.resource_arg.request_id_field, use_relative_name=use_relative_name) return message
def testGetInPatch(self, collection, expected_path): path = update.GetMaskFieldPath(self._MakeMethod(collection)) self.assertEqual(expected_path, path)