Skip to content

Commit

Permalink
🧹 use new inventory-format-ansible and `inventory-format-domainlist…
Browse files Browse the repository at this point in the history
…` names for flags (#3570)

* 🧹 use new `inventory-format-ansible` and `inventory-format-domainlist` names for flags
* 🧹 update tests
* 🧹 fix extended lint tests
  • Loading branch information
chris-rock authored Mar 15, 2024
1 parent 4e32ba6 commit 781b3e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
14 changes: 12 additions & 2 deletions apps/cnquery/cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@ func init() {
scanCmd.Flags().String("platform-id", "", "Select a specific target asset by providing its platform ID.")

scanCmd.Flags().String("inventory-file", "", "Set the path to the inventory file.")
scanCmd.Flags().Bool("inventory-ansible", false, "Set the inventory format to Ansible.")
scanCmd.Flags().Bool("inventory-domainlist", false, "Set the inventory format to domain list.")

_ = scanCmd.Flags().Bool("inventory-format-ansible", false, "Set the inventory format to Ansible.")
// "inventory-ansible" is deprecated, use "inventory-format-ansible" instead
_ = scanCmd.Flags().Bool("inventory-ansible", false, "Set the inventory format to Ansible.")
_ = scanCmd.Flags().MarkDeprecated("inventory-ansible", "use --inventory-format-ansible")
_ = scanCmd.Flags().MarkHidden("inventory-ansible")

_ = scanCmd.Flags().Bool("inventory-format-domainlist", false, "Set the inventory format to domain list.")
// "inventory-domainlist" is deprecated, use "inventory-format-domainlist" instead
_ = scanCmd.Flags().Bool("inventory-domainlist", false, "Set the inventory format to domain list.")
_ = scanCmd.Flags().MarkDeprecated("inventory-domainlist", "use --inventory-format-domainlist")
_ = scanCmd.Flags().MarkHidden("inventory-domainlist")

// bundles, packs & incognito mode
scanCmd.Flags().Bool("incognito", false, "Run in incognito mode. Do not report scan results to Mondoo Platform.")
Expand Down
6 changes: 4 additions & 2 deletions cli/inventoryloader/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func Parse() (*inventory.Inventory, error) {
}

// force detection
if viper.GetBool("inventory-ansible") {
if viper.GetBool("inventory-format-ansible") || viper.GetBool("inventory-ansible") {
log.Debug().Msg("parse ansible inventory")
inventory, err := parseAnsibleInventory(data)
if err != nil {
Expand All @@ -90,7 +90,7 @@ func Parse() (*inventory.Inventory, error) {
return inventory, nil
}

if viper.GetBool("inventory-domainlist") {
if viper.GetBool("inventory-format-domainlist") || viper.GetBool("inventory-domainlist") {
log.Debug().Msg("parse domainlist inventory")
inventory, err := parseDomainListInventory(data)
if err != nil {
Expand Down Expand Up @@ -119,6 +119,7 @@ func Parse() (*inventory.Inventory, error) {
}

func parseAnsibleInventory(data []byte) (*inventory.Inventory, error) {
log.Info().Msg("use ansible inventory")
inventory, err := ansibleinventory.Parse(data)
if err != nil {
return nil, err
Expand All @@ -127,6 +128,7 @@ func parseAnsibleInventory(data []byte) (*inventory.Inventory, error) {
}

func parseDomainListInventory(data []byte) (*inventory.Inventory, error) {
log.Info().Msg("use domainlist inventory")
inventory, err := domainlist.Parse(bytes.NewReader(data))
if err != nil {
return nil, err
Expand Down
28 changes: 14 additions & 14 deletions test/cli/testdata/cnquery_scan.ct
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ Available Commands:
mock Scan use a recording without an active connection

Flags:
--annotation stringToString Add an annotation to the asset. (default [])
--asset-name string User-override for the asset name
--detect-cicd Try to detect CI/CD environments. If detected, set the asset category to 'cicd'. (default true)
-h, --help help for scan
--incognito Run in incognito mode. Do not report scan results to Mondoo Platform.
--inventory-ansible Set the inventory format to Ansible.
--inventory-domainlist Set the inventory format to domain list.
--inventory-file string Set the path to the inventory file.
-j, --json Run the query and return the object in a JSON structure.
-o, --output string Set output format: compact, csv, full, json, summary, yaml (default "compact")
--platform-id string Select a specific target asset by providing its platform ID.
--props stringToString Custom values for properties (default [])
--querypack querypack-bundle Set the query packs to execute. This requires querypack-bundle. You can specify multiple UIDs.
-f, --querypack-bundle strings Path to local query pack file
--annotation stringToString Add an annotation to the asset. (default [])
--asset-name string User-override for the asset name
--detect-cicd Try to detect CI/CD environments. If detected, set the asset category to 'cicd'. (default true)
-h, --help help for scan
--incognito Run in incognito mode. Do not report scan results to Mondoo Platform.
--inventory-file string Set the path to the inventory file.
--inventory-format-ansible Set the inventory format to Ansible.
--inventory-format-domainlist Set the inventory format to domain list.
-j, --json Run the query and return the object in a JSON structure.
-o, --output string Set output format: compact, csv, full, json, summary, yaml (default "compact")
--platform-id string Select a specific target asset by providing its platform ID.
--props stringToString Custom values for properties (default [])
--querypack querypack-bundle Set the query packs to execute. This requires querypack-bundle. You can specify multiple UIDs.
-f, --querypack-bundle strings Path to local query pack file

Global Flags:
--api-proxy string Set proxy for communications with Mondoo API
Expand Down

0 comments on commit 781b3e3

Please sign in to comment.