Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pass through diffs and replaces
Browse files Browse the repository at this point in the history
VenelinMartinov committed Nov 20, 2024

Verified

This commit was signed with the committer’s verified signature.
cdavernas Charles d'Avernas
1 parent 449ed5e commit 27b43ab
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
@@ -18,8 +18,6 @@ import (
"context"
"encoding/json"
"fmt"
"sort"
"strings"

"github.com/blang/semver"
pbempty "github.com/golang/protobuf/ptypes/empty"
@@ -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{

0 comments on commit 27b43ab

Please sign in to comment.