-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3609 from hashicorp/f/importing-botservice-2022-0…
…9-15 `tools/importer-rest-api-specs`: adding a data workaround for `Azure/azure-rest-api-specs#27351` / importing `BotService` @ `2022-09-15`
- Loading branch information
Showing
4 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
.../importer-rest-api-specs/components/parser/dataworkarounds/workaround_botservice_27351.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters