Exemplo n.º 1
0
from DetailedHTTPException import DetailedHTTPException, error_handler
from Templates import ServiceRegistryHandler, Consent_form_Out, Sequences
from flask import request, Blueprint, current_app
from flask_restful import Resource, Api
from helpers import AccountManagerHandler, Helpers
from op_tasks import CR_installer
from requests import post
logger = logging.getLogger("sequence")
debug_log = logging.getLogger("debug")

api_CR_blueprint = Blueprint("api_CR_blueprint", __name__)
api = Api()
api.init_app(api_CR_blueprint)

sq = Sequences("Operator_Components Mgmnt", {})
Operator_public_key = {}
class ConsentFormHandler(Resource):
    def __init__(self):
        super(ConsentFormHandler, self).__init__()
        self.am_url = current_app.config["ACCOUNT_MANAGEMENT_URL"]
        self.am_user = current_app.config["ACCOUNT_MANAGEMENT_USER"]
        self.am_password = current_app.config["ACCOUNT_MANAGEMENT_PASSWORD"]
        self.timeout = current_app.config["TIMEOUT"]
        self.debug_mode = current_app.config["DEBUG_MODE"]
        try:
            self.AM = AccountManagerHandler(self.am_url, self.am_user, self.am_password, self.timeout)
        except Exception as e:
            debug_log.warn("Initialization of AccountManager failed. We will crash later but note it here.\n{}".format(repr(e)))
        self.SH = ServiceRegistryHandler(current_app.config["SERVICE_REGISTRY_SEARCH_DOMAIN"], current_app.config["SERVICE_REGISTRY_SEARCH_ENDPOINT"])
        self.getService = self.SH.getService
Exemplo n.º 2
0
# -*- coding: utf-8 -*-
from json import loads

from requests import get, post

from Templates import Service_ID_A, Service_ID_B, Sequences

sq = Sequences("UI", {})

operator_url = "http://localhost:5000/"

slr_flow1 = get("http://127.0.0.1:5000/api/1.2/slr/account/2/service/1")
print(slr_flow1.url, slr_flow1.reason, slr_flow1.status_code, slr_flow1.text)
slr_flow2 = get("http://127.0.0.1:5000/api/1.2/slr/account/2/service/2")
print(slr_flow2.url, slr_flow2.reason, slr_flow2.status_code, slr_flow2.text)

sq.send_to("Operator_SLR", "Get consent form.")
# This format needs to be specified, even if done with url params instead.
ids = {"sink": Service_ID_B, "source": Service_ID_A}

req = get(operator_url +
          "api/1.2/cr/consent_form/account/2?sink={}&source={}".format(
              Service_ID_B, Service_ID_A))

print(req.url, req.reason, req.status_code, req.text)
js = loads(req.text)

sq.send_to("Operator_SLR", "Posting filled ConsentForm")
#js.update(sq.sequence)
req = post(operator_url + "api/1.2/cr/consent_form/account/2", json=js)
import json
Exemplo n.º 3
0
from DetailedHTTPException import error_handler
from flask import Blueprint, request, current_app
from flask_restful import Resource, Api
from helpers import Helpers, Token_tool
import logging
from jwcrypto import jwk, jwt, jws
from json import loads, dumps
from Templates import Sequences
from signed_requests.json_builder import pop_handler
debug_log = logging.getLogger("debug")
logger = logging.getLogger("sequence")
api_Source_blueprint = Blueprint("api_Source_blueprint", __name__)
api = Api()
api.init_app(api_Source_blueprint)

sq = Sequences("Service_Components Mgmnt (Source)", {})
# import xmltodict
# @api.representation('application/xml')
# def output_xml(data, code, headers=None):
#     if isinstance(data, dict):
#         xm = {"response": data}
#         resp = make_response(xmltodict.unparse(xm, pretty=True), code)
#         resp.headers.extend(headers)
#         return resp


class Status(Resource):
    @error_handler
    def get(self):
        status = {"status": "running", "service_mode": "Source"}
        return status
Exemplo n.º 4
0

User is redirected to service login with the code.
USER: --> GET /login?code=somecode

User logins and agrees the linking. Surrogate ID is generated and sent to OPERATOR.
SERVICE: --> POST /register?surrogate=SURROGRATEID1&code=somecode
<-- :OPERATOR 200 OK
Using the code we link surrogate id to MyData Account and service confirming the link.

'''

logger = logging.getLogger("sequence")
debug_log = logging.getLogger("debug")

sq = Sequences("Service_Components Mgmnt", {})


def timeme(method):
    def wrapper(*args, **kw):
        startTime = int(round(time.time() * 1000))
        result = method(*args, **kw)
        endTime = int(round(time.time() * 1000))

        debug_log("{}{}".format(endTime - startTime, 'ms'))
        return result

    return wrapper


class Install_CR(Resource):
Exemplo n.º 5
0
from flask import Blueprint, current_app, request
from helpers import Helpers
import requests
from json import dumps, loads
from DetailedHTTPException import error_handler
from flask_restful import Resource, Api
import logging
from jwcrypto import jwk
from Templates import Sequences
debug_log = logging.getLogger("debug")
logger = logging.getLogger("sequence")
api_Sink_blueprint = Blueprint("api_Sink_blueprint", __name__)
api = Api()
api.init_app(api_Sink_blueprint)

sq = Sequences("Service_Components Mgmnt (Sink)", {})
# import xmltodict
# @api.representation('application/xml')
# def output_xml(data, code, headers=None):
#     if isinstance(data, dict):
#         xm = {"response": data}
#         resp = make_response(xmltodict.unparse(xm, pretty=True), code)
#         resp.headers.extend(headers)
#         return resp


class Status(Resource):
    @error_handler
    def get(self):
        status = {"status": "running", "service_mode": "Sink"}
        return status