Skip to content
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

tools/importer-rest-api-specs: adding a workaround for Azure/azure-rest-api-specs PR 26680 #3336

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package dataworkarounds

import (
"fmt"

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

var _ workaround = workaroundRecoveryServicesSiteRecovery26680{}

// workaroundRecoveryServicesSiteRecovery26680 works around the model `CreateCertificateOptions` being
// present within the API but not being documented in the API Definitions - as such this adds the missing
// model/fields to make this useful.
//
// Swagger PR: https://github.com/Azure/azure-rest-api-specs/pull/26680
type workaroundRecoveryServicesSiteRecovery26680 struct {
}

func (w workaroundRecoveryServicesSiteRecovery26680) IsApplicable(apiDefinition *models.AzureApiDefinition) bool {
if apiDefinition.ServiceName != "RecoveryServicesSiteRecovery" {
return false
}

apiVersions := map[string]struct{}{
"2022-10-01": {},
"2023-01-01": {},
"2023-02-01": {},
"2023-04-01": {},
"2023-06-01": {},
}
if _, apiVersionMatches := apiVersions[apiDefinition.ApiVersion]; !apiVersionMatches {
return false
}

if _, resourceExists := apiVersions["VaultCertificates"]; !resourceExists {
return false
}

return true
}

func (w workaroundRecoveryServicesSiteRecovery26680) Name() string {
return "RecoveryServicesSiteRecovery / 26680"
}

func (w workaroundRecoveryServicesSiteRecovery26680) Process(apiDefinition models.AzureApiDefinition) (*models.AzureApiDefinition, error) {
resource, ok := apiDefinition.Resources["VaultCertificates"]
if !ok {
return nil, fmt.Errorf("expected a Resource named `VaultCertificates` but didn't get one")
}

// 1. Add the missing model
resource.Models["CertificateCreateOptions"] = models.ModelDetails{
Fields: map[string]models.FieldDetails{
"ValidityInHours": {
Required: false,
JsonName: "validityInHours",
ObjectDefinition: &models.ObjectDefinition{
Type: models.ObjectDefinitionInteger,
},
},
},
}

// 2. Add the field referencing the missing model
model, ok := resource.Models["CertificateRequest"]
if !ok {
return nil, fmt.Errorf("expected a Model named `CertificateRequest` but didn't get one")
}
model.Fields["CertificateCreateOptions"] = models.FieldDetails{
Required: false,
ReadOnly: false,
Sensitive: false,
JsonName: "certificateCreateOptions",
Description: "",
CustomFieldType: nil,
ObjectDefinition: &models.ObjectDefinition{
ReferenceName: pointer.To("CertificateCreateOptions"),
Type: models.ObjectDefinitionReference,
},
}
resource.Models["CertificateRequest"] = model

apiDefinition.Resources["VaultCertificates"] = resource
return &apiDefinition, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var workarounds = []workaround{
workaroundRedis22407{},
workaroundMachineLearning25142{},

workaroundRecoveryServicesSiteRecovery26680{},

// @tombuildsstuff: this is an odd place for this however this allows working around inconsistencies in the Swagger
// we should look at moving this into the `resourceids` package when time allows.
workaroundInconsistentlyDefinedSegments{},
Expand Down
Loading