@@ -260,16 +260,18 @@ pub struct DeployData<'a> {
260
260
pub node_name : String ,
261
261
pub profile_name : String ,
262
262
263
- pub hostname : Option < & ' a str > ,
264
-
265
263
pub flags : & ' a Flags ,
266
264
pub node : & ' a settings:: Node ,
267
265
pub profile : & ' a settings:: Profile ,
268
266
pub merged_settings : settings:: GenericSettings ,
269
267
268
+ pub hostname : & ' a str ,
269
+
270
270
pub ssh_user : String ,
271
+ pub ssh_uri : String ,
271
272
pub temp_path : String ,
272
273
pub profile_path : String ,
274
+ pub profile_user : String ,
273
275
pub sudo : Option < String > ,
274
276
}
275
277
@@ -318,14 +320,6 @@ pub struct Flags {
318
320
pub rollback_succeeded : bool ,
319
321
}
320
322
321
- #[ derive( Debug ) ]
322
- pub struct DeployDefs {
323
- pub ssh_user : String ,
324
- pub profile_user : String ,
325
- pub profile_path : String ,
326
- pub sudo : Option < String > ,
327
- }
328
-
329
323
impl < ' a > DeployData < ' a > {
330
324
331
325
fn new (
@@ -351,14 +345,10 @@ impl<'a> DeployData<'a> {
351
345
Some ( ref x) => x. to_owned ( ) ,
352
346
None => "/tmp" . to_string ( ) ,
353
347
} ;
354
- let profile_user = match merged_settings. user {
355
- Some ( ref x) => x. to_owned ( ) ,
356
- None => match merged_settings. ssh_user {
357
- Some ( ref x) => x. to_owned ( ) ,
358
- None => {
359
- return Err ( DeployDataError :: NoProfileUser ( profile_name, node_name) )
360
- }
361
- } ,
348
+ let profile_user = if let Some ( ref x) = merged_settings. user { x. to_owned ( ) } else {
349
+ if let Some ( ref x) = merged_settings. ssh_user { x. to_owned ( ) } else {
350
+ return Err ( DeployDataError :: NoProfileUser ( profile_name, node_name) )
351
+ }
362
352
} ;
363
353
let profile_path = match profile. profile_settings . profile_path {
364
354
None => format ! ( "/nix/var/nix/profiles/{}" , match & profile_user[ ..] {
@@ -375,6 +365,11 @@ impl<'a> DeployData<'a> {
375
365
Some ( ref user) if user != & ssh_user => Some ( format ! ( "sudo -u {}" , user) ) ,
376
366
_ => None ,
377
367
} ;
368
+ let hostname = match hostname {
369
+ Some ( x) => x,
370
+ None => & node. node_settings . hostname ,
371
+ } ;
372
+ let ssh_uri = format ! ( "ssh://{}@{}" , & ssh_user, & hostname) ;
378
373
379
374
Ok ( DeployData {
380
375
repo,
@@ -384,114 +379,13 @@ impl<'a> DeployData<'a> {
384
379
profile,
385
380
hostname,
386
381
ssh_user,
382
+ ssh_uri,
387
383
temp_path,
388
384
profile_path,
385
+ profile_user,
389
386
sudo,
390
387
flags,
391
388
merged_settings,
392
389
} )
393
390
}
394
-
395
- pub fn defs ( & ' a self ) -> Result < DeployDefs , DeployDataError > {
396
- let ssh_user = match self . merged_settings . ssh_user {
397
- Some ( ref u) => u. clone ( ) ,
398
- None => whoami:: username ( ) ,
399
- } ;
400
- let profile_user = self . get_profile_user ( ) ?;
401
- let profile_path = self . get_profile_path ( ) ?;
402
- let sudo = self . sudo ( ) ?;
403
-
404
- Ok ( DeployDefs {
405
- ssh_user,
406
- profile_user,
407
- profile_path,
408
- sudo,
409
- } )
410
- }
411
-
412
- pub fn sudo ( & ' a self ) -> Result < Option < String > , DeployDataError > {
413
- let ssh_user = match self . merged_settings . ssh_user {
414
- Some ( ref u) => u. clone ( ) ,
415
- None => whoami:: username ( ) ,
416
- } ;
417
- Ok (
418
- match self . merged_settings . user {
419
- Some ( ref user) if user != & ssh_user => Some ( format ! ( "sudo -u {}" , user) ) ,
420
- _ => None ,
421
- }
422
- )
423
- }
424
-
425
- pub fn temp_path ( & ' a self ) -> Result < String , DeployDataError > {
426
- Ok (
427
- match self . merged_settings . temp_path {
428
- Some ( ref x) => x. to_owned ( ) ,
429
- None => "/tmp" . to_string ( ) ,
430
- }
431
- )
432
- }
433
-
434
- pub fn ssh_uri ( & ' a self ) -> Result < String , DeployDataError > {
435
-
436
- let hostname = match self . hostname {
437
- Some ( x) => x,
438
- None => & self . node . node_settings . hostname ,
439
- } ;
440
- let curr_user = & whoami:: username ( ) ;
441
- let ssh_user = match self . merged_settings . ssh_user {
442
- Some ( ref u) => u,
443
- None => curr_user,
444
- } ;
445
- Ok ( format ! ( "ssh://{}@{}" , ssh_user, hostname) )
446
- }
447
-
448
- // can be dropped once ssh fully supports ipv6 uris
449
- pub fn ssh_non_uri ( & ' a self ) -> Result < String , DeployDataError > {
450
-
451
- let hostname = match self . hostname {
452
- Some ( x) => x,
453
- None => & self . node . node_settings . hostname ,
454
- } ;
455
- let curr_user = & whoami:: username ( ) ;
456
- let ssh_user = match self . merged_settings . ssh_user {
457
- Some ( ref u) => u,
458
- None => curr_user,
459
- } ;
460
- Ok ( format ! ( "{}@{}" , ssh_user, hostname) )
461
- }
462
-
463
- pub fn ssh_opts ( & ' a self ) -> Result < impl Iterator < Item = & String > , DeployDataError > {
464
- Ok ( self . merged_settings . ssh_opts . iter ( ) )
465
- }
466
-
467
- pub fn get_profile_path ( & ' a self ) -> Result < String , DeployDataError > {
468
- let profile_user = self . get_profile_user ( ) ?;
469
- let profile_path = match self . profile . profile_settings . profile_path {
470
- None => match & profile_user[ ..] {
471
- "root" => format ! ( "/nix/var/nix/profiles/{}" , self . profile_name) ,
472
- _ => format ! (
473
- "/nix/var/nix/profiles/per-user/{}/{}" ,
474
- profile_user, self . profile_name
475
- ) ,
476
- } ,
477
- Some ( ref x) => x. clone ( ) ,
478
- } ;
479
- Ok ( profile_path)
480
- }
481
-
482
- pub fn get_profile_user ( & ' a self ) -> Result < String , DeployDataError > {
483
- let profile_user = match self . merged_settings . user {
484
- Some ( ref x) => x. clone ( ) ,
485
- None => match self . merged_settings . ssh_user {
486
- Some ( ref x) => x. clone ( ) ,
487
- None => {
488
- return Err ( DeployDataError :: NoProfileUser (
489
- self . profile_name . to_owned ( ) ,
490
- self . node_name . to_owned ( ) ,
491
- ) )
492
- }
493
- } ,
494
- } ;
495
- Ok ( profile_user)
496
- }
497
391
}
0 commit comments