def get(self, volume_name_or_id_str): # try to cast to int, in case it's an ID volume_name_or_id = None try: volume_name_or_id = int(volume_name_or_id_str) except: volume_name_or_id = volume_name_or_id_str volume = Volume.Read(volume_name_or_id) if volume is None: response_user_error(self, 404, "No such volume") response_end(self, 200, volume.volume_cert_bin, "application/octet-stream") return
def get(self, volume_name_or_id_str, volume_cert_version_str): volume_id = None volume_name = None volume_cert_version = None try: volume_id = int(volume_name_or_id_str) except: volume_name = volume_name_or_id_str try: volume_cert_version = int(volume_cert_version_str) except: response_end(self, 400, "Invalid Request", "text/plain") return if volume_id is None: # look up volume volume = Volume.Read(volume_name) if volume is None or volume.deleted: response_end(self, 404, "Not found", "text/plain") return volume_id = volume.volume_id volume_cert_bundle = VolumeCertBundle.Get(volume_id) if volume_cert_bundle is None: response_end(self, 404, "Not found", "text/plain") return # verify that it matches cert_bundle = VolumeCertBundle.Load(volume_cert_bundle) if cert_bundle.mtime_sec != volume_cert_version: # send gateway the URL to the latest cert bundle hdr = "%s/CERTBUNDLE/%s/%s" % (MS_URL, volume_name_or_id_str, cert_bundle.mtime_sec) self.response.headers['Location'] = hdr response_end(self, 302, "Location: %s" % hdr, "text/plain") return logging.info("Serve volume %s (%s)" % (volume_id, volume_cert_version)) response_end(self, 200, cert_bundle.SerializeToString(), "application/octet-stream") return