Skip to content

Commit

Permalink
importer-msgraph-metadata: workaround for group/UpdateGroup method wh…
Browse files Browse the repository at this point in the history
…ich also returns 200
  • Loading branch information
manicminer committed Sep 22, 2024
1 parent 54bc54d commit dfdc63a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package workarounds

import (
"fmt"
"slices"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/pandora/tools/importer-msgraph-metadata/components/parser"
)

var _ serviceWorkaround = workaroundGroups{}

// workaroundGroups adds a missing GET method for synchronization secrets, which is absent from upstream specs.
type workaroundGroups struct{}

func (workaroundGroups) Name() string {
return "Groups / set correct response status codes"
}

func (workaroundGroups) Process(apiVersion, serviceName string, resources parser.Resources, resourceIds parser.ResourceIds) error {
if serviceName != "groups" {
return nil
}

resource, ok := resources["Group"]
if !ok {
return fmt.Errorf("`Group` resource was not found for the `groups` service")
}

for i := range resource.Operations {
if resource.Operations[i].Name == "UpdateGroup" {
statusesFromSpec := make([]int, 0, len(resource.Operations[i].Responses))
for j := range resource.Operations[i].Responses {
statusesFromSpec = append(statusesFromSpec, resource.Operations[i].Responses[j].Status)
}

if !slices.Contains(statusesFromSpec, 200) {
resource.Operations[i].Responses = append(resource.Operations[i].Responses, parser.Response{
Status: 200,
ContentType: pointer.To("application/json"),
})
}
break
}
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var serviceWorkarounds = []serviceWorkaround{

// Service-specific workarounds
workaroundApplicationTemplates{},
workaroundGroups{},
workaroundSynchronizationSecrets{},
}

Expand Down

0 comments on commit dfdc63a

Please sign in to comment.