@@ -67,14 +67,13 @@ struct PromptPart<'a> {
67
67
68
68
fn print_deployment (
69
69
parts : & [ (
70
- & data:: Target ,
71
- data:: DeployData ,
70
+ & data:: DeployData ,
72
71
data:: DeployDefs ,
73
72
) ] ,
74
73
) -> Result < ( ) , toml:: ser:: Error > {
75
74
let mut part_map: HashMap < String , HashMap < String , PromptPart > > = HashMap :: new ( ) ;
76
75
77
- for ( _ , data, defs) in parts {
76
+ for ( data, defs) in parts {
78
77
part_map
79
78
. entry ( data. node_name . to_string ( ) )
80
79
. or_insert_with ( HashMap :: new)
@@ -110,8 +109,7 @@ pub enum PromptDeploymentError {
110
109
111
110
fn prompt_deployment (
112
111
parts : & [ (
113
- & data:: Target ,
114
- data:: DeployData ,
112
+ & data:: DeployData ,
115
113
data:: DeployDefs ,
116
114
) ] ,
117
115
) -> Result < ( ) , PromptDeploymentError > {
@@ -166,12 +164,9 @@ pub enum RunDeployError {
166
164
DeployProfile ( #[ from] deploy:: deploy:: DeployProfileError ) ,
167
165
#[ error( "Failed to push profile: {0}" ) ]
168
166
PushProfile ( #[ from] deploy:: push:: PushProfileError ) ,
169
- #[ error( "No profile named `{0}` was found" ) ]
170
- ProfileNotFound ( String ) ,
171
- #[ error( "No node named `{0}` was found" ) ]
172
- NodeNotFound ( String ) ,
173
- #[ error( "Profile was provided without a node name" ) ]
174
- ProfileWithoutNode ,
167
+ #[ error( "Failed to resolve target: {0}" ) ]
168
+ ResolveTarget ( #[ from] data:: ResolveTargetError ) ,
169
+
175
170
#[ error( "Error processing deployment definitions: {0}" ) ]
176
171
DeployDataDefs ( #[ from] data:: DeployDataDefsError ) ,
177
172
#[ error( "Failed to make printable TOML of deployment: {0}" ) ]
@@ -182,13 +177,6 @@ pub enum RunDeployError {
182
177
RevokeProfile ( #[ from] deploy:: deploy:: RevokeProfileError ) ,
183
178
}
184
179
185
- type ToDeploy < ' a > = Vec < (
186
- & ' a data:: Target ,
187
- & ' a settings:: Root ,
188
- ( & ' a str , & ' a settings:: Node ) ,
189
- ( & ' a str , & ' a settings:: Profile ) ,
190
- ) > ;
191
-
192
180
async fn run_deploy (
193
181
targets : Vec < data:: Target > ,
194
182
settings : Vec < settings:: Root > ,
@@ -197,127 +185,27 @@ async fn run_deploy(
197
185
cmd_settings : settings:: GenericSettings ,
198
186
cmd_flags : data:: Flags ,
199
187
) -> Result < ( ) , RunDeployError > {
200
- let to_deploy: ToDeploy = targets
201
- . iter ( )
202
- . zip ( & settings)
203
- . map ( |( target, root) | {
204
- let to_deploys: ToDeploy = match ( & target. node , & target. profile ) {
205
- ( Some ( node_name) , Some ( profile_name) ) => {
206
- let node = match root. nodes . get ( node_name) {
207
- Some ( x) => x,
208
- None => Err ( RunDeployError :: NodeNotFound ( node_name. to_owned ( ) ) ) ?,
209
- } ;
210
- let profile = match node. node_settings . profiles . get ( profile_name) {
211
- Some ( x) => x,
212
- None => Err ( RunDeployError :: ProfileNotFound ( profile_name. to_owned ( ) ) ) ?,
213
- } ;
214
-
215
- vec ! [ (
216
- & target,
217
- & root,
218
- ( node_name. as_str( ) , node) ,
219
- ( profile_name. as_str( ) , profile) ,
220
- ) ]
221
- }
222
- ( Some ( node_name) , None ) => {
223
- let node = match root. nodes . get ( node_name) {
224
- Some ( x) => x,
225
- None => return Err ( RunDeployError :: NodeNotFound ( node_name. to_owned ( ) ) ) ,
226
- } ;
227
-
228
- let mut profiles_list: Vec < ( & str , & settings:: Profile ) > = Vec :: new ( ) ;
229
-
230
- for profile_name in [
231
- node. node_settings . profiles_order . iter ( ) . collect ( ) ,
232
- node. node_settings . profiles . keys ( ) . collect :: < Vec < & String > > ( ) ,
233
- ]
234
- . concat ( )
235
- {
236
- let profile = match node. node_settings . profiles . get ( profile_name) {
237
- Some ( x) => x,
238
- None => {
239
- return Err ( RunDeployError :: ProfileNotFound (
240
- profile_name. to_owned ( ) ,
241
- ) )
242
- }
243
- } ;
244
-
245
- if !profiles_list. iter ( ) . any ( |( n, _) | n == profile_name) {
246
- profiles_list. push ( ( & profile_name, profile) ) ;
247
- }
248
- }
249
-
250
- profiles_list
251
- . into_iter ( )
252
- . map ( |x| ( target, root, ( node_name. as_str ( ) , node) , x) )
253
- . collect ( )
254
- }
255
- ( None , None ) => {
256
- let mut l = Vec :: new ( ) ;
257
-
258
- for ( node_name, node) in & root. nodes {
259
- let mut profiles_list: Vec < ( & str , & settings:: Profile ) > = Vec :: new ( ) ;
260
-
261
- for profile_name in [
262
- node. node_settings . profiles_order . iter ( ) . collect ( ) ,
263
- node. node_settings . profiles . keys ( ) . collect :: < Vec < & String > > ( ) ,
264
- ]
265
- . concat ( )
266
- {
267
- let profile = match node. node_settings . profiles . get ( profile_name) {
268
- Some ( x) => x,
269
- None => {
270
- return Err ( RunDeployError :: ProfileNotFound (
271
- profile_name. to_owned ( ) ,
272
- ) )
273
- }
274
- } ;
275
-
276
- if !profiles_list. iter ( ) . any ( |( n, _) | n == profile_name) {
277
- profiles_list. push ( ( & profile_name, profile) ) ;
278
- }
279
- }
280
-
281
- let ll: ToDeploy = profiles_list
282
- . into_iter ( )
283
- . map ( |x| ( target, root, ( node_name. as_str ( ) , node) , x) )
284
- . collect ( ) ;
285
-
286
- l. extend ( ll) ;
287
- }
288
-
289
- l
290
- }
291
- ( None , Some ( _) ) => return Err ( RunDeployError :: ProfileWithoutNode ) ,
292
- } ;
293
- Ok ( to_deploys)
294
- } )
295
- . collect :: < Result < Vec < ToDeploy > , RunDeployError > > ( ) ?
296
- . into_iter ( )
297
- . flatten ( )
298
- . collect ( ) ;
188
+ let deploy_datas_ = targets. into_iter ( ) . zip ( & settings)
189
+ . map (
190
+ |( target, root) |
191
+ target. resolve (
192
+ & root,
193
+ & cmd_settings,
194
+ & cmd_flags,
195
+ hostname. as_deref ( ) ,
196
+ )
197
+ )
198
+ . collect :: < Result < Vec < Vec < data:: DeployData < ' _ > > > , data:: ResolveTargetError > > ( ) ?;
199
+ let deploy_datas: Vec < & data:: DeployData < ' _ > > = deploy_datas_. iter ( ) . flatten ( ) . collect ( ) ;
299
200
300
201
let mut parts: Vec < (
301
- & data:: Target ,
302
- data:: DeployData ,
202
+ & data:: DeployData ,
303
203
data:: DeployDefs ,
304
204
) > = Vec :: new ( ) ;
305
205
306
- for ( target, root, ( node_name, node) , ( profile_name, profile) ) in to_deploy {
307
- let deploy_data = data:: make_deploy_data (
308
- & root. generic_settings ,
309
- & cmd_settings,
310
- & cmd_flags,
311
- node,
312
- node_name,
313
- profile,
314
- profile_name,
315
- hostname. as_deref ( ) ,
316
- ) ;
317
-
206
+ for deploy_data in deploy_datas {
318
207
let deploy_defs = deploy_data. defs ( ) ?;
319
-
320
- parts. push ( ( target, deploy_data, deploy_defs) ) ;
208
+ parts. push ( ( deploy_data, deploy_defs) ) ;
321
209
}
322
210
323
211
if cmd_flags. interactive {
@@ -326,11 +214,11 @@ async fn run_deploy(
326
214
print_deployment ( & parts[ ..] ) ?;
327
215
}
328
216
329
- for ( target , deploy_data, deploy_defs) in & parts {
217
+ for ( deploy_data, deploy_defs) in & parts {
330
218
deploy:: push:: push_profile ( deploy:: push:: PushProfileData {
331
219
supports_flakes : & supports_flakes,
332
220
check_sigs : & cmd_flags. checksigs ,
333
- repo : & target . repo ,
221
+ repo : & deploy_data . repo ,
334
222
deploy_data : & deploy_data,
335
223
deploy_defs : & deploy_defs,
336
224
keep_result : & cmd_flags. keep_result ,
@@ -346,7 +234,7 @@ async fn run_deploy(
346
234
// In case of an error rollback any previoulsy made deployment.
347
235
// Rollbacks adhere to the global seeting to auto_rollback and secondary
348
236
// the profile's configuration
349
- for ( _ , deploy_data, deploy_defs) in & parts {
237
+ for ( deploy_data, deploy_defs) in & parts {
350
238
if let Err ( e) = deploy:: deploy:: deploy_profile ( deploy_data, deploy_defs, cmd_flags. dry_activate ) . await
351
239
{
352
240
error ! ( "{}" , e) ;
0 commit comments