當前位置: 首頁>>代碼示例>>Python>>正文


Python falcon.HTTPNotFound方法代碼示例

本文整理匯總了Python中falcon.HTTPNotFound方法的典型用法代碼示例。如果您正苦於以下問題:Python falcon.HTTPNotFound方法的具體用法?Python falcon.HTTPNotFound怎麽用?Python falcon.HTTPNotFound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在falcon的用法示例。


在下文中一共展示了falcon.HTTPNotFound方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: on_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_post(self, req, resp, cn):
        """
        Sign a certificate signing request
        """
        try:
            cert, buf = self.authority.sign(cn,
                profile=config.PROFILES[req.get_param("profile", default="rw")],
                overwrite=True,
                signer=req.context.get("user").name)
            # Mailing and long poll publishing implemented in the function above
        except EnvironmentError: # no such CSR
            raise falcon.HTTPNotFound()

        resp.body = "Certificate successfully signed"
        resp.status = falcon.HTTP_201
        resp.location = os.path.join(req.relative_uri, "..", "..", "signed", cn)
        logger.info("Signing request %s signed by %s from %s", cn,
            req.context.get("user"), req.context.get("remote_addr")) 
開發者ID:laurivosandi,項目名稱:certidude,代碼行數:20,代碼來源:request.py

示例2: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_get(self, req, resp):
        if not self.healthcheck_path:
            logger.error('Healthcheck path not set')
            raise falcon.HTTPNotFound()

        try:
            with open(self.healthcheck_path) as f:
                health = f.readline().strip()
        except IOError:
            raise falcon.HTTPNotFound()

        try:
            connection = db.connect()
            cursor = connection.cursor()
            cursor.execute('SELECT version()')
            cursor.close()
            connection.close()
        except Exception:
            resp.status = HTTP_503
            resp.content_type = 'text/plain'
            resp.body = 'Could not connect to database'
        else:
            resp.status = HTTP_200
            resp.content_type = 'text/plain'
            resp.body = health 
開發者ID:linkedin,項目名稱:iris-relay,代碼行數:27,代碼來源:app.py

示例3: guarded_session

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def guarded_session():
    '''
    Context manager that will automatically close session on exceptions
    '''
    try:
        session = Session()
        yield session
    except IrisValidationException as e:
        session.close()
        raise HTTPBadRequest('Validation error', str(e))
    except (HTTPForbidden, HTTPUnauthorized, HTTPNotFound, HTTPBadRequest):
        session.close()
        raise
    except Exception:
        session.close()
        logger.exception('SERVER ERROR')
        raise 
開發者ID:linkedin,項目名稱:iris,代碼行數:19,代碼來源:db.py

示例4: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_get(req, resp, key):
    """Get ical file for a user or team's oncall calendar with no contact
    information.  Key can be requested at /api/v0/ical_key.

    """
    roles = req.get_param_as_list('roles')

    name_and_type = get_name_and_type_from_key(key)
    if name_and_type is None:
        raise HTTPNotFound()

    name, type = name_and_type
    start = int(time.time())
    events = []
    if type == 'user':
        events = get_user_events(name, start, roles=roles)
    elif type == 'team':
        events = get_team_events(name, start, roles=roles, include_subscribed=True)

    resp.body = ical.events_to_ical(events, name, contact=False)
    resp.set_header('Content-Type', 'text/calendar') 
開發者ID:linkedin,項目名稱:oncall,代碼行數:23,代碼來源:public_ical.py

示例5: on_delete

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_delete(req, resp, schedule_id):
    """
    Delete a schedule by id. Only allowed for team admins.

    **Example request:**

    .. sourcecode:: http

        DELETE /api/v0/schedules/1234 HTTP/1.1

    :statuscode 200: Successful delete
    :statuscode 404: Schedule not found
    """
    connection = db.connect()
    cursor = connection.cursor()
    verify_auth(req, schedule_id, connection, cursor)
    cursor.execute('DELETE FROM `schedule` WHERE `id`=%s', int(schedule_id))
    deleted = cursor.rowcount
    connection.commit()
    cursor.close()
    connection.close()

    if deleted == 0:
        raise HTTPNotFound() 
開發者ID:linkedin,項目名稱:oncall,代碼行數:26,代碼來源:schedule.py

