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

Add another non-standard error code for RP registration #20860

Merged
merged 1 commit into from
May 16, 2023

Conversation

jhendrixMSFT
Copy link
Member

Fixes #19900

@jhendrixMSFT jhendrixMSFT merged commit 6879d7e into Azure:main May 16, 2023
@jhendrixMSFT jhendrixMSFT deleted the azcore_register_rp branch May 16, 2023 19:56
jhendrixMSFT added a commit to jhendrixMSFT/azure-sdk-for-go that referenced this pull request Jun 5, 2023
jhendrixMSFT added a commit that referenced this pull request Jun 5, 2023
* Retry policy will always clone the *http.Request (#20843)

* Retry policy will always clone the *http.Request

This ensures that the entirety of the request is restored on retries.

* simplify test

* Handle more error codes when an RP isn't registered (#20848)

There's more than one error code returned from unregistered RPs.

* Add another non-standard error code for RP registration (#20860)

* Prep azcore v1.6.1 for release

Cherry-picked the following commits.
- a3b2c13
- 889be58
- 6879d7e
@felipebbc
Copy link

Hi @jhendrixMSFT

The issue #19900 with the Resource Provider registration has not been resolved by adding the non-standard error code Subscription Not Registered.

The sdk also checks if the response has a 409 error code:

// getting a 409 is the first indication that the RP might need to be registered, check error response
if err != nil || resp.StatusCode != http.StatusConflict {
return resp, err

The error message from the Microsoft.Security/pricings@2022-03-01 call returns a 404 error code, so the provider registration doesn't move forward.

Also, the provider registration requires that the error message contain the provider name in the error.details.target field

func getProvider(re requestError) (string, error) {
if len(re.ServiceError.Details) > 0 {
return re.ServiceError.Details[0].Target, nil
}
return "", errors.New("unexpected empty Details")
}

The error message from the Microsoft.Security/pricings@2022-03-01 does not contain the error.details.target field, it only contains error.code and error.message:

│ PUT https://management.azure.com/subscriptions/[subscription-id]/providers/Microsoft.Security/pricings/VirtualMachines?api-version=2022-03-01
│ --------------------------------------------------------------------------------
│ RESPONSE 404: 404 Not Found
│ ERROR CODE: Subscription Not Registered
│ --------------------------------------------------------------------------------
│ {
│   "error": {
│     "code": "Subscription Not Registered",
│     "message": "Please register to Microsoft.Security in order to view your security status"
│   }
│ }
│ -------------------------------------------------------------------------------- 

I tested out a solution adding the 404 code on line 94 and adding a regex to extract the resource provider name from the error.message. It works but I understand this is not a good solution.

Looking for you to see how we can allow automatic resource provider registration in this scenario.

@jhendrixMSFT
Copy link
Member Author

@felipebbc could you please open a new issue for this so we can track it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource provider not registred automatically for Microsoft.Security/pricings
3 participants