Skip to content

Commit

Permalink
importer-msgraph-metadata: workaround to remove nonexistent `administ…
Browse files Browse the repository at this point in the history
…rativeunit` resources in the beta API, since these actually exist in their own service
  • Loading branch information
manicminer committed Sep 25, 2024
1 parent f93bb90 commit ffd3a71
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package workarounds

import (
"strings"

"github.com/hashicorp/pandora/tools/importer-msgraph-metadata/components/parser"
"github.com/hashicorp/pandora/tools/importer-msgraph-metadata/components/versions"
)

var _ serviceWorkaround = workaroundAdministrativeUnits{}

// workaroundAdministrativeUnits removes nonexistent `AdministrativeUnit` resources from the `Directory` service in
// the beta API, as these resources exist in the `administrativeUnits` service for this API version.
type workaroundAdministrativeUnits struct{}

func (workaroundAdministrativeUnits) Name() string {
return "Administrative Units / remove nonexistent resources"
}

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

if serviceName != "directory" {
return nil
}

resourcesToDelete := make([]string, 0)
for resourceName := range resources {
if strings.HasPrefix(resourceName, "DirectoryAdministrativeUnit") {
resourcesToDelete = append(resourcesToDelete, resourceName)
}
}

for _, resourceName := range resourcesToDelete {
delete(resources, resourceName)
}

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

// Service-specific workarounds
workaroundAdministrativeUnits{},
workaroundApplicationTemplates{},
workaroundEntitlementManagementAccessPackageAccessPackageResourceRoleScope{},
workaroundEntitlementManagementRoleAssignment{},
Expand Down

0 comments on commit ffd3a71

Please sign in to comment.