示例6: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_get(req, resp, team):
    """Get the secret key that grants public access to team's oncall
    calendar for the logged-in user.

    **Example request:**

    .. sourcecode:: http

        GET /api/v0/ical_key/team/jteam HTTP/1.1
        Content-Type: text/plain

        ef895425-5f49-11ea-8eee-10e7c6352aff

    """
    challenger = req.context['user']

    key = get_ical_key(challenger, team, 'team')
    if key is None:
        raise HTTPNotFound()

    resp.body = key
    resp.set_header('Content-Type', 'text/plain') 
開發者ID:linkedin,項目名稱:oncall,代碼行數:24,代碼來源:ical_key_team.py

示例7: on_delete

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_delete(req, resp, team, subscription, role):
    check_team_auth(team, req)
    connection = db.connect()
    cursor = connection.cursor()

    cursor.execute('''DELETE FROM `team_subscription`
                      WHERE team_id = (SELECT `id` FROM `team` WHERE `name` = %s)
                      AND `subscription_id` = (SELECT `id` FROM `team` WHERE `name` = %s)\
                      AND `role_id` = (SELECT `id` FROM `role` WHERE `name` = %s)''',
                   (team, subscription, role))
    deleted = cursor.rowcount
    connection.commit()
    cursor.close()
    connection.close()
    if deleted == 0:
        raise HTTPNotFound() 
開發者ID:linkedin,項目名稱:oncall,代碼行數:18,代碼來源:team_subscription.py

示例8: on_delete

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_delete(req, resp, service):
    """
    Delete a service. Currently unused/debug only.
    """
    connection = db.connect()
    cursor = connection.cursor()

    # FIXME: also delete team service mappings?
    cursor.execute('DELETE FROM `service` WHERE `name`=%s', service)
    deleted = cursor.rowcount
    connection.commit()
    cursor.close()
    connection.close()

    if deleted == 0:
        raise HTTPNotFound() 
開發者ID:linkedin,項目名稱:oncall,代碼行數:18,代碼來源:service.py

示例9: _alarm_definition_delete

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def _alarm_definition_delete(self, tenant_id, id):

        sub_alarm_definition_rows = (
            self._alarm_definitions_repo.get_sub_alarm_definitions(id))
        alarm_metric_rows = self._alarm_definitions_repo.get_alarm_metrics(
            tenant_id, id)
        sub_alarm_rows = self._alarm_definitions_repo.get_sub_alarms(
            tenant_id, id)

        if not self._alarm_definitions_repo.delete_alarm_definition(
                tenant_id, id):
            raise falcon.HTTPNotFound

        self._send_alarm_definition_deleted_event(id,
                                                  sub_alarm_definition_rows)

        self._send_alarm_event(u'alarm-deleted', tenant_id, id,
                               alarm_metric_rows, sub_alarm_rows, None, None) 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:20,代碼來源:alarm_definitions.py

示例10: whitelist_subject

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def whitelist_subject(func):
    def wrapped(self, req, resp, cn, *args, **kwargs):
        from ipaddress import ip_address
        from certidude import authority
        from xattr import getxattr
        try:
            path, buf, cert, signed, expires = authority.get_signed(cn)
        except IOError:
            raise falcon.HTTPNotFound()
        else:
            # First attempt to authenticate client with certificate
            buf = req.get_header("X-SSL-CERT")
            if buf:
                header, _, der_bytes = pem.unarmor(buf.replace("\t", "").encode("ascii"))
                origin_cert = x509.Certificate.load(der_bytes)
                if origin_cert.native == cert.native:
                    logger.debug("Subject authenticated using certificates")
                    return func(self, req, resp, cn, *args, **kwargs)

            # For backwards compatibility check source IP address
            # TODO: make it disableable
            try:
                inner_address = getxattr(path, "user.lease.inner_address").decode("ascii")
            except IOError:
                raise falcon.HTTPForbidden("Forbidden", "Remote address %s not whitelisted" % req.context.get("remote_addr"))
            else:
                if req.context.get("remote_addr") != ip_address(inner_address):
                    raise falcon.HTTPForbidden("Forbidden", "Remote address %s mismatch" % req.context.get("remote_addr"))
                else:
                    return func(self, req, resp, cn, *args, **kwargs)
    return wrapped 
開發者ID:laurivosandi,項目名稱:certidude,代碼行數:33,代碼來源:firewall.py

