本文整理汇总了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"))
示例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
示例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
示例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')
示例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()
示例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')
示例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()
示例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()
示例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)
示例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
示例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")
示例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()
示例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"))
示例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
示例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)