Skip to content

tools/importer-rest-api-specs: adding a data workaround for Azure/azure-rest-api-specs#27351 / importing BotService @ 2022-09-15 #3609

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

Merged
merged 3 commits into from
Jan 17, 2024
Merged
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
4 changes: 4 additions & 0 deletions config/resource-manager.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ service "blueprint" {
name = "Blueprints"
available = ["2018-11-01-preview"]
}
service "botservice" {
name = "BotService"
available = ["2022-09-15"]
}
service "chaos" {
name = "ChaosStudio"
available = ["2023-04-15-preview", "2023-11-01", "2024-01-01"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package dataworkarounds

import (
"fmt"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/pandora/tools/importer-rest-api-specs/models"
)

var _ workaround = workaroundBotService27351{}

type workaroundBotService27351 struct {
}

func (workaroundBotService27351) IsApplicable(apiDefinition *models.AzureApiDefinition) bool {
// This workaround fixes an issue where the BotService Channel URI is defined using two subtly different Resource IDs.
// Fix: https://github.com/Azure/azure-rest-api-specs/pull/27351
//
// The DELETE and GET define the Uri Parameter `channelName` as a String - whereas the PATCH and POST define it as
// a Constant.
// The result of this is that whilst we switch out the Resource ID for a Common ID, this inconsistency means we end up
// with 2 different Resource IDs in the output, the Common ID (`BotServiceChannelId`) using a Constant Segment and another
// Resource ID (`ChannelId`) using a String segment.
//
// As such this workaround fixes this issue by normalizing the resulting output - since these are the same endpoint/should
// support the same values for this URI Segment.
serviceMatches := apiDefinition.ServiceName == "BotService"
apiVersions := map[string]struct{}{
"2021-05-01-preview": {},
"2022-06-15-preview": {},
"2023-09-15-preview": {},
"2020-06-02": {},
"2021-03-01": {},
"2022-09-15": {},
}
_, apiVersionMatches := apiVersions[apiDefinition.ApiVersion]
return serviceMatches && apiVersionMatches
}

func (workaroundBotService27351) Name() string {
return "BotService / 27351"
}

func (workaroundBotService27351) Process(input models.AzureApiDefinition) (*models.AzureApiDefinition, error) {
output := input

resource, ok := output.Resources["Channel"]
if !ok {
return nil, fmt.Errorf("expected a Resource named `Channel` but didn't get one")
}
// ensure we've got the Resource ID we're going to switch over to
if _, ok := resource.ResourceIds["BotServiceChannelId"]; !ok {
return nil, fmt.Errorf("expected a Resource ID named `BotServiceChannelId` but didn't get one")
}

// ensure we've got the mismatched Resource ID in order to remove it
if _, ok := resource.ResourceIds["ChannelId"]; !ok {
return nil, fmt.Errorf("expected a Resource ID named `ChannelId` but didn't get one")
}
delete(resource.ResourceIds, "ChannelId")

for operationName, operation := range resource.Operations {
if operation.ResourceIdName != nil && *operation.ResourceIdName == "ChannelId" {
operation.ResourceIdName = pointer.To("BotServiceChannelId")
}
resource.Operations[operationName] = operation
}

output.Resources["Channel"] = resource

return &output, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ var workarounds = []workaround{
workaroundAutomation25108{},
workaroundAutomation25435{},
workaroundBatch21291{},
workaroundBotService27351{},
workaroundContainerService21394{},
workaroundDataFactory23013{},
workaroundDevCenter26189{},
workaroundHDInsight26838{},
workaroundLoadTest20961{},
workaroundRedis22407{},
workaroundMachineLearning25142{},

workaroundRecoveryServicesSiteRecovery26680{},

// @tombuildsstuff: this is an odd place for this however this allows working around inconsistencies in the Swagger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,33 @@ func (commonIdBotServiceChannel) id() models.ParsedResourceId {
name := "BotServiceChannel"
return models.ParsedResourceId{
CommonAlias: &name,
Constants: map[string]resourcemanager.ConstantDetails{},
Constants: map[string]resourcemanager.ConstantDetails{
"BotServiceChannelType": {
CaseInsensitive: false,
Type: resourcemanager.StringConstant,
Values: map[string]string{
"AcsChatChannel": "AcsChatChannel",
"AlexaChannel": "AlexaChannel",
"DirectLineChannel": "DirectLineChannel",
"DirectLineSpeechChannel": "DirectLineSpeechChannel",
"EmailChannel": "EmailChannel",
"KikChannel": "KikChannel",
"FacebookChannel": "FacebookChannel",
"LineChannel": "LineChannel",
"M365Extensions": "M365Extensions",
"MsTeamsChannel": "MsTeamsChannel",
"Omnichannel": "Omnichannel",
"OutlookChannel": "OutlookChannel",
"SearchAssistant": "SearchAssistant",
"SkypeChannel": "SkypeChannel",
"SlackChannel": "SlackChannel",
"SmsChannel": "SmsChannel",
"TelegramChannel": "TelegramChannel",
"TelephonyChannel": "TelephonyChannel",
"WebChatChannel": "WebChatChannel",
},
},
},
Segments: []resourcemanager.ResourceIdSegment{
models.StaticResourceIDSegment("staticSubscriptions", "subscriptions"),
models.SubscriptionIDResourceIDSegment("subscriptionId"),
Expand Down