Esempio n. 1
0
def get_AuthToken(cr_id, operator_url, app_config):
    print(operator_url, cr_id)
    helpers = Helpers(app_config)
    print(cr_id)
    token = get("{}/api/1.3/cr/auth_token/{}".format(
        operator_url, cr_id))  # TODO Get api path from some config?
    print(token.url, token.reason, token.status_code, token.text)
    store_dict = {cr_id: dumps(loads(token.text.encode()))}
    helpers.storeToken(store_dict)

    cr_csr = helpers.get_cr_json(cr_id)
    cr_tool = CR_tool()
    cr_tool.cr = cr_csr

    user_id = cr_tool.get_surrogate_id()
    rs_id = cr_tool.get_rs_id()

    #req = get("http://service_components:7000/api/1.3/sink_flow/init")
    #print(req.url, req.status_code, req.content)

    data = {
        "cr_id": cr_id,
        "user_id": user_id,
        "rs_id": urllib.quote_plus(rs_id)
    }
    print(dumps(data, indent=2))
Esempio n. 2
0
class DebugDataFlow(Resource):
    def __init__(self):
        super(DebugDataFlow, self).__init__()
        self.service_url = current_app.config["SERVICE_URL"]
        self.own_url = current_app.config["SINK_URL"]
        self.operator_url = current_app.config["OPERATOR_URL"]
        self.helpers = Helpers(current_app.config)

    @error_handler
    @api_logging
    def get(self, rs_id):
        debug_log.info("Got rs_id {} to DebugDataFlow endpoint".format(rs_id))
        records = self.helpers.query_db_multiple(
            "select rs_id, cr_id, slr_id, surrogate_id from cr_storage", ())
        #rs_id =
        debug_log.info(
            "DB query resulted in following results:\n{}".format(records))
        for record in records:
            rs_id = record[0]
            cr_id = record[1]
            tool = CR_tool()
            tool.cr = self.helpers.get_cr_json(cr_id)
            role = tool.get_role()
            debug_log.info("Found role {}".format(role))
            if role == "Sink":
                if record[0] == rs_id:
                    surrogate_id = record[3]
                    payload = {
                        "user_id": surrogate_id,
                        "cr_id": cr_id,
                        "rs_id": urllib.quote_plus(rs_id)
                    }
                    # TODO get the url from, config
                    debug_log.info(dumps(payload, indent=2))
                    req = requests.post(self.own_url + "/api/1.3/sink_flow/dc",
                                        json=payload)
                    return req.content