-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dataworkaround: add a workaround for storagecache 32537 (#4661)
* add a data workaround for storage cache 32537 * was here, now gone * use correct PR number in comment Co-authored-by: catriona-m <[email protected]> --------- Co-authored-by: catriona-m <[email protected]>
- Loading branch information
1 parent
d73e911
commit 0f8684e
Showing
3 changed files
with
55 additions
and
6 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
52 changes: 52 additions & 0 deletions
52
...nternal/components/apidefinitions/parser/dataworkarounds/workaround_storagecache_32537.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,52 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package dataworkarounds | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdkModels "github.com/hashicorp/pandora/tools/data-api-sdk/v1/models" | ||
) | ||
|
||
// workaroundStorageCache32537 is a workaround to convert the `percentComplete` field to a float | ||
// which is what the API returns and results in an unmarshaling error in the SDK when trying to | ||
// read the response body - this can be removed when PR https://github.com/Azure/azure-rest-api-specs/pull/32537 | ||
// has been merged | ||
type workaroundStorageCache32537 struct { | ||
} | ||
|
||
func (w workaroundStorageCache32537) IsApplicable(serviceName string, apiVersion sdkModels.APIVersion) bool { | ||
return serviceName == "StorageCache" && apiVersion.APIVersion == "2023-05-01" | ||
} | ||
|
||
func (w workaroundStorageCache32537) Name() string { | ||
return "StorageCache / 32537" | ||
} | ||
|
||
func (w workaroundStorageCache32537) Process(input sdkModels.APIVersion) (*sdkModels.APIVersion, error) { | ||
resource, ok := input.Resources["AmlFilesystems"] | ||
if !ok { | ||
return nil, fmt.Errorf(`expected to find the API Resource "AmlFilesystems" but didn't`) | ||
} | ||
|
||
model, ok := resource.Models["AmlFilesystemArchiveStatus"] | ||
if !ok { | ||
return nil, fmt.Errorf(`expected the API resource "AmlFilesystems" to contain Model "AmlFilesystemArchiveStatus" but it didn't`) | ||
} | ||
|
||
field, ok := model.Fields["PercentComplete"] | ||
if !ok { | ||
return nil, fmt.Errorf(`expected the Model "AmlFilesystemArchiveStatus" to contain the field "PercentComplete" but it didn't'`) | ||
} | ||
|
||
field.ObjectDefinition = sdkModels.SDKObjectDefinition{ | ||
Type: sdkModels.FloatSDKObjectDefinitionType, | ||
} | ||
|
||
model.Fields["PercentComplete"] = field | ||
resource.Models["AmlFilesystemArchiveStatus"] = model | ||
input.Resources["AmlFilesystems"] = resource | ||
|
||
return &input, 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