Commit fcfdfa4f authored by Ivan Tyagov's avatar Ivan Tyagov

Use username / password to authenticate against ERP5 backend.

parent 853ba03f
...@@ -23,11 +23,15 @@ a('--ip', help='The IP address on which the OPCUA Server runs', default="127.0.0 ...@@ -23,11 +23,15 @@ a('--ip', help='The IP address on which the OPCUA Server runs', default="127.0.0
a('--port', help='The port on which the OPCUA Server runs', default="4840") a('--port', help='The port on which the OPCUA Server runs', default="4840")
a('--xml', help='Path of XML to configure Server. See asyncua doc for more details.', default=None) a('--xml', help='Path of XML to configure Server. See asyncua doc for more details.', default=None)
a('--erp5-url', help='URL of ERP5 instance to which data shall be send.', default=None) a('--erp5-url', help='URL of ERP5 instance to which data shall be send.', default=None)
a('--erp5-username', help='Username of ERP5 instance to which data shall be send.', default=None)
a('--erp5-password', help='Password of ERP5 instance to which data shall be send.', default=None)
args = parser.parse_args() args = parser.parse_args()
ip = args.ip ip = args.ip
port = args.port port = args.port
xml = args.xml xml = args.xml
erp5_url = args.erp5_url erp5_url = args.erp5_url
erp5_username = args.erp5_username
erp5_password = args.erp5_password
ERP5_REQUEST_API = "ERP5Site_handleOPCUARequest" ERP5_REQUEST_API = "ERP5Site_handleOPCUARequest"
@dataclass(frozen=True) @dataclass(frozen=True)
...@@ -42,6 +46,7 @@ class ERP5Handler(asyncua.common.subscription.SubHandler): ...@@ -42,6 +46,7 @@ class ERP5Handler(asyncua.common.subscription.SubHandler):
def call(self, http_method = "POST", **data): def call(self, http_method = "POST", **data):
params = urllib.parse.quote_plus(json.dumps({k: str(v) for k, v in data.items()})) params = urllib.parse.quote_plus(json.dumps({k: str(v) for k, v in data.items()}))
self.session.auth = (erp5_username, erp5_password)
if http_method == "POST": if http_method == "POST":
self.session.post(f"{self.uri}?data={params}") self.session.post(f"{self.uri}?data={params}")
elif http_method == "GET": elif http_method == "GET":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment