Skip to content

Commit

Permalink
Fix OPC Discovery Handler resolving IP bug (#584)
Browse files Browse the repository at this point in the history
* fix opc ip duplicate path error

Signed-off-by: harrisontin <[email protected]>

* Update patch version

Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* address feedback

Signed-off-by: harrisontin <[email protected]>

---------

Signed-off-by: harrisontin <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
harrison-tin and github-actions[bot] committed Apr 17, 2023
1 parent 0171597 commit adb2df9
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 43 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "agent"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "controller"
version = "0.10.2"
version = "0.10.3"
authors = ["<[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
4 changes: 2 additions & 2 deletions deployment/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.10.2
version: 0.10.3

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 0.10.2
appVersion: 0.10.3
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "debug-echo-discovery-handler"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "onvif-discovery-handler"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opcua-discovery-handler"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "udev-discovery-handler"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/debug-echo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-debug-echo"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/onvif/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-onvif"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/opcua/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-opcua"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
38 changes: 26 additions & 12 deletions discovery-handlers/opcua/src/discovery_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::wrappers::{
};
use ::url::Url;
use akri_discovery_utils::filtering::{should_include, FilterList};
use anyhow::Context;
use log::{error, info, trace};
use opcua::client::prelude::*;
use opcua::core::constants::DEFAULT_OPC_UA_SERVER_PORT;
Expand Down Expand Up @@ -193,29 +194,37 @@ fn get_socket_addr(url: &str) -> Result<SocketAddr, anyhow::Error> {
}

// This checks if the discovery_url can be resolved, if not use ip address instead
fn get_discovery_url_ip(ip_url: &str, discovery_url: String) -> Result<String, anyhow::Error> {
let url = Url::parse(&discovery_url)
.map_err(|_| anyhow::format_err!("could not parse url {discovery_url}"))?;
if url.scheme() != OPC_TCP_SCHEME {
fn get_discovery_url_ip(
ip_url_str: &str,
discovery_url_str: String,
) -> Result<String, anyhow::Error> {
let ip_url = Url::parse(ip_url_str).with_context(|| "could not parse url {ip_url_str}")?;
let discovery_url = Url::parse(&discovery_url_str)
.with_context(|| "could not parse url {discovery_url_str}")?;
if discovery_url.scheme() != OPC_TCP_SCHEME {
return Err(anyhow::format_err!(
"format of OPC UA url {} is not valid",
url
discovery_url
));
}
let mut path = url.path().to_string();
let host = url.host_str().unwrap();
let port = url.port().unwrap_or(DEFAULT_OPC_UA_SERVER_PORT);
let mut path = discovery_url.path().to_string();
let host = discovery_url.host_str().unwrap();
let port = discovery_url.port().unwrap_or(DEFAULT_OPC_UA_SERVER_PORT);

let addr_str = format!("{}:{}", host, port);

// check if the hostname can be resolved to socket address
match addr_str.to_socket_addrs() {
Ok(_url) => Ok(discovery_url),
Ok(_url) => Ok(discovery_url_str),
Err(_) => {
if ip_url.ends_with('/') && path.starts_with('/') {
if ip_url_str.ends_with('/') && path.starts_with('/') {
path.remove(0);
}
let url = format!("{}{}", ip_url, path);
let url = if ip_url.path() == "" || ip_url.path() == "/" {
format!("{}{}", ip_url, path)
} else {
ip_url_str.to_string()
};
trace!(
"get_discovery_url_ip - cannot resolve the application url from server, using ip address instead of hostname: {}",
url
Expand Down Expand Up @@ -466,14 +475,19 @@ mod tests {
#[test]
// Test that it converts the discovery url to an ip address if the discovery url is a hostname that is not resolvable
fn test_get_discovery_url_ip() {
let ip_url = "opc.tcp://192.168.0.1:50000/";
let ip_url = "opc.tcp://192.168.0.1:50000";
let ip_url2 = "opc.tcp://192.168.0.1:50000/OPCUA/Simluation";

// OPCTest.invalid is not a valid hostname, it should be overwritten by the ip_url
let discovery_url = "opc.tcp://OPCTest.invalid:50000/OPCUA/Simluation";
assert_eq!(
get_discovery_url_ip(ip_url, discovery_url.to_string()).unwrap(),
"opc.tcp://192.168.0.1:50000/OPCUA/Simluation"
);
assert_eq!(
get_discovery_url_ip(ip_url2, discovery_url.to_string()).unwrap(),
"opc.tcp://192.168.0.1:50000/OPCUA/Simluation"
);

// 192.168.0.2 is a valid ip address, it should not be overwritten
let discovery_url = "opc.tcp://192.168.0.2:50000/OPCUA/Simluation";
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/udev/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-udev"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion discovery-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-discovery-utils"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion samples/brokers/udev-video-broker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "udev-video-broker"
version = "0.10.2"
version = "0.10.3"
authors = ["Kate Goldenring <[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion shared/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-shared"
version = "0.10.2"
version = "0.10.3"
authors = ["<[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.2
0.10.3
2 changes: 1 addition & 1 deletion webhooks/validating/configuration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "webhook-configuration"
version = "0.10.2"
version = "0.10.3"
authors = ["DazWilkin <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down

0 comments on commit adb2df9

Please sign in to comment.