diff --git a/README.md b/README.md index c788594..6fde689 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,8 @@ Global Flags: --profile string Configuration profile ``` +> **Note:** Use `--source merged` flag to show only the changes that will be applied to the remote branch, instead of displaying the complete configuration difference. It ignores all skipped entities and fields. + Sample execution ``` diff --git a/internal/cac/api/source.go b/internal/cac/api/source.go index f291e56..457c259 100644 --- a/internal/cac/api/source.go +++ b/internal/cac/api/source.go @@ -13,6 +13,7 @@ var ErrUnknownSource = errors.New("unknown source") const ( SourceLocal SourceType = "local" SourceRemote SourceType = "remote" + SourceMerged SourceType = "merged" ) func SourceFromString(s string) (SourceType, error) { @@ -21,6 +22,8 @@ func SourceFromString(s string) (SourceType, error) { return SourceLocal, nil case "remote": return SourceRemote, nil + case "merged": + return SourceMerged, nil } return "", ErrUnknownSource diff --git a/internal/cac/app.go b/internal/cac/app.go index 8c874ed..f6b9f02 100644 --- a/internal/cac/app.go +++ b/internal/cac/app.go @@ -117,6 +117,34 @@ func (a *Application) PickSource(source string, tenant bool) (api.Source, error) } return c, nil + case api.SourceMerged: + var ( + c *client.Client + err error + ) + + ms, err := storage.InitMultiStorage(conf.Storage, constructor) + + if err != nil { + return nil, err + } + + storages := ms.Storages + + if c, err = client.InitClient(conf.Client); err != nil { + return nil, err + } + + if !tenant { + storages = append(storages, c) + } else { + storages = append(storages, c.Tenant()) + } + + return &storage.MultiStorage{ + Storages: storages, + Config: ms.Config, + }, nil } return nil, api.ErrUnknownSource diff --git a/internal/cac/diff/diff.go b/internal/cac/diff/diff.go index 4af34f8..c90778b 100644 --- a/internal/cac/diff/diff.go +++ b/internal/cac/diff/diff.go @@ -2,12 +2,14 @@ package diff import ( "context" + "regexp" + "github.com/cloudentity/acp-client-go/clients/hub/models" "github.com/cloudentity/cac/internal/cac/api" "github.com/cloudentity/cac/internal/cac/utils" "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "golang.org/x/exp/slog" - "regexp" ) type Options struct { @@ -162,10 +164,15 @@ func Tree(source models.Rfc7396PatchOperation, target models.Rfc7396PatchOperati diffOpts = append(diffOpts, filterSecretFields) } - var out = cmp.Diff(target, source, diffOpts) + // sorting slices to avoid diffs due to different order + diffOpts = append(diffOpts, cmpopts.SortSlices(func(a, b string) bool { + return a < b + })) + + out := cmp.Diff(target, source, diffOpts) if options.Color { - return colorize(out), nil + out = colorize(out) } return out, nil