Skip to content

Commit ae1c865

Browse files
committed
hub integration
Signed-off-by: Emily McMullan <[email protected]>
1 parent 15a4d99 commit ae1c865

File tree

9 files changed

+2638
-1188
lines changed

9 files changed

+2638
-1188
lines changed

cmd/analyze.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,35 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
148148
}
149149

150150
// get profile options for analysis
151-
profile := &Profile{}
152151
if analyzeCmd.profile != "" {
152+
stat, err := os.Stat(analyzeCmd.profile)
153+
if err != nil {
154+
return fmt.Errorf("failed to stat profiles directory %s: %w", analyzeCmd.profile, err)
155+
}
156+
157+
if !stat.IsDir() {
158+
return fmt.Errorf("found profiles path %s is not a directory", analyzeCmd.profile)
159+
}
153160
profilePath := filepath.Join(analyzeCmd.profile, "profile.yaml")
154-
err := analyzeCmd.getSettingsFromProfile(profilePath)
161+
err = analyzeCmd.setSettingsFromProfile(profilePath, cmd)
155162
if err != nil {
156163
analyzeCmd.log.Error(err, "failed to get settings from profile")
157164
return err
158165
}
159166
} else {
160-
// check for profile in default path
161-
// TODO profile names
162-
profilePath := filepath.Join(profilePath, "profile-.yaml")
163-
_, err := os.Stat(profilePath)
164-
// do not return err if profile is not found
167+
// check for a single profile in default path
168+
profilesDir := filepath.Join(analyzeCmd.input, ProfilePath)
169+
profilePath, err := analyzeCmd.findSingleProfile(profilesDir)
165170
if err != nil {
166-
return nil
171+
analyzeCmd.log.Error(err, "did not find valid profile in default path")
167172
}
168-
err = analyzeCmd.getSettingsFromProfile(profilePath)
169-
if err != nil {
170-
analyzeCmd.log.Error(err, "failed to get settings from profile")
171-
return err
173+
if profilePath != "" {
174+
analyzeCmd.log.Info("using found profile", "profile", profilePath)
175+
err = analyzeCmd.setSettingsFromProfile(profilePath, cmd)
176+
if err != nil {
177+
analyzeCmd.log.Error(err, "failed to get settings from profile")
178+
return err
179+
}
172180
}
173181
}
174182

@@ -302,6 +310,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
302310
}
303311
// Note: CreateJSONOutput and GenerateStaticReport are already called
304312
// within RunAnalysisHybridInProcess, so no need to call them here
313+
305314
return nil
306315
},
307316
}
@@ -356,12 +365,6 @@ func (a *analyzeCommand) Validate(ctx context.Context, cmd *cobra.Command) error
356365
return nil
357366
}
358367

359-
if a.profile != "" {
360-
err := a.validateProfile(cmd)
361-
if err != nil {
362-
return err
363-
}
364-
}
365368
if a.labelSelector != "" && (len(a.sources) > 0 || len(a.targets) > 0) {
366369
return fmt.Errorf("must not specify label-selector and sources or targets")
367370
}

0 commit comments

Comments
 (0)