Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
attr_names.append(CIAttributeCache.get(attr.attr_id).attr_name)
attr_names = set(attr_names)
for attr_name in attr_names:
Table = TableMap(attr_name=attr_name).table
db.session.query(Table).filter(Table.ci_id == ci_id).delete()
db.session.query(CIRelation).filter(
CIRelation.first_ci_id == ci_id).delete()
db.session.query(CIRelation).filter(
CIRelation.second_ci_id == ci_id).delete()
# db.session.query(CIAttributeHistory).filter(
# CIAttributeHistory.ci_id == ci_id).delete()
db.session.flush()
db.session.delete(ci)
try:
db.session.commit()
except Exception as e:
db.session.rollback()
current_app.logger.error("delete CI error, {0}".format(str(e)))
return abort(400, "delete CI error, {0}".format(str(e)))
# todo: write history
ci_delete.apply_async([ci.ci_id], queue="cmdb_async")
return ci_id
return abort(404, "CI {0} not found".format(ci_id))
def delete(self, attr_id):
attr, name = db.session.query(CIAttribute).filter_by(
attr_id=attr_id).first(), None
if attr:
if attr.is_choice:
choice_table = type_map["choice"].get(attr.value_type)
db.session.query(choice_table).filter(
choice_table.attr_id == attr_id).delete()
db.session.flush()
name = attr.attr_name
CIAttributeCache.clean(attr)
db.session.delete(attr)
try:
db.session.commit()
except Exception as e:
db.session.rollback()
current_app.logger.error("delete attribute error, {0}".format(
str(e)))
return abort(500, str(e))
else:
return abort(404, "attribute you want to delete is not existed")
return name
if attr.is_index else attr.value_type
value_table = type_map.get("table").get(table_key)
v = args.get(unique_key)
if value_table and v:
item = db.session.query(value_table).filter(
value_table.ci_id == ci_id).filter(
value_table.attr_id == attr.attr_id).first()
if item:
converter = type_map.get("converter").get(attr.value_type)
try:
item.value = converter(v)
except:
return abort(400, "value is illegal")
db.session.add(item)
try:
db.session.commit()
except Exception as e:
db.session.rollback()
current_app.logger.error(str(e))
return abort(400, "update unique failed")
ci_cache.apply_async([ci_id], queue="cmdb_async")
decoded_token = decode_token(encoded_token)
jti = decoded_token['jti']
token_type = decoded_token['type']
user_identity = decoded_token[identity_claim]
expires = _epoch_utc_to_datetime(decoded_token['exp'])
revoked = False
db_token = TokenBlacklist(
jti=jti,
token_type=token_type,
user_identity=user_identity,
expires=expires,
revoked=revoked,
)
db.session.add(db_token)
db.session.commit()
if p is None:
return abort(404, "parent {0} is not existed".format(parent))
c = CITypeCache.get(child)
if c is None:
return abort(404, "child {0} is not existed".format(child))
existed = db.session.query(CITypeRelation.ctr_id).filter_by(
parent_id=parent).filter_by(child_id=child).first()
if existed is not None:
return True, existed.ctr_id
ctr = CITypeRelation()
ctr.parent_id = parent
ctr.child_id = child
ctr.relation_type = relation_type
db.session.add(ctr)
try:
db.session.commit()
except Exception as e:
db.session.rollback()
current_app.logger.error(
"add CITypeRelation is error, {0}".format(str(e)))
return abort(
500, "add CITypeRelation is error, {0}".format(str(e)))
return ctr.ctr_id
def delete(self, cr_id):
cr = db.session.query(CIRelation).filter(
CIRelation.cr_id == cr_id).first()
cr_id = cr.cr_id
first_ci = cr.first_ci_id
second_ci = cr.second_ci_id
if cr is not None:
db.session.delete(cr)
try:
db.session.commit()
except Exception as e:
db.session.rollback()
current_app.logger.error(
"delete CIRelation is error, {0}".format(str(e)))
return abort(
400, "delete CIRelation is error, {0}".format(str(e)))
his_manager = CIRelationHistoryManager()
his_manager.add(cr_id, first_ci, second_ci,
cr.relation_type, operate_type="delete")
return True
return abort(404, "CI relation is not existed")
for size, image in images.iteritems():
imageio = StringIO()
image.save(imageio, format=image.ext)
f = ext.storage.save(
'%s_%s.%s' % (
os.path.splitext(name)[0],
size,
image.ext
),
imageio
)
setattr(upload, u'%s_name' % size, f.name.decode('utf-8'))
setattr(upload, u'%s_url' % size, f.url.decode('utf-8'))
ext.db.session.add(upload)
ext.db.session.commit()
if choice_value:
is_choice = True
attr.attr_name = args[0]
attr.attr_alias = args[1]
if not args[1]:
attr.attr_alias = args[0]
attr.is_choice = is_choice
attr.is_multivalue = kwargs.get("is_multivalue", False)
attr.is_uniq = kwargs.get("is_uniq", False)
attr.value_type = kwargs.get("value_type", "text")
db.session.add(attr)
db.session.flush()
if is_choice:
self._add_choice_value(choice_value, attr.attr_id, attr.value_type)
try:
db.session.commit()
except Exception as e:
db.session.rollback()
current_app.logger.error("update attribute error, {0}".format(
str(e)))
return False, str(e)
CIAttributeCache.clean(attr)
return True, attr.attr_id
def signupfunc():
if request.method == 'POST':
robj = request.get_json()
user = User(username=robj['name'], email=robj['email'])
user.set_password(robj['password'])
db.session.add(user)
db.session.commit()
return 'request'