diff --git a/Cargo.lock b/Cargo.lock index 847d6b3..501585b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -255,9 +255,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cc" -version = "1.0.83" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "0f8e7c90afad890484a21653d08b6e209ae34770fb5ee298f9c699fcc1e5c856" dependencies = [ "libc", ] @@ -333,7 +333,7 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "core-protobuf-data-access" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/ibeji#9f019edb0dea509a435b5579ddd11b076a764829" +source = "git+https://github.com/eclipse-ibeji/ibeji#56ddbafaf73bde471d23d2680c01e818008068cf" dependencies = [ "prost", "prost-types", @@ -471,9 +471,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" dependencies = [ "humantime", "is-terminal", @@ -490,9 +490,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" +checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" dependencies = [ "libc", "windows-sys", @@ -549,7 +549,7 @@ dependencies = [ [[package]] name = "freyja" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "crossbeam", "env_logger", @@ -565,12 +565,12 @@ dependencies = [ [[package]] name = "freyja-build-common" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" [[package]] name = "freyja-common" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "config", "freyja-contracts", @@ -583,15 +583,12 @@ dependencies = [ [[package]] name = "freyja-contracts" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "async-trait", "crossbeam", "proc-macros", "serde", - "strum", - "strum_macros", - "tokio", ] [[package]] @@ -734,9 +731,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ "cfg-if", "libc", @@ -752,7 +749,7 @@ checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "grpc-provider-proxy-v1" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "async-trait", "crossbeam", @@ -763,6 +760,7 @@ dependencies = [ "log", "samples-protobuf-data-access", "serde", + "serde_json", "tempfile", "tonic", "tower", @@ -825,9 +823,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" dependencies = [ "bytes", "fnv", @@ -848,7 +846,7 @@ dependencies = [ [[package]] name = "http-mock-provider-proxy" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "async-trait", "axum", @@ -965,7 +963,7 @@ dependencies = [ [[package]] name = "in-memory-mock-cloud-adapter" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "async-trait", "freyja-contracts", @@ -977,7 +975,7 @@ dependencies = [ [[package]] name = "in-memory-mock-digital-twin-adapter" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "async-trait", "freyja-build-common", @@ -990,7 +988,7 @@ dependencies = [ [[package]] name = "in-memory-mock-mapping-client" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "async-trait", "freyja-build-common", @@ -1003,7 +1001,7 @@ dependencies = [ [[package]] name = "in-memory-mock-provider-proxy" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "async-trait", "crossbeam", @@ -1027,9 +1025,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", "hashbrown 0.14.2", @@ -1069,9 +1067,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" dependencies = [ "wasm-bindgen", ] @@ -1095,9 +1093,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.149" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "linked-hash-map" @@ -1107,9 +1105,9 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" [[package]] name = "log" @@ -1231,9 +1229,9 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "openssl" -version = "0.10.57" +version = "0.10.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" +checksum = "7a257ad03cd8fb16ad4172fedf8094451e1af1c4b70097636ef2eac9a5f0cc33" dependencies = [ "bitflags 2.4.1", "cfg-if", @@ -1263,9 +1261,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.93" +version = "0.9.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" +checksum = "40a4130519a360279579c2053038317e40eff64d13fd3f004f9e1b72b8a6aaf9" dependencies = [ "cc", "libc", @@ -1373,7 +1371,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.0.2", + "indexmap 2.1.0", ] [[package]] @@ -1448,7 +1446,7 @@ dependencies = [ [[package]] name = "proc-macros" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "convert_case", "proc-macro2", @@ -1513,7 +1511,7 @@ dependencies = [ [[package]] name = "provider-proxy-selector" version = "0.1.0" -source = "git+https://github.com/eclipse-ibeji/freyja#2424bb10e407cd4cca00f79e7edbc49199ec55bd" +source = "git+https://github.com/eclipse-ibeji/freyja#045fdc25a1525f188be2f1166325763b6783fdd8" dependencies = [ "async-trait", "crossbeam", @@ -1522,9 +1520,6 @@ dependencies = [ "http-mock-provider-proxy", "in-memory-mock-provider-proxy", "log", - "proc-macros", - "strum", - "strum_macros", "tokio", ] @@ -1698,7 +1693,7 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "samples-protobuf-data-access" version = "1.0.0" -source = "git+https://github.com/eclipse-ibeji/ibeji#9f019edb0dea509a435b5579ddd11b076a764829" +source = "git+https://github.com/eclipse-ibeji/ibeji#56ddbafaf73bde471d23d2680c01e818008068cf" dependencies = [ "prost", "prost-types", @@ -1748,18 +1743,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.190" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" +checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.190" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" +checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" dependencies = [ "proc-macro2", "quote", @@ -1768,9 +1763,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" dependencies = [ "itoa", "ryu", @@ -1802,7 +1797,7 @@ dependencies = [ [[package]] name = "service_discovery_proto" version = "0.1.0" -source = "git+https://github.com/eclipse-chariott/chariott#ac671d0d769568d23d8b2bfdd46ac57b36681e2e" +source = "git+https://github.com/eclipse-chariott/chariott#81474c771d8092ec7bb5fb7bd48c328a6dc56eba" dependencies = [ "prost", "tokio", @@ -1871,9 +1866,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", @@ -1984,9 +1979,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.33.0" +version = "1.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" +checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" dependencies = [ "backtrace", "bytes", @@ -2011,9 +2006,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", @@ -2253,9 +2248,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2263,9 +2258,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" dependencies = [ "bumpalo", "log", @@ -2278,9 +2273,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.37" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" dependencies = [ "cfg-if", "js-sys", @@ -2290,9 +2285,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2300,9 +2295,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", @@ -2313,15 +2308,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml b/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml index bb70667..e005e47 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/Cargo.toml @@ -11,6 +11,7 @@ license = "MIT" [dependencies] async-trait = { workspace = true } azure-cloud-connector-proto = { workspace = true } +freyja-build-common = { workspace = true } freyja-common = { workspace = true } freyja-contracts = { workspace = true } futures = { workspace = true } diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs b/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs index 3ee420a..47b4b6f 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/build.rs @@ -2,19 +2,10 @@ // Licensed under the MIT license. // SPDX-License-Identifier: MIT -use std::env; +use freyja_build_common::copy_config; -use freyja_build_common::copy_to_build_out_dir; - -const RES_DIR_NAME: &str = "res"; -const DEFAULT_CONFIG_FILE: &str = "azure_cloud_connector_adapter_config.default.json"; +const CONFIG_FILE_STEM: &str = "azure_cloud_connector_adapter_config"; fn main() { - // Current directory of the build script is the package's root directory - let config_path = env::current_dir() - .unwrap() - .join(RES_DIR_NAME) - .join(DEFAULT_CONFIG_FILE); - - copy_to_build_out_dir(config_path, DEFAULT_CONFIG_FILE); + copy_config(CONFIG_FILE_STEM); } diff --git a/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs b/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs index 976a0a6..6f29f55 100644 --- a/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs +++ b/freyja_adapters/cloud/azure_cloud_connector_adapter/src/azure_cloud_connector_adapter.rs @@ -12,6 +12,7 @@ use log::debug; use serde::{Deserialize, Serialize}; use tonic::transport::Channel; +use freyja_build_common::config_file_stem; use freyja_common::{config_utils, out_dir, retry_utils::execute_with_retry}; use freyja_contracts::cloud_adapter::{ CloudAdapter, CloudAdapterError, CloudMessageRequest, CloudMessageResponse, @@ -19,7 +20,6 @@ use freyja_contracts::cloud_adapter::{ use crate::config::Config; -const CONFIG_FILE_STEM: &str = "azure_cloud_connector_adapter_config"; const MODEL_ID_KEY: &str = "model_id"; const INSTANCE_ID_KEY: &str = "instance_id"; const INSTANCE_PROPERTY_PATH_KEY: &str = "instance_property_path"; @@ -85,7 +85,7 @@ impl CloudAdapter for AzureCloudConnectorAdapter { fn create_new() -> Result { let cloud_connector_client = futures::executor::block_on(async { let config: Config = config_utils::read_from_files( - CONFIG_FILE_STEM, + config_file_stem!(), config_utils::JSON_EXT, out_dir!(), CloudAdapterError::io, diff --git a/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml b/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml index fa7c2ef..8878c9b 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml +++ b/freyja_adapters/digital_twin/ibeji_adapter/Cargo.toml @@ -11,6 +11,7 @@ license = "MIT" [dependencies] async-trait = { workspace = true } core-protobuf-data-access = { workspace = true } +freyja-build-common = { workspace = true } freyja-common = { workspace = true } freyja-contracts = { workspace = true } futures = { workspace = true } diff --git a/freyja_adapters/digital_twin/ibeji_adapter/build.rs b/freyja_adapters/digital_twin/ibeji_adapter/build.rs index e93e689..02dfd75 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/build.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/build.rs @@ -2,19 +2,10 @@ // Licensed under the MIT license. // SPDX-License-Identifier: MIT -use std::env; +use freyja_build_common::copy_config; -use freyja_build_common::copy_to_build_out_dir; - -const RES_DIR_NAME: &str = "res"; -const DEFAULT_CONFIG_FILE: &str = "ibeji_adapter_config.default.json"; +const CONFIG_FILE_STEM: &str = "ibeji_adapter_config"; fn main() { - // Current directory of the build script is the package's root directory - let config_path = env::current_dir() - .unwrap() - .join(RES_DIR_NAME) - .join(DEFAULT_CONFIG_FILE); - - copy_to_build_out_dir(config_path, DEFAULT_CONFIG_FILE); + copy_config(CONFIG_FILE_STEM); } diff --git a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs index 4208da5..0acc734 100644 --- a/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs +++ b/freyja_adapters/digital_twin/ibeji_adapter/src/ibeji_adapter.rs @@ -6,28 +6,24 @@ use std::time::Duration; use async_trait::async_trait; use core_protobuf_data_access::invehicle_digital_twin::v1::{ - invehicle_digital_twin_client::InvehicleDigitalTwinClient, EndpointInfo, FindByIdRequest, + invehicle_digital_twin_client::InvehicleDigitalTwinClient, + FindByIdRequest as IbejiFindByIdRequest, }; -use log::{info, warn}; +use log::info; use service_discovery_proto::service_registry::v1::service_registry_client::ServiceRegistryClient; use service_discovery_proto::service_registry::v1::DiscoverRequest; use tonic::{transport::Channel, Request}; +use crate::config::{self, ChariottDiscoverRequest, Config}; +use freyja_build_common::config_file_stem; use freyja_common::{config_utils, out_dir, retry_utils::execute_with_retry}; use freyja_contracts::{ digital_twin_adapter::{ - DigitalTwinAdapter, DigitalTwinAdapterError, GetDigitalTwinProviderRequest, - GetDigitalTwinProviderResponse, + DigitalTwinAdapter, DigitalTwinAdapterError, FindByIdRequest, FindByIdResponse, }, - entity::Entity, + entity::{Entity, EntityEndpoint}, }; -use crate::config::{self, ChariottDiscoverRequest, Config}; - -const CONFIG_FILE_STEM: &str = "ibeji_adapter_config"; -const GET_OPERATION: &str = "Get"; -const SUBSCRIBE_OPERATION: &str = "Subscribe"; - /// Contacts the In-Vehicle Digital Twin Service in Ibeji pub struct IbejiAdapter { client: InvehicleDigitalTwinClient, @@ -77,7 +73,7 @@ impl DigitalTwinAdapter for IbejiAdapter { /// Creates a new instance of a DigitalTwinAdapter with default settings fn create_new() -> Result { let config = config_utils::read_from_files( - CONFIG_FILE_STEM, + config_file_stem!(), config_utils::JSON_EXT, out_dir!(), DigitalTwinAdapterError::io, @@ -146,10 +142,10 @@ impl DigitalTwinAdapter for IbejiAdapter { /// - `request`: the request for finding an entity's access information async fn find_by_id( &self, - request: GetDigitalTwinProviderRequest, - ) -> Result { + request: FindByIdRequest, + ) -> Result { let entity_id = request.entity_id; - let request = tonic::Request::new(FindByIdRequest { + let request = tonic::Request::new(IbejiFindByIdRequest { id: entity_id.clone(), }); @@ -166,62 +162,35 @@ impl DigitalTwinAdapter for IbejiAdapter { .entity_access_info .ok_or(format!("Cannot find {entity_id} with find_by_id")) .map_err(DigitalTwinAdapterError::entity_not_found)?; - let entity_endpoint_info_list = entity_access_info.endpoint_info_list; - - let endpoint: Option<(EndpointInfo, String)> = entity_endpoint_info_list - .into_iter() - .find_map(|endpoint_info| { - endpoint_info.operations.iter().find_map(|operation| { - if *operation == SUBSCRIBE_OPERATION || *operation == GET_OPERATION { - return Some((endpoint_info.clone(), operation.clone())); - } - None - }) - }); - - if endpoint.is_none() { - let message = format!("No access info to connect with {entity_id}"); - warn!("{message}"); - return Err(DigitalTwinAdapterError::communication(message)); - } - - let (endpoint, _) = endpoint.unwrap(); - - // If both Subscribe and Get are supported, then we pick Subscribe over Get - let operation = if endpoint - .operations - .iter() - .any(|op| op == SUBSCRIBE_OPERATION) - { - String::from(SUBSCRIBE_OPERATION) - } else { - String::from(GET_OPERATION) - }; - - let entity_uri = config::get_uri(&endpoint.uri).map_err(DigitalTwinAdapterError::io)?; - let entity = Entity { - id: entity_id, - description: Some(entity_access_info.description), - name: Some(entity_access_info.name), - operation, - uri: entity_uri, - protocol: endpoint.protocol, - }; - - Ok(GetDigitalTwinProviderResponse { entity }) + Ok(FindByIdResponse { + entity: Entity { + id: entity_access_info.id, + name: Some(entity_access_info.name), + description: Some(entity_access_info.description), + endpoints: entity_access_info + .endpoint_info_list + .into_iter() + .map(|e| EntityEndpoint { + protocol: e.protocol, + operations: e.operations, + uri: e.uri, + }) + .collect(), + }, + }) } } #[cfg(test)] mod ibeji_digital_twin_adapter_tests { - use super::*; - use core_protobuf_data_access::invehicle_digital_twin::v1::{ - invehicle_digital_twin_server::InvehicleDigitalTwin, EntityAccessInfo, FindByIdRequest, - FindByIdResponse, RegisterRequest, RegisterResponse, + invehicle_digital_twin_server::InvehicleDigitalTwin, EndpointInfo, EntityAccessInfo, + FindByIdResponse as IbejiFindByIdResponse, RegisterRequest, RegisterResponse, }; - use tonic::{Request, Response, Status}; + use tonic::{Response, Status}; + + use super::*; const AMBIENT_AIR_TEMPERATURE_ID: &str = "dtmi:sdv:Vehicle:Cabin:HVAC:AmbientAirTemperature;1"; @@ -231,8 +200,8 @@ mod ibeji_digital_twin_adapter_tests { impl InvehicleDigitalTwin for MockInVehicleTwin { async fn find_by_id( &self, - request: Request, - ) -> Result, Status> { + request: Request, + ) -> Result, Status> { let entity_id = request.into_inner().id; if entity_id != AMBIENT_AIR_TEMPERATURE_ID { @@ -240,6 +209,7 @@ mod ibeji_digital_twin_adapter_tests { "Unable to find the entity with id {entity_id}", )); } + let endpoint_info = EndpointInfo { protocol: String::from("grpc"), uri: String::from("http://[::1]:40010"), // Devskim: ignore DS137138 @@ -254,7 +224,7 @@ mod ibeji_digital_twin_adapter_tests { endpoint_info_list: vec![endpoint_info], }; - let response = FindByIdResponse { + let response = IbejiFindByIdResponse { entity_access_info: Some(entity_access_info), }; @@ -327,7 +297,7 @@ mod ibeji_digital_twin_adapter_tests { let client = create_test_grpc_client(bind_path.clone()).await; let ibeji_digital_twin_adapter = IbejiAdapter { client }; - let request = GetDigitalTwinProviderRequest { + let request = FindByIdRequest { entity_id: String::from("invalid_entity"), }; @@ -335,14 +305,12 @@ mod ibeji_digital_twin_adapter_tests { assert!(result.is_err()); - let request = GetDigitalTwinProviderRequest { + let request = FindByIdRequest { entity_id: String::from(AMBIENT_AIR_TEMPERATURE_ID), }; + let result = ibeji_digital_twin_adapter.find_by_id(request).await; assert!(result.is_ok()); - - let response = result.unwrap(); - assert_eq!(response.entity.operation, SUBSCRIBE_OPERATION); }; tokio::select! {