Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions sdk/management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Azure Management Libraries require a `TokenCredential` implementation for authen
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.0-beta.5</version>
<version>1.0.8</version>
</dependency>
```
[//]: # ({x-version-update-end})
Expand All @@ -58,7 +58,7 @@ Azure Management Libraries require a `TokenCredential` implementation for authen
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>1.5.2</version>
<version>1.5.3</version>
</dependency>
```
[//]: # ({x-version-update-end})
Expand Down
9 changes: 2 additions & 7 deletions sdk/management/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-management</artifactId>
Expand Down Expand Up @@ -113,13 +108,13 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>1.4.0</version>
<version>1.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.0-beta.3</version>
<version>1.0.8</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
12 changes: 8 additions & 4 deletions sdk/resources/mgmt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<legal>
<![CDATA[[INFO] Any downloads listed may be third party software. Microsoft grants you no rights for third party software.]]></legal>
<version>${project.version}</version>
</properties>

<developers>
Expand All @@ -47,10 +48,6 @@
</developers>

<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-management</artifactId>
Expand Down Expand Up @@ -92,6 +89,13 @@
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Comment on lines +91 to +96

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Now doing this for version @yungezz


<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,17 @@ public abstract class AzureServiceClient {

private final ClientLogger logger = new ClientLogger(getClass());

private static final Map<String, String> PROPERTIES =
CoreUtils.getProperties("azure.properties");

protected AzureServiceClient(HttpPipeline httpPipeline, AzureEnvironment environment) {
((AzureJacksonAdapter) serializerAdapter).serializer().registerModule(DateTimeDeserializer.getModule());
}

private static final String OS;
private static final String OS_NAME;
private static final String OS_VERSION;
private static final String JAVA_VERSION;
private static final String SDK_VERSION = "2.0.0-SNAPSHOT";

static {
OS_NAME = System.getProperty("os.name");
OS_VERSION = System.getProperty("os.version");
OS = OS_NAME + "/" + OS_VERSION;
String version = System.getProperty("java.version");
JAVA_VERSION = version != null ? version : "Unknown";
}

private final SerializerAdapter serializerAdapter = new AzureJacksonAdapter();

private String sdkName;
private static String sdkVersion;

/**
* Gets serializer adapter for JSON serialization/de-serialization.
Expand All @@ -83,24 +73,14 @@ public SerializerAdapter getSerializerAdapter() {
* @return the default client context.
*/
public Context getContext() {
Context context = new Context("java.version", JAVA_VERSION);
if (!CoreUtils.isNullOrEmpty(OS_NAME)) {
context = context.addData("os.name", OS_NAME);
}
if (!CoreUtils.isNullOrEmpty(OS_VERSION)) {
context = context.addData("os.version", OS_VERSION);
}
if (sdkName == null) {
String packageName = this.getClass().getPackage().getName();
if (packageName.endsWith(".models")) {
sdkName = packageName.substring(0, packageName.length() - ".models".length());
} else {
sdkName = packageName;
}
sdkName = this.getClass().getPackage().getName();
}
context = context.addData("Sdk-Name", sdkName);
context = context.addData("Sdk-Version", SDK_VERSION);
return context;
if (sdkVersion == null) {
sdkVersion = PROPERTIES.getOrDefault("version", "UnknownVersion");
}
return new Context("Sdk-Name", sdkName)
.addData("Sdk-Version", sdkVersion);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,12 @@ public class UserAgentPolicy implements HttpPipelinePolicy {
private static final String SDK_VERSION_KEY = "Sdk-Version";
private static final String APPLICATION_ID_KEY = "Application-Id";

private static final String OS_NAME = System.getProperty("os.name");
private static final String OS_VERSION = System.getProperty("os.version");
private static final String JAVA_VERSION = System.getProperty("java.version");

/*
* The base User-Agent header format is azsdk-java-<client_lib>/<sdk_version>. Additional information such as the
* application ID will be prepended and platform telemetry will be appended, a fully configured User-Agent header
* format is <application_id> azsdk-java-<client_lib>/<sdk_version> <platform_info>.
*/
private static final String DEFAULT_USER_AGENT_FORMAT = "azsdk-java-%s/%s";

// From the design guidelines, the platform info format is:
// <language runtime>; <os name> <os version>
private static final String PLATFORM_INFO_FORMAT = "%s; %s %s";

private final String defaultSdkName = this.getClass().getPackage().getName();
private final String defaultSdkVersion = this.getClass().getPackage().getSpecificationVersion();

private final HttpLogOptions httpLogOptions;
private final Configuration configuration;

private static final UserAgentPolicy DEFAULT_USER_AGENT_POLICY = new UserAgentPolicy(null, null);

/**
* @return default user agent policy
*/
public static UserAgentPolicy getDefaultUserAgentPolicy() {
return DEFAULT_USER_AGENT_POLICY;
}

/**
* @param httpLogOptions used for get application id
* @param configuration used for check telemetry enable or not
Expand All @@ -69,31 +45,30 @@ public UserAgentPolicy(HttpLogOptions httpLogOptions, Configuration configuratio
}
}

protected String buildUserAgent(String applicationId, String sdkName, String sdkVersion) {
private static String toUserAgentString(String applicationId, String sdkName, String sdkVersion, Configuration configuration) {
StringBuilder userAgentBuilder = new StringBuilder();

// Only add the application ID if it is present as it is optional.
if (applicationId != null) {
applicationId = applicationId.length() > 24 ? applicationId.substring(0, 24) : applicationId;
userAgentBuilder.append(applicationId).append(" ");
}

// Add the required default User-Agent string.
userAgentBuilder.append(String.format(DEFAULT_USER_AGENT_FORMAT, sdkName, sdkVersion));

// Only add the platform telemetry if it is allowed as it is optional.
if (!telemetryDisabled()) {
String platformInfo = String.format(PLATFORM_INFO_FORMAT, JAVA_VERSION, OS_NAME, OS_VERSION);
userAgentBuilder.append(" ")
.append("(")
.append(platformInfo)
.append(")");
userAgentBuilder.append("azsdk-java").append("-").append(sdkName).append("/").append(sdkVersion);
if (!isTelemetryDisabled(configuration)) {
userAgentBuilder.append(" ").append("(").append(getPlatformInfo()).append(")");
}

return userAgentBuilder.toString();
}

private boolean telemetryDisabled() {
return configuration.get(Configuration.PROPERTY_AZURE_TELEMETRY_DISABLED, false);
private static String getPlatformInfo() {
String javaVersion = Configuration.getGlobalConfiguration().get("java.version");
String osName = Configuration.getGlobalConfiguration().get("os.name");
String osVersion = Configuration.getGlobalConfiguration().get("os.version");
return String.format("%s; %s; %s", javaVersion, osName, osVersion);
}

private static boolean isTelemetryDisabled(Configuration configuration) {
return configuration == null ? (Boolean)Configuration.getGlobalConfiguration().get("AZURE_TELEMETRY_DISABLED", false) : (Boolean)configuration.get("AZURE_TELEMETRY_DISABLED", false);
}

@Override
Expand Down Expand Up @@ -124,7 +99,9 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
applicationId = httpLogOptions.getApplicationId();
}

context.getHttpRequest().setHeader(USER_AGENT_KEY, buildUserAgent(applicationId, sdkName, sdkVersion));
context.getHttpRequest().setHeader(USER_AGENT_KEY,
//UserAgentUtil.toUserAgentString(applicationId, sdkName, sdkVersion, configuration));
toUserAgentString(applicationId, sdkName, sdkVersion, configuration));
return next.process();
}
}
1 change: 1 addition & 0 deletions sdk/resources/mgmt/src/main/resources/azure.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=${project.version}