-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RSDK-9887] get agent config from app #417
Changes from 10 commits
a8b7238
0570dd4
7c424fa
9a71a85
2fb566c
1d25a6e
ba230d8
058f5c6
5a864a9
589c320
1857697
b69bf5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,15 @@ | |
use crate::proto::app::v1::CertificateRequest; | ||
use crate::proto::app::v1::CertificateResponse; | ||
use crate::proto::{ | ||
app::v1::{ | ||
AgentInfo, ConfigRequest, ConfigResponse, LogRequest, NeedsRestartRequest, | ||
NeedsRestartResponse, | ||
app::{ | ||
agent::v1::{ | ||
DeviceAgentConfigRequest, DeviceAgentConfigResponse, DeviceSubsystemConfig, HostInfo, | ||
VersionInfo, | ||
}, | ||
v1::{ | ||
AgentInfo, ConfigRequest, ConfigResponse, LogRequest, NeedsRestartRequest, | ||
NeedsRestartResponse, | ||
}, | ||
}, | ||
common::v1::LogEntry, | ||
rpc::{ | ||
|
@@ -323,6 +329,46 @@ impl AppClient { | |
Ok((Box::new(cfg_response), datetime)) | ||
} | ||
|
||
pub async fn get_agent_config(&self) -> Result<Box<DeviceAgentConfigResponse>, AppClientError> { | ||
let host_info = Some(HostInfo { | ||
platform: "micro-rdk/esp32".to_string(), | ||
distro: "esp32".to_string(), | ||
tags: Default::default(), | ||
}); | ||
|
||
let version_info = Some(VersionInfo { | ||
agent_running: "none".to_string(), | ||
..Default::default() | ||
}); | ||
mattjperez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let req = DeviceAgentConfigRequest { | ||
id: self.robot_credentials.robot_id.clone(), | ||
host_info, | ||
version_info, | ||
subsystem_versions: Default::default(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you eliminate even namign this field in favor of |
||
}; | ||
let body = encode_request(req)?; | ||
|
||
let r = self | ||
.grpc_client | ||
.build_request( | ||
"/viam.app.agent.v1.AgentDeviceService/DeviceAgentConfig", | ||
Some(&self.jwt), | ||
"", | ||
BodyExt::boxed(Full::new(body).map_err(|never| match never {})), | ||
) | ||
.map_err(AppClientError::AppGrpcClientError)?; | ||
|
||
let (mut r, headers) = self.grpc_client.send_request(r).await?; | ||
|
||
if r.is_empty() { | ||
return Err(AppClientError::AppClientEmptyBody); | ||
} | ||
let cfg_response = DeviceAgentConfigResponse::decode(r.split_off(5))?; | ||
|
||
Ok(Box::new(cfg_response)) | ||
} | ||
|
||
pub async fn push_logs(&self, logs: Vec<LogEntry>) -> Result<(), AppClientError> { | ||
let req = LogRequest { | ||
id: self.robot_credentials.robot_id.clone(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,10 @@ | |
#[cfg(feature = "data")] | ||
use crate::common::data_collector::DataCollectorConfig; | ||
use crate::google; | ||
use crate::proto::{app::v1::ComponentConfig, common::v1::ResourceName}; | ||
use crate::proto::{ | ||
app::{agent::v1::DeviceAgentConfigResponse, v1::ComponentConfig}, | ||
common::v1::ResourceName, | ||
}; | ||
|
||
use std::collections::HashMap; | ||
use std::num::{ParseFloatError, ParseIntError}; | ||
|
@@ -20,6 +23,72 @@ pub enum AttributeError { | |
ValidationError(String), | ||
} | ||
|
||
impl TryFrom<&DeviceAgentConfigResponse> for AgentConfig { | ||
type Error = AttributeError; | ||
fn try_from(value: &DeviceAgentConfigResponse) -> Result<Self, Self::Error> { | ||
if let Some(ref additional_networks) = value.additional_networks { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of |
||
let network_settings = additional_networks | ||
.fields | ||
.iter() | ||
.filter_map(|(_k, v)| { | ||
let local_kind: Option<Kind> = | ||
v.kind.clone().and_then(|v| Kind::try_from(v).ok()); | ||
local_kind | ||
.as_ref() | ||
.and_then(|v| NetworkSetting::try_from(v).ok()) | ||
}) | ||
.collect::<Vec<NetworkSetting>>(); | ||
Ok(Self { network_settings }) | ||
} else { | ||
Err(AttributeError::ConversionImpossibleError) | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct AgentConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a slight preference for having the struct be introduced before any |
||
pub network_settings: Vec<NetworkSetting>, | ||
} | ||
|
||
pub struct NetworkSetting { | ||
ssid: String, | ||
password: String, | ||
priority: usize, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe priority is permitted to be negative, so I don't think a |
||
} | ||
|
||
impl TryFrom<&Kind> for NetworkSetting { | ||
type Error = AttributeError; | ||
fn try_from(value: &Kind) -> Result<Self, Self::Error> { | ||
let ssid: String = value | ||
.get("ssid")? | ||
.ok_or(AttributeError::ConversionImpossibleError)? | ||
.try_into()?; | ||
let password: String = value | ||
.get("psk")? | ||
.ok_or(AttributeError::ConversionImpossibleError)? | ||
.try_into()?; | ||
let priority: usize = value | ||
.get("priority")? | ||
.ok_or(AttributeError::ConversionImpossibleError)? | ||
.try_into()?; | ||
Ok(Self { | ||
ssid, | ||
password, | ||
priority, | ||
}) | ||
} | ||
} | ||
|
||
impl std::fmt::Debug for NetworkSetting { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!( | ||
f, | ||
"NetworkSetting {{ ssid: {}, password: ***, priority: {} }}", | ||
self.ssid, self.priority | ||
) | ||
} | ||
} | ||
|
||
impl From<ParseIntError> for AttributeError { | ||
fn from(_: ParseIntError) -> AttributeError { | ||
AttributeError::ParseNumError | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if we just don't set
agent_running
?