示例#1
0
def _generate_id() -> str:
    """Generate the image identifier.

  Returns:
    The image identifier as a string.
  """
    hw = hw_info.HWInfo()
    return ('%s-%s' % (str(hw.BiosSerial()), str(uuid.uuid4())[:7])).upper()
示例#2
0
    def GetSignedUrl(self, relative_path: Text) -> Text:
        """Passes data the sign endpoint to retrieve signed URL.

    Args:
      relative_path: the relative path of the file being downloaded.

    Raises:
      BCError: Error with retrieving info from sign endpoint

    Returns:
      A signed_url string
    """
        if not FLAGS.use_signed_url:
            raise BCError('use_signed_url flag not configured.')

        if FLAGS.sign_endpoint is None or FLAGS.seed_path is None:
            raise BCError(
                'sign_endpoint and seed_path cannot be None when using'
                'Signed URL.')

        hwinfo = hw_info.HWInfo()
        drive_letter = self._GetDisk(constants.USB_VOLUME_LABEL).strip(':')

        data = self._ReadFile()
        data = {
            'Path':
            relative_path,
            'Mac':
            hwinfo.MacAddresses(),
            'Seed':
            data['Seed'],
            'Signature':
            data['Signature'],
            'Hash':
            self._GetHash(fr'{drive_letter}:\sources\boot.wim').decode('utf-8')
        }

        req = json.dumps(data,
                         ensure_ascii=True,
                         sort_keys=True,
                         indent=None,
                         separators=(',', ': '))
        try:
            res = requests.post(FLAGS.sign_endpoint, data=req)
        except requests.exceptions.ConnectionError as e:
            raise BCError(e)

        if res.status_code != 200 or res.json(
        )['Status'] != 'Success' or not res.json()['SignedURL']:
            raise BCError(
                'Invalid response from signed url. Code: %s, Status: %s' %
                (res.status_code, res.json()['Status']))
        return res.json()['SignedURL']
示例#3
0
 def _HWInfo(self):
     if not self._hw_info:
         self._hw_info = hw_info.HWInfo()
     return self._hw_info
示例#4
0
 def setUp(self, _):
     self.hwinfo = hw_info.HWInfo()