Skip to content

Commit

Permalink
http-client-java, remove impression pixel (microsoft#5911)
Browse files Browse the repository at this point in the history
for Azure/azure-sdk-for-java#44083

Also update readme template for `AzureCloud`
  • Loading branch information
weidongxu-microsoft authored Feb 8, 2025
1 parent e95cced commit ebc483b
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.54.1</version>
<version>1.55.0</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -47,12 +47,12 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-json</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-xml</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ private static ClassType.Builder getClassTypeBuilder(Class<?> classKey) {
public static final ClassType CLIENT_LOGGER = ClassType.getClassTypeBuilder(ClientLogger.class).build();
public static final ClassType LOG_LEVEL = ClassType.getClassTypeBuilder(LogLevel.class).build();

public static final ClassType AZURE_CLOUD
= new ClassType.Builder(false).packageName("com.azure.core").name("AzureCloud").build();

public static final ClassType AZURE_ENVIRONMENT
= new ClassType.Builder(false).packageName("com.azure.core.management").name("AzureEnvironment").build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public class Project {
public enum Dependency {
// azure
AZURE_CLIENT_SDK_PARENT("com.azure", "azure-client-sdk-parent", "1.7.0"),
AZURE_CORE("com.azure", "azure-core", "1.54.1"),
AZURE_CORE_MANAGEMENT("com.azure", "azure-core-management", "1.15.6"),
AZURE_CORE_HTTP_NETTY("com.azure", "azure-core-http-netty", "1.15.7"),
AZURE_CORE_TEST("com.azure", "azure-core-test", "1.27.0-beta.4"),
AZURE_IDENTITY("com.azure", "azure-identity", "1.15.0"),
AZURE_CORE_EXPERIMENTAL("com.azure", "azure-core-experimental", "1.0.0-beta.56"),
AZURE_CORE("com.azure", "azure-core", "1.55.0"),
AZURE_CORE_MANAGEMENT("com.azure", "azure-core-management", "1.16.0"),
AZURE_CORE_HTTP_NETTY("com.azure", "azure-core-http-netty", "1.15.8"),
AZURE_CORE_TEST("com.azure", "azure-core-test", "1.27.0-beta.5"),
AZURE_IDENTITY("com.azure", "azure-identity", "1.15.1"),
AZURE_CORE_EXPERIMENTAL("com.azure", "azure-core-experimental", "1.0.0-beta.57"),

CLIENTCORE("io.clientcore", "core", "1.0.0-beta.2");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public String write(Project project) {
return TemplateUtil.loadTextFromResource("Readme_protocol.txt", TemplateUtil.SERVICE_NAME,
project.getServiceName(), TemplateUtil.SERVICE_DESCRIPTION, project.getServiceDescriptionForMarkdown(),
TemplateUtil.GROUP_ID, project.getGroupId(), TemplateUtil.ARTIFACT_ID, project.getArtifactId(),
TemplateUtil.ARTIFACT_VERSION, project.getVersion(), TemplateUtil.PACKAGE_NAME, project.getNamespace(),
TemplateUtil.IMPRESSION_PIXEL, getImpression(project));
TemplateUtil.ARTIFACT_VERSION, project.getVersion(), TemplateUtil.PACKAGE_NAME, project.getNamespace());
}

protected static String getImpression(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class TemplateUtil {
public static final String ARTIFACT_ID = "artifact-id";
public static final String ARTIFACT_VERSION = "artifact-version";
public static final String PACKAGE_NAME = "package-name";
public static final String IMPRESSION_PIXEL = "impression-pixel";
// public static final String IMPRESSION_PIXEL = "impression-pixel";

public static final String MANAGER_CLASS = "manager-class";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,3 @@ For details on contributing to this repository, see the [contributing guide](htt
[jdk]: https://learn.microsoft.com/azure/developer/java/fundamentals/
[azure_subscription]: https://azure.microsoft.com/free/
[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity

{{impression-pixel}}
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-json</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-xml</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.54.1</version>
<version>1.55.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>1.15.7</version>
<version>1.15.8</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.27.0-beta.4</version>
<version>1.27.0-beta.5</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-management</artifactId>
<version>1.15.6</version>
<version>1.16.0</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ public void write(FluentLiveTests liveTests, JavaFile javaFile) {
classBlock.privateMemberVariable(liveTests.getManagerType().getName(), liveTests.getManagerName());
// write setup
classBlock.annotation("Override");
classBlock.publicMethod("void beforeTest()",
methodBlock -> methodBlock.line(String.format(
"%s = %s.configure().withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))"
+ ".authenticate("
+ "new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureEnvironment.AZURE)"
+ ");",
liveTests.getManagerName(), liveTests.getManagerType().getName())));
classBlock.publicMethod("void beforeTest()", methodBlock -> methodBlock.line(String.format(
"%s = %s.configure().withLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC))"
+ ".authenticate("
+ "new DefaultAzureCredentialBuilder().build(), new AzureProfile(AzureCloud.AZURE_PUBLIC_CLOUD)"
+ ");",
liveTests.getManagerName(), liveTests.getManagerType().getName())));
// write method signature
if (!CoreUtils.isNullOrEmpty(testCase.getDescription())) {
classBlock.javadocComment(testCase.getDescription());
Expand Down Expand Up @@ -75,7 +74,7 @@ private void addImports(FluentLiveTests liveTests, JavaFile javaFile) {
javaFile.declareImport(liveTests.getManagerType().getFullName());
javaFile.declareImport("org.junit.jupiter.api.Test", "org.junit.jupiter.api.BeforeEach");
javaFile.declareImport("com.azure.identity.DefaultAzureCredentialBuilder",
"com.azure.core.management.profile.AzureProfile", "com.azure.core.management.AzureEnvironment");
"com.azure.core.management.profile.AzureProfile", "com.azure.core.models.AzureCloud");
javaFile.declareImport("com.azure.core.test.annotation.DoNotRecord", "com.azure.core.test.TestBase");
javaFile.declareImport("com.azure.core.http.policy.HttpLogOptions",
"com.azure.core.http.policy.HttpLogDetailLevel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void write(ClientMethodInfo info, JavaFile javaFile) {
= new HashSet<>(Arrays.asList(AccessToken.class.getName(), ClassType.HTTP_CLIENT.getFullName(),
ClassType.HTTP_HEADERS.getFullName(), ClassType.HTTP_REQUEST.getFullName(),
HttpResponse.class.getName(), "com.azure.core.test.http.MockHttpResponse",
ClassType.AZURE_ENVIRONMENT.getFullName(), AzureProfile.class.getName(), "org.junit.jupiter.api.Test",
ClassType.AZURE_CLOUD.getFullName(), AzureProfile.class.getName(), "org.junit.jupiter.api.Test",
ByteBuffer.class.getName(), Mono.class.getName(), Flux.class.getName(),
StandardCharsets.class.getName(), OffsetDateTime.class.getName()));

Expand Down Expand Up @@ -141,7 +141,7 @@ public void write(ClientMethodInfo info, JavaFile javaFile) {
methodBlock.line(exampleMethodName + " manager = " + exampleMethodName + ".configure()"
+ ".withHttpClient(httpClient).authenticate(tokenRequestContext -> "
+ "Mono.just(new AccessToken(\"this_is_a_token\", OffsetDateTime.MAX)), "
+ "new AzureProfile(\"\", \"\", AzureEnvironment.AZURE));");
+ "new AzureProfile(\"\", \"\", AzureCloud.AZURE_PUBLIC_CLOUD));");
methodBlock.line();
// method invocation
methodBlock.line(clientMethodInvocationWithResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public String write(FluentProject project) {
TemplateUtil.SERVICE_DESCRIPTION, project.getServiceDescriptionForMarkdown(), TemplateUtil.GROUP_ID,
project.getGroupId(), TemplateUtil.ARTIFACT_ID, project.getArtifactId(), TemplateUtil.ARTIFACT_VERSION,
project.getVersion(), TemplateUtil.MANAGER_CLASS, FluentStatic.getFluentManager().getType().getName(),
TemplateUtil.SAMPLE_CODES, sampleCodesBuilder.toString(), TemplateUtil.IMPRESSION_PIXEL,
getImpression(project));
TemplateUtil.SAMPLE_CODES, sampleCodesBuilder.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ Azure subscription ID can be configured via `AZURE_SUBSCRIPTION_ID` environment
Assuming the use of the `DefaultAzureCredential` credential class, the client can be authenticated using the following code:

```java
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
AzureProfile profile = new AzureProfile(AzureCloud.AZURE_PUBLIC_CLOUD);
TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.build();
{{manager-class}} manager = {{manager-class}}
.authenticate(credential, profile);
```

The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.
The sample code assumes global Azure. Please change the `AzureCloud.AZURE_PUBLIC_CLOUD` variable if otherwise.

See [Authentication][authenticate] for more options.

Expand Down Expand Up @@ -99,5 +99,3 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m
[cg]: https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md
[coc]: https://opensource.microsoft.com/codeofconduct/
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/

{{impression-pixel}}
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.54.1</version>
<version>1.55.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-json</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-xml</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.27.0-beta.4</version>
<version>1.27.0-beta.5</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -50,12 +50,12 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.15.0</version>
<version>1.15.1</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-management</artifactId>
<version>1.15.6</version>
<version>1.16.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down

0 comments on commit ebc483b

Please sign in to comment.