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

⭐️ inventory template support #3940

Merged
merged 1 commit into from
May 8, 2024
Merged

Conversation

chris-rock
Copy link
Member

@chris-rock chris-rock commented May 8, 2024

When cnquery is used in CI/CD pipelines, users want to leverage the inventory file which allows a lot of pre-configuration. If you want to scan different assets for different environments you also want to re-use the same template but allow some custom variables so that usage in CI/CD is easier. This PR introduces inventory templates. Just define a template and use the getenv function to access environment variables:

spec:
  assets:
    - name: {{ getenv "ASSET_NAME" }}
      connections:
        - type: local
          discover:
            targets:
              - auto
      annotations:
        application:  {{ getenv "APPLICATION" }}

This inventory can now be used as following:

ASSET_NAME="my_asset" APPLICATION="my-super-app" cnquery scan --inventory-template template.yaml

@chris-rock chris-rock force-pushed the chris-rock/inventory-template branch 2 times, most recently from 6f2bc2a to 109bf5b Compare May 8, 2024 09:32
@@ -214,16 +214,12 @@ func getCobraScanConfig(cmd *cobra.Command, runtime *providers.Runtime, cliRes *
config.DisplayUsedConfig()

props := viper.GetStringMapString("props")
annotations := viper.GetStringMapString("annotation")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the binding was wrong, so this never worked before

// for all assets
_ = viper.BindPFlag("incognito", cmd.Flags().Lookup("incognito"))
_ = viper.BindPFlag("insecure", cmd.Flags().Lookup("insecure"))
_ = viper.BindPFlag("querypacks", cmd.Flags().Lookup("querypack"))
_ = viper.BindPFlag("sudo.active", cmd.Flags().Lookup("sudo"))
_ = viper.BindPFlag("record", cmd.Flags().Lookup("record"))
// NOTE: we may "annotation" to "annotations" to align it with the internal config struct
_ = viper.BindPFlag("annotations", cmd.Flags().Lookup("annotation"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required since the options use "annotations"

@chris-rock chris-rock force-pushed the chris-rock/inventory-template branch from 109bf5b to 2e5bf05 Compare May 8, 2024 09:38
Copy link
Member

@imilchev imilchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

github-actions bot commented May 8, 2024

Test Results

2 985 tests  +1   2 984 ✅ +1   1m 19s ⏱️ -5s
  329 suites ±0       1 💤 ±0 
   23 files   ±0       0 ❌ ±0 

Results for commit 2e5bf05. ± Comparison against base commit 3a2bb65.

This pull request removes 3 and adds 4 tests. Note that renamed tests count towards both.
go.mondoo.com/cnquery/v11/llx ‑ TestSuccess/2024-05-07_10:21:28.867063803_+0000_UTC_m=+0.007198754
go.mondoo.com/cnquery/v11/llx ‑ TestTruthy/2024-05-07_10:21:28.867063803_+0000_UTC_m=+0.007198754
go.mondoo.com/cnquery/v11/llx ‑ TestTruthy/2024-05-07_10:21:28.867063803_+0000_UTC_m=+0.007198754#01
go.mondoo.com/cnquery/v11/cli/inventoryloader ‑ TestInventoryTemplate
go.mondoo.com/cnquery/v11/llx ‑ TestSuccess/2024-05-07_10:26:48.980076762_+0000_UTC_m=+0.015816193
go.mondoo.com/cnquery/v11/llx ‑ TestTruthy/2024-05-07_10:26:48.980076762_+0000_UTC_m=+0.015816193
go.mondoo.com/cnquery/v11/llx ‑ TestTruthy/2024-05-07_10:26:48.980076762_+0000_UTC_m=+0.015816193#01

@chris-rock chris-rock merged commit da9236b into main May 8, 2024
15 checks passed
@chris-rock chris-rock deleted the chris-rock/inventory-template branch May 8, 2024 09:50
@github-actions github-actions bot locked and limited conversation to collaborators May 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants