Skip to content

Commit

Permalink
auto-genereated rc.3
Browse files Browse the repository at this point in the history
  • Loading branch information
migara committed Jan 22, 2025
1 parent 7289a85 commit db762fb
Show file tree
Hide file tree
Showing 49 changed files with 82,886 additions and 80,621 deletions.
24 changes: 1 addition & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.7
toolchain go1.23.3

require (
github.com/PaloAltoNetworks/pango v0.10.3-0.20250117155811-a636e84aede9
github.com/PaloAltoNetworks/pango v0.10.3-0.20250122182133-6c5f32cdd60a
github.com/hashicorp/terraform-plugin-framework v1.12.0
github.com/hashicorp/terraform-plugin-framework-validators v0.14.0
github.com/hashicorp/terraform-plugin-go v0.24.0
Expand All @@ -17,26 +17,16 @@ require (
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Kunde21/markdownfmt/v3 v3.1.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.7.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/cli v1.1.6 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand All @@ -52,36 +42,25 @@ require (
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.21.0 // indirect
github.com/hashicorp/terraform-json v0.23.0 // indirect
github.com/hashicorp/terraform-plugin-docs v0.20.1 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yuin/goldmark v1.7.7 // indirect
github.com/yuin/goldmark-meta v1.1.0 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.23.0 // indirect
Expand All @@ -92,6 +71,5 @@ require (
google.golang.org/grpc v1.66.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
64 changes: 2 additions & 62 deletions go.sum

Large diffs are not rendered by default.

36 changes: 29 additions & 7 deletions internal/manager/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (o *EntryObjectManager[E, L, S]) UpdateMany(ctx context.Context, location L
return found, true
}

for _, elt := range planEntries {
for idx, elt := range planEntries {
eltEntryName := elt.EntryName()
var processedEntry *entryObjectWithState[E]

Expand Down Expand Up @@ -257,11 +257,13 @@ func (o *EntryObjectManager[E, L, S]) UpdateMany(ctx context.Context, location L
processedStateEntriesByName[processedEntry.Entry.EntryName()] = *processedEntry
} else {
processedEntry = &entryObjectWithState[E]{
Entry: elt,
State: entryMissing,
Entry: elt,
StateIdx: idx,
}

if !o.matcher(elt, stateElt.Entry) {
if o.matcher(elt, stateElt.Entry) {
processedEntry.State = entryOk
} else {
processedEntry.State = entryOutdated
}
processedStateEntriesByName[elt.EntryName()] = *processedEntry
Expand All @@ -273,6 +275,13 @@ func (o *EntryObjectManager[E, L, S]) UpdateMany(ctx context.Context, location L
return nil, &Error{err: err, message: "failed to get a list of existing entries from the server"}
}

for name, elt := range stateEntriesByName {
if _, processedEntryFound := processedStateEntriesByName[name]; !processedEntryFound {
elt.State = entryDeleted
processedStateEntriesByName[name] = elt
}
}

updates := xmlapi.NewMultiConfig(len(planEntries))

for _, existingEntry := range existing {
Expand Down Expand Up @@ -353,6 +362,12 @@ func (o *EntryObjectManager[E, L, S]) UpdateMany(ctx context.Context, location L
delete(processedStateEntriesByName, elt.Entry.EntryName())
elt.Entry.SetEntryName(elt.NewName)
processedStateEntriesByName[elt.NewName] = elt
case entryDeleted:
updates.Add(&xmlapi.Config{
Action: "delete",
Xpath: util.AsXpath(path),
Target: o.client.GetTarget(),
})
case entryUnknown:
slog.Warn("Entry state is still unknown after reconciliation", "Name", elt.Entry.EntryName())
case entryOk:
Expand All @@ -367,9 +382,16 @@ func (o *EntryObjectManager[E, L, S]) UpdateMany(ctx context.Context, location L
}
}

entries := make([]E, len(processedStateEntriesByName))
for _, elt := range processedStateEntriesByName {
entries[elt.StateIdx] = elt.Entry
existing, err = o.service.List(ctx, location, "get", "", "")
if err != nil && !sdkerrors.IsObjectNotFound(err) {
return nil, fmt.Errorf("Failed to list remote entries: %w", err)
}

entries := make([]E, len(planEntries))
for _, elt := range existing {
if planEntry, found := planEntriesByName[elt.EntryName()]; found {
entries[planEntry.StateIdx] = elt
}
}

return entries, nil
Expand Down
20 changes: 15 additions & 5 deletions internal/manager/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,27 @@ var _ = Describe("Entry", func() {
Context("UpdateMany()", func() {
Context("when entries from the plan are missing from the server", func() {
It("should recreate them, and return back list of all managed entries", func() {
entries := []*MockEntryObject{{Name: "4", Value: "D"}}
processed, err := sdk.UpdateMany(ctx, location, entries, entries)
expected := append(existing, &MockEntryObject{Name: "4", Value: "D"})
processed, err := sdk.UpdateMany(ctx, location, existing, expected)

Expect(err).ToNot(HaveOccurred())
Expect(processed).To(HaveExactElements(entries))

expected := append(existing, entries...)
Expect(processed).To(HaveExactElements(expected))
Expect(client.list()).To(HaveExactElements(expected))
})

})

Context("when some entries are removed from the plan", func() {
It("should properly remove deleted entries from the server and return back updated list", func() {
stateEntries := []*MockEntryObject{{Name: "1", Value: "A"}, {Name: "2", Value: "B"}, {Name: "3", Value: "C"}}
planEntries := []*MockEntryObject{{Name: "1", Value: "A"}, {Name: "3", Value: "C"}}
processed, err := sdk.UpdateMany(ctx, location, stateEntries, planEntries)

Expect(err).ToNot(HaveOccurred())
Expect(processed).To(HaveExactElements(planEntries))
Expect(client.list()).To(HaveExactElements(planEntries))
})
})
})

Context("Delete()", func() {
Expand Down
21 changes: 18 additions & 3 deletions internal/manager/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (o *UuidObjectManager[E, L, S]) CreateMany(ctx context.Context, location L,
}

existing, err = o.service.List(ctx, location, "get", "", "")
if err != nil {
if err != nil && !sdkerrors.IsObjectNotFound(err) {
return nil, fmt.Errorf("Failed to list remote entries: %w", err)
}

Expand Down Expand Up @@ -535,6 +535,8 @@ func (o *UuidObjectManager[E, L, S]) UpdateMany(ctx context.Context, location L,
}
}

createOps := make([]*xmlapi.Config, len(planEntries))

for _, elt := range processedStateEntries {
path, err := location.XpathWithEntryName(o.client.Versioning(), elt.Entry.EntryName())
if err != nil {
Expand All @@ -547,7 +549,14 @@ func (o *UuidObjectManager[E, L, S]) UpdateMany(ctx context.Context, location L,
}

switch elt.State {
case entryMissing, entryOutdated:
case entryMissing:
createOps[elt.StateIdx] = &xmlapi.Config{
Action: "edit",
Xpath: util.AsXpath(path),
Element: xmlEntry,
Target: o.client.GetTarget(),
}
case entryOutdated:
updates.Add(&xmlapi.Config{
Action: "edit",
Xpath: util.AsXpath(path),
Expand Down Expand Up @@ -582,6 +591,12 @@ func (o *UuidObjectManager[E, L, S]) UpdateMany(ctx context.Context, location L,
}
}

for _, elt := range createOps {
if elt != nil {
updates.Add(elt)
}
}

if len(updates.Operations) > 0 {
if _, _, _, err := o.client.MultiConfig(ctx, updates, false, nil); err != nil {
return nil, &Error{err: err, message: "failed to execute MultiConfig command"}
Expand All @@ -602,7 +617,7 @@ func (o *UuidObjectManager[E, L, S]) UpdateMany(ctx context.Context, location L,
}

existing, err = o.service.List(ctx, location, "get", "", "")
if err != nil {
if err != nil && !sdkerrors.IsObjectNotFound(err) {
return nil, fmt.Errorf("Failed to list remote entries: %w", err)
}

Expand Down
Loading

0 comments on commit db762fb

Please sign in to comment.