Skip to content

Commit

Permalink
importer-msgraph-metadata: workaround for identityGovernance/DeleteEn…
Browse files Browse the repository at this point in the history
…titlementManagementAccessPackageResourceRoleScope method which actually returns 200
  • Loading branch information
manicminer committed Sep 23, 2024
1 parent ee8297c commit 8586e1a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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"
"github.com/hashicorp/pandora/tools/importer-msgraph-metadata/components/versions"
)

var _ serviceWorkaround = workaroundEntitlementManagementAccessPackageAccessPackageResourceRoleScope{}

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

func (workaroundEntitlementManagementAccessPackageAccessPackageResourceRoleScope) Name() string {
return "EntitlementManagementAccessPackageAccessPackageResourceRoleScope / set correct response status codes"
}

func (workaroundEntitlementManagementAccessPackageAccessPackageResourceRoleScope) Process(apiVersion, serviceName string, resources parser.Resources, resourceIds parser.ResourceIds) error {
if apiVersion != versions.ApiVersionBeta {
return nil
}

if serviceName != "identityGovernance" {
return nil
}

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

for i := range resource.Operations {
if resource.Operations[i].Name == "DeleteEntitlementManagementAccessPackageResourceRoleScope" {
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 @@ -33,6 +33,7 @@ var serviceWorkarounds = []serviceWorkaround{

// Service-specific workarounds
workaroundApplicationTemplates{},
workaroundEntitlementManagementAccessPackageAccessPackageResourceRoleScope{},
workaroundGroups{},
workaroundSynchronizationSecrets{},
}
Expand Down

0 comments on commit 8586e1a

Please sign in to comment.