From 00de07530c48ef11363e8239fe0ce46fb30d945b Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 8 Jan 2024 13:21:44 +0100 Subject: [PATCH 1/2] `tools/importer-rest-api-specs`: detecting the Common IDs for Bot Service Fixes https://github.com/hashicorp/pandora/issues/2830 Unblocks https://github.com/hashicorp/pandora/pull/3511 --- .../resourceids/common_id_bot_service.go | 28 +++++++++++++++++ .../common_id_bot_service_channel.go | 30 +++++++++++++++++++ .../parser/resourceids/common_ids.go | 6 +++- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tools/importer-rest-api-specs/components/parser/resourceids/common_id_bot_service.go create mode 100644 tools/importer-rest-api-specs/components/parser/resourceids/common_id_bot_service_channel.go diff --git a/tools/importer-rest-api-specs/components/parser/resourceids/common_id_bot_service.go b/tools/importer-rest-api-specs/components/parser/resourceids/common_id_bot_service.go new file mode 100644 index 00000000000..d6dd385424d --- /dev/null +++ b/tools/importer-rest-api-specs/components/parser/resourceids/common_id_bot_service.go @@ -0,0 +1,28 @@ +package resourceids + +import ( + "github.com/hashicorp/pandora/tools/importer-rest-api-specs/models" + "github.com/hashicorp/pandora/tools/sdk/resourcemanager" +) + +var _ commonIdMatcher = commonIdBotService{} + +type commonIdBotService struct{} + +func (commonIdBotService) id() models.ParsedResourceId { + name := "BotService" + return models.ParsedResourceId{ + CommonAlias: &name, + Constants: map[string]resourcemanager.ConstantDetails{}, + Segments: []resourcemanager.ResourceIdSegment{ + models.StaticResourceIDSegment("staticSubscriptions", "subscriptions"), + models.SubscriptionIDResourceIDSegment("subscriptionId"), + models.StaticResourceIDSegment("staticResourceGroups", "resourceGroups"), + models.ResourceGroupResourceIDSegment("resourceGroupName"), + models.StaticResourceIDSegment("staticProviders", "providers"), + models.ResourceProviderResourceIDSegment("staticMicrosoftBotService", "Microsoft.BotService"), + models.StaticResourceIDSegment("staticBotServices", "botServices"), + models.UserSpecifiedResourceIDSegment("botServiceName"), + }, + } +} diff --git a/tools/importer-rest-api-specs/components/parser/resourceids/common_id_bot_service_channel.go b/tools/importer-rest-api-specs/components/parser/resourceids/common_id_bot_service_channel.go new file mode 100644 index 00000000000..d974dcdcb89 --- /dev/null +++ b/tools/importer-rest-api-specs/components/parser/resourceids/common_id_bot_service_channel.go @@ -0,0 +1,30 @@ +package resourceids + +import ( + "github.com/hashicorp/pandora/tools/importer-rest-api-specs/models" + "github.com/hashicorp/pandora/tools/sdk/resourcemanager" +) + +var _ commonIdMatcher = commonIdBotServiceChannel{} + +type commonIdBotServiceChannel struct{} + +func (commonIdBotServiceChannel) id() models.ParsedResourceId { + name := "BotServiceChannel" + return models.ParsedResourceId{ + CommonAlias: &name, + Constants: map[string]resourcemanager.ConstantDetails{}, + Segments: []resourcemanager.ResourceIdSegment{ + models.StaticResourceIDSegment("staticSubscriptions", "subscriptions"), + models.SubscriptionIDResourceIDSegment("subscriptionId"), + models.StaticResourceIDSegment("staticResourceGroups", "resourceGroups"), + models.ResourceGroupResourceIDSegment("resourceGroupName"), + models.StaticResourceIDSegment("staticProviders", "providers"), + models.ResourceProviderResourceIDSegment("staticMicrosoftBotService", "Microsoft.BotService"), + models.StaticResourceIDSegment("staticBotServices", "botServices"), + models.UserSpecifiedResourceIDSegment("botServiceName"), + models.StaticResourceIDSegment("staticChannels", "channels"), + models.ConstantResourceIDSegment("channelType", "BotServiceChannelType"), + }, + } +} diff --git a/tools/importer-rest-api-specs/components/parser/resourceids/common_ids.go b/tools/importer-rest-api-specs/components/parser/resourceids/common_ids.go index 711ed10dd67..02fd7b28e25 100644 --- a/tools/importer-rest-api-specs/components/parser/resourceids/common_ids.go +++ b/tools/importer-rest-api-specs/components/parser/resourceids/common_ids.go @@ -49,6 +49,10 @@ var commonIdTypes = []commonIdMatcher{ commonIdAutomationCompilationJob{}, // (@stephybun) CompilationJobId segment is defined in three different ways `jobId`, `compilationJobId` and `compilationJobName` commonIdProvisioningService{}, // (@jackofallops): Inconsistent user specified fields in the swagger - `provisioningServices/{resourceName}` vs `provisioningServices/{provisioningServiceName}` + // Bot Service + commonIdBotService{}, + commonIdBotServiceChannel{}, + // HDInsight commonIdHDInsightCluster{}, @@ -65,7 +69,7 @@ var commonIdTypes = []commonIdMatcher{ commonIdSqlManagedInstanceDatabase{}, commonIdSqlServer{}, - // Spring Cloud + // Spring Cloud commonIdSpringCloudService{}, // Storage From f14eaef74358570bbd732039097a7efeeafb81c3 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 8 Jan 2024 13:56:13 +0100 Subject: [PATCH 2/2] `tools/importer-rest-api-specs`: Resource ID matching now ignores the constant name The Resource ID defined within the API Definitions and the Common ID may have a differing Name and/or Values therefore we can't rely on the name being the same. Providing the Resource ID Segment is the same Type and has a Reference, as long as the rest of the Resource ID Segments match then we can assume these are the same Resource ID. This works around an issue where a couple of the Resource IDs in Bot Service only support a subset of the Constant Values and where the name of the Constant differs between the API Definitions and the Common ID. --- tools/importer-rest-api-specs/models/resource_ids.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/importer-rest-api-specs/models/resource_ids.go b/tools/importer-rest-api-specs/models/resource_ids.go index 2009007bb89..ebd36d73397 100644 --- a/tools/importer-rest-api-specs/models/resource_ids.go +++ b/tools/importer-rest-api-specs/models/resource_ids.go @@ -64,9 +64,10 @@ func (pri ParsedResourceId) Matches(other ParsedResourceId) bool { if first.ConstantReference == nil && second.ConstantReference != nil { return false } - if first.ConstantReference != nil && second.ConstantReference != nil && *first.ConstantReference != *second.ConstantReference { - return false - } + + // We're intentionally not checking the constants involved, since both the name and values could differ + // between different operations due to data issues - however when either happens we'd end up using a + // Common ID to resolve this - therefore presuming the rest of the Resource ID matches we should be good. continue }