-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Remove hard-coded version and name from clients #6557
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
Changes from 2 commits
0a27f41
76078dc
cd06b80
a0dfff8
f3e2274
5e8feeb
fb02039
74e3fa3
9db258c
910db97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ | |
| */ | ||
| public final class CoreUtils { | ||
| private static final String COMMA = ","; | ||
| private static final String NAME = "name"; | ||
| private static final String VERSION = "version"; | ||
|
|
||
| private CoreUtils() { | ||
| // Exists only to defeat instantiation. | ||
|
|
@@ -162,12 +164,19 @@ public static <T> Publisher<T> extractAndFetch(PagedResponse<T> page, Context co | |
|
|
||
|
|
||
| /** | ||
| * Helper method that returns an immutable {@link Map} of properties defined in {@code propertiesFileName}. | ||
| * Helper method that returns {@link UserAgentProperties} from properties defined in {@code propertiesFileName}. | ||
| * | ||
| * @param propertiesFileName The file name defining the properties. | ||
| * @return an immutable {@link Map}. | ||
| * @return {@link UserAgentProperties}. | ||
| */ | ||
| public static Map<String, String> getProperties(String propertiesFileName) { | ||
| public static UserAgentProperties getUserAgentPropertiesFromProperties(String propertiesFileName) { | ||
|
sima-zhu marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also is this name appropriate getUserAgentPropertiesFromProperties -> getUserAgentPropertiesFromFile ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is actually property files. A particular file.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what object used for. If it needs to have more info for user agent, we can simply extend the object. I reverted the getProperties to public one. If we want to put any other info to property file, we can still use |
||
| Map<String, String> propertyMap = getProperties(propertiesFileName); | ||
| String name = propertyMap.getOrDefault(NAME, "UnknownName"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| String version = propertyMap.getOrDefault(VERSION, "UnknownVersion"); | ||
| return new UserAgentProperties(name, version); | ||
| } | ||
|
|
||
| private static Map<String, String> getProperties(String propertiesFileName) { | ||
| ClientLogger logger = new ClientLogger(CoreUtils.class); | ||
| try (InputStream inputStream = CoreUtils.class.getClassLoader() | ||
| .getResourceAsStream(propertiesFileName)) { | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| name=${project.artifactId} | ||
| version=${project.version} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| credentials_required=Azure Key Vault credentials are required. | ||
| vault_endpoint_required=Azure Key Vault endpoint url is required. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,10 @@ | |
| import com.azure.core.annotation.ServiceClientBuilder; | ||
| import com.azure.core.http.policy.HttpPolicyProviders; | ||
| import com.azure.core.util.Configuration; | ||
| import com.azure.core.util.CoreUtils; | ||
| import com.azure.core.util.UserAgentProperties; | ||
| import com.azure.core.util.logging.ClientLogger; | ||
| import com.azure.security.keyvault.keys.implementation.KeyVaultCredentialPolicy; | ||
| import com.azure.security.keyvault.keys.implementation.AzureKeyVaultConfiguration; | ||
| import com.azure.security.keyvault.keys.models.JsonWebKey; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
@@ -63,7 +64,9 @@ | |
| @ServiceClientBuilder(serviceClients = CryptographyClient.class) | ||
| public final class CryptographyClientBuilder { | ||
| final List<HttpPipelinePolicy> policies; | ||
| final UserAgentProperties properties; | ||
| private final ClientLogger logger = new ClientLogger(CryptographyClientBuilder.class); | ||
| private static final String AZURE_KEY_VAULT_KEYS = "azure-key-vault-keys.properties"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does these file name need to be documented in README or documentation so user know about these names ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version is internal use stuff. README is for public to use. I don't think it needs to put in README. What do you think? Or I can leave a comment above the line.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Users don't need to know about this file. |
||
| private TokenCredential credential; | ||
| private HttpPipeline pipeline; | ||
| private JsonWebKey jsonWebKey; | ||
|
|
@@ -81,6 +84,7 @@ public CryptographyClientBuilder() { | |
| retryPolicy = new RetryPolicy(); | ||
| httpLogOptions = new HttpLogOptions(); | ||
| policies = new ArrayList<>(); | ||
| properties = CoreUtils.getUserAgentPropertiesFromProperties(AZURE_KEY_VAULT_KEYS); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -153,8 +157,8 @@ HttpPipeline setupPipeline() { | |
|
|
||
| // Closest to API goes first, closest to wire goes last. | ||
| final List<HttpPipelinePolicy> policies = new ArrayList<>(); | ||
| policies.add(new UserAgentPolicy(httpLogOptions.getApplicationId(), AzureKeyVaultConfiguration.SDK_NAME, AzureKeyVaultConfiguration.SDK_VERSION, | ||
| buildConfiguration)); | ||
| policies.add(new UserAgentPolicy(httpLogOptions.getApplicationId(), properties.getName(), | ||
| properties.getVersion(), buildConfiguration)); | ||
| HttpPolicyProviders.addBeforeRetryPolicies(policies); | ||
| policies.add(retryPolicy); | ||
| policies.add(new KeyVaultCredentialPolicy(credential)); | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| name=${project.artifactId} | ||
| version=${project.version} |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| name=${project.artifactId} | ||
| version=${project.version} |
Uh oh!
There was an error while loading. Please reload this page.