komatsu_forwarder_main.py 1.37 KB
Newer Older
lenekaethe's avatar
lenekaethe committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from s3i import IdentityProvider, Directory, Broker, GetValueRequest, ServiceReply, ServiceRequest, TokenType
import uuid
import json
import jwt
import base64
import time
import datetime
import requests
import threading
import pykka

import sys, os
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
import config
import importlib
configData = importlib.import_module("config."+"komatsu_forwarder")
import digitalTwin
from Komatsu_Forwarder import ForwarderMessageDistributer

print("Hello I'm the Komatsu Forwarder. I can forward if you send me a forwarding job.")

def callback(ch, method, properties, body):
    msgDis_ref.tell(body)

if __name__ == "__main__":
    idp = IdentityProvider(grant_type='client_credentials', identity_provider_url="https://idp.s3i.vswf.dev/",
                           realm='KWH', client_id=configData.DATA["thingId"], client_secret=configData.CLIENT_SECRET)
    access_token = idp.get_token(TokenType.ACCESS_TOKEN)
    s3i_broker = Broker(
            auth_form='Username/Password', username=" ", password=access_token, host="rabbitmq.s3i.vswf.dev")

    msgDis_ref = ForwarderMessageDistributer.start(idp)
    s3i_broker.receive("s3ibs://"+configData.DATA["thingId"], callback) #TODO get own Endpoint with Dir