mirror of https://github.com/veops/cmdb.git
flask init-cache
This commit is contained in:
parent
5f2a0d1a7b
commit
173c120b64
|
@ -2,7 +2,7 @@
|
||||||
# maybe use: cd ..
|
# maybe use: cd ..
|
||||||
FROM centos:7.6.1810 AS cmdb-api
|
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
|
RUN mkdir -p /data/apps/cmdb /data/apps/cmdb/logs
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import click
|
||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
|
|
||||||
import api.lib.cmdb.ci
|
import api.lib.cmdb.ci
|
||||||
|
from api.extensions import db
|
||||||
from api.extensions import rd
|
from api.extensions import rd
|
||||||
from api.models.cmdb import CI
|
from api.models.cmdb import CI
|
||||||
|
|
||||||
|
@ -14,11 +15,17 @@ from api.models.cmdb import CI
|
||||||
@click.command()
|
@click.command()
|
||||||
@with_appcontext
|
@with_appcontext
|
||||||
def init_cache():
|
def init_cache():
|
||||||
|
db.session.remove()
|
||||||
|
|
||||||
cis = CI.get_by(to_dict=False)
|
cis = CI.get_by(to_dict=False)
|
||||||
for ci in cis:
|
for ci in cis:
|
||||||
|
|
||||||
|
if list(filter(lambda x: x, rd.get([ci.id]))):
|
||||||
|
continue
|
||||||
|
|
||||||
m = api.lib.cmdb.ci.CIManager()
|
m = api.lib.cmdb.ci.CIManager()
|
||||||
ci_dict = m.get_ci_by_id_from_db(ci.id, need_children=False, use_master=False)
|
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.delete(ci.id)
|
||||||
rd.add({ci.id: json.dumps(ci_dict)})
|
rd.add({ci.id: json.dumps(ci_dict)})
|
||||||
|
|
||||||
|
db.session.remove()
|
||||||
|
|
|
@ -74,8 +74,6 @@ class AttributeValueManager(object):
|
||||||
deserialize = type_map["deserialize"][value_type]
|
deserialize = type_map["deserialize"][value_type]
|
||||||
try:
|
try:
|
||||||
v = deserialize(value)
|
v = deserialize(value)
|
||||||
if isinstance(v, markupsafe.Markup):
|
|
||||||
v = str(v)
|
|
||||||
return v
|
return v
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return abort(400, "attribute value <{0}> is invalid".format(value))
|
return abort(400, "attribute value <{0}> is invalid".format(value))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ from future.moves.urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
def build_api_key(path, params):
|
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
|
key = g.user.key
|
||||||
secret = g.user.secret
|
secret = g.user.secret
|
||||||
values = "".join([str(params[k]) for k in sorted(params.keys())
|
values = "".join([str(params[k]) for k in sorted(params.keys())
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
import jwt
|
import jwt
|
||||||
|
@ -20,7 +22,7 @@ def _auth_with_key():
|
||||||
secret = request.values.get('_secret')
|
secret = request.values.get('_secret')
|
||||||
path = request.path
|
path = request.path
|
||||||
keys = sorted(request.values.keys())
|
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)
|
user, authenticated = User.query.authenticate_with_key(key, secret, req_args, path)
|
||||||
if user and authenticated:
|
if user and authenticated:
|
||||||
login_user(user)
|
login_user(user)
|
||||||
|
|
|
@ -69,6 +69,6 @@ class RedisHandler(object):
|
||||||
try:
|
try:
|
||||||
ret = self.r.hdel(self.prefix, key_id)
|
ret = self.r.hdel(self.prefix, key_id)
|
||||||
if not ret:
|
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:
|
except Exception as e:
|
||||||
current_app.logger.error("delete redis key error, {0}".format(str(e)))
|
current_app.logger.error("delete redis key error, {0}".format(str(e)))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM node:alpine as builder
|
FROM node:alpine AS builder
|
||||||
|
|
||||||
LABEL description="cmdb-ui"
|
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
|
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
|
RUN mkdir /etc/nginx/html && rm -f /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue