@@ -2,6 +2,8 @@ use std::error::Error;
22use std:: fmt:: { Display , Formatter } ;
33use std:: str:: FromStr ;
44
5+ use crate :: auth_monitor_options:: AuthMonitorOptions ;
6+
57const OPTION_PREFIX : & str = "--" ;
68const OPTION_PREFIX_LENGTH : usize = OPTION_PREFIX . len ( ) ;
79
@@ -11,13 +13,9 @@ const OPTION_VALUE_SEPARATOR_LENGTH: usize = 1;
1113const MAX_FAILED_ATTEMPTS_OPTION : & str = "max-failed-attempts" ;
1214const RESET_AFTER_SECONDS_OPTION : & str = "reset-after-seconds" ;
1315
14- const MAX_FAILED_ATTEMPTS : i32 = 3 ;
15- const RESET_AFTER_SECONDS : i32 = 1800 ;
16-
1716pub struct AuthMonitorParams {
1817 pub filepath : String ,
19- pub max_failed_attempts : i32 ,
20- pub reset_after_seconds : i32 ,
18+ pub options : AuthMonitorOptions ,
2119}
2220
2321impl AuthMonitorParams {
@@ -42,11 +40,11 @@ impl AuthMonitorParams {
4240 } ;
4341 match & option_name[ OPTION_PREFIX_LENGTH ..] {
4442 MAX_FAILED_ATTEMPTS_OPTION => {
45- params. max_failed_attempts =
43+ params. options . max_failed_attempts =
4644 Self :: parse_option_value ( option_name, option_value) ?;
4745 }
4846 RESET_AFTER_SECONDS_OPTION => {
49- params. reset_after_seconds =
47+ params. options . reset_after_seconds =
5048 Self :: parse_option_value ( option_name, option_value) ?;
5149 }
5250 _ => Err ( format ! ( "Unknown option {}" , argument) ) ?,
@@ -82,13 +80,13 @@ impl AuthMonitorParams {
8280 if self . filepath . is_empty ( ) {
8381 Err ( "File path not specified" ) ?;
8482 }
85- if self . max_failed_attempts <= 0 {
83+ if self . options . max_failed_attempts <= 0 {
8684 return Err ( format ! (
8785 "{} must be greater than 0" ,
8886 MAX_FAILED_ATTEMPTS_OPTION
8987 ) ) ?;
9088 }
91- if self . reset_after_seconds <= 0 {
89+ if self . options . reset_after_seconds <= 0 {
9290 return Err ( format ! (
9391 "{} must be greater than 0" ,
9492 RESET_AFTER_SECONDS_OPTION
@@ -102,8 +100,7 @@ impl Default for AuthMonitorParams {
102100 fn default ( ) -> Self {
103101 return AuthMonitorParams {
104102 filepath : String :: new ( ) ,
105- max_failed_attempts : MAX_FAILED_ATTEMPTS ,
106- reset_after_seconds : RESET_AFTER_SECONDS ,
103+ options : AuthMonitorOptions :: default ( ) ,
107104 } ;
108105 }
109106}
@@ -112,8 +109,8 @@ impl Display for AuthMonitorParams {
112109 fn fmt ( & self , formatter : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
113110 return write ! (
114111 formatter,
115- "filepath={}, max_failed_attempts={}, reset_after_seconds= {}" ,
116- self . filepath, self . max_failed_attempts , self . reset_after_seconds
112+ "filepath={}, options: {}" ,
113+ self . filepath, self . options
117114 ) ;
118115 }
119116}
0 commit comments