@@ -162,24 +162,24 @@ impl TracerFlareManager {
162162 Ok ( tracer_flare)
163163 }
164164
165- /// Handle the `RemoteConfigFile ` and return the action that tracer flare needs
166- /// to perform. This function also updates the `TracerFlareManager` state based on the
167- /// received configuration.
165+ /// Handle the `RemoteConfigData ` and return the action the tracer flare
166+ /// needs to perform. This function also updates the `TracerFlareManager`
167+ /// state based on the received configuration.
168168 ///
169169 /// # Arguments
170170 ///
171- /// * `file ` - RemoteConfigFile received by the Listener .
171+ /// * `data ` - RemoteConfigData .
172172 /// * `tracer_flare` - TracerFlareManager object to update with the received configuration.
173173 ///
174174 /// # Returns
175175 ///
176176 /// * `Ok(ReturnAction)` - If successful.
177- /// * `FlareError(msg)` - If something fail .
178- pub fn handle_remote_config_file (
177+ /// * `FlareError(msg)` - If something fails .
178+ pub fn handle_remote_config_data (
179179 & mut self ,
180- file : RemoteConfigFile ,
180+ data : & RemoteConfigData ,
181181 ) -> Result < ReturnAction , FlareError > {
182- let action = file . try_into ( ) ;
182+ let action = data . try_into ( ) ;
183183 if let Ok ( ReturnAction :: Set ( _) ) = action {
184184 if self . collecting {
185185 return Ok ( ReturnAction :: None ) ;
@@ -191,6 +191,33 @@ impl TracerFlareManager {
191191 }
192192 action
193193 }
194+
195+ /// Handle the `RemoteConfigFile` and return the action that tracer flare needs
196+ /// to perform. This function also updates the `TracerFlareManager` state based on the
197+ /// received configuration.
198+ ///
199+ /// # Arguments
200+ ///
201+ /// * `file` - RemoteConfigFile received by the Listener.
202+ /// * `tracer_flare` - TracerFlareManager object to update with the received configuration.
203+ ///
204+ /// # Returns
205+ ///
206+ /// * `Ok(ReturnAction)` - If successful.
207+ /// * `FlareError(msg)` - If something fail.
208+ pub fn handle_remote_config_file (
209+ & mut self ,
210+ file : RemoteConfigFile ,
211+ ) -> Result < ReturnAction , FlareError > {
212+ match file. contents ( ) . as_ref ( ) {
213+ Ok ( data) => self . handle_remote_config_data ( data) ,
214+ Err ( e) => {
215+ // If encounter an error we need to stop collecting
216+ self . collecting = false ;
217+ Err ( FlareError :: ParsingError ( e. to_string ( ) ) )
218+ }
219+ }
220+ }
194221}
195222
196223/// Enum that holds the different log levels possible
@@ -292,28 +319,45 @@ impl TryFrom<RemoteConfigFile> for ReturnAction {
292319 /// * `Ok(ReturnAction)` - If successful.
293320 /// * `FlareError(msg)` - If something fail.
294321 fn try_from ( file : RemoteConfigFile ) -> Result < Self , Self :: Error > {
295- let config = file. contents ( ) ;
296- match config. as_ref ( ) {
297- Ok ( data) => match data {
298- RemoteConfigData :: TracerFlareConfig ( agent_config) => {
299- if agent_config. name . starts_with ( "flare-log-level." ) {
300- if let Some ( log_level) = & agent_config. config . log_level {
301- let log_level = log_level. as_str ( ) . try_into ( ) ?;
302- return Ok ( ReturnAction :: Set ( log_level) ) ;
303- }
322+ match file. contents ( ) . as_ref ( ) {
323+ Ok ( data) => data. try_into ( ) ,
324+ Err ( e) => Err ( FlareError :: ParsingError ( e. to_string ( ) ) ) ,
325+ }
326+ }
327+ }
328+
329+ impl TryFrom < & RemoteConfigData > for ReturnAction {
330+ type Error = FlareError ;
331+
332+ /// Check the `&RemoteConfigData` and return the action the tracer flare
333+ /// needs to perform.
334+ ///
335+ /// # Arguments
336+ ///
337+ /// * `data` - &RemoteConfigData
338+ ///
339+ /// # Returns
340+ ///
341+ /// * `Ok(ReturnAction)` - If successful
342+ /// * `FlareError(msg)` - If something fails
343+ fn try_from ( data : & RemoteConfigData ) -> Result < Self , Self :: Error > {
344+ match data {
345+ RemoteConfigData :: TracerFlareConfig ( agent_config) => {
346+ if agent_config. name . starts_with ( "flare-log-level." ) {
347+ if let Some ( log_level) = & agent_config. config . log_level {
348+ let log_level = log_level. as_str ( ) . try_into ( ) ?;
349+ return Ok ( ReturnAction :: Set ( log_level) ) ;
304350 }
305351 }
306- RemoteConfigData :: TracerFlareTask ( agent_task ) => {
307- if agent_task . task_type . eq ( "tracer_flare" ) {
308- return Ok ( ReturnAction :: Send ( agent_task. to_owned ( ) ) ) ;
309- }
352+ }
353+ RemoteConfigData :: TracerFlareTask ( agent_task ) => {
354+ if agent_task. task_type . eq ( "tracer_flare" ) {
355+ return Ok ( ReturnAction :: Send ( agent_task . to_owned ( ) ) ) ;
310356 }
311- _ => return Ok ( ReturnAction :: None ) ,
312- } ,
313- Err ( e) => {
314- return Err ( FlareError :: ParsingError ( e. to_string ( ) ) ) ;
315357 }
358+ _ => return Ok ( ReturnAction :: None ) ,
316359 }
360+
317361 Ok ( ReturnAction :: None )
318362 }
319363}
0 commit comments