Example #1
0
    def _InsertPayloadSignatures(self, signatures):
        """Put payload signatures into the payload they sign.

    Args:
      signatures: List of signatures for the payload.
    """
        logging.info('Inserting payload signatures into %s.',
                     self.signed_payload_file)

        signature_files = [
            utils.CreateTempFileWithContents(s, base_dir=self.work_dir)
            for s in signatures
        ]
        signature_file_names = [
            path_util.ToChrootPath(f.name) for f in signature_files
        ]

        cmd = [
            'delta_generator',
            '-in_file=' + path_util.ToChrootPath(self.payload_file),
            '-signature_file=' + ':'.join(signature_file_names),
            '-out_file=' + path_util.ToChrootPath(self.signed_payload_file),
            '-out_metadata_size_file=' +
            path_util.ToChrootPath(self.metadata_size_file)
        ]

        self._RunGeneratorCmd(cmd)
        self._ReadMetadataSizeFile()

        for f in signature_files:
            f.close()
Example #2
0
def CreateWithContents(gs_uri, contents, **kwargs):
  """Creates the specified file with specified contents.

  Args:
    gs_uri: The URI of a file on Google Storage.
    contents: Contents to write to the file.
    kwargs: Additional options to pass directly to RunGsutilCommand, beyond the
      explicit ones above.  See RunGsutilCommand itself.

  Raises:
    CopyFail: If it fails for any reason.
  """
  with utils.CreateTempFileWithContents(contents) as content_file:
    Copy(content_file.name, gs_uri, **kwargs)
Example #3
0
    def testCreateTempFileWithContents(self):
        """Verify that we create a temp file with the right message in it."""

        message = 'Test Message With Rocks In'

        # Create the temp file.
        with utils.CreateTempFileWithContents(message) as temp_file:
            temp_name = temp_file.name

            # Verify the name is valid.
            self.assertTrue(os.path.exists(temp_name))

            # Verify it has the right contents
            with open(temp_name, 'r') as f:
                contents = f.readlines()

            self.assertEqual([message], contents)

        # Verify the temp file goes away when we close it.
        self.assertFalse(os.path.exists(temp_name))
    def _InsertPayloadSignatures(self, signatures):
        """Put payload signatures into the payload they sign.

    Args:
      signatures: List of signatures for the payload.
    """
        logging.info('Inserting payload signatures into %s.',
                     self.signed_payload_file)

        signature_files = [
            utils.CreateTempFileWithContents(s) for s in signatures
        ]
        signature_file_names = [f.name for f in signature_files]

        cmd = [
            'delta_generator', '-in_file=' + self.payload_file,
            '-signature_file=' + ':'.join(signature_file_names),
            '-out_file=' + self.signed_payload_file
        ]

        self._RunGeneratorCmd(cmd)

        for f in signature_files:
            f.close()