Skip to content

importer-msgraph-metadata: Add workarounds for several bugs in Graph Api Spec #4519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package workarounds

import (
"fmt"

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

var _ dataWorkaround = workaroundConnectedOrganization{}

// workaroundConnectedOrganization adds missing fields and fixes some field types.
type workaroundConnectedOrganization struct{}

func (workaroundConnectedOrganization) Name() string {
return "Connected Organization / identitySources is not read-only"
}

func (workaroundConnectedOrganization) Process(apiVersion string, models parser.Models, constants parser.Constants, resourceIds parser.ResourceIds) error {
model, ok := models["microsoft.graph.connectedOrganization"]
if !ok {
return fmt.Errorf("`connectedOrganization` model not found")
}

// `identitySources` is not read-only
if _, ok = model.Fields["identitySources"]; !ok {
return fmt.Errorf("`identitySources` field not found")
}
model.Fields["identitySources"].ReadOnly = false

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package workarounds

import (
"fmt"

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

var _ dataWorkaround = workaroundCrossTenantAccessPolicyConfigurationPartner{}

// workaroundCrossTenantAccessPolicyConfigurationPartner adds missing fields and fixes some field types.
type workaroundCrossTenantAccessPolicyConfigurationPartner struct{}

func (workaroundCrossTenantAccessPolicyConfigurationPartner) Name() string {
return "Cross Tenant Access Policy Configuration Partner / tenantId is not read-only"
}

func (workaroundCrossTenantAccessPolicyConfigurationPartner) Process(apiVersion string, models parser.Models, constants parser.Constants, resourceIds parser.ResourceIds) error {
model, ok := models["microsoft.graph.crossTenantAccessPolicyConfigurationPartner"]
if !ok {
return fmt.Errorf("`crossTenantAccessPolicyConfigurationPartner` model not found")
}

// `tenantId` is not read-only
if _, ok = model.Fields["tenantId"]; !ok {
return fmt.Errorf("`tenantId` field not found")
}
model.Fields["tenantId"].ReadOnly = false

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package workarounds

import (
"fmt"

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

var _ dataWorkaround = workaroundUnifiedRoleManagementPolicy{}

// workaroundUnifiedRoleManagementPolicy adds missing fields and fixes some field types.
type workaroundUnifiedRoleManagementPolicy struct{}

func (workaroundUnifiedRoleManagementPolicy) Name() string {
return "Unified Role Management Policy / lastModifiedBy and lastModifiedDateTime are read-only"
}

func (workaroundUnifiedRoleManagementPolicy) Process(apiVersion string, models parser.Models, constants parser.Constants, resourceIds parser.ResourceIds) error {
model, ok := models["microsoft.graph.unifiedRoleManagementPolicy"]
if !ok {
return fmt.Errorf("`unifiedRoleManagementPolicy` model not found")
}

// `lastModifiedBy` is read-only
if _, ok = model.Fields["lastModifiedBy"]; !ok {
return fmt.Errorf("`lastModifiedBy` field not found")
}
model.Fields["lastModifiedBy"].ReadOnly = true

// `lastModifiedDateTime` is read-only
if _, ok = model.Fields["lastModifiedDateTime"]; !ok {
return fmt.Errorf("`lastModifiedDateTime` field not found")
}
model.Fields["lastModifiedDateTime"].ReadOnly = true

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var workarounds = []dataWorkaround{
workaroundApplication{},
workaroundConditionalAccessPolicy{},
workaroundUnifiedRoleAssignment{},
workaroundUnifiedRoleManagementPolicy{},
workaroundConnectedOrganization{},
workaroundCrossTenantAccessPolicyConfigurationPartner{},
}

// serviceWorkarounds make post-parsing changes to individual services and are able to make any changes to resources
Expand Down