summaryrefslogtreecommitdiffstats
path: root/crates/core/c8y_api
diff options
context:
space:
mode:
authorLukasz Woznicki <lukasz.woznicki@softwareag.com>2022-02-09 13:55:02 +0000
committerLukasz Woznicki <lukasz.woznicki@softwareag.com>2022-02-18 09:41:55 +0000
commitad065ec206ad3b48f9e1cc48080f4d2ecfe85a2e (patch)
tree2042dc1a03440f61b112006d6f12b532f0610566 /crates/core/c8y_api
parentb1907dc4780709bad572a7108314c563eb02b70a (diff)
Move module to subdirectories and adjust use
Signed-off-by: Lukasz Woznicki <lukasz.woznicki@softwareag.com>
Diffstat (limited to 'crates/core/c8y_api')
-rw-r--r--crates/core/c8y_api/src/http_proxy.rs34
1 files changed, 33 insertions, 1 deletions
diff --git a/crates/core/c8y_api/src/http_proxy.rs b/crates/core/c8y_api/src/http_proxy.rs
index ceffe1ab..281b6a62 100644
--- a/crates/core/c8y_api/src/http_proxy.rs
+++ b/crates/core/c8y_api/src/http_proxy.rs
@@ -1,6 +1,7 @@
use crate::json_c8y::{
C8yCreateEvent, C8yManagedObject, C8yUpdateSoftwareListResponse, InternalIdResponse,
};
+
use async_trait::async_trait;
use c8y_smartrest::{error::SMCumulocityMapperError, smartrest_deserializer::SmartRestJwtResponse};
use mqtt_channel::{Connection, PubChannel, StreamExt, Topic, TopicFilter};
@@ -19,7 +20,7 @@ const RETRY_TIMEOUT_SECS: u64 = 60;
/// An HttpProxy handles http requests to C8y on behalf of the device.
#[async_trait]
-pub trait C8YHttpProxy {
+pub trait C8YHttpProxy: Send + Sync {
async fn init(&mut self) -> Result<(), SMCumulocityMapperError>;
fn url_is_in_my_tenant_domain(&self, url: &str) -> bool;
@@ -341,6 +342,37 @@ impl C8YHttpProxy for JwtAuthHttpProxy {
}
}
+pub struct FakeC8YHttpProxy {}
+
+#[async_trait::async_trait]
+impl C8YHttpProxy for FakeC8YHttpProxy {
+ async fn init(&mut self) -> Result<(), SMCumulocityMapperError> {
+ Ok(())
+ }
+
+ fn url_is_in_my_tenant_domain(&self, _url: &str) -> bool {
+ true
+ }
+
+ async fn get_jwt_token(&mut self) -> Result<SmartRestJwtResponse, SMCumulocityMapperError> {
+ Ok(SmartRestJwtResponse::try_new("71,fake-token")?)
+ }
+
+ async fn send_software_list_http(
+ &mut self,
+ _c8y_software_list: &C8yUpdateSoftwareListResponse,
+ ) -> Result<(), SMCumulocityMapperError> {
+ Ok(())
+ }
+
+ async fn upload_log_binary(
+ &mut self,
+ _log_content: &str,
+ ) -> Result<String, SMCumulocityMapperError> {
+ Ok("fake/upload/url".into())
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;