Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_not_found():
with pytest.raises(falcon.HTTPNotFound) as redirect:
hug.redirect.not_found()
assert "404" in redirect.value.status
def on_get(self, req, resp):
key = req.get_param('key')
url = self.settings_manager.get_proxy(key)
if url is None or url == "":
raise falcon.HTTPNotFound()
resp.json = {'url': url}
def signup(username, password):
if db.session.query(exists().where(User.username == username)).scalar():
raise HTTPNotFound(title='Cannot', description='asdfas')
u = User(username=username, password=password)
print(u)
db.session.add(u)
return {'token': generate_token(u)}
def __call__(self, current):
current.log.info("CRUD CALL")
self.set_current(current)
if 'model' not in current.input:
self.list_models()
else:
self.model_class = model_registry.get_model(current.input['model'])
self.object_id = self.input.get('object_id')
if self.object_id:
try:
self.object = self.model_class(current).objects.get(self.object_id)
if self.object.deleted:
raise HTTPNotFound()
except:
raise HTTPNotFound()
else:
self.object = self.model_class(current)
current.log.info('Calling %s_view of %s' % (
(self.cmd or 'list'), self.model_class.__name__))
self.__class__.__dict__['%s_view' % (self.cmd or 'list')](self)
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)
logging.exception("CODE: "+err.response.text)
if 'code' not in json.loads(err.response.text)['error']:
code = json.loads(err.response.text)['code']
else:
code = json.loads(err.response.text)['error']['code']
if code == 401:
raise falcon.HTTPUnauthorized(json.loads(err.response.text)['error']['title'],
json.loads(err.response.text))
elif code == 403:
raise falcon.HTTPForbidden(json.loads(err.response.text)['error']['title'],
json.loads(err.response.text))
elif code == 404:
raise falcon.HTTPNotFound()
raise
except sessionNotFound as err:
raise falcon.HTTPNotFound()
except falcon.HTTPError as err:
logging.exception("Falcon "+err.title)
raise
except Exception as err:
try:
logging.exception(err.message)
except:
logging.exception("Unexpected exception")
raise
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
def _delete_transform(self, tenant_id, transform_id):
try:
self._transforms_repo.delete_transform(tenant_id, transform_id)
except repository_exceptions.DoesNotExistException:
raise falcon.HTTPNotFound()
except repository_exceptions.RepositoryException as ex:
LOG.error(ex)
raise falcon.HTTPInternalServerError('Service unavailable',
ex.message)
def on_delete(self, req, resp, dataset_id, **kwargs):
"""Delete a dataset from the service
This method will delete the entry from the datbase and will also
delete the entire datasets generated by them on filesystem.
:param integer dataset_id: Unique ID of dataset
:returns: Nothing if operation was successful
:rtype: 204 NO CONTENT
"""
try:
delete_task = async_tasks.delete_dataset_by_id(dataset_id)
except LookupError:
raise falcon.HTTPNotFound(description="Couldn't locate dataset")
except OSError as err:
raise falcon.HTTPInternalServerError(description=str(err))
else:
resp.status = falcon.HTTP_204
def on_put(self, req, resp, domain, username):
"""
Reset password
"""
if not re.match("[a-z][a-z0-9]{1,31}$", username):
raise falcon.HTTPBadRequest("Error", "Invalid username")
temporary_password = generate_password(8)
args = domain2dn(domain), ldap.SCOPE_SUBTREE, "(&(objectClass=posixAccount)(uid=%s))" % username, []
for dn_user, attributes in self.conn.search_s(*args):
email = attributes.get(settings.LDAP_USER_ATTRIBUTE_RECOVERY_EMAIL, [""]).pop()
break
else:
print "No such user: %s" % username
raise falcon.HTTPNotFound()
recipients = [settings.ADMIN_EMAIL]
# if "@" in email:
# recipients.append(email)
self.mailer.enqueue(
settings.ADMIN_EMAIL,
recipients,
"Teie parool on lähtestatud",
"email-password-reset",
username = username,
password = temporary_password,
server_helpdesk={"email": settings.ADMIN_EMAIL, "name": settings.ADMIN_NAME}
)
self.conn.passwd_s(dn_user, None, temporary_password)