Beispiel #1
0
    def get_config(self, request):
        """Gets a config file."""
        try:
            validation.validate_config_set(request.config_set)
            validation.validate_path(request.path)
        except ValueError as ex:
            raise endpoints.BadRequestException(ex.message)
        res = self.GetConfigResponseMessage()

        if not self.can_read_config_set(request.config_set):
            logging.warning('%s does not have access to %s',
                            auth.get_current_identity().to_bytes(),
                            request.config_set)
            raise_config_not_found()

        res.revision, res.content_hash = (storage.get_config_hash_async(
            request.config_set, request.path,
            revision=request.revision).get_result())
        if not res.content_hash:
            raise_config_not_found()

        if not request.hash_only:
            res.content = (storage.get_config_by_hash_async(
                res.content_hash).get_result())
            if not res.content:
                logging.warning(
                    'Config hash is found, but the blob is not.\n'
                    'File: "%s:%s:%s". Hash: %s', request.config_set,
                    request.revision, request.path, res.content_hash)
                raise_config_not_found()
        return res
Beispiel #2
0
  def get_config(self, request):
    """Gets a config file."""
    try:
      validation.validate_config_set(request.config_set)
      validation.validate_path(request.path)
    except ValueError as ex:
      raise endpoints.BadRequestException(ex.message)
    res = self.GetConfigResponseMessage()

    if not self.can_read_config_set(request.config_set):
      logging.warning(
          '%s does not have access to %s',
          auth.get_current_identity().to_bytes(),
          request.config_set)
      raise_config_not_found()

    res.revision, res.content_hash = (
        storage.get_config_hash_async(
            request.config_set, request.path, revision=request.revision)
        .get_result())
    if not res.content_hash:
      raise_config_not_found()

    if not request.hash_only:
      res.content = (
          storage.get_config_by_hash_async(res.content_hash).get_result())
      if not res.content:
        logging.warning(
            'Config hash is found, but the blob is not.\n'
            'File: "%s:%s:%s". Hash: %s', request.config_set,
            request.revision, request.path, res.content_hash)
        raise_config_not_found()
    return res
Beispiel #3
0
 def test_get_latest_config(self):
   self.put_file('foo', 'deadbeef', 'config.cfg', 'content')
   revision, content_hash = storage.get_config_hash_async(
       'foo', 'config.cfg').get_result()
   self.assertEqual(revision, 'deadbeef')
   self.assertEqual(
       content_hash, 'v1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea')
Beispiel #4
0
 def test_get_latest_config(self):
   self.put_file('foo', 'deadbeef', 'config.cfg', 'content')
   revision, content_hash = storage.get_config_hash_async(
       'foo', 'config.cfg').get_result()
   self.assertEqual(revision, 'deadbeef')
   self.assertEqual(
       content_hash, 'v1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea')
Beispiel #5
0
 def test_get_non_existing_config(self):
   revision, content_hash = storage.get_config_hash_async(
       'foo', 'config.cfg', revision='deadbeef').get_result()
   self.assertEqual(revision, None)
   self.assertEqual(content_hash, None)
Beispiel #6
0
 def test_get_latest_non_existing_config_set(self):
   revision, content_hash = storage.get_config_hash_async(
       'foo', 'config.yaml').get_result()
   self.assertEqual(revision, None)
   self.assertEqual(content_hash, None)
Beispiel #7
0
 def test_get_non_existing_config(self):
   revision, content_hash = storage.get_config_hash_async(
       'foo', 'config.cfg', revision='deadbeef').get_result()
   self.assertEqual(revision, None)
   self.assertEqual(content_hash, None)
Beispiel #8
0
 def test_get_latest_non_existing_config_set(self):
   revision, content_hash = storage.get_config_hash_async(
       'foo', 'config.yaml').get_result()
   self.assertEqual(revision, None)
   self.assertEqual(content_hash, None)
Beispiel #9
0
 def test_get_latest_config(self):
     self.put_file("foo", "deadbeef", "config.cfg", "content")
     revision, content_hash = storage.get_config_hash_async("foo", "config.cfg").get_result()
     self.assertEqual(revision, "deadbeef")
     self.assertEqual(content_hash, "v1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea")
Beispiel #10
0
 def test_get_non_existing_config(self):
     revision, content_hash = storage.get_config_hash_async("foo", "config.cfg", revision="deadbeef").get_result()
     self.assertEqual(revision, None)
     self.assertEqual(content_hash, None)