@@ -252,43 +252,12 @@ func inspectComponents(ctx context.Context, cfgPath string, opts inspectComponen
252
252
return err
253
253
}
254
254
255
- // Load the requirements before trying to load the configuration. These should always load
256
- // even if the configuration is wrong.
257
- platform , err := component .LoadPlatformDetail ()
258
- if err != nil {
259
- return fmt .Errorf ("failed to gather system information: %w" , err )
260
- }
261
- specs , err := component .LoadRuntimeSpecs (paths .Components (), platform )
262
- if err != nil {
263
- return fmt .Errorf ("failed to detect inputs and outputs: %w" , err )
264
- }
265
-
266
- isAdmin , err := utils .HasRoot ()
267
- if err != nil {
268
- return fmt .Errorf ("error checking for root/Administrator privileges: %w" , err )
269
- }
270
-
271
- m , lvl , err := getConfigWithVariables (ctx , l , cfgPath , opts .variablesWait , ! isAdmin )
255
+ comps , err := getComponentsFromPolicy (ctx , l , cfgPath , opts .variablesWait )
272
256
if err != nil {
257
+ // error already includes the context
273
258
return err
274
259
}
275
260
276
- monitorFn , err := getMonitoringFn (ctx , m )
277
- if err != nil {
278
- return fmt .Errorf ("failed to get monitoring: %w" , err )
279
- }
280
-
281
- agentInfo , err := info .NewAgentInfoWithLog (ctx , "error" , false )
282
- if err != nil {
283
- return fmt .Errorf ("could not load agent info: %w" , err )
284
- }
285
-
286
- // Compute the components from the computed configuration.
287
- comps , err := specs .ToComponents (m , monitorFn , lvl , agentInfo )
288
- if err != nil {
289
- return fmt .Errorf ("failed to render components: %w" , err )
290
- }
291
-
292
261
// Hide configuration unless toggled on.
293
262
if ! opts .showConfig {
294
263
for i , comp := range comps {
@@ -349,6 +318,47 @@ func inspectComponents(ctx context.Context, cfgPath string, opts inspectComponen
349
318
return printComponents (allowed , blocked , streams )
350
319
}
351
320
321
+ func getComponentsFromPolicy (ctx context.Context , l * logger.Logger , cfgPath string , variablesWait time.Duration ) ([]component.Component , error ) {
322
+ // Load the requirements before trying to load the configuration. These should always load
323
+ // even if the configuration is wrong.
324
+ platform , err := component .LoadPlatformDetail ()
325
+ if err != nil {
326
+ return nil , fmt .Errorf ("failed to gather system information: %w" , err )
327
+ }
328
+ specs , err := component .LoadRuntimeSpecs (paths .Components (), platform )
329
+ if err != nil {
330
+ return nil , fmt .Errorf ("failed to detect inputs and outputs: %w" , err )
331
+ }
332
+
333
+ isAdmin , err := utils .HasRoot ()
334
+ if err != nil {
335
+ return nil , fmt .Errorf ("error checking for root/Administrator privileges: %w" , err )
336
+ }
337
+
338
+ m , lvl , err := getConfigWithVariables (ctx , l , cfgPath , variablesWait , ! isAdmin )
339
+ if err != nil {
340
+ return nil , err
341
+ }
342
+
343
+ monitorFn , err := getMonitoringFn (ctx , m )
344
+ if err != nil {
345
+ return nil , fmt .Errorf ("failed to get monitoring: %w" , err )
346
+ }
347
+
348
+ agentInfo , err := info .NewAgentInfoWithLog (ctx , "error" , false )
349
+ if err != nil {
350
+ return nil , fmt .Errorf ("could not load agent info: %w" , err )
351
+ }
352
+
353
+ // Compute the components from the computed configuration.
354
+ comps , err := specs .ToComponents (m , monitorFn , lvl , agentInfo )
355
+ if err != nil {
356
+ return nil , fmt .Errorf ("failed to render components: %w" , err )
357
+ }
358
+
359
+ return comps , nil
360
+ }
361
+
352
362
func getMonitoringFn (ctx context.Context , cfg map [string ]interface {}) (component.GenerateMonitoringCfgFn , error ) {
353
363
config , err := config .NewConfigFrom (cfg )
354
364
if err != nil {
0 commit comments