def get_config_multi(config_sets, path, hashes_only): """Returns configs at |path| in all config sets. Returns empty config list if requester does not have project access. """ if not acl.has_project_access(): raise endpoints.ForbiddenException() res = GetConfigMultiResponseMessage() configs = storage.get_latest_multi(config_sets, path, hashes_only) for config in configs: if not hashes_only and config.get('content') is None: logging.error( 'Blob %s referenced from %s:%s:%s was not found', config['content_hash'], config['config_set'], config['revision'], path) continue res.configs.append(res.ConfigEntry( config_set=config['config_set'], revision=config['revision'], content_hash=config['content_hash'], content=config.get('content'), )) return res
def get_projects(self, request): # pylint: disable=W0613 """Gets list of registered projects. The project list is stored in services/luci-config:projects.cfg. """ return self.GetProjectsResponseMessage(projects=[ p for p in get_projects() if acl.has_project_access(p.id) ], )
def get_projects(self, request): # pylint: disable=W0613 """Gets list of registered projects. The project list is stored in services/luci-config:projects.cfg. """ return self.GetProjectsResponseMessage( projects=[p for p in get_projects() if acl.has_project_access(p.id)], )
def get_refs(self, request): """Gets list of refs of a project.""" if not acl.has_project_access(request.project_id): raise endpoints.NotFoundException() ref_names = get_ref_names(request.project_id) if ref_names is None: # Project not found raise endpoints.NotFoundException() res = self.GetRefsResponseMessage() res.refs = [res.Ref(name=ref) for ref in ref_names] return res
def get_config_multi(config_sets, path, hashes_only): """Returns configs at |path| in all config sets. Returns empty config list if requester does not have project access. """ if not acl.has_project_access(): raise endpoints.ForbiddenException() res = GetConfigMultiResponseMessage() configs = storage.get_latest_multi(config_sets, path, hashes_only) for config in configs: if not hashes_only and config.get('content') is None: logging.error('Blob %s referenced from %s:%s:%s was not found', config['content_hash'], config['config_set'], config['revision'], path) continue res.configs.append( res.ConfigEntry( config_set=config['config_set'], revision=config['revision'], content_hash=config['content_hash'], content=config.get('content'), )) return res
def test_can_read_project_config_no_access(self): self.assertFalse(acl.has_project_access('projects/swarming')) self.assertFalse(acl.can_read_config_set('projects/swarming/refs/heads/x'))
def test_admin_can_read_all(self): self.mock(auth, 'is_admin', mock.Mock(return_value=True)) self.assertTrue(acl.can_read_config_set('services/swarming')) self.assertTrue(acl.can_read_config_set('projects/chromium')) self.assertTrue(acl.has_project_access('chromium'))
def test_can_read_project_config_no_access(self): self.assertFalse(acl.has_project_access('projects/swarming')) self.assertFalse( acl.can_read_config_set('projects/swarming/refs/heads/x'))
def test_admin_can_read_all(self): self.mock(auth, "is_admin", mock.Mock(return_value=True)) self.assertTrue(acl.can_read_config_set("services/swarming")) self.assertTrue(acl.can_read_config_set("projects/chromium")) self.assertTrue(acl.has_project_access("chromium"))