Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix fail if config file not found #608

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/cnspec/cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ var policyPublishCmd = &cobra.Command{
if optsErr != nil {
log.Fatal().Err(optsErr).Msg("could not load configuration")
}
err := config.ValidateUserProvidedConfigPath()
if err != nil {
log.Fatal().Err(err).Msg("Could not load user provided config")
}
config.DisplayUsedConfig()

filename := args[0]
Expand Down
4 changes: 4 additions & 0 deletions apps/cnspec/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func register(token string) {
}

// print the used config to the user
err := config.ValidateUserProvidedConfigPath()
if err != nil {
log.Fatal().Err(err).Msg("Could not load user provided config")
}
config.DisplayUsedConfig()

httpClient, err = opts.GetHttpClient()
Expand Down
4 changes: 4 additions & 0 deletions apps/cnspec/cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ the credentials cannot be used in future anymore.
}

// print the used config to the user
err = config.ValidateUserProvidedConfigPath()
if err != nil {
log.Fatal().Err(err).Msg("Could not load user provided config")
}
config.DisplayUsedConfig()

// determine information about the client
Expand Down
6 changes: 5 additions & 1 deletion apps/cnspec/cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ func getCobraScanConfig(cmd *cobra.Command, args []string, provider providers.Pr
if optsErr != nil {
log.Fatal().Err(optsErr).Msg("could not load configuration")
}
var err error
err = config.ValidateUserProvidedConfigPath()
if err != nil {
log.Fatal().Err(err).Msg("Could not load user provided config")
}
config.DisplayUsedConfig()

// display activated features
Expand All @@ -484,7 +489,6 @@ func getCobraScanConfig(cmd *cobra.Command, args []string, provider providers.Pr
}

props := map[string]string{}
var err error
propsFlag := cmd.Flags().Lookup("props")
if propsFlag != nil {
props, err = cmd.Flags().GetStringToString("props")
Expand Down
4 changes: 4 additions & 0 deletions apps/cnspec/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func getServeConfig() (*scanConfig, error) {
if optsErr != nil {
log.Fatal().Err(optsErr).Msg("could not load configuration")
}
err := config.ValidateUserProvidedConfigPath()
if err != nil {
log.Fatal().Err(err).Msg("Could not load user provided config")
}
config.DisplayUsedConfig()

logClientInfo(opts.SpaceMrn, opts.AgentMrn, opts.ServiceAccountMrn)
Expand Down
4 changes: 4 additions & 0 deletions apps/cnspec/cmd/serve_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ var serveApiCmd = &cobra.Command{
if optsErr != nil {
log.Fatal().Err(optsErr).Msg("could not load configuration")
}
err := config.ValidateUserProvidedConfigPath()
if err != nil {
log.Fatal().Err(err).Msg("Could not load user provided config")
}
config.DisplayUsedConfig()

serviceAccount := opts.GetServiceCredential()
Expand Down
4 changes: 4 additions & 0 deletions apps/cnspec/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Status sends a ping to Mondoo Platform to verify the credentials.
log.Fatal().Err(optsErr).Msg("could not load configuration")
}

err := config.ValidateUserProvidedConfigPath()
if err != nil {
log.Fatal().Err(err).Msg("Could not load user provided config")
}
config.DisplayUsedConfig()

s := Status{
Expand Down