-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cscli: improved hub management (#3352)
- Loading branch information
Showing
61 changed files
with
3,115 additions
and
2,649 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cliitem | ||
|
||
import ( | ||
"fmt" | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
|
||
"gopkg.in/yaml.v3" | ||
|
||
"github.com/crowdsecurity/crowdsec/pkg/cwhub" | ||
) | ||
|
||
func inspectItem(hub *cwhub.Hub, item *cwhub.Item, wantMetrics bool, output string, prometheusURL string, wantColor string) error { | ||
// This is dirty... | ||
// We want to show current dependencies (from content), not latest (from index). | ||
// The item is modifed but after this function the whole hub should be thrown away. | ||
// A cleaner way would be to copy the struct first. | ||
item.Dependencies = item.CurrentDependencies() | ||
|
||
switch output { | ||
case "human", "raw": | ||
enc := yaml.NewEncoder(os.Stdout) | ||
enc.SetIndent(2) | ||
|
||
if err := enc.Encode(item); err != nil { | ||
return fmt.Errorf("unable to encode item: %w", err) | ||
} | ||
case "json": | ||
b, err := json.MarshalIndent(*item, "", " ") | ||
if err != nil { | ||
return fmt.Errorf("unable to serialize item: %w", err) | ||
} | ||
|
||
fmt.Print(string(b)) | ||
} | ||
|
||
if output != "human" { | ||
return nil | ||
} | ||
|
||
if item.State.Tainted { | ||
fmt.Println() | ||
fmt.Printf(`This item is tainted. Use "%s %s inspect --diff %s" to see why.`, filepath.Base(os.Args[0]), item.Type, item.Name) | ||
fmt.Println() | ||
} | ||
|
||
if wantMetrics { | ||
fmt.Printf("\nCurrent metrics: \n") | ||
|
||
if err := showMetrics(prometheusURL, hub, item, wantColor); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.