def put(self): req_data = json.loads(json.dumps(request.form)) secret = req_data["secret"] make_secret_value = req_data["make_secret_value"] authority = req_data["authority"] id = req_data["account_id"] if secret != make_secret_value: abort("secret_not_mate") DBsession.query(aws_model.CmdbUser).filter_by(id=id).update({ "authority": authority, "secret": secret, }) try: aws_model.DBsession.commit() except exc.SQLAlchemyError: aws_model.DBsession.rollback() cmdb_obj = aws_model.CmdbUser() res_acc = cmdb_obj.get_accunt return res_acc, 201, None
def put(self): req_data = json.loads(json.dumps(request.form)) account = req_data["account"] secret = req_data["secret"] authority = req_data["authority"] user = DBsession.query( aws_model.CmdbUser).filter_by(account=account).first() if user: abort('cmdb_user_exited') else: now = datetime.datetime.now() user_ins = aws_model.CmdbUser(authority=authority, account=account, secret=secret, data_create_time=now, data_status=True) aws_model.DBsession.add(user_ins) try: aws_model.DBsession.commit() except exc.SQLAlchemyError: aws_model.DBsession.rollback() else: uid = DBsession.query( aws_model.CmdbUser.id).filter_by(account=account).first() self.payload["data"]["id"] = uid self.payload["data"]["authority"] = authority token = jwt.encode(self.payload, app.config['SECRET'], algorithm='HS256') return token, 201, None
def put(self): req_data = json.loads(json.dumps(request.form)) id = req_data["account_id"] platform = req_data["platform"] account = str(req_data["account"]) secret = str(req_data["secret"]) mark = req_data["mark"] now = datetime.datetime.now() DBsession.query(aws_model.OpsAccountManage).filter_by(id=id).update({ "platform": platform, "account": account, "secret": secret, "mark": mark, "data_update_time": now }) try: aws_model.DBsession.commit() except exc.SQLAlchemyError: aws_model.DBsession.rollback() abort('add_config_error') else: acc_obj = aws_model.OpsAccountManage() res_acc = acc_obj.get_accunt return res_acc, 200, None
def delete(self): req_data = json.loads(json.dumps(request.form)) account_id = int(req_data["account_id"]) try: res = DBsession.query( aws_model.WinXinAcount).filter_by(id=account_id).first() setattr(res, "data_status", False) DBsession.commit() except exc.SQLAlchemyError: aws_model.DBsession.rollback() else: acc_obj = aws_model.WinXinAcount() res_acc = acc_obj.get_accunt return res_acc, 200, None
def get_accunt(self): res_acc = DBsession.query(CmdbUser).filter( CmdbUser.data_status == True).order_by(CmdbUser.id).all() for res in res_acc: res.data_create_time = res.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") return res_acc
def post(self): req_data = json.loads(json.dumps(request.form)) account = req_data["account"] secret = req_data["secret"] make_secret_value = req_data["make_secret_value"] authority = req_data["authority"] if secret != make_secret_value: abort("secret_not_mate") user = DBsession.query( aws_model.CmdbUser).filter_by(account=account).first() if user: abort("cmdb_user_exited") now = datetime.datetime.now() account_ins = aws_model.CmdbUser(authority=authority, account=account, secret=secret, data_create_time=now, data_status=True) aws_model.DBsession.add(account_ins) try: aws_model.DBsession.commit() except exc.SQLAlchemyError: aws_model.DBsession.rollback() cmdb_obj = aws_model.CmdbUser() res_acc = cmdb_obj.get_accunt return res_acc, 201, None
def access_token(token): try: user_token = jwt.decode(token, app.config["SECRET"]) except Exception: user_name = "quxiaotong" return user_name user_name = DBsession.query( aws_model.CmdbUser.account).filter_by(id=user_token["uid"]).first() return user_name
def delete(self): req_data = json.loads(json.dumps(request.form)) account_ids = eval(req_data["data"])["account_id"] if isinstance(account_ids, int): account_ids = str(account_ids) for account_id in account_ids: account_id = int(account_id) try: DBsession.query(aws_model.OpsAccountManage).filter_by( id=account_id).delete() DBsession.commit() except exc.SQLAlchemyError: aws_model.DBsession.rollback() acc_obj = aws_model.OpsAccountManage() res_acc = acc_obj.get_accunt return res_acc, 200, None
def vpc_to_api(self): db_res_vpc = DBsession.query(Vpc).filter( Vpc.data_status == True).order_by(Vpc.id).all() for vpc_ins in db_res_vpc: vpc_ins.data_create_time = vpc_ins.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") vpc_ins.data_update_time = vpc_ins.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return db_res_vpc
def delete(self): req_data = json.loads(json.dumps(request.form)) account_ids = eval(req_data["data"])["account_id"] if isinstance(account_ids, int): account_ids = str(account_ids) for account_id in account_ids: account_id = int(account_id) try: res = DBsession.query( aws_model.CmdbUser).filter_by(id=account_id).first() setattr(res, "data_status", False) DBsession.commit() except exc.SQLAlchemyError: aws_model.DBsession.rollback() acc_obj = aws_model.CmdbUser() res_acc = acc_obj.get_accunt return res_acc, 200, None
def get_sysconfig(self, app_name): try: res_app = DBsession.query(App).filter(App.name == app_name).first() res_sysconfig = res_app.sysconfig for res in res_sysconfig: res.data_update_time = res.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return res_sysconfig except Exception as e: abort("app_name not find")
def iam_to_api(self): db_res_iam = DBsession.query(Iam).filter( Iam.data_status == True).order_by(Iam.id).all() for iam_ins in db_res_iam: iam_ins.aws_create_time = iam_ins.aws_create_time.strftime( "%Y-%m-%d %H:%M:%S") iam_ins.data_create_time = iam_ins.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") iam_ins.data_update_time = iam_ins.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return db_res_iam
def s3_to_api(self): db_res_s3 = DBsession.query(S3).filter( S3.data_status == True).order_by(S3.id).all() for s3_ins in db_res_s3: s3_ins.aws_create_time = s3_ins.aws_create_time.strftime( "%Y-%m-%d %H:%M:%S") s3_ins.data_create_time = s3_ins.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") s3_ins.data_update_time = s3_ins.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return db_res_s3
def vol_to_api(self): db_res_vol = DBsession.query(Volume).filter( Volume.data_status == True).order_by(Volume.id).all() for vol_ins in db_res_vol: vol_ins.aws_create_time = vol_ins.aws_create_time.strftime( "%Y-%m-%d %H:%M:%S") vol_ins.data_create_time = vol_ins.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") vol_ins.data_update_time = vol_ins.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return db_res_vol
def elb_to_api(self): db_res_elb = DBsession.query(Elb).filter( Elb.data_status == True).order_by(Elb.id).all() for elb_ins in db_res_elb: elb_ins.aws_create_time = elb_ins.aws_create_time.strftime( "%Y-%m-%d %H:%M:%S") elb_ins.data_create_time = elb_ins.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") elb_ins.data_update_time = elb_ins.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return db_res_elb
def get_accunt(self): res_acc = DBsession.query(OpsAccountManage).filter( OpsAccountManage.data_status == True).order_by( OpsAccountManage.id).all() for res in res_acc: res.platform = str(res.platform) res.mark = str(res.mark) res.data_create_time = res.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") res.data_update_time = res.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return res_acc
def ec_to_api(self): db_res_ec = DBsession.query(Elasticache).filter( Elasticache.data_status == True).order_by(Elasticache.id).all() for ec_ins in db_res_ec: memory = ec_ins.ec_type.memory ec_ins.memory_num = int(memory) ec_ins.aws_create_time = ec_ins.aws_create_time.strftime( "%Y-%m-%d %H:%M:%S") ec_ins.data_create_time = ec_ins.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") ec_ins.data_update_time = ec_ins.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return db_res_ec
def detail_ec2(self, ip): ec2_ins = DBsession.query(Ec2).filter(Ec2.private_ip == ip).first() cpu = ec2_ins.ec2_type.cpu memory = ec2_ins.ec2_type.memory ec2_ins.cpu_num = int(cpu) ec2_ins.memory_num = int(memory) ec2_ins.aws_create_time = ec2_ins.aws_create_time.strftime( "%Y-%m-%d %H:%M:%S") ec2_ins.data_create_time = ec2_ins.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") ec2_ins.data_update_time = ec2_ins.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return ec2_ins
def put(self): req_data = json.loads(json.dumps(request.form)) use_type = req_data["use_type"] name = req_data["name"] mail = str(req_data["mail"]) secret = str(req_data["secret"]) type = req_data["type"] use_name = req_data["use_name"] phone = req_data["phone"] now = datetime.datetime.now() DBsession.query(aws_model.WinXinAcount).filter_by(id=id).update({ "use_type": use_type, "name": name, "mail": mail, "secret": secret, "type": type, "use_name": use_name, "phone": phone, "data_update_time": now }) try: aws_model.DBsession.commit() except exc.SQLAlchemyError: aws_model.DBsession.rollback() abort('add_config_error') else: acc_obj = aws_model.WinXinAcount() res_acc = acc_obj.get_accunt return res_acc, 200, None
def rds_to_api(self): db_res_rds = DBsession.query(Rds).filter( Rds.data_status == True).order_by(Rds.id).all() for rds_ins in db_res_rds: cpu = rds_ins.rds_type.cpu memory = rds_ins.rds_type.memory rds_ins.cpu = int(cpu) rds_ins.memory = int(memory) rds_ins.aws_create_time = rds_ins.aws_create_time.strftime( "%Y-%m-%d %H:%M:%S") rds_ins.data_create_time = rds_ins.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") rds_ins.data_update_time = rds_ins.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return db_res_rds
def ec2_to_api(self, page_size, page_index): db_res_ec2 = DBsession.query(Ec2).filter( Ec2.data_status == True).order_by(Ec2.id).limit(page_size).offset( (page_index - 1) * page_size).all() for ec2_ins in db_res_ec2: cpu = ec2_ins.ec2_type.cpu memory = ec2_ins.ec2_type.memory ec2_ins.cpu_num = int(cpu) ec2_ins.memory_num = int(memory) ec2_ins.aws_create_time = ec2_ins.aws_create_time.strftime( "%Y-%m-%d %H:%M:%S") ec2_ins.data_create_time = ec2_ins.data_create_time.strftime( "%Y-%m-%d %H:%M:%S") ec2_ins.data_update_time = ec2_ins.data_update_time.strftime( "%Y-%m-%d %H:%M:%S") return db_res_ec2
def post(self): req_data = json.loads(json.dumps(request.form)) account = req_data["account"] secret = req_data["secret"] user = DBsession.query(aws_model.CmdbUser).filter( aws_model.CmdbUser.account == account and aws_model.CmdbUser.data_status == True).first() if not user: abort('cmdb_user_not_found') elif user.secret != secret: abort('cmdb_user_secret_error') else: res_data = [] res_token = {} self.payload["uid"] = user.id self.payload["authority"] = user.authority token = bytes.decode( jwt.encode(self.payload, app.config['SECRET'], algorithm='HS256')) res_token["access_token"] = token res_data.append(res_token) return res_data, 201, None