hashicorp / go-azure-sdk

An opinionated Go SDK for Azure Resource Manager
Mozilla Public License 2.0
35 stars 47 forks source link

`sdk`: Feature request for customizable client options #1118

Open wuxu92 opened 2 weeks ago

wuxu92 commented 2 weeks ago

Is there an existing issue for this?

Community Note

Currently, the RequestOptions are generated by Pandora and cannot be customized by the method caller. For example, see managedhsms/method_createorupdate.go#L25-L34.

It would be great if we could modify these options to customize at least the ExpectedStatusCodes and RetryFunc in some scenarios. The default retryCheck returns true for 5xx responses, but for services like managed HSM, we should not retry on a 503 status code due to capacity check failure.

{
    "error": {
        "code": "503",
        "message": "Capacity check failed"
    }
}

Proposal

Since the SDK method signatures are defined and should not change, one way to pass custom information is through the ctx parameter. We can then apply them during the NewRequest method.

    ctx = context.WithValue(ctx, "request-options", func(opts *RequestOptions) {
        opts.RetryFunc = func() {xxx}
    })
    if err := client.ManagedHsmClient.CreateOrUpdateThenPoll(ctx, id, hsm); err != nil {
        return fmt.Errorf("creating %s: %+v", id, err)
    }

If this looks reasonable and acceptable, I'd be happy to submit a PR to add this feature.

Service Name

sdk

API Versions Required

N/A

References

No response