Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/versioning/external_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,4 @@ media_com.microsoft.azure:adal4j;1.2.0
servicebus_com.microsoft.azure:azure-client-authentication;1.6.7

# sdk\storage\azure-storage-blob-cryptography\pom.xml
storage_com.microsoft.azure:azure-storage;8.4.0
storage_com.microsoft.azure:azure-storage;8.4.0
3 changes: 0 additions & 3 deletions eng/versioning/version_client_java_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

# The file format here should be the relative path from the root of the azure-sdk-for-java
sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ClientConstants.java
sdk/keyvault/azure-security-keyvault-certificates/src/main/java/com/azure/security/keyvault/certificates/AzureKeyVaultConfiguration.java
sdk/keyvault/azure-security-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/implementation/AzureKeyVaultConfiguration.java
sdk/keyvault/azure-security-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/AzureKeyVaultConfiguration.java
sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/BuilderHelper.java
Comment thread
sima-zhu marked this conversation as resolved.
sdk/storage/azure-storage-blob-cryptography/src/main/java/com/azure/storage/blob/specialized/cryptography/BlobCryptographyConfiguration.java
sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/implementation/util/BuilderHelper.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.azure.core.http.policy.UserAgentPolicy;
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.data.appconfiguration.implementation.ConfigurationClientCredentials;
import com.azure.data.appconfiguration.implementation.ConfigurationCredentialsPolicy;
Expand Down Expand Up @@ -77,15 +78,12 @@ public final class ConfigurationClientBuilder {
private static final String ACCEPT_HEADER = "Accept";
private static final String ACCEPT_HEADER_VALUE = "application/vnd.microsoft.azconfig.kv+json";
private static final String APP_CONFIG_PROPERTIES = "azure-appconfig.properties";
private static final String NAME = "name";
private static final String VERSION = "version";
private static final RetryPolicy DEFAULT_RETRY_POLICY = new RetryPolicy("retry-after-ms", ChronoUnit.MILLIS);

private final ClientLogger logger = new ClientLogger(ConfigurationClientBuilder.class);
private final List<HttpPipelinePolicy> policies;
private final HttpHeaders headers;
private final String clientName;
private final String clientVersion;
private final UserAgentProperties properties;

private ConfigurationClientCredentials credential;
private TokenCredential tokenCredential;
Expand All @@ -105,9 +103,7 @@ public ConfigurationClientBuilder() {
policies = new ArrayList<>();
httpLogOptions = new HttpLogOptions();

Map<String, String> properties = CoreUtils.getProperties(APP_CONFIG_PROPERTIES);
clientName = properties.getOrDefault(NAME, "UnknownName");
clientVersion = properties.getOrDefault(VERSION, "UnknownVersion");
properties = CoreUtils.getUserAgentPropertiesFromProperties(APP_CONFIG_PROPERTIES);

headers = new HttpHeaders()
.put(ECHO_REQUEST_ID_HEADER, "true")
Expand Down Expand Up @@ -175,8 +171,8 @@ public ConfigurationAsyncClient buildAsyncClient() {
// Closest to API goes first, closest to wire goes last.
final List<HttpPipelinePolicy> policies = new ArrayList<>();

policies.add(new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion,
buildConfiguration));
policies.add(new UserAgentPolicy(httpLogOptions.getApplicationId(), properties.getName(),
properties.getVersion(), buildConfiguration));
policies.add(new RequestIdPolicy());
policies.add(new AddHeadersPolicy(headers));
policies.add(new AddDatePolicy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Comment thread
sima-zhu marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is this name appropriate getUserAgentPropertiesFromProperties -> getUserAgentPropertiesFromFile ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually property files. A particular file.
Is getUserAgentProperties enough for the name. I don't like the name either.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have getProperties() method that returns a map. Client libraries should call that method and look up whatever properties they want. UserAgentProperties is too specific and will not allow for additional properties to be read from properties file.

@sima-zhu sima-zhu Nov 26, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 getProperties().

Map<String, String> propertyMap = getProperties(propertiesFileName);
String name = propertyMap.getOrDefault(NAME, "UnknownName");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnknownName and UnknownVersion can also be made constants.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ public void findFirstOfTypeWithNoneOfType() {

@Test
public void testProperties() {
assertNotNull(CoreUtils.getProperties("azure-core.properties").get("version"));
assertNotNull(CoreUtils.getProperties("azure-core.properties").get("name"));
assertTrue(CoreUtils.getProperties("azure-core.properties").get("version")
assertNotNull(CoreUtils.getUserAgentPropertiesFromProperties("azure-core.properties").getVersion());
assertNotNull(CoreUtils.getUserAgentPropertiesFromProperties("azure-core.properties").getName());
assertTrue(CoreUtils.getUserAgentPropertiesFromProperties("azure-core.properties").getVersion()
Comment thread
sima-zhu marked this conversation as resolved.
Outdated
.matches("\\d.\\d.\\d([-a-zA-Z0-9.])*"));
}

@Test
public void testMissingProperties() {
assertNotNull(CoreUtils.getProperties("foo.properties"));
assertTrue(CoreUtils.getProperties("foo.properties").isEmpty());
assertNull(CoreUtils.getProperties("azure-core.properties").get("foo"));
assertTrue(CoreUtils.getUserAgentPropertiesFromProperties("foo.properties")
.getVersion().matches("UnknownVersion"));
assertTrue(CoreUtils.getUserAgentPropertiesFromProperties("foo.properties")
.getName().matches("UnknownName"));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.Configuration;
import com.azure.core.util.UserAgentProperties;
import com.azure.core.util.logging.ClientLogger;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -55,8 +56,9 @@
@ServiceClientBuilder(serviceClients = {CertificateClient.class, CertificateAsyncClient.class})
public final class CertificateClientBuilder {
private final ClientLogger logger = new ClientLogger(CertificateClientBuilder.class);

private static final String AZURE_KEY_VAULT_CERTIFICATES_PROPERTIES = "azure-key-vault-certificates.properties";
private final List<HttpPipelinePolicy> policies;
private final UserAgentProperties properties;
private TokenCredential credential;
private HttpPipeline pipeline;
private URL vaultUrl;
Expand All @@ -73,6 +75,7 @@ public CertificateClientBuilder() {
retryPolicy = new RetryPolicy();
httpLogOptions = new HttpLogOptions();
policies = new ArrayList<>();
properties = CoreUtils.getUserAgentPropertiesFromProperties(AZURE_KEY_VAULT_CERTIFICATES_PROPERTIES);
}

/**
Expand Down Expand Up @@ -108,11 +111,13 @@ public CertificateClient buildClient() {
* {@link CertificateClientBuilder#vaultUrl(String)} have not been set.
*/
public CertificateAsyncClient buildAsyncClient() {
Configuration buildConfiguration = (configuration == null) ? Configuration.getGlobalConfiguration().clone() : configuration;
Configuration buildConfiguration = (configuration == null) ? Configuration.getGlobalConfiguration().clone() :
configuration;
URL buildEndpoint = getBuildEndpoint(buildConfiguration);

if (buildEndpoint == null) {
throw logger.logExceptionAsError(new IllegalStateException(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED)));
throw logger.logExceptionAsError(new IllegalStateException(
KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.VAULT_END_POINT_REQUIRED)));
}
CertificateServiceVersion serviceVersion = version != null ? version : CertificateServiceVersion.getLatest();

Expand All @@ -121,12 +126,14 @@ public CertificateAsyncClient buildAsyncClient() {
}

if (credential == null) {
throw logger.logExceptionAsError(new IllegalStateException(KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.CREDENTIALS_REQUIRED)));
throw logger.logExceptionAsError(new IllegalStateException(
KeyVaultErrorCodeStrings.getErrorString(KeyVaultErrorCodeStrings.CREDENTIALS_REQUIRED)));
}

// 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));
Expand Down
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
Expand Up @@ -17,8 +17,8 @@
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.annotation.ServiceClientBuilder;
import com.azure.core.util.UserAgentProperties;
import com.azure.core.util.logging.ClientLogger;
import com.azure.security.keyvault.keys.implementation.AzureKeyVaultConfiguration;
import com.azure.security.keyvault.keys.implementation.KeyVaultCredentialPolicy;

import java.net.MalformedURLException;
Expand Down Expand Up @@ -60,8 +60,10 @@
@ServiceClientBuilder(serviceClients = KeyClient.class)
public final class KeyClientBuilder {
private final ClientLogger logger = new ClientLogger(KeyClientBuilder.class);
private static final String AZURE_KEY_VAULT_KEYS = "azure-key-vault-keys.properties";

private final List<HttpPipelinePolicy> policies;
private final UserAgentProperties properties;
private TokenCredential credential;
private HttpPipeline pipeline;
private URL vaultUrl;
Expand All @@ -78,6 +80,7 @@ public KeyClientBuilder() {
retryPolicy = new RetryPolicy();
httpLogOptions = new HttpLogOptions();
policies = new ArrayList<>();
properties = CoreUtils.getUserAgentPropertiesFromProperties(AZURE_KEY_VAULT_KEYS);
}

/**
Expand Down Expand Up @@ -136,7 +139,7 @@ public KeyAsyncClient buildAsyncClient() {

// 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,
policies.add(new UserAgentPolicy(httpLogOptions.getApplicationId(), properties.getName(), properties.getVersion(),
buildConfiguration));
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(retryPolicy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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;
Expand All @@ -81,6 +84,7 @@ public CryptographyClientBuilder() {
retryPolicy = new RetryPolicy();
httpLogOptions = new HttpLogOptions();
policies = new ArrayList<>();
properties = CoreUtils.getUserAgentPropertiesFromProperties(AZURE_KEY_VAULT_KEYS);
}

/**
Expand Down Expand Up @@ -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));
Expand Down

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
Expand Up @@ -21,7 +21,6 @@
import com.azure.core.test.TestBase;
import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.security.keyvault.keys.implementation.AzureKeyVaultConfiguration;
import com.azure.security.keyvault.keys.models.CreateKeyOptions;
import com.azure.security.keyvault.keys.models.KeyType;
import com.azure.security.keyvault.keys.models.KeyVaultKey;
Expand All @@ -47,6 +46,8 @@ public abstract class KeyClientTestBase extends TestBase {
private static final String KEY_NAME = "javaKeyTemp";
private static final KeyType RSA_KEY_TYPE = KeyType.RSA;
private static final KeyType EC_KEY_TYPE = KeyType.EC;
private static final String SDK_NAME = "client_name";
private static final String SDK_VERSION = "client_version";

@Override
protected String getTestName() {
Expand All @@ -70,7 +71,7 @@ <T> T clientSetup(Function<HttpPipeline, T> clientBuilder) {
HttpClient httpClient;
// Closest to API goes first, closest to wire goes last.
final List<HttpPipelinePolicy> policies = new ArrayList<>();
policies.add(new UserAgentPolicy(AzureKeyVaultConfiguration.SDK_NAME, AzureKeyVaultConfiguration.SDK_VERSION, Configuration.getGlobalConfiguration().clone(), KeyServiceVersion.getLatest()));
policies.add(new UserAgentPolicy(SDK_NAME, SDK_VERSION, Configuration.getGlobalConfiguration().clone(), KeyServiceVersion.getLatest()));
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(new RetryPolicy());
if (credential != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.azure.core.test.TestBase;
import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.security.keyvault.keys.implementation.AzureKeyVaultConfiguration;
import org.junit.jupiter.api.Test;

import java.math.BigInteger;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.UserAgentProperties;
import com.azure.core.util.logging.ClientLogger;
import com.azure.security.keyvault.secrets.implementation.KeyVaultCredentialPolicy;

Expand Down Expand Up @@ -58,8 +59,10 @@
@ServiceClientBuilder(serviceClients = SecretClient.class)
public final class SecretClientBuilder {
private final ClientLogger logger = new ClientLogger(SecretClientBuilder.class);
private static final String AZURE_KEY_VAULT_SECRETS = "azure-key-vault-secrets.properties";

private final List<HttpPipelinePolicy> policies;
final UserAgentProperties properties;
private TokenCredential credential;
private HttpPipeline pipeline;
private URL vaultUrl;
Expand All @@ -76,6 +79,7 @@ public SecretClientBuilder() {
retryPolicy = new RetryPolicy();
httpLogOptions = new HttpLogOptions();
policies = new ArrayList<>();
properties = CoreUtils.getUserAgentPropertiesFromProperties(AZURE_KEY_VAULT_SECRETS);
}

/**
Expand Down Expand Up @@ -137,8 +141,8 @@ public SecretAsyncClient buildAsyncClient() {

// 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));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=${project.artifactId}
version=${project.version}
Loading