flask init-cache

This commit is contained in:
pycook 2019-11-11 15:46:57 +08:00
parent 5f2a0d1a7b
commit 173c120b64
7 changed files with 18 additions and 10 deletions

View File

@ -2,7 +2,7 @@
# maybe use: cd ..
FROM centos:7.6.1810 AS cmdb-api
LABEL description="Python3.7.5,cmdb"
LABEL description="Python2.7.5,cmdb"
RUN mkdir -p /data/apps/cmdb /data/apps/cmdb/logs

View File

@ -7,6 +7,7 @@ import click
from flask.cli import with_appcontext
import api.lib.cmdb.ci
from api.extensions import db
from api.extensions import rd
from api.models.cmdb import CI
@ -14,11 +15,17 @@ from api.models.cmdb import CI
@click.command()
@with_appcontext
def init_cache():
db.session.remove()
cis = CI.get_by(to_dict=False)
for ci in cis:
if list(filter(lambda x: x, rd.get([ci.id]))):
continue
m = api.lib.cmdb.ci.CIManager()
ci_dict = m.get_ci_by_id_from_db(ci.id, need_children=False, use_master=False)
if rd.get([ci.id]):
return
rd.delete(ci.id)
rd.add({ci.id: json.dumps(ci_dict)})
db.session.remove()

View File

@ -74,8 +74,6 @@ class AttributeValueManager(object):
deserialize = type_map["deserialize"][value_type]
try:
v = deserialize(value)
if isinstance(v, markupsafe.Markup):
v = str(v)
return v
except ValueError:
return abort(400, "attribute value <{0}> is invalid".format(value))

View File

@ -1,5 +1,6 @@
# -*- coding:utf-8 -*-
from __future__ import unicode_literals
import hashlib
@ -11,7 +12,7 @@ from future.moves.urllib.parse import urlparse
def build_api_key(path, params):
g.user is not None or abort(403, u"您得登陆才能进行该操作")
g.user is not None or abort(403, "您得登陆才能进行该操作")
key = g.user.key
secret = g.user.secret
values = "".join([str(params[k]) for k in sorted(params.keys())

View File

@ -1,6 +1,8 @@
# -*- coding:utf-8 -*-
from __future__ import unicode_literals
from functools import wraps
import jwt
@ -20,7 +22,7 @@ def _auth_with_key():
secret = request.values.get('_secret')
path = request.path
keys = sorted(request.values.keys())
req_args = [request.values[k] for k in keys if str(k) not in ("_key", "_secret")]
req_args = [request.values[k] for k in keys if k not in ("_key", "_secret")]
user, authenticated = User.query.authenticate_with_key(key, secret, req_args, path)
if user and authenticated:
login_user(user)

View File

@ -69,6 +69,6 @@ class RedisHandler(object):
try:
ret = self.r.hdel(self.prefix, key_id)
if not ret:
current_app.logger.warn("[%d] is not in redis".format(key_id))
current_app.logger.warn("[{0}] is not in redis".format(key_id))
except Exception as e:
current_app.logger.error("delete redis key error, {0}".format(str(e)))

View File

@ -1,4 +1,4 @@
FROM node:alpine as builder
FROM node:alpine AS builder
LABEL description="cmdb-ui"
@ -9,7 +9,7 @@ WORKDIR /data/apps/cmdb-ui
RUN sed -i "s#http://127.0.0.1:5000##g" .env && yarn install && yarn build
FROM nginx:alpine
FROM nginx:alpine AS cmdb-ui
RUN mkdir /etc/nginx/html && rm -f /etc/nginx/conf.d/default.conf