Skip to content

Commit

Permalink
⭐️ install provider before lint and fmt (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock authored Oct 18, 2023
1 parent fb706c9 commit 94f702e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apps/cnspec/cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ func init() {
rootCmd.AddCommand(policyBundlesCmd)
}

// ensureProviders ensures that all providers are locally installed
func ensureProviders() error {
providerList := []string{}

for k := range providers.DefaultProviders {
providerList = append(providerList, k)
}

// ensure that the providers are loaded
for _, connectionName := range providerList {
if _, err := providers.EnsureProvider(connectionName, "", true, nil); err != nil {
return err
}
}
return nil
}

var policyBundlesCmd = &cobra.Command{
Use: "bundle",
Short: "Manage policy bundles.",
Expand Down Expand Up @@ -87,6 +104,7 @@ var policyLintCmd = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {
log.Info().Str("file", args[0]).Msg("lint policy bundle")
ensureProviders()

files, err := policy.WalkPolicyBundleFiles(args[0])
if err != nil {
Expand Down Expand Up @@ -135,6 +153,7 @@ var policyFmtCmd = &cobra.Command{
Short: "Apply style formatting to one or more policy bundles.",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ensureProviders()
for _, path := range args {
err := bundle.FormatRecursive(path)
if err != nil {
Expand Down Expand Up @@ -163,6 +182,8 @@ var policyPublishCmd = &cobra.Command{
}
config.DisplayUsedConfig()

ensureProviders()

filename := args[0]
log.Info().Str("file", filename).Msg("load policy bundle")
files, err := policy.WalkPolicyBundleFiles(args[0])
Expand Down

0 comments on commit 94f702e

Please sign in to comment.