-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add azldev advanced ct-tools config-dump command
#55
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
Open
sameluch
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
sameluch:add-ct-tools-config-dump
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4966c86
feat: add `azldev advanced ct-tools config-dump` command
sameluch fd80dee
refactor: address PR review for ct-tools config-dump
sameluch 73e4ba4
fix: improve determinism and error handling in ct-tools config-dump
sameluch 3ec2824
fix: use repo-relative path for scenario test data in ct-tools test
sameluch f3d59de
fix: replace visited set with recursion stack for cycle detection
sameluch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
docs/user/reference/cli/azldev_advanced_ct-tools_config-dump.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,94 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package advanced | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/microsoft/azure-linux-dev-tools/internal/app/azldev" | ||
| "github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/core/cttools" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func ctToolsOnAppInit(_ *azldev.App, parentCmd *cobra.Command) { | ||
| parentCmd.AddCommand(NewCTToolsCmd()) | ||
| } | ||
|
|
||
| // Constructs a [cobra.Command] for the "ct-tools" subcommand hierarchy. | ||
| func NewCTToolsCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "ct-tools", | ||
| Short: "Control Tower tools", | ||
| Long: `Control Tower tools for working with distro configuration. | ||
|
|
||
| Provides utilities for parsing, resolving, and dumping the fully merged | ||
| distro configuration used by Control Tower environments.`, | ||
| } | ||
|
|
||
| cmd.AddCommand(NewConfigDumpCmd()) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| // Options controlling the config-dump command. | ||
| type ConfigDumpOptions struct { | ||
| // Path to the top-level TOML configuration file. | ||
| ConfigPath string | ||
| // The Control Tower environment to filter for (e.g. "ct-dev"). | ||
| Environment string | ||
| } | ||
|
|
||
| // Constructs a [cobra.Command] for the "ct-tools config-dump" subcommand. | ||
| func NewConfigDumpCmd() *cobra.Command { | ||
| options := &ConfigDumpOptions{} | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "config-dump", | ||
| Short: "Dump fully resolved distro config", | ||
| Long: `Parse and resolve all distro configuration TOML files starting from a | ||
| top-level file, merge includes, expand all templates (koji-targets, | ||
| build-roots, mock-options), and output the fully resolved configuration | ||
| filtered to a specific Control Tower environment.`, | ||
| Example: ` # Dump config for ct-dev as JSON | ||
| azldev advanced ct-tools config-dump \ | ||
| --ct-config /path/to/azurelinux.toml \ | ||
| --environment ct-dev -O json`, | ||
| RunE: azldev.RunFuncWithoutRequiredConfig(func(env *azldev.Env) (results interface{}, err error) { | ||
| return RunConfigDump(env, options) | ||
| }), | ||
| } | ||
sameluch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| cmd.Flags().StringVar( | ||
| &options.ConfigPath, "ct-config", "", | ||
| "Path to the top-level CT distro TOML configuration file", | ||
| ) | ||
|
|
||
| envHelp := "Control Tower environment name " + | ||
| "(e.g. ct-dev, ct-staging, ct-prod)" | ||
| cmd.Flags().StringVar(&options.Environment, "environment", "", envHelp) | ||
|
|
||
| _ = cmd.MarkFlagRequired("ct-config") | ||
| _ = cmd.MarkFlagRequired("environment") | ||
| _ = cmd.MarkFlagFilename("ct-config", "toml") | ||
|
|
||
| return cmd | ||
sameluch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // RunConfigDump loads, resolves, filters, and returns the distro configuration. | ||
| func RunConfigDump(env *azldev.Env, options *ConfigDumpOptions) (*cttools.DistroConfig, error) { | ||
| config, err := cttools.LoadConfig(env.FS(), options.ConfigPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to load config from %#q:\n%w", options.ConfigPath, err) | ||
| } | ||
|
|
||
| if err := cttools.ResolveTemplates(config); err != nil { | ||
| return nil, fmt.Errorf("failed to resolve templates:\n%w", err) | ||
| } | ||
|
|
||
| if err := cttools.FilterEnvironment(config, options.Environment); err != nil { | ||
| return nil, fmt.Errorf("failed to filter environment:\n%w", err) | ||
| } | ||
|
|
||
| return config, nil | ||
| } | ||
This file contains hidden or 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,41 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package advanced_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/advanced" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestNewCTToolsCmd(t *testing.T) { | ||
| cmd := advanced.NewCTToolsCmd() | ||
| require.NotNil(t, cmd) | ||
| assert.Equal(t, "ct-tools", cmd.Use) | ||
| } | ||
|
|
||
| func TestNewConfigDumpCmd(t *testing.T) { | ||
| cmd := advanced.NewConfigDumpCmd() | ||
| require.NotNil(t, cmd) | ||
| assert.Equal(t, "config-dump", cmd.Use) | ||
| } | ||
|
|
||
| func TestCTToolsCmd_HasConfigDumpSubcommand(t *testing.T) { | ||
| cmd := advanced.NewCTToolsCmd() | ||
|
|
||
| subCmds := cmd.Commands() | ||
| found := false | ||
|
|
||
| for _, sub := range subCmds { | ||
| if sub.Use == "config-dump" { | ||
| found = true | ||
|
|
||
| break | ||
| } | ||
| } | ||
|
|
||
| assert.True(t, found, "ct-tools should have config-dump subcommand") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.