@@ -32,17 +32,20 @@ pub enum AliasConfig {
3232 url : String ,
3333 #[ serde( skip_serializing_if = "Option::is_none" ) ]
3434 token : Option < String > ,
35+ #[ serde( default , skip_serializing_if = "std::ops::Not::not" ) ]
36+ insecure : bool ,
3537 } ,
3638 Db {
3739 database_url : String ,
3840 } ,
3941}
4042
4143impl AliasConfig {
42- pub fn api ( url : impl Into < String > , token : Option < String > ) -> Self {
44+ pub fn api ( url : impl Into < String > , token : Option < String > , insecure : bool ) -> Self {
4345 Self :: Api {
4446 url : url. into ( ) ,
4547 token,
48+ insecure,
4649 }
4750 }
4851
@@ -71,7 +74,10 @@ pub struct Config {
7174impl Default for Config {
7275 fn default ( ) -> Self {
7376 let mut aliases = HashMap :: new ( ) ;
74- aliases. insert ( "cloud" . to_string ( ) , AliasConfig :: api ( DEFAULT_API_URL , None ) ) ;
77+ aliases. insert (
78+ "cloud" . to_string ( ) ,
79+ AliasConfig :: api ( DEFAULT_API_URL , None , false ) ,
80+ ) ;
7581
7682 Self {
7783 version : 1 ,
@@ -163,30 +169,51 @@ mod tests {
163169
164170 #[ test]
165171 fn test_alias_config_api ( ) {
166- let alias = AliasConfig :: api ( "https://example.com/api" , Some ( "token123" . to_string ( ) ) ) ;
172+ let alias = AliasConfig :: api (
173+ "https://example.com/api" ,
174+ Some ( "token123" . to_string ( ) ) ,
175+ false ,
176+ ) ;
167177
168178 assert_eq ! ( alias. type_name( ) , "api" ) ;
169179
170- if let AliasConfig :: Api { url, token } = alias {
180+ if let AliasConfig :: Api {
181+ url,
182+ token,
183+ insecure,
184+ } = alias
185+ {
171186 assert_eq ! ( url, "https://example.com/api" ) ;
172187 assert_eq ! ( token, Some ( "token123" . to_string( ) ) ) ;
188+ assert ! ( !insecure) ;
173189 } else {
174190 panic ! ( "Expected Api variant" ) ;
175191 }
176192 }
177193
178194 #[ test]
179195 fn test_alias_config_api_no_token ( ) {
180- let alias = AliasConfig :: api ( "https://example.com/api" , None ) ;
196+ let alias = AliasConfig :: api ( "https://example.com/api" , None , false ) ;
181197
182- if let AliasConfig :: Api { url, token } = alias {
198+ if let AliasConfig :: Api { url, token, .. } = alias {
183199 assert_eq ! ( url, "https://example.com/api" ) ;
184200 assert ! ( token. is_none( ) ) ;
185201 } else {
186202 panic ! ( "Expected Api variant" ) ;
187203 }
188204 }
189205
206+ #[ test]
207+ fn test_alias_config_api_insecure ( ) {
208+ let alias = AliasConfig :: api ( "https://dev.localhost/api" , None , true ) ;
209+
210+ if let AliasConfig :: Api { insecure, .. } = alias {
211+ assert ! ( insecure) ;
212+ } else {
213+ panic ! ( "Expected Api variant" ) ;
214+ }
215+ }
216+
190217 #[ test]
191218 fn test_alias_config_db ( ) {
192219 let alias = AliasConfig :: db ( "postgres://user:pass@localhost/db" ) ;
@@ -211,7 +238,7 @@ mod tests {
211238 let cloud = config. aliases . get ( "cloud" ) . unwrap ( ) ;
212239 assert_eq ! ( cloud. type_name( ) , "api" ) ;
213240
214- if let AliasConfig :: Api { url, token } = cloud {
241+ if let AliasConfig :: Api { url, token, .. } = cloud {
215242 assert_eq ! ( url, DEFAULT_API_URL ) ;
216243 assert ! ( token. is_none( ) ) ;
217244 }
@@ -231,7 +258,7 @@ mod tests {
231258
232259 let result = config. set_alias (
233260 "prod" ,
234- AliasConfig :: api ( "https://prod.example.com" , None ) ,
261+ AliasConfig :: api ( "https://prod.example.com" , None , false ) ,
235262 false ,
236263 ) ;
237264
@@ -243,7 +270,11 @@ mod tests {
243270 fn test_set_alias_exists_no_force ( ) {
244271 let mut config = Config :: default ( ) ;
245272
246- let result = config. set_alias ( "cloud" , AliasConfig :: api ( "https://other.com" , None ) , false ) ;
273+ let result = config. set_alias (
274+ "cloud" ,
275+ AliasConfig :: api ( "https://other.com" , None , false ) ,
276+ false ,
277+ ) ;
247278
248279 assert ! ( matches!( result, Err ( ConfigError :: AliasExists ( _) ) ) ) ;
249280 }
@@ -253,7 +284,7 @@ mod tests {
253284 let mut config = Config :: default ( ) ;
254285 let new_url = "https://new.example.com" ;
255286
256- let result = config. set_alias ( "cloud" , AliasConfig :: api ( new_url, None ) , true ) ;
287+ let result = config. set_alias ( "cloud" , AliasConfig :: api ( new_url, None , false ) , true ) ;
257288
258289 assert ! ( result. is_ok( ) ) ;
259290
@@ -301,7 +332,7 @@ mod tests {
301332 config
302333 . set_alias (
303334 "prod" ,
304- AliasConfig :: api ( "https://prod.example.com" , None ) ,
335+ AliasConfig :: api ( "https://prod.example.com" , None , false ) ,
305336 false ,
306337 )
307338 . unwrap ( ) ;
@@ -323,14 +354,18 @@ mod tests {
323354
324355 #[ test]
325356 fn test_json_serialization_api ( ) {
326- let alias = AliasConfig :: api ( "https://example.com/api" , Some ( "token123" . to_string ( ) ) ) ;
357+ let alias = AliasConfig :: api (
358+ "https://example.com/api" ,
359+ Some ( "token123" . to_string ( ) ) ,
360+ false ,
361+ ) ;
327362
328363 let json = serde_json:: to_string ( & alias) . unwrap ( ) ;
329364 let parsed: AliasConfig = serde_json:: from_str ( & json) . unwrap ( ) ;
330365
331366 assert_eq ! ( parsed. type_name( ) , "api" ) ;
332367
333- if let AliasConfig :: Api { url, token } = parsed {
368+ if let AliasConfig :: Api { url, token, .. } = parsed {
334369 assert_eq ! ( url, "https://example.com/api" ) ;
335370 assert_eq ! ( token, Some ( "token123" . to_string( ) ) ) ;
336371 }
@@ -368,7 +403,7 @@ mod tests {
368403
369404 #[ test]
370405 fn test_json_api_without_token_skips_field ( ) {
371- let alias = AliasConfig :: api ( "https://example.com" , None ) ;
406+ let alias = AliasConfig :: api ( "https://example.com" , None , false ) ;
372407
373408 let json = serde_json:: to_string ( & alias) . unwrap ( ) ;
374409
0 commit comments