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
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
def get_ref_configs(self, request): """Gets configs in all ref config sets.""" try: validation.validate_path(request.path) except ValueError as ex: raise endpoints.BadRequestException(ex.message) return get_config_multi('refs', request.path, request.hashes_only)
def get_project_configs(self, request): """Gets configs in all project config sets.""" try: validation.validate_path(request.path) except ValueError as ex: raise endpoints.BadRequestException(ex.message) def iter_project_config_sets(): for project in get_projects(): yield 'projects/%s' % project.id return get_config_multi( iter_project_config_sets(), request.path, request.hashes_only)
def validate_config(self, request): logging.debug("requester: %s, config_set: %s, paths: %s", auth.get_current_identity().to_bytes(), request.config_set, [f.path for f in request.files]) try: validation.validate_config_set(request.config_set) if not request.files: raise ValueError('Must specify files to validate') for f in request.files: validation.validate_path(f.path) except ValueError as ex: raise endpoints.BadRequestException(ex.message) if not acl.can_validate(request.config_set): logging.warning('%s does not have validation access', auth.get_current_identity().to_bytes()) raise endpoints.ForbiddenException() futs = [] for f in request.files: ctx = cfg_validation.Context() with ctx.prefix(f.path + ': '): futs.append( validation.validate_config_async(request.config_set, f.path, f.content, ctx=ctx)) ndb.Future.wait_all(futs) msgs = [] for f, fut in zip(request.files, futs): for msg in fut.get_result().messages: msgs.append( cfg_endpoint.ValidationMessage( path=f.path, severity=common.Severity.lookup_by_number( msg.severity), text=msg.text)) return self.ValidateConfigResponseMessage(messages=msgs)