示例11: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_get(self, req, resp, cn):
        """
        Fetch certificate signing request as PEM
        """

        try:
            path, buf, _, submitted = self.authority.get_request(cn)
        except errors.RequestDoesNotExist:
            logger.warning("Failed to serve non-existant request %s to %s",
                cn, req.context.get("remote_addr"))
            raise falcon.HTTPNotFound()

        resp.set_header("Content-Type", "application/pkcs10")
        logger.debug("Signing request %s was downloaded by %s",
            cn, req.context.get("remote_addr"))

        preferred_type = req.client_prefers(("application/json", "application/x-pem-file"))

        if preferred_type == "application/x-pem-file":
            # For certidude client, curl scripts etc
            resp.set_header("Content-Type", "application/x-pem-file")
            resp.set_header("Content-Disposition", ("attachment; filename=%s.pem" % cn))
            resp.body = buf
        elif preferred_type == "application/json":
            # For web interface events
            resp.set_header("Content-Type", "application/json")
            resp.set_header("Content-Disposition", ("attachment; filename=%s.json" % cn))
            resp.body = json.dumps(dict(
                submitted = submitted,
                common_name = cn,
                address = getxattr(path, "user.request.address").decode("ascii"), # TODO: move to authority.py
                md5sum = hashlib.md5(buf).hexdigest(),
                sha1sum = hashlib.sha1(buf).hexdigest(),
                sha256sum = hashlib.sha256(buf).hexdigest(),
                sha512sum = hashlib.sha512(buf).hexdigest()), cls=MyEncoder)
        else:
            raise falcon.HTTPUnsupportedMediaType(
                "Client did not accept application/json or application/x-pem-file") 
開發者ID:laurivosandi,項目名稱:certidude,代碼行數:40,代碼來源:request.py

示例12: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_get(self, req, resp, cn):
        try:
            path, buf, cert, signed, expires = self.authority.get_signed(cn)
            return dict(
                last_seen =     xattr.getxattr(path, "user.lease.last_seen").decode("ascii"),
                inner_address = xattr.getxattr(path, "user.lease.inner_address").decode("ascii"),
                outer_address = xattr.getxattr(path, "user.lease.outer_address").decode("ascii")
            )
        except EnvironmentError: # Certificate or attribute not found
            raise falcon.HTTPNotFound() 
開發者ID:laurivosandi,項目名稱:certidude,代碼行數:12,代碼來源:lease.py

示例13: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_get(self, req, resp, serial_number):
        try:
            path, buf, cert, signed, expires, revoked, reason = self.authority.get_revoked(serial_number)
        except EnvironmentError:
            logger.warning("Failed to serve non-existant revoked certificate with serial %s to %s",
                serial_number, req.context.get("remote_addr"))
            raise falcon.HTTPNotFound()
        resp.set_header("Content-Type", "application/x-pem-file")
        resp.set_header("Content-Disposition", ("attachment; filename=%x.pem" % cert.serial_number))
        resp.body = buf
        logger.debug("Served revoked certificate with serial %s to %s",
            serial_number, req.context.get("remote_addr")) 
開發者ID:laurivosandi,項目名稱:certidude,代碼行數:14,代碼來源:revoked.py

示例14: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_get(self, req, resp, cn):
        """
        Return extended attributes stored on the server.
        This not only contains tags and lease information,
        but might also contain some other sensitive information.
        """
        try:
            path, buf, cert, attribs = self.authority.get_attributes(cn,
                namespace=self.namespace, flat=True)
        except IOError:
            raise falcon.HTTPNotFound()
        else:
            return attribs 
開發者ID:laurivosandi,項目名稱:certidude,代碼行數:15,代碼來源:attrib.py

示例15: on_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTPNotFound [as 別名]
def on_post(self, req, resp, cn):
        namespace = ("user.%s." % self.namespace).encode("ascii")
        try:
            path, buf, cert, signed, expires = self.authority.get_signed(cn)
        except IOError:
            raise falcon.HTTPNotFound()
        else:
            for key in req.params:
                if not re.match("[a-z0-9_\.]+$", key):
                    raise falcon.HTTPBadRequest("Invalid key %s" % key)
            valid = set()
            modified = False
            for key, value in req.params.items():
                identifier = ("user.%s.%s" % (self.namespace, key)).encode("ascii")
                try:
                    if getxattr(path, identifier).decode("utf-8") != value:
                        modified = True
                except OSError: # no such attribute
                    pass
                setxattr(path, identifier, value.encode("utf-8"))
                valid.add(identifier)
            for key in listxattr(path):
                if not key.startswith(namespace):
                    continue
                if key not in valid:
                    modified = True
                    removexattr(path, key)
            if modified:
                push.publish("attribute-update", cn) 
開發者ID:laurivosandi,項目名稱:certidude,代碼行數:31,代碼來源:attrib.py


注:本文中的falcon.HTTPNotFound方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。