-
Notifications
You must be signed in to change notification settings - Fork 259
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 resource_id() extension method to Secrets #2052
Conversation
Parsing the name anv version from the resource ID (URL) is something we do across other Azure SDK languages and makes the API much more user-friendly. It's common to need to parse the name and version from a secret (or key or certificate) and pass into subsequent calls.
@RickWinter @JeffreyRichter I think we really need to take this one. We have similar utilities in our public APIs for most (all?) other Azure SDK languages because parsing the name and version out of a resource ID (URL) is often necessary to pass back into the client. This is also a good example of how service partners add value to their otherwise generated crates. |
As an example, instead of devs having to write code like this (or even less concise, which is likely for people newer to the language): They can simply write: let id = secret.resource_id()?;
let secret = client.get_secret(id.name, id.version.unwrap_or_default(), None).await?; |
I'm OK with this in concept. For Azure Storage, all languages should have an equivalent of this type: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob#URLParts which has a ParseURL function. That being said, if a "convenience" function were put on a client to wrap this no-client-required functionality, I think that would be OK. In Go, we did not do this for all the various Blob clients. |
Hanging it off a resource as an "extension method" makes sense in this case. It's not associated with a client either. For Storage I could see something like Go's (/cc @vincenttran-msft) but Key Vault really only needs to expose the name and optional version. That said, I could get behind the "parts" nomenclature as a general rule of thumb. In most other languages for Key Vault we called this something like
I'll name the getters the same and expose the vault URI but I think the extension method approach here is more idiomatic. In hindsight, I don't know why I didn't do that for .NET. |
It'd be great to return a bunch of borrowed |
This also turns the `source_id` (nee `id`) and `vault_url` (new) into owned `String`s because we don't really intend customers to do anything with them as `Url`s. If they really need a `Url` from it they can parse it into one, but there are really no supported scenarios for this for callers of this crate. The `endpoint` parameter - the `vault_url` here - `name`, and `version` parameters are all `&str` slices.
I turned the /cc @chlowell |
Parsing the name anv version from the resource ID (URL) is something we do across other Azure SDK languages and makes the API much more user-friendly. It's common to need to parse the name and version from a secret (or key or certificate) and pass into subsequent calls.