Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
3 changes: 3 additions & 0 deletions internal/cac/api/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions internal/cac/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions internal/cac/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Loading