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]) if not request.config_set: raise endpoints.BadRequestException('Must specify a config_set') if not request.files: raise endpoints.BadRequestException( 'Must specify files to validate') for f in request.files: if not f.path: raise endpoints.BadRequestException( 'Must specify the path of a file') if not acl.has_validation_access(): logging.warning('%s does not have validation access', auth.get_current_identity().to_bytes()) raise endpoints.ForbiddenException() if not 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 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) # return the severities and the texts 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)
def attempt_to_msg(entity): if entity is None: return None return ConfigSet.ImportAttempt( timestamp=utils.datetime_to_timestamp(entity.time), revision=Revision( id=entity.revision.id, url=entity.revision.url, timestamp=utils.datetime_to_timestamp(entity.revision.time), committer_email=entity.revision.committer_email, ) if entity.revision else None, success=entity.success, message=entity.message, validation_messages=[ cfg_endpoint.ValidationMessage(severity=m.severity, text=m.text) for m in entity.validation_messages ], )