Skip to content

Commit a0d4de5

Browse files
tools/importer-rest-api-specs: adding a workaround covering Azure/azure-rest-api-specs#26883
1 parent 2142f47 commit a0d4de5

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package dataworkarounds
2+
3+
import (
4+
"fmt"
5+
"github.com/hashicorp/go-azure-helpers/lang/pointer"
6+
"github.com/hashicorp/pandora/tools/importer-rest-api-specs/models"
7+
)
8+
9+
var _ workaround = workaroundNginx26883{}
10+
11+
// workaroundNginx26883 works around an issue in Nginx where Nginx Configuration is defined as
12+
// a user configurable value - but is a singleton and thus only supports a single value (`default`).
13+
// Therefore, this is an operation on the Nginx Deployment, rather than being a separate resouce
14+
// in its own right, and is created by the API by default - so
15+
// Swagger PR: https://github.com/Azure/azure-rest-api-specs/pull/26883
16+
type workaroundNginx26883 struct {
17+
}
18+
19+
func (workaroundNginx26883) IsApplicable(apiDefinition *models.AzureApiDefinition) bool {
20+
serviceMatches := apiDefinition.ServiceName == "Nginx"
21+
apiVersionMatches := apiDefinition.ApiVersion == "2022-08-01" || apiDefinition.ApiVersion == "2023-04-01"
22+
return serviceMatches && apiVersionMatches
23+
}
24+
25+
func (workaroundNginx26883) Name() string {
26+
return "Nginx / 26883"
27+
}
28+
29+
func (workaroundNginx26883) Process(apiDefinition models.AzureApiDefinition) (*models.AzureApiDefinition, error) {
30+
resource, ok := apiDefinition.Resources["NginxConfiguration"]
31+
if !ok {
32+
return nil, fmt.Errorf("couldn't find API Resource NginxConfiguration")
33+
}
34+
35+
// validate that the replacement Resource ID is present (which comes from the List operation)
36+
if _, ok := resource.ResourceIds["NginxDeploymentId"]; !ok {
37+
return nil, fmt.Errorf("couldn't find ResourceId `NginxDeploymentId` within API Resource `NginxConfiguration`")
38+
}
39+
// check the old ID is here (so the workaround is still valid)
40+
if _, ok := resource.ResourceIds["ConfigurationId"]; !ok {
41+
return nil, fmt.Errorf("couldn't find ResourceId `ConfigurationId` within API Resource `NginxConfiguration`")
42+
}
43+
44+
operationNames := []string{
45+
"ConfigurationsCreateOrUpdate",
46+
"ConfigurationsDelete",
47+
"ConfigurationsGet",
48+
}
49+
for _, operationName := range operationNames {
50+
operation, ok := resource.Operations[operationName]
51+
if !ok {
52+
return nil, fmt.Errorf("couldn't find Operation %q", operationName)
53+
}
54+
operation.ResourceIdName = pointer.To("NginxDeploymentId")
55+
resource.Operations[operationName] = operation
56+
}
57+
delete(resource.ResourceIds, "ConfigurationId")
58+
59+
apiDefinition.Resources["NginxConfiguration"] = resource
60+
return &apiDefinition, nil
61+
}

tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var workarounds = []workaround{
2020
workaroundLoadTest20961{},
2121
workaroundRedis22407{},
2222
workaroundMachineLearning25142{},
23+
workaroundNginx26883{},
2324

2425
workaroundRecoveryServicesSiteRecovery26680{},
2526

0 commit comments

Comments
 (0)