def CreateRequests(self, args):
        """Returns the request necessary for adding the SSL certificate."""

        ssl_certificate_ref = self.CreateGlobalReference(
            args.name, resource_type='sslCertificates')
        certificate = file_utils.ReadFile(args.certificate, 'certificate')
        private_key = file_utils.ReadFile(args.private_key, 'private key')

        request = self.messages.ComputeSslCertificatesInsertRequest(
            sslCertificate=self.messages.SslCertificate(
                name=ssl_certificate_ref.Name(),
                certificate=certificate,
                privateKey=private_key,
                description=args.description),
            project=self.project)

        return [request]
def ConstructMetadataMessage(message_classes,
                             metadata=None,
                             metadata_from_file=None,
                             existing_metadata=None):
  """Creates a Metadata message from the given dicts of metadata.

  Args:
    message_classes: An object containing API message classes.
    metadata: A dict mapping metadata keys to metadata values or None.
    metadata_from_file: A dict mapping metadata keys to file names
      containing the keys' values or None.
    existing_metadata: If not None, the given metadata values are
      combined with this Metadata message.

  Raises:
    ToolException: If metadata and metadata_from_file contain duplicate
      keys or if there is a problem reading the contents of a file in
      metadata_from_file.

  Returns:
    A Metadata protobuf.
  """
  metadata = metadata or {}
  metadata_from_file = metadata_from_file or {}

  new_metadata_dict = copy.deepcopy(metadata)
  for key, file_path in metadata_from_file.iteritems():
    if key in new_metadata_dict:
      raise exceptions.ToolException(
          'Encountered duplicate metadata key [{0}].'.format(key))

    new_metadata_dict[key] = file_utils.ReadFile(
        file_path, 'metadata key [{0}]'.format(key))

  existing_metadata_dict = _MetadataMessageToDict(existing_metadata)
  existing_metadata_dict.update(new_metadata_dict)
  new_metadata_message = _DictToMetadataMessage(message_classes,
                                                existing_metadata_dict)

  if existing_metadata:
    new_metadata_message.fingerprint = existing_metadata.fingerprint

  return new_metadata_message
  def CreateRequests(self, args):

    name = args.name
    if not name:
      name = gaia_utils.GetDefaultAccountName(self.http)

    user_ref = self.CreateAccountsReference(
        name, resource_type='users')

    valid_key_types = [
        'ssh-rsa', 'ssh-dss', 'ecdsa-sha2-nistp256', 'ssh-ed25519']

    public_keys = []
    for key_file in args.public_key_files:
      key_text = file_utils.ReadFile(key_file, 'public-key')

      if key_text.split(' ', 1)[0] not in valid_key_types:
        raise exceptions.ToolException(
            'You must specify a public key file that contains a key of a '
            'supported form. Supported forms are {0}.'
            .format(', '.join(valid_key_types))
        )
      public_keys.append(key_text)

    formatted_expiration = time_utils.CalculateExpiration(args.expire)

    requests = []
    for key in public_keys:
      public_key_message = self.messages.PublicKey(
          description=args.description,
          expirationTimestamp=formatted_expiration,
          key=key)

      request = self.messages.ComputeaccountsUsersAddPublicKeyRequest(
          project=self.project,
          publicKey=public_key_message,
          user=user_ref.Name())
      requests.append(request)

    return requests