11use tracing:: { info} ;
22use crate :: app:: app:: App ;
3- use crate :: models:: auth:: Auth ;
4- use crate :: models:: auth:: Auth :: { BasicAuth , BearerToken } ;
3+ use crate :: models:: auth:: auth:: Auth ;
4+ use crate :: models:: auth:: basic:: BasicAuth ;
5+ use crate :: models:: auth:: bearer_token:: BearerToken ;
56
67impl App < ' _ > {
78 pub fn modify_request_auth ( & mut self , collection_index : usize , request_index : usize , auth : Auth ) -> anyhow:: Result < ( ) > {
@@ -29,11 +30,11 @@ impl App<'_> {
2930 info ! ( "Auth basic username set to \" {}\" " , basic_auth_username) ;
3031
3132 match & selected_request. auth {
32- BasicAuth { password, .. } => {
33- selected_request. auth = BasicAuth {
33+ Auth :: BasicAuth ( BasicAuth { password, .. } ) => {
34+ selected_request. auth = Auth :: BasicAuth ( BasicAuth {
3435 username : basic_auth_username,
3536 password : password. to_string ( )
36- } ;
37+ } ) ;
3738 }
3839 _ => { }
3940 }
@@ -51,11 +52,11 @@ impl App<'_> {
5152 info ! ( "Auth basic password set to \" {}\" " , basic_auth_password) ;
5253
5354 match & selected_request. auth {
54- BasicAuth { username, .. } => {
55- selected_request. auth = BasicAuth {
55+ Auth :: BasicAuth ( BasicAuth { username, .. } ) => {
56+ selected_request. auth = Auth :: BasicAuth ( BasicAuth {
5657 username : username. to_string ( ) ,
5758 password : basic_auth_password
58- } ;
59+ } ) ;
5960 }
6061 _ => { }
6162 }
@@ -73,13 +74,44 @@ impl App<'_> {
7374 info ! ( "Auth bearer token set to \" {}\" " , bearer_token) ;
7475
7576 match & selected_request. auth {
76- BearerToken { .. } => {
77- selected_request. auth = BearerToken { token : bearer_token } ;
77+ Auth :: BearerToken ( BearerToken { .. } ) => {
78+ selected_request. auth = Auth :: BearerToken ( BearerToken { token : bearer_token } ) ;
7879 }
7980 _ => { }
8081 }
8182 }
8283
8384 self . save_collection_to_file ( collection_index) ;
8485 }
85- }
86+
87+ pub fn modify_request_auth_secret ( & mut self , collection_index : usize , request_index : usize , secret : String ) {
88+ let local_selected_request = self . get_request_as_local_from_indexes ( & ( collection_index, request_index) ) ;
89+
90+ {
91+ let mut selected_request = local_selected_request. write ( ) ;
92+ let jwt_token = selected_request. auth . get_jwt_mut ( ) ;
93+
94+ info ! ( "Auth JWT secret set to \" {}\" " , secret) ;
95+
96+ jwt_token. secret = secret. to_string ( ) ;
97+ }
98+
99+ self . save_collection_to_file ( collection_index) ;
100+ }
101+
102+ pub fn modify_request_auth_payload ( & mut self , collection_index : usize , request_index : usize , payload : String ) {
103+ let local_selected_request = self . get_request_as_local_from_indexes ( & ( collection_index, request_index) ) ;
104+
105+ {
106+ let mut selected_request = local_selected_request. write ( ) ;
107+ let jwt_token = selected_request. auth . get_jwt_mut ( ) ;
108+
109+ info ! ( "Auth JWT payload set to \" {}\" " , payload) ;
110+
111+ jwt_token. payload = payload;
112+ }
113+
114+ self . save_collection_to_file ( collection_index) ;
115+ }
116+
117+ }
0 commit comments