Hi James,
Thanks for getting back to me, I'd all but given up. Thanks for the info on listing managed-hsm vaults. GetVault isn't the answer as it's not that we want to list 1 but a given number. It's good to know that top is ignored and I'm assuming we can expect to get a listing for all the managed-hsm vaults - we can live with that.
Thanks to your above links I joined the Gopher slack channel to see if I could talk to someone about my next issue. I've described it below and it's a little long winded but I hope it makes sense, please contact me if it doesn't.
We are using azure-sdk-for-go - latest version
To get the first set of keys from using the azure-sdk-for-go keyClient.GetKeys() is called. This returns a KeyListResultPage.
This works fine but again always returns 10 keys for managed-hsm vaults instead of the requested number but that is a minor issue only as the call is repeated until there is no more keys.
The major issue is:
To get the next set of NextWithContext() is called. For managed hsm vaults this returns the first set of keys again, so a never ending loop situation is created.
I had to make it work for our product so I wrote custom GetNextKeys() function and this is what I found.
In the sdk the prepare function for NextKeys is keyListResultPreparer() and it initializes the http request as per:
return autorest.Prepare((&http.Request{}).WithContext(ctx),
autorest.AsJSON(),
autorest.AsGet(),
autorest.WithBaseURL(to.String(klr.NextLink)))
In the custom function I wrote I initialized the http request in the same way as per:
req, err := autorest.Prepare((&http.Request{}).WithContext(ctx),
autorest.AsJSON(),
autorest.AsGet(),
autorest.WithBaseURL(to.String(nextLink)),
)
and proceeded to use go lang's http library calls to fetch the keys but this still gave the same result ie: it fetched the first set of keys again.
To make it work properly I had to change the initialisation of the request to:
req, err := autorest.Prepare((&http.Request{}).WithContext(ctx),
autorest.AsJSON(),
autorest.AsGet(),
//autorest.WithBaseURL(to.String(nextLink)),
)
and assign the url to the request with:
u, err = url.Parse(*keys.Response.NextLink)
req.URL = u
Now I can fetch successive pages of keys.
The difference in the URL between the two requests is:
- Managed HSM Vaults Request URL using autorest.WithBaseURL
Request URL assigning the result of url.Parsehttps://SarahHSM8.managedhsm.azure.net/keys?%24skiptoken=K1JJRDp-NGZZQ0FONnM3eHhXQUFBQUFBQUFBQT09I1JUOjEjVFJDOjEwI0lTVjoyI0lFTzo2NTU2Nw&maxresults=25 This returns the first set of keys in postman - wrong
https://SarahHSM8.managedhsm.azure.net/keys?maxresults=25&$skiptoken=K1JJRDp-NGZZQ0FONnM3eHhXQUFBQUFBQUFBQT09I1JUOjEjVFJDOjEwI0lTVjoyI0lFTzo2NTU2Nw This returns the next set of keys in postman - right
- Non-Managed HSM Request URL using autorest.WithBaseURL https://cckm-test-premium-new.vault.azure.net:443/keys?%24skiptoken=eyJOZXh0TWFya2VyIjoiMiE3MiFNREF3TURBNUlXdGxlUzlVUlZOVU9TRXdNREF3TWpnaE9UazVPUzB4TWkwek1WUXlNem8xT1RvMU9TNDVPVGs1T1RrNVdpRS0iLCJUYXJnZXRMb2NhdGlvbiI6MH0&api-version=7.1&maxresults=25
The returns the next lot of keys in postman (with or without :433) - right Request URL assigning the result of url.Parse
https://cckm-test-premium-new.vault.azure.net:443/keys?api-version=7.1&$skiptoken=eyJOZXh0TWFya2VyIjoiMiE3MiFNREF3TURBNUlXdGxlUzlVUlZOVU9TRXdNREF3TWpnaE9UazVPUzB4TWkwek1WUXlNem8xT1RvMU9TNDVPVGs1T1RrNVdpRS0iLCJUYXJnZXRMb2NhdGlvbiI6MH0&maxresults=25
This returns the next lot of keys in postman (with or without :433) - right
So the same function, keys.NextKeys(), works fine for non-managed hsm vaults as does our custom function.
It would seem that non-managed hsm vaults are OK with the url's created by azure-sdk-for-go but managed-hsm vaults are not.
The same thing applies to fetching successive pages of deleted keys for managed-hsm vaults.
Appreciate any help on this as it would be preferable to be using the sdk for this call.
I am hoping someone reaches out to me on slack but there might be a terrible time difference as I'm gmt +10.
Thanks Sarah