def __init__(self, adaptor_id, config, template=None): super().__init__() self.config = config if template and not isinstance(template, ToscaTemplate): raise AdaptorCritical("Template is not a valid TOSCAParser object") self.ID = adaptor_id self.tpl = template try: self.sp_data = utils.get_yaml_data(PATH_TO_POLICY) except FileNotFoundError: self.sp_data = {"services": {"_sample": {"scaledown": 0, "scaleup": 100}}} logger.info("ScalingPolicyAdaptor ready!")
def switchConfig(self, conf, state): self.conf = conf self.gameloop = get_yaml_data(conf)['gameloop'] self.buildTag() self.gameState = state
def _save_file(self, id_app, path): """ method called by the engine to dump the current template being treated to the files/templates directory, with as name the ID of the app. """ data = utils.get_yaml_data(path) utils.dump_order_yaml(data, "files/templates/{}.yaml".format(id_app))
# -*- coding: utf-8 -*- """ :author: T8840 :tag: Thinking is a good thing! :description: """ import mitmproxy.http import json import os, sys parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, parentdir) from utils import get_yaml_data data = get_yaml_data('./mock_response.yaml') path_resp_list = [j for i in data.values() for j in i] path_list = [i['path'] for i in path_resp_list[::2]] resp_list = [i['response'] for i in path_resp_list[1::2]] class MockResponse: def response(self, flow: mitmproxy.http.HTTPFlow): if flow.request.path in path_list: mock_response = json.dumps(resp_list[path_list.index( flow.request.path)], ensure_ascii=False) flow.response.content = bytes(mock_response.encode('utf8')) else: return
import re from mitmproxy import ( http, ctx, ) from urllib.parse import urlparse from collections import namedtuple import os, sys parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, parentdir) from utils import get_yaml_data, urlDe from log_collect.compare import Rabbit yaml_data = get_yaml_data('./allow.yaml') AllowRule = namedtuple('AllowRule', ['allow_path_rule', 'allow_host_rule']) allow_rule = AllowRule( yaml_data.get('allow').get('path'), yaml_data.get('allow').get('host')) save_type = ['save_file', 'save_mysql', 'save_rabbit'][0] class RecordHttpPost: def save_flow_to(self, content): if save_type == "save_file": record_dump_file = './record_post_contents' + '.txt' self.save_file = open(record_dump_file, 'a') self.save_file.write('%s \n' % (content))
:description: 除了添加在filter.yaml文件中需要忽略的后缀,其他所有的请求与响应都会被记录 """ import re from mitmproxy import ( http, ctx, ) import os, sys parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, parentdir) from utils import get_yaml_data yaml_data = get_yaml_data('./filter.yaml') def get_filter_rule(data): ignore = data.get('ignore') ignore_rule = ''.join([j for i in ignore for j in i.values() ]).replace('/', '').replace('*.', '|').lstrip('|') return ignore_rule class HTTPRecordAll: def __init__(self): self.record_dump_file = './record_all_file' + '.txt' self.save_file = open(self.record_dump_file, 'w') def done(self):
from flask import Flask import click from flask_cli import FlaskCLI from utils import * import pandas as pd app = Flask(__name__) FlaskCLI(app) WIN = sys.platform.startswith('win') if WIN: prefix = 'sqlite:///' else: prefix = 'sqlite:////' config_file = 'config.yaml' config = get_yaml_data(config_file) logfile = config['logfile'] dbname = config['dbname'] app.config['SQLALCHEMY_DATABASE_URI'] = prefix + os.path.join( app.root_path, dbname) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) class Price(db.Model): ts_code = db.Column(db.String(9), primary_key=True) trade_date = db.Column(db.String(8), primary_key=True) open = db.Column(db.Float) high = db.Column(db.Float) low = db.Column(db.Float)