Skip to content

Commit

Permalink
tools/importer-rest-api-specs: adding a Swagger Data Workaround for R…
Browse files Browse the repository at this point in the history
…ecoveryServices Site Recovery

Temporarily works around Azure/azure-rest-api-specs#21667 until that's fixed upstream
  • Loading branch information
tombuildsstuff committed Nov 28, 2022
1 parent 8c18118 commit 47069ea
Showing 1 changed file with 161 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package parser

import (
"fmt"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/pandora/tools/sdk/resourcemanager"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/pandora/tools/importer-rest-api-specs/models"
Expand Down Expand Up @@ -78,6 +80,165 @@ func patchSwaggerData(input []models.AzureApiDefinition, logger hclog.Logger) (*
}
}

// Works around https://github.com/Azure/azure-rest-api-specs/pull/21667 which is where the Swagger segments
// are inconsistent, both named as `replicatedProtectedItemName` and `replicationProtectedItemName`
if item.ServiceName == "RecoveryServicesSiteRecovery" && (item.ApiVersion == "2022-05-01" || item.ApiVersion == "2022-10-01") {
resourcesToPatch := []string{
"RecoveryPoints",
"ReplicationProtectedItems",
"TargetComputeSizes",
}
for _, resourceName := range resourcesToPatch {
if resource, ok := item.Resources[resourceName]; ok {
if rid, ok := resource.ResourceIds["ReplicationProtectedItem"]; ok {
expectedResourceId := models.ParsedResourceId{
Segments: []resourcemanager.ResourceIdSegment{
{
Type: resourcemanager.StaticSegment,
Name: "staticSubscriptions",
FixedValue: pointer.To("subscriptions"),
},
{
Type: resourcemanager.SubscriptionIdSegment,
Name: "subscriptionId",
},
{
Type: resourcemanager.StaticSegment,
Name: "staticResourceGroups",
FixedValue: pointer.To("resourceGroups"),
},
{
Type: resourcemanager.ResourceGroupSegment,
Name: "resourceGroupName",
},
{
Type: resourcemanager.StaticSegment,
Name: "staticProviders",
FixedValue: pointer.To("providers"),
},
{
Type: resourcemanager.ResourceProviderSegment,
Name: "staticMicrosoftRecoveryServices",
FixedValue: pointer.To("Microsoft.RecoveryServices"),
},
{
Type: resourcemanager.StaticSegment,
Name: "staticVaults",
FixedValue: pointer.To("vaults"),
},
{
Type: resourcemanager.UserSpecifiedSegment,
Name: "resourceName",
},
{
Type: resourcemanager.StaticSegment,
Name: "staticReplicationFabrics",
FixedValue: pointer.To("replicationFabrics"),
},
{
Type: resourcemanager.UserSpecifiedSegment,
Name: "fabricName",
},
{
Type: resourcemanager.StaticSegment,
Name: "staticReplicationProtectionContainers",
FixedValue: pointer.To("replicationProtectionContainers"),
},
{
Type: resourcemanager.UserSpecifiedSegment,
Name: "protectionContainerName",
},
{
Type: resourcemanager.StaticSegment,
Name: "staticReplicationProtectedItems",
FixedValue: pointer.To("replicationProtectedItems"),
},
{
Type: resourcemanager.UserSpecifiedSegment,
Name: "replicatedProtectedItemName",
},
},
Constants: map[string]resourcemanager.ConstantDetails{},
}
correctedResourceId := models.ParsedResourceId{
Segments: []resourcemanager.ResourceIdSegment{
{
Type: resourcemanager.StaticSegment,
Name: "staticSubscriptions",
FixedValue: pointer.To("subscriptions"),
},
{
Type: resourcemanager.SubscriptionIdSegment,
Name: "subscriptionId",
},
{
Type: resourcemanager.StaticSegment,
Name: "staticResourceGroups",
FixedValue: pointer.To("resourceGroups"),
},
{
Type: resourcemanager.ResourceGroupSegment,
Name: "resourceGroupName",
},
{
Type: resourcemanager.StaticSegment,
Name: "staticProviders",
FixedValue: pointer.To("providers"),
},
{
Type: resourcemanager.ResourceProviderSegment,
Name: "staticMicrosoftRecoveryServices",
FixedValue: pointer.To("Microsoft.RecoveryServices"),
},
{
Type: resourcemanager.StaticSegment,
Name: "staticVaults",
FixedValue: pointer.To("vaults"),
},
{
Type: resourcemanager.UserSpecifiedSegment,
Name: "resourceName",
},
{
Type: resourcemanager.StaticSegment,
Name: "staticReplicationFabrics",
FixedValue: pointer.To("replicationFabrics"),
},
{
Type: resourcemanager.UserSpecifiedSegment,
Name: "fabricName",
},
{
Type: resourcemanager.StaticSegment,
Name: "staticReplicationProtectionContainers",
FixedValue: pointer.To("replicationProtectionContainers"),
},
{
Type: resourcemanager.UserSpecifiedSegment,
Name: "protectionContainerName",
},
{
Type: resourcemanager.StaticSegment,
Name: "staticReplicationProtectedItems",
FixedValue: pointer.To("replicationProtectedItems"),
},
{
Type: resourcemanager.UserSpecifiedSegment,
Name: "replicationProtectedItemName",
},
},
Constants: map[string]resourcemanager.ConstantDetails{},
}
if rid.Matches(expectedResourceId) {
rid.Segments = correctedResourceId.Segments
}
resource.ResourceIds["ReplicationProtectedItem"] = rid
}
item.Resources[resourceName] = resource
}
}
}

output = append(output, item)
}

Expand Down

0 comments on commit 47069ea

Please sign in to comment.