def cancelacion(self, params): code = self.validate(params) if code == 0: db = Database(dbhost=Utils.get_secret("pg_host"), dbuser=Utils.get_secret("soapdbuser"), dbpass=Utils.get_secret("soapdbpass")) rows = db.find_msisdn(params["msisdn"]) if len(rows) < 1: code = 503 else: values = rows[0] if values["estado"] != "ALTA": code = 503 else: values["estado"] = "CANCELAR" code = db.update_telcel_trans(values) db.insert_telcel_hist(values) return code
def com_6(self, params): logger.info("Request COM_6 processing", extra={'props': {"raw": params, "app": config["name"], "label": config["name"]}}) code = self.validate(params) if code == 0: db = Database(dbhost=Utils.get_secret("pg_host"), dbuser=Utils.get_secret("soapdbuser"), dbpass=Utils.get_secret("soapdbpass")) rows = db.find_msisdn(params["msisdn"]) logger.info("Finding rows:"+str(len(rows)), extra={'props': {"raw": params, "app": config["name"], "label": config["name"]}}) if len(rows) < 1: code = 406 else: value = rows[0] code = value["msisdn"]+"|"+value["iccid"]+"|"+value["cveplan"]+"|"+value["cvetpoinst"]+"|"+value["estado"] if value["estado"] == "SUSPENDIDA": code = code + "|"+str(700) elif value["estado"] == "CANCELAR": code = code + "|" + str(800) return code
def connect_db(): try: pghost = Utils.get_secret("pg_host") pguser = Utils.get_secret("pg_user") pgpass = Utils.get_secret("pg_pass") conn = pg.connect(host=pghost, user=pguser, password=pgpass, port="5432", database="cementos") return conn except (Exception, pg.Error) as error: logger.error("Can't connect to postgres", extra={ 'error': { "raw": error, "app": config["name"], "label": config["name"] } }) return None
def alta(self, params): code = self.validate(params) if code == 0: if "iccid" not in params or len(params["iccid"]) != 19: code = 200 elif "cveplan" not in params or params["cveplan"] == "": code = 600 elif "cvetpoinst" not in params or params["cvetpoinst"] == "": code = 600 else: db = Database(dbhost=Utils.get_secret("pg_host"), dbuser=Utils.get_secret("soapdbuser"), dbpass=Utils.get_secret("soapdbpass")) rows = db.find_iccid(params["iccid"]) if len(rows) > 0: code = 501 else: id = db.insert_telcel_trans(params) if int(id) > 0: rec = db.select_telcel(id) code = db.insert_telcel_hist(rec) else: code = 401 return code
import json_logging import logging import sys json_logging.ENABLE_JSON_LOGGING = True json_logging.init() logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler(sys.stdout)) config = Utils.read_config("package.json") env_cfg = config[os.environ["environment"]] if env_cfg["secrets"]: mzone_user = Utils.get_secret("centinelaz_user") mzone_pass = Utils.get_secret("centinelaz_pass") mzone_secret = Utils.get_secret("mzone_secret") centinela_token = Utils.get_secret("centinela_token") pghost = Utils.get_secret("pg_host") pguser = Utils.get_secret("pg_user") pgpass = Utils.get_secret("pg_pass") else: mzone_user = env_cfg["mzone_user"] mzone_pass = env_cfg["mzone_pass"] mzone_secret = env_cfg["mzone_secret"] centinela_token = "" pghost = env_cfg["pg_host"] pguser = env_cfg["pg_user"] pgpass = env_cfg["pg_pass"]
json_logging.init() logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler(sys.stdout)) config = Utils.read_config("package.json") if os.environ is None or "environment" not in os.environ: env_cfg = config["dev"] else: env_cfg = config[os.environ["environment"]] url = env_cfg["API_URL"] rabbitmq = env_cfg["RABBITMQ_URL"] if env_cfg["secrets"]: mzone_user = Utils.get_secret("mzone_user") mzone_pass = Utils.get_secret("mzone_pass") mzone_secret = Utils.get_secret("mzone_secret") rabbit_user = Utils.get_secret("rabbitmq_user") rabbit_pass = Utils.get_secret("rabbitmq_passw") api_pass = Utils.get_secret("token_key") else: mzone_user = env_cfg["mzone_user"] mzone_pass = env_cfg["mzone_pass"] mzone_secret = env_cfg["mzone_secret"] rabbit_user = env_cfg["rabbitmq_user"] rabbit_pass = env_cfg["rabbitmq_passw"] api_pass = env_cfg["token_key"] def get_subscriptions(template, mz=None):
json_logging.init() logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler(sys.stdout)) config = Utils.read_config("package.json") env_cfg = config[os.environ["environment"]] url = env_cfg["API_URL"] rabbitmq = env_cfg["RABBITMQ_URL"] endpoint = env_cfg["ENDPOINT"] transmer_user = "" transmer_pass = "" if env_cfg["secrets"]: rabbit_user = Utils.get_secret("rabbitmq_user") rabbit_pass = Utils.get_secret("rabbitmq_passw") transmer_user = Utils.get_secret("transmer_user") transmer_pass = Utils.get_secret("transmer_pass") else: rabbit_user = env_cfg["rabbitmq_user"] rabbit_pass = env_cfg["rabbitmq_passw"] transmer = Transmer(transmer_user, transmer_pass, endpoint) def get_vehicle(unit_id): response = requests.get(url + "/api/vehicles?Unit_Id=" + unit_id) vehicles = response.json() if len(vehicles) > 0: return vehicles[0]
json_logging.ENABLE_JSON_LOGGING = True json_logging.init() logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler(sys.stdout)) config = Utils.read_config("package.json") env_cfg = config[os.environ["environment"]] url = env_cfg["API_URL"] rabbitmq = env_cfg["RABBITMQ_URL"] chep_url = "http://ws4.altotrack.com/WSPosiciones_Chep/WSPosiciones_Chep.svc?wsdl" if env_cfg["secrets"]: rabbit_user = Utils.get_secret("rabbitmq_user") rabbit_pass = Utils.get_secret("rabbitmq_passw") else: rabbit_user = env_cfg["rabbitmq_user"] rabbit_pass = env_cfg["rabbitmq_passw"] chep = Chep("", "", chep_url) def get_vehicle(unit_id): response = requests.get(url + "/api/vehicles?Unit_Id=" + unit_id) vehicles = response.json() if len(vehicles) > 0: return vehicles[0] else: logger.error("Vehicle not found",
import math app = Flask(__name__) app.config["DEBUG"] = True config = Utils.read_config("package.json") env_cfg = {} if os.environ is None or "environment" not in os.environ: env_cfg = config["dev"] else: env_cfg = config[os.environ["environment"]] UTC = int(env_cfg["UTC"]) if env_cfg["secrets"]: db_user = Utils.get_secret("tumsa_dbuser") db_pass = Utils.get_secret("tumsa_dbpass") else: db_user = env_cfg["dbuser"] db_pass = env_cfg["dbpass"] @app.route('/api/version', methods=['GET']) def version(): return config["version"] @app.route('/api/viajes', methods=['POST']) def viajes(): m = MZone()