Skip to content

Commit

Permalink
pass through diffs and replaces
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Nov 21, 2024
1 parent 0a9ec74 commit 4fe072a
Showing 1 changed file with 11 additions and 45 deletions.
56 changes: 11 additions & 45 deletions pkg/pf/internal/plugin/provider_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"context"
"encoding/json"
"fmt"
"sort"
"strings"

"github.com/blang/semver"
pbempty "github.com/golang/protobuf/ptypes/empty"
Expand Down Expand Up @@ -92,55 +90,23 @@ func (p *providerServer) marshalDiff(diff plugin.DiffResult) (*pulumirpc.DiffRes
// Infer the result from the detailed diff.
var diffs, replaces []string
var detailedDiff map[string]*pulumirpc.PropertyDiff
if len(diff.DetailedDiff) == 0 {
diffs = make([]string, len(diff.ChangedKeys))
for i, k := range diff.ChangedKeys {
diffs[i] = string(k)
}
replaces = make([]string, len(diff.ReplaceKeys))
for i, k := range diff.ReplaceKeys {
replaces[i] = string(k)
}
} else {
changes = pulumirpc.DiffResponse_DIFF_SOME

properties := map[string]struct{}{}
if len(diff.DetailedDiff) != 0 {
detailedDiff = make(map[string]*pulumirpc.PropertyDiff)
for path, diff := range diff.DetailedDiff {
for k := range detailedDiff {
// Turn the attribute name into a top-level property name by trimming everything after the first dot.
if firstSep := strings.IndexAny(k, ".["); firstSep != -1 {
k = k[:firstSep]
}
properties[k] = struct{}{}
}

var kind pulumirpc.PropertyDiff_Kind
switch diff.Kind {
case pl.DiffAdd:
kind = pulumirpc.PropertyDiff_ADD
case pl.DiffAddReplace:
kind, replaces = pulumirpc.PropertyDiff_ADD_REPLACE, append(replaces, path)
case pl.DiffDelete:
kind = pulumirpc.PropertyDiff_DELETE
case pl.DiffDeleteReplace:
kind, replaces = pulumirpc.PropertyDiff_DELETE, append(replaces, path)
case pl.DiffUpdate:
kind = pulumirpc.PropertyDiff_UPDATE
case pl.DiffUpdateReplace:
kind, replaces = pulumirpc.PropertyDiff_UPDATE_REPLACE, append(replaces, path)
}

detailedDiff[path] = &pulumirpc.PropertyDiff{
Kind: kind,
Kind: pulumirpc.PropertyDiff_Kind(diff.Kind), //nolint:gosec
InputDiff: diff.InputDiff,
}
}
diffs = make([]string, 0, len(properties))
for k := range properties {
diffs = append(diffs, k)
}
sort.Strings(diffs)
}

diffs = make([]string, len(diff.ChangedKeys))
for i, k := range diff.ChangedKeys {
diffs[i] = string(k)
}
replaces = make([]string, len(diff.ReplaceKeys))
for i, k := range diff.ReplaceKeys {
replaces[i] = string(k)
}

return &pulumirpc.DiffResponse{
Expand Down

0 comments on commit 4fe072a

Please sign in to comment.