def get(self, **url): query = self.getQueryFromURL(url) self.log.debug("Got query: %s", query) release, update_type = AUS.evaluateRules(query) # passing {},None returns empty xml if release: response_products = release.getResponseProducts() response_blobs = [] if response_products: # if we have a SuperBlob, we process the response products and # concatenate their inner XMLs for product in response_products: product_query = query.copy() product_query["product"] = product response_release, response_update_type = AUS.evaluateRules(product_query) if not response_release: continue response_blobs.append({'product_query': product_query, 'response_release': response_release, 'response_update_type': response_update_type}) else: response_blobs.append({'product_query': query, 'response_release': release, 'response_update_type': update_type}) xml = ['<?xml version="1.0"?>'] xml.append('<updates>') # We only sample the first blob for the header and footer, since we # assume that all blobs will have similar ones. We might want to # verify that all of them are indeed the same in the future. xml.append(response_blobs[0]['response_release'] .getHeaderXML(response_blobs[0]['product_query'], response_blobs[0]['response_update_type'])) for response_blob in response_blobs: xml.extend(response_blob['response_release'] .getInnerXML(response_blob['product_query'], response_blob['response_update_type'], app.config["WHITELISTED_DOMAINS"], app.config["SPECIAL_FORCE_HOSTS"])) # Sampling the footer from the first blob xml.append(response_blobs[0]['response_release'].getFooterXML()) xml.append('</updates>') # ensure valid xml by using the right entity for ampersand xml = re.sub('&(?!amp;)', '&', '\n'.join(xml)) else: xml = ['<?xml version="1.0"?>'] xml.append('<updates>') xml.append('</updates>') xml = "\n".join(xml) self.log.debug("Sending XML: %s", xml) response = make_response(xml) response.mimetype = "text/xml" return response
def get(self, **url): query = self.getQueryFromURL(url) self.log.debug("Got query: %s", query) release, update_type = AUS.evaluateRules(query) # passing {},None returns empty xml xml = AUS.createXML(query, release, update_type) self.log.debug("Sending XML: %s", xml) response = make_response(xml) response.mimetype = 'text/xml' return response
def get(self, queryVersion, **url): query = self.getQueryFromURL(queryVersion, url) self.log.debug("Got query: %s", query) if query: rule = AUS.evaluateRules(query) else: rule = {} # passing {},{} returns empty xml self.log.debug("Got rule: %s", rule) xml = AUS.createXML(query, rule) self.log.debug("Sending XML: %s", xml) response = make_response(xml) response.mimetype = 'text/xml' return response
def getQueryFromURL(self, queryVersion, url): """ Use regexp to turn "update/3/Firefox/4.0b13pre/20110303122430/Darwin_x86_64-gcc-u-i386-x86_64/en-US/nightly/Darwin%2010.6.0/default/default/update.xml?force=1" into testUpdate = { 'product': 'Firefox', 'version': '4.0b13pre', 'buildID': '20110303122430', 'buildTarget': 'Darwin_x86_64-gcc-u-i386-x86_64', 'locale': 'en-US', 'channel': 'nightly', 'osVersion': 'Darwin%2010.6.0', 'distribution': 'default', 'distVersion': 'default', 'headerArchitecture': 'Intel', 'force': True, 'name': '' } """ # TODO support older URL versions. catlee suggests splitting on /, easy to use conditional assignment then query = url.copy() # TODO: Better way of dispatching different versions when we actually have to deal with them. if queryVersion == 3: query['name'] = AUS.identifyRequest(query) ua = request.headers.get('User-Agent') query['headerArchitecture'] = self.getHeaderArchitecture(query['buildTarget'], ua) query['force'] = (int(request.args.get('force', 0)) == 1) return query return {}
def get(self, **url): query = self.getQueryFromURL(url) self.log.debug("Got query: %s", query) release, update_type = AUS.evaluateRules(query) # passing {},None returns empty xml if release: xml = release.createXML(query, update_type, app.config["WHITELISTED_DOMAINS"], app.config["SPECIAL_FORCE_HOSTS"]) else: xml = ['<?xml version="1.0"?>'] xml.append('<updates>') xml.append('</updates>') xml = "\n".join(xml) self.log.debug("Sending XML: %s", xml) response = make_response(xml) response.mimetype = "text/xml" return response
def get(self, **url): query = self.getQueryFromURL(url) self.log.debug("Got query: %s", query) release, update_type = AUS.evaluateRules(query) # passing {},None returns empty xml if release: response_products = release.getResponseProducts() response_blobs = [] response_blob_names = release.getResponseBlobs() if response_products: # if we have a SuperBlob of gmp, we process the response products and # concatenate their inner XMLs for product in response_products: product_query = query.copy() product_query["product"] = product response_release, response_update_type = AUS.evaluateRules(product_query) if not response_release: continue response_blobs.append({'product_query': product_query, 'response_release': response_release, 'response_update_type': response_update_type}) elif response_blob_names: for blob_name in response_blob_names: # if we have a SuperBlob of systemaddons, we process the response products and # concatenate their inner XMLs product_query = query.copy() product = dbo.releases.getReleases(name=blob_name, limit=1)[0]['product'] product_query["product"] = product response_release = dbo.releases.getReleaseBlob(name=blob_name) if not response_release: self.log.warning("No release found with name: %s", blob_name) continue response_blobs.append({'product_query': product_query, 'response_release': response_release, 'response_update_type': update_type}) else: response_blobs.append({'product_query': query, 'response_release': release, 'response_update_type': update_type}) # getHeaderXML() returns outermost header for an update which # is same for all release type xml = release.getHeaderXML() # we assume that all blobs will have similar ones. We might want to # verify that all of them are indeed the same in the future. # Appending Header # In case of superblob Extracting Header form parent release xml.append(release.getInnerHeaderXML(query, update_type, app.config["WHITELISTED_DOMAINS"], app.config["SPECIAL_FORCE_HOSTS"])) for response_blob in response_blobs: xml.extend(response_blob['response_release'] .getInnerXML(response_blob['product_query'], response_blob['response_update_type'], app.config["WHITELISTED_DOMAINS"], app.config["SPECIAL_FORCE_HOSTS"])) # Appending Footer # In case of superblob Extracting Header form parent release xml.append(release.getInnerFooterXML(query, update_type, app.config["WHITELISTED_DOMAINS"], app.config["SPECIAL_FORCE_HOSTS"])) xml.append(release.getFooterXML()) # ensure valid xml by using the right entity for ampersand xml = re.sub('&(?!amp;)', '&', '\n'.join(xml)) else: xml = ['<?xml version="1.0"?>'] xml.append('<updates>') xml.append('</updates>') xml = "\n".join(xml) self.log.debug("Sending XML: %s", xml) response = make_response(xml) response.headers["Cache-Control"] = self.cacheControl response.mimetype = "text/xml" return response
def get(self, **url): query = self.getQueryFromURL(url) self.log.debug("Got query: %s", query) release, update_type = AUS.evaluateRules(query) # passing {},None returns empty xml if release: response_products = release.getResponseProducts() response_blobs = [] if response_products: # if we have a SuperBlob, we process the response products and # concatenate their inner XMLs for product in response_products: product_query = query.copy() product_query["product"] = product response_release, response_update_type = AUS.evaluateRules( product_query) if not response_release: continue response_blobs.append({ 'product_query': product_query, 'response_release': response_release, 'response_update_type': response_update_type }) else: response_blobs.append({ 'product_query': query, 'response_release': release, 'response_update_type': update_type }) xml = ['<?xml version="1.0"?>'] xml.append('<updates>') # We only sample the first blob for the header and footer, since we # assume that all blobs will have similar ones. We might want to # verify that all of them are indeed the same in the future. xml.append(response_blobs[0]['response_release'].getHeaderXML( response_blobs[0]['product_query'], response_blobs[0]['response_update_type'])) for response_blob in response_blobs: xml.extend(response_blob['response_release'].getInnerXML( response_blob['product_query'], response_blob['response_update_type'], app.config["WHITELISTED_DOMAINS"], app.config["SPECIAL_FORCE_HOSTS"])) # Sampling the footer from the first blob xml.append(response_blobs[0]['response_release'].getFooterXML()) xml.append('</updates>') # ensure valid xml by using the right entity for ampersand xml = re.sub('&(?!amp;)', '&', '\n'.join(xml)) else: xml = ['<?xml version="1.0"?>'] xml.append('<updates>') xml.append('</updates>') xml = "\n".join(xml) self.log.debug("Sending XML: %s", xml) response = make_response(xml) response.mimetype = "text/xml" return response
parser.add_option("-d", "--db", dest="db", help="database to use, relative to inputdir") parser.add_option("-p", "--port", dest="port", type="int", help="port for server") parser.add_option("--host", dest="host", default='127.0.0.1', help="host to listen on. for example, 0.0.0.0 binds on all interfaces.") parser.add_option("--whitelist-domain", dest="whitelistedDomains", action="append") parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose output") options, args = parser.parse_args() # Logging needs to get set-up before importing the application # to make sure that logging done from other modules uses our Logger. from auslib.log import log_format, BalrogLogger logging.setLoggerClass(BalrogLogger) log_level = logging.INFO if options.verbose: log_level = logging.DEBUG logging.basicConfig(level=log_level, format=log_format) from auslib.web.base import app, AUS AUS.setDb(options.db) AUS.db.setDomainWhitelist(options.whitelistedDomains) try: AUS.db.create() except DatabaseAlreadyControlledError: pass app.config['SECRET_KEY'] = 'abc123' app.config['DEBUG'] = True app.run(port=options.port, host=options.host)
def get(self, **url): query = self.getQueryFromURL(url) self.log.debug("Got query: %s", query) release, update_type = AUS.evaluateRules(query) # passing {},None returns empty xml if release: response_products = release.getResponseProducts() response_blobs = [] response_blob_names = release.getResponseBlobs() if response_products: # if we have a SuperBlob of gmp, we process the response products and # concatenate their inner XMLs for product in response_products: product_query = query.copy() product_query["product"] = product response_release, response_update_type = AUS.evaluateRules( product_query) if not response_release: continue response_blobs.append({ 'product_query': product_query, 'response_release': response_release, 'response_update_type': response_update_type }) elif response_blob_names: for blob_name in response_blob_names: # if we have a SuperBlob of systemaddons, we process the response products and # concatenate their inner XMLs product_query = query.copy() product = dbo.releases.getReleases(name=blob_name, limit=1)[0]['product'] product_query["product"] = product response_release = dbo.releases.getReleaseBlob( name=blob_name) if not response_release: self.log.warning("No release found with name: %s", blob_name) continue response_blobs.append({ 'product_query': product_query, 'response_release': response_release, 'response_update_type': update_type }) else: response_blobs.append({ 'product_query': query, 'response_release': release, 'response_update_type': update_type }) # getHeaderXML() returns outermost header for an update which # is same for all release type xml = release.getHeaderXML() # we assume that all blobs will have similar ones. We might want to # verify that all of them are indeed the same in the future. # Appending Header # In case of superblob Extracting Header form parent release xml.append( release.getInnerHeaderXML(query, update_type, app.config["WHITELISTED_DOMAINS"], app.config["SPECIAL_FORCE_HOSTS"])) for response_blob in response_blobs: xml.extend(response_blob['response_release'].getInnerXML( response_blob['product_query'], response_blob['response_update_type'], app.config["WHITELISTED_DOMAINS"], app.config["SPECIAL_FORCE_HOSTS"])) # Appending Footer # In case of superblob Extracting Header form parent release xml.append( release.getInnerFooterXML(query, update_type, app.config["WHITELISTED_DOMAINS"], app.config["SPECIAL_FORCE_HOSTS"])) xml.append(release.getFooterXML()) # ensure valid xml by using the right entity for ampersand xml = re.sub('&(?!amp;)', '&', '\n'.join(xml)) else: xml = ['<?xml version="1.0"?>'] xml.append('<updates>') xml.append('</updates>') xml = "\n".join(xml) self.log.debug("Sending XML: %s", xml) response = make_response(xml) response.headers["Cache-Control"] = self.cacheControl response.mimetype = "text/xml" return response