diff --git a/CHANGELOG.md b/CHANGELOG.md index 01f93e6..067f143 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,25 @@ # Changelog All notable changes to this project will be documented in this file. +## Release 2.2.0 + +### New features +- Basic authentication setup +- New function 'sendRequest' +- Check if persistent data to load provides all relevant parameters. Otherwise add default values + +### Improvements +- 'sendInternalRequest' returns now the HTTP response +- FlowConfig handling +- Minor docu improvements + +### Bugfix +- Wrong instance handling within FlowConfig +- FlowConfig priority was not instance specific +- Legacy bindings of ValueDisplay elements and FileUpload feature within UI did not work if deployed with VS Code AppSpace SDK +- UI differs if deployed via Appstudio or VS Code AppSpace SDK +- Fullscreen icon of iFrame was visible + ## Release 2.1.0 ### New features diff --git a/CSK_Module_MultiHTTPClient/pages/pages/CSK_Module_MultiHTTPClient/CSK_Module_MultiHTTPClient.css b/CSK_Module_MultiHTTPClient/pages/pages/CSK_Module_MultiHTTPClient/CSK_Module_MultiHTTPClient.css index 58b571e..4c8b347 100644 --- a/CSK_Module_MultiHTTPClient/pages/pages/CSK_Module_MultiHTTPClient/CSK_Module_MultiHTTPClient.css +++ b/CSK_Module_MultiHTTPClient/pages/pages/CSK_Module_MultiHTTPClient/CSK_Module_MultiHTTPClient.css @@ -104,5 +104,5 @@ .myCustomButton_CSK_Module_MultiHTTPClient { border-radius: 30px; - padding-right: 0px; + padding: 11px; } \ No newline at end of file diff --git a/CSK_Module_MultiHTTPClient/pages/pages/CSK_Module_MultiHTTPClient/CSK_Module_MultiHTTPClient.html b/CSK_Module_MultiHTTPClient/pages/pages/CSK_Module_MultiHTTPClient/CSK_Module_MultiHTTPClient.html index 4d5a266..724e17e 100644 --- a/CSK_Module_MultiHTTPClient/pages/pages/CSK_Module_MultiHTTPClient/CSK_Module_MultiHTTPClient.html +++ b/CSK_Module_MultiHTTPClient/pages/pages/CSK_Module_MultiHTTPClient/CSK_Module_MultiHTTPClient.html @@ -7,13 +7,12 @@ - - +

+ HTTP Client +

- - + +
@@ -60,8 +59,9 @@ style="justify-content: center; align-items: center"> + type="outline" title="Add instance"> + + @@ -69,9 +69,10 @@ + type="outline" + title="Reset instances to one single instance. New setup needs to be saved and restart app to clear old threads."> + + + type="outline" + title="Load configured parameters from CSK_PersistentData module."> + + + type="outline" + title="Save current configured parameters of this module within CSK_PersistentData module."> + + + value="Interface" + title="Physical Ethernet interface to be used by the client"> + value="Client active" + title="Activate HTTP client instance"> + value="Verbose mode" + title="Check to enable HTTP client verbose mode"> @@ -350,12 +356,115 @@
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + value="Client Authentication" + title="Check to enable client authentication"> + crown-path="success" + converter="(value)=>{console.log(`event finished ${JSON.stringify(value)}`); return typeof value == 'boolean' ? value : value.success;}"> - - + crown-event="CSK_MultiHTTPClient/OnNewStatusClientActivated"> + @@ -470,13 +579,13 @@ event="finished" crown-function="CSK_MultiHTTPClient/setClientCertificateFile" protocol="crownMSGPACK" - crown-path="success"> + crown-path="success" + converter="(value)=>{console.log(`event finished ${JSON.stringify(value)}`); return typeof value == 'boolean' ? value : value.success;}"> - - + crown-event="CSK_MultiHTTPClient/OnNewStatusClientActivated"> + @@ -524,13 +633,13 @@ event="finished" crown-function="CSK_MultiHTTPClient/setClientCertificateKeyFile" protocol="crownMSGPACK" - crown-path="success"> + crown-path="success" + converter="(value)=>{console.log(`event finished ${JSON.stringify(value)}`); return typeof value == 'boolean' ? value : value.success;}"> - - + crown-event="CSK_MultiHTTPClient/OnNewStatusClientActivated"> + @@ -584,7 +693,7 @@ style="align-items: stretch"> + value="Proxy" title="Check to enable proxy"> + value="Hostname verification" + title="Check to enable hostname verification"> + value="Peer verification" + title="Check to enable peer verification"> + + + title="Add header"> + + + title="Remove header"> + + + type="primary" + title="Add request if no request is selected or Edit the selected request"> + + + type="outline" title="Remove request"> + + { + const shadowToggle = userItem.shadowRoot + const finalToggleSW = shadowToggle?.querySelector('div') + finalToggleSW?.classList.add('hasIcon') + }); + if (theme == 'CSK_Style'){ var headerToolbar = `.sopasjs-ui-header-toolbar-wrapper { background-color: #FFFFFF; }` var uiHeader = `.sopasjs-ui-header>.app-logo { margin-right:0px; }` diff --git a/CSK_Module_MultiHTTPClient/pages/src/index.ts b/CSK_Module_MultiHTTPClient/pages/src/index.ts index b01cd60..9806bd8 100644 --- a/CSK_Module_MultiHTTPClient/pages/src/index.ts +++ b/CSK_Module_MultiHTTPClient/pages/src/index.ts @@ -12,6 +12,10 @@ document.addEventListener('sopasjs-ready', () => { page_Setup.remove(); setTimeout(() => { + const element = document.querySelector("div.sjs-wrapper > div > div.sjs-fullscreen-toggle") + if(element) { + element.parentElement.removeChild(element) + } document.title = 'CSK_Module_MultiHTTPClient' }, 500); }) \ No newline at end of file diff --git a/CSK_Module_MultiHTTPClient/project.mf.xml b/CSK_Module_MultiHTTPClient/project.mf.xml index a6f2abf..fd5488a 100644 --- a/CSK_Module_MultiHTTPClient/project.mf.xml +++ b/CSK_Module_MultiHTTPClient/project.mf.xml @@ -275,6 +275,14 @@ INFO: Other modules can check via "Script.isServedAsEvent" if event of sepecific Notify if module can be used on device. + + Notify status if HTTP basic authentication should be used. + + + + Notify user for basic authentication. + + Function to set the name of the parameters if saved/loaded via the CSK_PersistentData module. @@ -500,6 +508,31 @@ IMPORTANT: As instances start their own threads, the module needs to be restarte Function to reset main configuration of module. + + Function to set status to use HTTP basic authentication. + + + + Function to set user for HTTP basic authentication. + + + + Function to set password for user of HTTP basic authentication. + + + + Example of dynamically served function to send a request of a specific instance. + +NUM will be replaced by the number of instance (e.g. "sendRequest1"). + +INFO: Other modules can check via "Script.isServedAsFunction" if function of sepecific instance exists. + +Needs then to be called via "Script.callFunction". + + + + + + + + @@ -530,7 +563,7 @@ IMPORTANT: As instances start their own threads, the module needs to be restarte SICK AG - 2.1.0 + 2.2.0 low false false diff --git a/CSK_Module_MultiHTTPClient/scripts/CSK_Module_MultiHTTPClient.lua b/CSK_Module_MultiHTTPClient/scripts/CSK_Module_MultiHTTPClient.lua index 7c2a9c3..00abc97 100644 --- a/CSK_Module_MultiHTTPClient/scripts/CSK_Module_MultiHTTPClient.lua +++ b/CSK_Module_MultiHTTPClient/scripts/CSK_Module_MultiHTTPClient.lua @@ -50,10 +50,9 @@ local multiHTTPClient_Instances = {} -- Handle all instances local multiHTTPClientController = require('Communication/MultiHTTPClient/MultiHTTPClient_Controller') if _G.availableAPIs.default and _G.availableAPIs.specific then - local setInstanceHandle = require('Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_FlowConfig') + require('Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_FlowConfig') table.insert(multiHTTPClient_Instances, multiHTTPClient_Model.create(1)) -- Create at least 1 instance multiHTTPClientController.setMultiHTTPClient_Instances_Handle(multiHTTPClient_Instances) -- share handle of instances - setInstanceHandle(multiHTTPClient_Instances) else _G.logger:warning("CSK_MultiHTTPClient: Relevant CROWN(s) not available on device. Module is not supported...") end diff --git a/CSK_Module_MultiHTTPClient/scripts/CSK_MultiHTTPClient_Processing.lua b/CSK_Module_MultiHTTPClient/scripts/CSK_MultiHTTPClient_Processing.lua index 5d7a78d..299e887 100644 --- a/CSK_Module_MultiHTTPClient/scripts/CSK_MultiHTTPClient_Processing.lua +++ b/CSK_Module_MultiHTTPClient/scripts/CSK_MultiHTTPClient_Processing.lua @@ -32,6 +32,10 @@ processingParams.clientActivated = scriptParams:get('clientActivated') processingParams.hostnameVerification = scriptParams:get('hostnameVerification') processingParams.peerVerification = scriptParams:get('peerVerification') processingParams.cookieStore = scriptParams:get('cookieStore') +processingParams.basicAuthentication = scriptParams:get('basicAuthentication') +processingParams.basicAuthenticationUser = scriptParams:get('basicAuthenticationUser') +processingParams.basicAuthenticationPassword = scriptParams:get('basicAuthenticationPassword') + processingParams.clientAuthentication = scriptParams:get('clientAuthentication') processingParams.caBundleFileName = scriptParams:get('caBundleFileName') processingParams.clientCertificateType = scriptParams:get('clientCertificateType') @@ -119,6 +123,11 @@ local function updateClient() clientObject = HTTPClient.create() clientObject:setVerbose(processingParams.verboseMode) + + if processingParams.basicAuthentication then + clientObject:setAuthCredentials(processingParams.basicAuthenticationUser, processingParams.basicAuthenticationPassword) + end + if processingParams.clientAuthentication then if File.exists(processingParams.caBundleFileName) then clientObject:setCABundle(processingParams.caBundleFileName) @@ -179,12 +188,14 @@ end --- Function to execute a request ---@param tempRequestActive bool Status if it is just a temporarly configured request or a preconfigured one ----@param showResponse bool Status if repsonse should be notified as event (e.g. to show it on UI) ----@param eventName string Name of event to notify the response -local function sendRequest(tempRequestActive, showResponse, eventName) +---@param showResponse bool Status if response should be notified as event (e.g. to show it on UI) +---@param eventName string? Optional name of event to notify the response +---@return string response Response of HTTP request +local function sendInternalRequest(tempRequestActive, showResponse, eventName) local timerQueueSize = 0 local eventQueueSize = 0 + local jsonResponse = {} if tempRequestActive then updateInternalRequest(processingParams) @@ -200,37 +211,50 @@ local function sendRequest(tempRequestActive, showResponse, eventName) if timerQueueSize >= processingParams.queueSize-1 or eventQueueSize >= processingParams.queueSize-1 then _G.logger:warning(nameOfModule .. ": Internal request queue too high '(Timer:" .. tostring(timerQueueSize) .. '/Events:' .. tostring(eventQueueSize) .. ")'. Will skip new requests...") + return '' else local tic = DateTime.getTimestamp() + local response = clientObject:execute(request) local procTime = DateTime.getTimestamp() - tic local success = HTTPClient.Response.getSuccess(response) + jsonResponse.Success = tostring(success) _G.logger:fine(nameOfModule .. ": Response success = " .. tostring(success)) -- Check response local responseMessage = 'After ' .. tostring(procTime) .. 'ms --> ' .. 'Request success = ' .. tostring(success) .. '\n' - responseMessage = responseMessage .. 'Code: ' .. HTTPClient.Response.getStatusCode(response) .. '\n' + local statusCode = HTTPClient.Response.getStatusCode(response) + responseMessage = responseMessage .. 'Code: ' .. statusCode .. '\n' + jsonResponse.StatusCode = statusCode if success then -- Check if extended information of the response should be shown if processingParams.extendedResponse then - responseMessage = responseMessage .. 'Request content type: ' .. HTTPClient.Response.getContentType(response) .. '\n' + local contentType = HTTPClient.Response.getContentType(response) + responseMessage = responseMessage .. 'Request content type: ' .. contentType .. '\n' + jsonResponse.ContentType = contentType local tempKeys = HTTPClient.Response.getHeaderKeys(response) + jsonResponse.Headers = {} for _, headerKeys in pairs(tempKeys) do + jsonResponse.Headers[headerKeys] = {} local suc, tempValues = HTTPClient.Response.getHeaderValues(response, headerKeys) for _, headerValue in pairs(tempValues) do responseMessage = responseMessage .. 'Header-key: ' .. headerKeys .. ' = ' .. headerValue .. '\n' + table.insert(jsonResponse.Headers[headerKeys], headerValue) end end end + jsonResponse.Response = HTTPClient.Response.getContent(response) responseMessage = responseMessage .. helperFuncs.jsonLine2Table(HTTPClient.Response.getContent(response)) .. '\n' else local error = HTTPClient.Response.getError(response) local errorDetail = HTTPClient.Response.getErrorDetail(response) + jsonResponse.Error = error + jsonResponse.ErrorDetail = errorDetail responseMessage = responseMessage .. 'Error = ' .. error .. '\n' .. 'Error details = ' .. errorDetail .. '\n' end if eventName then @@ -244,8 +268,27 @@ local function sendRequest(tempRequestActive, showResponse, eventName) Script.notifyEvent("MultiHTTPClient_OnNewValueToForward" .. multiHTTPClientInstanceNumberString, "MultiHTTPClient_OnNewResponseMessage", responseMessage) end end + return json.encode(jsonResponse) + end +end + +local function sendRequest(mode, endpoint, port, header, body, contentType) + processingParams.extendedResponse = true + processingParams.requestMode = mode + processingParams.requestEndpoint = endpoint + processingParams.requestPort = port + + if body then + processingParams.requestContent = body + else + processingParams.requestContent = '' end + + local response = sendInternalRequest(true, false) + + return response end +Script.serveFunction('CSK_MultiHTTPClient.sendRequest' .. multiHTTPClientInstanceNumberString, sendRequest, 'string, string, int, string:?, string:?, string:?', 'string') --- Function to set timer if request should be executed periodically ---@param requestName string Name of preconfigured request @@ -260,9 +303,9 @@ local function setTimer(requestName) if processingParams.clientActivated then setSpecificRequest(requestName) if selectedRequest == requestName then - sendRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) + sendInternalRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) else - sendRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) + sendInternalRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) end end end @@ -306,9 +349,9 @@ local function setRegisteredEvent(requestName) end setSpecificRequest(requestName) if selectedRequest == requestName then - sendRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) + sendInternalRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) else - sendRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) + sendInternalRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName) end end end @@ -501,7 +544,7 @@ local function handleOnNewProcessingParameter(multiHTTPClientNo, parameter, valu elseif parameter == 'sendRequest' then if processingParams.clientActivated then - sendRequest(true, true) + sendInternalRequest(true, true) end elseif parameter == 'headerUpdate' then diff --git a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_FlowConfig.lua b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_FlowConfig.lua index f3a0f71..daa738d 100644 --- a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_FlowConfig.lua +++ b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_FlowConfig.lua @@ -5,26 +5,10 @@ require('Communication.MultiHTTPClient.FlowConfig.MultiHTTPClient_SendRequest') --- Reference to the multiHTTPClient_Instances handle -local multiHTTPClient_Instances - --- Function to react if FlowConfig was updated local function handleOnClearOldFlow() if _G.availableAPIs.default and _G.availableAPIs.specific then - for i = 1, # multiHTTPClient_Instances do - if multiHTTPClient_Instances[i].parameters.flowConfigPriority then - CSK_MultiHTTPClient.clearFlowConfigRelevantConfiguration() - break - end - end + CSK_MultiHTTPClient.clearFlowConfigRelevantConfiguration() end end Script.register('CSK_FlowConfig.OnClearOldFlow', handleOnClearOldFlow) - ---- Function to get access to the multiHTTPClient_Instances ----@param handle handle Handle of multiHTTPClient_Instances object -local function setMultiHTTPClient_Instances_Handle(handle) - multiHTTPClient_Instances = handle -end - -return setMultiHTTPClient_Instances_Handle \ No newline at end of file diff --git a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_SendRequest.lua b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_SendRequest.lua index 66bf6b8..1871c66 100644 --- a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_SendRequest.lua +++ b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_SendRequest.lua @@ -43,13 +43,13 @@ local function create(instance, requestName, mode, protocol, endpoint, port) local fullInstanceName = tostring(instance) .. tostring(requestName) -- Check if same instance is already configured - if instance < 1 or nil ~= instanceTable[fullInstanceName] then + if instanceTable[fullInstanceName] ~= nil then _G.logger:warning(nameOfModule .. ': Instance invalid or already in use, please choose another one') return nil else -- Otherwise create handle and store the restriced resource local handle = Container.create() - instanceTable[instance] = instance + instanceTable[fullInstanceName] = fullInstanceName Container.add(handle, 'Instance', instance) Container.add(handle, 'RequestName', requestName) Container.add(handle, 'Mode', mode) diff --git a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Controller.lua b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Controller.lua index 38a7b8e..6c80d89 100644 --- a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Controller.lua +++ b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Controller.lua @@ -28,7 +28,7 @@ local json = require('Communication/MultiHTTPClient/helper/Json') ---------------------------------------------------------------- local function emptyFunction() end -Script.serveFunction("CSK_MultiHTTPClient.processInstanceNUM", emptyFunction) +Script.serveFunction("CSK_MultiHTTPClient.sendRequestNUM", emptyFunction) Script.serveEvent('CSK_MultiHTTPClient.OnNewResponseNUM', 'MultiHTTPClient_OnNewResponseNUM') Script.serveEvent("CSK_MultiHTTPClient.OnNewResponseNUM_NAME", "MultiHTTPClient_OnNewResponseNUM_NAME") @@ -42,6 +42,10 @@ Script.serveEvent('CSK_MultiHTTPClient.OnNewStatusModuleVersion', 'MultiHTTPClie Script.serveEvent('CSK_MultiHTTPClient.OnNewStatusCSKStyle', 'MultiHTTPClient_OnNewStatusCSKStyle') Script.serveEvent('CSK_MultiHTTPClient.OnNewStatusModuleIsActive', 'MultiHTTPClient_OnNewStatusModuleIsActive') Script.serveEvent('CSK_MultiHTTPClient.OnNewStatusClientActivated', 'MultiHTTPClient_OnNewStatusClientActivated') + +Script.serveEvent('CSK_MultiHTTPClient.OnNewStatusBasicAuthentication', 'MultiHTTPClient_OnNewStatusBasicAuthentication') +Script.serveEvent('CSK_MultiHTTPClient.OnNewStatusBasicAuthenticationUser', 'MultiHTTPClient_OnNewStatusBasicAuthenticationUser') + Script.serveEvent('CSK_MultiHTTPClient.OnNewStatusClientAuthentication', 'MultiHTTPClient_OnNewStatusClientAuthentication') Script.serveEvent('CSK_MultiHTTPClient.OnNewClientCertificateType', 'MultiHTTPClient_OnNewClientCertificateType') @@ -296,6 +300,9 @@ local function handleOnExpiredTmrMultiHTTPClient() Script.notifyEvent('MultiHTTPClient_OnNewStatusClientActivated', multiHTTPClient_Instances[selectedInstance].parameters.clientActivated) Script.notifyEvent('MultiHTTPClient_OnNewStatusClientAuthentication', multiHTTPClient_Instances[selectedInstance].parameters.clientAuthentication) + Script.notifyEvent('MultiHTTPClient_OnNewStatusBasicAuthentication', multiHTTPClient_Instances[selectedInstance].parameters.basicAuthentication) + Script.notifyEvent('MultiHTTPClient_OnNewStatusBasicAuthenticationUser', multiHTTPClient_Instances[selectedInstance].parameters.basicAuthenticationUser) + Script.notifyEvent('MultiHTTPClient_OnNewClientCertificateType', multiHTTPClient_Instances[selectedInstance].parameters.clientCertificateType) Script.notifyEvent('MultiHTTPClient_OnNewClientCertificateKeyType', multiHTTPClient_Instances[selectedInstance].parameters.clientCertificateKeyType) Script.notifyEvent('MultiHTTPClient_OnNewCookieStore', multiHTTPClient_Instances[selectedInstance].parameters.cookieStore) @@ -411,10 +418,44 @@ local function setPeerVerification(state) end Script.serveFunction('CSK_MultiHTTPClient.setPeerVerification', setPeerVerification) +local function setBasicAuthentication(status) + if multiHTTPClient_Instances[selectedInstance].parameters.clientActivated == false then + _G.logger:fine(nameOfModule .. ": Set 'basicAuthentication' of instance" .. tostring(selectedInstance) .. ' = ' .. tostring(status)) + multiHTTPClient_Instances[selectedInstance].parameters.basicAuthentication = status + Script.notifyEvent('MultiHTTPClient_OnNewStatusBasicAuthentication', status) + Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'basicAuthentication', status) + else + _G.logger:fine(nameOfModule .. ": Client currently active. No setup possible.") + end +end +Script.serveFunction('CSK_MultiHTTPClient.setBasicAuthentication', setBasicAuthentication) + +local function setBasicAuthenticationUser(user) + if multiHTTPClient_Instances[selectedInstance].parameters.clientActivated == false then + _G.logger:fine(nameOfModule .. ": Set 'basicAuthenticationUser' of instance" .. tostring(selectedInstance) .. ' = ' .. tostring(user)) + multiHTTPClient_Instances[selectedInstance].parameters.basicAuthenticationUser = user + Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'basicAuthenticationUser', user) + else + _G.logger:fine(nameOfModule .. ": Client currently active. No setup possible.") + end +end +Script.serveFunction('CSK_MultiHTTPClient.setBasicAuthenticationUser', setBasicAuthenticationUser) + +local function setBasicAuthenticationPassword(password) + if multiHTTPClient_Instances[selectedInstance].parameters.clientActivated == false then + _G.logger:fine(nameOfModule .. ": Set 'basicAuthenticationPassword' of instance" .. tostring(selectedInstance)) + multiHTTPClient_Instances[selectedInstance].parameters.basicAuthenticationPassword = password + Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'basicAuthenticationPassword', password) + else + _G.logger:fine(nameOfModule .. ": Client currently active. No setup possible.") + end +end +Script.serveFunction('CSK_MultiHTTPClient.setBasicAuthenticationPassword', setBasicAuthenticationPassword) + local function setClientAuthentication(state) if multiHTTPClient_Instances[selectedInstance].parameters.clientActivated == false then _G.logger:fine(nameOfModule .. ": Set 'clientAuthentication' of instance" .. tostring(selectedInstance) .. ' = ' .. tostring(state)) - multiHTTPClient_Instances[selectedInstance].parameters.authenticationEnabled = state + multiHTTPClient_Instances[selectedInstance].parameters.clientAuthentication = state Script.notifyEvent('MultiHTTPClient_OnNewStatusClientAuthentication', state) Script.notifyEvent("MultiHTTPClient_OnNewProcessingParameter", selectedInstance, 'clientAuthentication', state) else @@ -918,9 +959,11 @@ Script.serveFunction('CSK_MultiHTTPClient.getStatusModuleActive', getStatusModul local function clearFlowConfigRelevantConfiguration() for i = 1, #multiHTTPClient_Instances do - for key, value in pairs(multiHTTPClient_Instances[i].parameters.requests) do - setSelectedRequest(key) - removeRequest() + if multiHTTPClient_Instances[i].parameters.flowConfigPriority then + for key, value in pairs(multiHTTPClient_Instances[i].parameters.requests) do + setSelectedRequest(key) + removeRequest() + end end end end @@ -972,6 +1015,8 @@ local function loadParameters() _G.logger:info(nameOfModule .. ": Loaded parameters for multiHTTPClientObject " .. tostring(selectedInstance) .. " from CSK_PersistentData module.") multiHTTPClient_Instances[selectedInstance].parameters = helperFuncs.convertContainer2Table(data) + multiHTTPClient_Instances[selectedInstance].parameters = helperFuncs.checkParameters(multiHTTPClient_Instances[selectedInstance].parameters, helperFuncs.defaultParameters.getParameters()) + -- If something needs to be configured/activated with new loaded data Script.notifyEvent('MultiHTTPClient_OnNewProcessingParameter', selectedInstance, 'fullSetup', data) --announceExternalEventsAndFunctions() -- future usage diff --git a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Model.lua b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Model.lua index ff248e8..aed6a6c 100644 --- a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Model.lua +++ b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Model.lua @@ -77,45 +77,12 @@ function multiHTTPClient.create(multiHTTPClientInstanceNo) -- Parameters to be saved permanently if wanted self.parameters = {} - self.parameters.flowConfigPriority = CSK_FlowConfig ~= nil or false -- Status if FlowConfig should have priority for FlowConfig relevant configurations - self.parameters.processingFile = 'CSK_MultiHTTPClient_Processing' -- which file to use for processing (will be started in own thread) - self.parameters.clientActivated = false -- Set if HTTP client should be active - self.parameters.proxyEnabled = false -- Status if proxy is enabled - self.parameters.proxyUsername = '' -- Username for proxy - self.parameters.proxyPassword = '' -- Password for proxy - self.parameters.proxyURL = '' -- Proxy URL - self.parameters.proxyPort = 8080 -- Proxy port - self.parameters.hostnameVerification = false -- Status if HTTP client should use hostname verification - self.parameters.peerVerification = false -- Status if HTTP client should use peer verification - self.parameters.cookieStore = '' -- File where the client’s cookies should be stored stored in 'public/CSK_HTTPClient/' - - self.parameters.clientAuthentication = false -- Status if HTTP client authentification is enabled + self.parameters = self.helperFuncs.defaultParameters.getParameters() -- Load default parameters + + -- Instance specific parameters self.parameters.caBundleFileName = 'public/CSK_HTTPClient/CABundle_Instance' .. self.multiHTTPClientInstanceNoString .. '.pem' -- Location of CA bundle file - self.parameters.clientCertificateActive = false -- Status if client authentication should be used - self.parameters.clientCertificateType = 'pem' -- Format of client certificate, like 'pem', 'der', 'pkcs#12' self.parameters.clientCertificateFileName = 'public/CSK_HTTPClient/ClientCertificate_Instance' .. self.multiHTTPClientInstanceNoString .. '.' -- Location of client certification file - self.parameters.clientCertificateKeyType = 'pem' -- Format of client certificate, like 'pem', 'der' self.parameters.clientCertificateKeyFileName = 'public/CSK_HTTPClient/ClientCertificateKey_Instance' .. self.multiHTTPClientInstanceNoString .. '.' -- Path to file containing the client’s private key - self.parameters.clientCertificateKeyPassphrase = '' -- Optional passphrase for the private key - - self.parameters.extendedResponse = false -- Status if reponse should include extended information like header keys, etc. - self.parameters.verboseMode = false -- Status if HTTP client should run in verbose mode - self.parameters.queueSize = 5 -- Size of max queue for requests before stopping to execute new requests - - self.parameters.requests = {} -- Table of requests to save - --[[ Sample of request parameters: - requestParameters = { - requestName = ..., -- Name of request - requestMode = ..., -- Mode of request - requestEndpoint = ..., -- Endpoint URL of request - requestPort = ..., -- Port of request - requestContent = ..., -- Content of request (body payload) - requestContentType = ..., -- Type of content - requestPeriodic = ..., -- Status if request should be triggered periodically - requestPeriod = ..., -- Cycle time for periodical request - headers = {...}, -- Table of header keys + values - registeredEvent = ... -- Event to register to execute request (optionally forwarding data of event via request content) - }]] self.currentDevice = Engine.getTypeName() -- Name of device module is running on if self.currentDevice == 'Webdisplay' then self.parameters.interface = 'ETH1' -- Interface to use for HTTP client diff --git a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Parameters.lua b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Parameters.lua new file mode 100644 index 0000000..ff637a0 --- /dev/null +++ b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/MultiHTTPClient_Parameters.lua @@ -0,0 +1,62 @@ +---@diagnostic disable: redundant-parameter, undefined-global + +--*************************************************************** +-- Inside of this script, you will find the relevant parameters +-- for this module and its default values +--*************************************************************** + +local functions = {} + +local function getParameters() + local multiHTTPClientParameters = {} + + multiHTTPClientParameters.flowConfigPriority = CSK_FlowConfig ~= nil or false -- Status if FlowConfig should have priority for FlowConfig relevant configurations + multiHTTPClientParameters.processingFile = 'CSK_MultiHTTPClient_Processing' -- which file to use for processing (will be started in own thread) + multiHTTPClientParameters.clientActivated = false -- Set if HTTP client should be active + multiHTTPClientParameters.interface = '' -- Interface to use for HTTP client (must be set individually) + multiHTTPClientParameters.proxyEnabled = false -- Status if proxy is enabled + multiHTTPClientParameters.proxyUsername = '' -- Username for proxy + multiHTTPClientParameters.proxyPassword = '' -- Password for proxy + multiHTTPClientParameters.proxyURL = '' -- Proxy URL + multiHTTPClientParameters.proxyPort = 8080 -- Proxy port + multiHTTPClientParameters.hostnameVerification = false -- Status if HTTP client should use hostname verification + multiHTTPClientParameters.peerVerification = false -- Status if HTTP client should use peer verification + multiHTTPClientParameters.cookieStore = '' -- File where the client’s cookies should be stored stored in 'public/CSK_HTTPClient/' + + multiHTTPClientParameters.basicAuthentication = false -- Status if HTTP basic authentication should be used + multiHTTPClientParameters.basicAuthenticationUser = '' -- Username for HTTP basic authentication + multiHTTPClientParameters.basicAuthenticationPassword = '' -- Password for HTTP basic authentication + + multiHTTPClientParameters.clientAuthentication = false -- Status if HTTP client authentification is enabled + multiHTTPClientParameters.caBundleFileName = 'public/CSK_HTTPClient/CABundle_InstanceX.pem' -- Location of CA bundle file (must be set individually) + multiHTTPClientParameters.clientCertificateActive = false -- Status if client authentication should be used + multiHTTPClientParameters.clientCertificateType = 'pem' -- Format of client certificate, like 'pem', 'der', 'pkcs#12' + multiHTTPClientParameters.clientCertificateFileName = 'public/CSK_HTTPClient/ClientCertificate_InstanceX.' -- Location of client certification file (must be set individually) + multiHTTPClientParameters.clientCertificateKeyType = 'pem' -- Format of client certificate, like 'pem', 'der' + multiHTTPClientParameters.clientCertificateKeyFileName = 'public/CSK_HTTPClient/ClientCertificateKey_InstanceX.' -- Path to file containing the client’s private key (must be set individually) + multiHTTPClientParameters.clientCertificateKeyPassphrase = '' -- Optional passphrase for the private key + + multiHTTPClientParameters.extendedResponse = false -- Status if reponse should include extended information like header keys, etc. + multiHTTPClientParameters.verboseMode = false -- Status if HTTP client should run in verbose mode + multiHTTPClientParameters.queueSize = 5 -- Size of max queue for requests before stopping to execute new requests + + multiHTTPClientParameters.requests = {} -- Table of requests to save + --[[ Sample of request parameters: + requestParameters = { + requestName = ..., -- Name of request + requestMode = ..., -- Mode of request + requestEndpoint = ..., -- Endpoint URL of request + requestPort = ..., -- Port of request + requestContent = ..., -- Content of request (body payload) + requestContentType = ..., -- Type of content + requestPeriodic = ..., -- Status if request should be triggered periodically + requestPeriod = ..., -- Cycle time for periodical request + headers = {...}, -- Table of header keys + values + registeredEvent = ... -- Event to register to execute request (optionally forwarding data of event via request content) + }]] + + return multiHTTPClientParameters +end +functions.getParameters = getParameters + +return functions \ No newline at end of file diff --git a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/helper/funcs.lua b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/helper/funcs.lua index f2ba6ee..d1c528f 100644 --- a/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/helper/funcs.lua +++ b/CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/helper/funcs.lua @@ -7,9 +7,13 @@ --**********************Start Global Scope ********************************* --************************************************************************** +local nameOfModule = 'CSK_MultiHTTPClient' + local funcs = {} -- Providing standard JSON functions funcs.json = require('Communication/MultiHTTPClient/helper/Json') +-- Default parameters for instances of module +funcs.defaultParameters = require('Communication/MultiHTTPClient/MultiHTTPClient_Parameters') --************************************************************************** --********************** End Global Scope ********************************** @@ -248,6 +252,27 @@ local function jsonLine2Table(intiStr, startInd, tab, resStr) end funcs.jsonLine2Table = jsonLine2Table +--- Function to compare table content. Optionally will fill missing values within content table with values of defaultTable +---@param content auto Data to check +---@param defaultTable auto Reference data +---@return auto[] content Update of data +local function checkParameters(content, defaultTable) + for key, value in pairs(defaultTable) do + if type(value) == 'table' then + if content[key] == nil then + _G.logger:info(nameOfModule .. ": Created missing parameters table '" .. tostring(key) .. "'") + content[key] = {} + end + content[key] = checkParameters(content[key], defaultTable[key]) + elseif content[key] == nil then + _G.logger:info(nameOfModule .. ": Missing parameter '" .. tostring(key) .. "'. Adding default value '" .. tostring(defaultTable[key]) .. "'") + content[key] = defaultTable[key] + end + end + return content +end +funcs.checkParameters = checkParameters + return funcs --************************************************************************** diff --git a/README.md b/README.md index 3fd8535..385ed67 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,9 @@ Tested on |Device|Firmware|Module version| |--|--|--| -|SIM1012|V2.4.2|V2.1.0| +|SICK AppEngine|V1.7.0|V2.2.0| |SICK AppEngine|V1.7.0|V2.0.0| +|SIM1012|V2.4.2|V2.1.0| |SIM1012|V2.4.2|V2.0.0| |SIM1012|V2.3.0|V1.0.0| diff --git a/docu/CSK_Module_MultiHTTPClient.html b/docu/CSK_Module_MultiHTTPClient.html index 9b39091..664539f 100644 --- a/docu/CSK_Module_MultiHTTPClient.html +++ b/docu/CSK_Module_MultiHTTPClient.html @@ -6,7 +6,7 @@ -Documentation - CSK_Module_MultiHTTPClient 2.1.0 +Documentation - CSK_Module_MultiHTTPClient 2.2.0