diff --git a/sdk/monitor/azure-monitor-ingestion/CHANGELOG.md b/sdk/monitor/azure-monitor-ingestion/CHANGELOG.md
index 53d412567e5e..30a74593c1f2 100644
--- a/sdk/monitor/azure-monitor-ingestion/CHANGELOG.md
+++ b/sdk/monitor/azure-monitor-ingestion/CHANGELOG.md
@@ -4,6 +4,9 @@
### Features Added
+- Introduced `LogsIngestionAudience` to allow specification of the audience of logs ingestion clients.
+- Support for the scopes of non-public clouds.
+
### Breaking Changes
### Bugs Fixed
diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java
index 9d27d086e59c..071e0eb274d3 100644
--- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java
+++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java
@@ -20,6 +20,7 @@
import com.azure.core.util.logging.ClientLogger;
import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesClientBuilder;
import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesServiceVersion;
+import com.azure.monitor.ingestion.models.LogsIngestionAudience;
import java.net.MalformedURLException;
import java.net.URL;
@@ -171,6 +172,19 @@ public LogsIngestionClientBuilder credential(TokenCredential tokenCredential) {
return this;
}
+
+ /**
+ * Sets the audience for the authorization scope of log ingestion clients. If this value is not set, the default
+ * audience will be the azure public cloud.
+ *
+ * @param audience the audience value.
+ * @return the updated {@link LogsIngestionClientBuilder}.
+ */
+ public LogsIngestionClientBuilder audience(LogsIngestionAudience audience) {
+ innerLogBuilder.audience(audience);
+ return this;
+ }
+
/**
* {@inheritDoc}
*/
diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesAsyncClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesAsyncClient.java
index 736c735ca2e4..6410374635f8 100644
--- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesAsyncClient.java
+++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesAsyncClient.java
@@ -17,14 +17,17 @@
import com.azure.core.util.BinaryData;
import reactor.core.publisher.Mono;
-/** Initializes a new instance of the asynchronous IngestionUsingDataCollectionRulesClient type. */
+/**
+ * Initializes a new instance of the asynchronous IngestionUsingDataCollectionRulesClient type.
+ */
@ServiceClient(builder = IngestionUsingDataCollectionRulesClientBuilder.class, isAsync = true)
public final class IngestionUsingDataCollectionRulesAsyncClient {
- @Generated private final IngestionUsingDataCollectionRulesClientImpl serviceClient;
+ @Generated
+ private final IngestionUsingDataCollectionRulesClientImpl serviceClient;
/**
* Initializes an instance of IngestionUsingDataCollectionRulesAsyncClient class.
- *
+ *
* @param serviceClient the service client implementation.
*/
@Generated
@@ -34,28 +37,23 @@ public final class IngestionUsingDataCollectionRulesAsyncClient {
/**
* Ingestion API used to directly ingest data using Data Collection Rules
- *
- *
See error response code and error response message for more detail.
- *
- *
Header Parameters
- *
+ *
+ * See error response code and error response message for more detail.
+ *
Header Parameters
*
* Header Parameters
* | Name | Type | Required | Description |
* | Content-Encoding | String | No | gzip |
* | x-ms-client-request-id | String | No | Client request Id |
*
- *
* You can add these to a request with {@link RequestOptions#addHeader}
- *
- * Request Body Schema
- *
+ *
Request Body Schema
* {@code
* [
* Object (Required)
* ]
* }
- *
+ *
* @param ruleId The immutable Id of the Data Collection Rule resource.
* @param stream The streamDeclaration name as defined in the Data Collection Rule.
* @param body An array of objects matching the schema defined by the provided stream.
@@ -68,8 +66,8 @@ public final class IngestionUsingDataCollectionRulesAsyncClient {
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> uploadWithResponse(
- String ruleId, String stream, BinaryData body, RequestOptions requestOptions) {
+ public Mono> uploadWithResponse(String ruleId, String stream, BinaryData body,
+ RequestOptions requestOptions) {
return this.serviceClient.uploadWithResponseAsync(ruleId, stream, body, requestOptions);
}
}
diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClient.java
index 4fe8cb55eb44..9af4b9ba8ed3 100644
--- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClient.java
+++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClient.java
@@ -16,45 +16,43 @@
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
-/** Initializes a new instance of the synchronous IngestionUsingDataCollectionRulesClient type. */
+/**
+ * Initializes a new instance of the synchronous IngestionUsingDataCollectionRulesClient type.
+ */
@ServiceClient(builder = IngestionUsingDataCollectionRulesClientBuilder.class)
public final class IngestionUsingDataCollectionRulesClient {
- @Generated private final IngestionUsingDataCollectionRulesClientImpl serviceClient;
+ @Generated
+ private final IngestionUsingDataCollectionRulesClientImpl serviceClient;
/**
* Initializes an instance of IngestionUsingDataCollectionRulesClient class.
- *
- * @param client the async client.
+ *
+ * @param serviceClient the service client implementation.
*/
@Generated
- IngestionUsingDataCollectionRulesClient(IngestionUsingDataCollectionRulesClientImpl client) {
- this.serviceClient = client;
+ IngestionUsingDataCollectionRulesClient(IngestionUsingDataCollectionRulesClientImpl serviceClient) {
+ this.serviceClient = serviceClient;
}
/**
* Ingestion API used to directly ingest data using Data Collection Rules
- *
- * See error response code and error response message for more detail.
- *
- *
Header Parameters
- *
+ *
+ * See error response code and error response message for more detail.
+ *
Header Parameters
*
* Header Parameters
* | Name | Type | Required | Description |
* | Content-Encoding | String | No | gzip |
* | x-ms-client-request-id | String | No | Client request Id |
*
- *
* You can add these to a request with {@link RequestOptions#addHeader}
- *
- * Request Body Schema
- *
+ *
Request Body Schema
* {@code
* [
* Object (Required)
* ]
* }
- *
+ *
* @param ruleId The immutable Id of the Data Collection Rule resource.
* @param stream The streamDeclaration name as defined in the Data Collection Rule.
* @param body An array of objects matching the schema defined by the provided stream.
@@ -67,8 +65,8 @@ public final class IngestionUsingDataCollectionRulesClient {
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
- public Response uploadWithResponse(
- String ruleId, String stream, BinaryData body, RequestOptions requestOptions) {
+ public Response uploadWithResponse(String ruleId, String stream, BinaryData body,
+ RequestOptions requestOptions) {
return this.serviceClient.uploadWithResponse(ruleId, stream, body, requestOptions);
}
}
diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java
index fba9adabadcf..e42664a70497 100644
--- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java
+++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.
-
package com.azure.monitor.ingestion.implementation;
+import com.azure.monitor.ingestion.models.LogsIngestionAudience;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ServiceClientBuilder;
import com.azure.core.client.traits.ConfigurationTrait;
@@ -12,6 +12,7 @@
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
+import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
@@ -20,9 +21,8 @@
import com.azure.core.http.policy.AddHeadersFromContextPolicy;
import com.azure.core.http.policy.AddHeadersPolicy;
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy;
-import com.azure.core.http.policy.CookiePolicy;
-import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpLoggingPolicy;
+import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.HttpPolicyProviders;
import com.azure.core.http.policy.RequestIdPolicy;
@@ -33,36 +33,44 @@
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.builder.ClientBuilderUtil;
+import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.serializer.JacksonAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.stream.Collectors;
-/** A builder for creating a new instance of the IngestionUsingDataCollectionRulesClient type. */
+/**
+ * A builder for creating a new instance of the IngestionUsingDataCollectionRulesClient type.
+ */
@ServiceClientBuilder(
- serviceClients = {
- IngestionUsingDataCollectionRulesClient.class,
- IngestionUsingDataCollectionRulesAsyncClient.class
- })
+ serviceClients = {
+ IngestionUsingDataCollectionRulesClient.class,
+ IngestionUsingDataCollectionRulesAsyncClient.class })
public final class IngestionUsingDataCollectionRulesClientBuilder
- implements HttpTrait,
- ConfigurationTrait,
- TokenCredentialTrait,
- EndpointTrait {
- @Generated private static final String SDK_NAME = "name";
+ implements HttpTrait,
+ ConfigurationTrait,
+ TokenCredentialTrait,
+ EndpointTrait {
- @Generated private static final String SDK_VERSION = "version";
+ @Generated
+ private static final String SDK_NAME = "name";
- @Generated private static final String[] DEFAULT_SCOPES = new String[] {"https://monitor.azure.com//.default"};
+ @Generated
+ private static final String SDK_VERSION = "version";
+
+ @Generated
+ private static final String[] DEFAULT_SCOPES = new String[] { "https://monitor.azure.com//.default" };
@Generated
private static final Map PROPERTIES = CoreUtils.getProperties("azure-monitor-ingestion.properties");
- @Generated private final List pipelinePolicies;
+ @Generated
+ private final List pipelinePolicies;
- /** Create an instance of the IngestionUsingDataCollectionRulesClientBuilder. */
+ /**
+ * Create an instance of the IngestionUsingDataCollectionRulesClientBuilder.
+ */
@Generated
public IngestionUsingDataCollectionRulesClientBuilder() {
this.pipelinePolicies = new ArrayList<>();
@@ -71,12 +79,18 @@ public IngestionUsingDataCollectionRulesClientBuilder() {
/*
* The HTTP pipeline to send requests through.
*/
- @Generated private HttpPipeline pipeline;
+ @Generated
+ private HttpPipeline pipeline;
- /** {@inheritDoc}. */
+ /**
+ * {@inheritDoc}.
+ */
@Generated
@Override
public IngestionUsingDataCollectionRulesClientBuilder pipeline(HttpPipeline pipeline) {
+ if (this.pipeline != null && pipeline == null) {
+ LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
+ }
this.pipeline = pipeline;
return this;
}
@@ -84,9 +98,12 @@ public IngestionUsingDataCollectionRulesClientBuilder pipeline(HttpPipeline pipe
/*
* The HTTP client used to send the request.
*/
- @Generated private HttpClient httpClient;
+ @Generated
+ private HttpClient httpClient;
- /** {@inheritDoc}. */
+ /**
+ * {@inheritDoc}.
+ */
@Generated
@Override
public IngestionUsingDataCollectionRulesClientBuilder httpClient(HttpClient httpClient) {
@@ -97,9 +114,12 @@ public IngestionUsingDataCollectionRulesClientBuilder httpClient(HttpClient http
/*
* The logging configuration for HTTP requests and responses.
*/
- @Generated private HttpLogOptions httpLogOptions;
+ @Generated
+ private HttpLogOptions httpLogOptions;
- /** {@inheritDoc}. */
+ /**
+ * {@inheritDoc}.
+ */
@Generated
@Override
public IngestionUsingDataCollectionRulesClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
@@ -110,9 +130,12 @@ public IngestionUsingDataCollectionRulesClientBuilder httpLogOptions(HttpLogOpti
/*
* The client options such as application ID and custom headers to set on a request.
*/
- @Generated private ClientOptions clientOptions;
+ @Generated
+ private ClientOptions clientOptions;
- /** {@inheritDoc}. */
+ /**
+ * {@inheritDoc}.
+ */
@Generated
@Override
public IngestionUsingDataCollectionRulesClientBuilder clientOptions(ClientOptions clientOptions) {
@@ -123,9 +146,12 @@ public IngestionUsingDataCollectionRulesClientBuilder clientOptions(ClientOption
/*
* The retry options to configure retry policy for failed requests.
*/
- @Generated private RetryOptions retryOptions;
+ @Generated
+ private RetryOptions retryOptions;
- /** {@inheritDoc}. */
+ /**
+ * {@inheritDoc}.
+ */
@Generated
@Override
public IngestionUsingDataCollectionRulesClientBuilder retryOptions(RetryOptions retryOptions) {
@@ -133,7 +159,9 @@ public IngestionUsingDataCollectionRulesClientBuilder retryOptions(RetryOptions
return this;
}
- /** {@inheritDoc}. */
+ /**
+ * {@inheritDoc}.
+ */
@Generated
@Override
public IngestionUsingDataCollectionRulesClientBuilder addPolicy(HttpPipelinePolicy customPolicy) {
@@ -145,9 +173,12 @@ public IngestionUsingDataCollectionRulesClientBuilder addPolicy(HttpPipelinePoli
/*
* The configuration store that is used during construction of the service client.
*/
- @Generated private Configuration configuration;
+ @Generated
+ private Configuration configuration;
- /** {@inheritDoc}. */
+ /**
+ * {@inheritDoc}.
+ */
@Generated
@Override
public IngestionUsingDataCollectionRulesClientBuilder configuration(Configuration configuration) {
@@ -158,9 +189,12 @@ public IngestionUsingDataCollectionRulesClientBuilder configuration(Configuratio
/*
* The TokenCredential used for authentication.
*/
- @Generated private TokenCredential tokenCredential;
+ @Generated
+ private TokenCredential tokenCredential;
- /** {@inheritDoc}. */
+ /**
+ * {@inheritDoc}.
+ */
@Generated
@Override
public IngestionUsingDataCollectionRulesClientBuilder credential(TokenCredential tokenCredential) {
@@ -171,9 +205,12 @@ public IngestionUsingDataCollectionRulesClientBuilder credential(TokenCredential
/*
* The service endpoint
*/
- @Generated private String endpoint;
+ @Generated
+ private String endpoint;
- /** {@inheritDoc}. */
+ /**
+ * {@inheritDoc}.
+ */
@Generated
@Override
public IngestionUsingDataCollectionRulesClientBuilder endpoint(String endpoint) {
@@ -184,7 +221,8 @@ public IngestionUsingDataCollectionRulesClientBuilder endpoint(String endpoint)
/*
* Service version
*/
- @Generated private IngestionUsingDataCollectionRulesServiceVersion serviceVersion;
+ @Generated
+ private IngestionUsingDataCollectionRulesServiceVersion serviceVersion;
/**
* Sets Service version.
@@ -193,8 +231,8 @@ public IngestionUsingDataCollectionRulesClientBuilder endpoint(String endpoint)
* @return the IngestionUsingDataCollectionRulesClientBuilder.
*/
@Generated
- public IngestionUsingDataCollectionRulesClientBuilder serviceVersion(
- IngestionUsingDataCollectionRulesServiceVersion serviceVersion) {
+ public IngestionUsingDataCollectionRulesClientBuilder
+ serviceVersion(IngestionUsingDataCollectionRulesServiceVersion serviceVersion) {
this.serviceVersion = serviceVersion;
return this;
}
@@ -202,7 +240,8 @@ public IngestionUsingDataCollectionRulesClientBuilder serviceVersion(
/*
* The retry policy that will attempt to retry failed requests, if applicable.
*/
- @Generated private RetryPolicy retryPolicy;
+ @Generated
+ private RetryPolicy retryPolicy;
/**
* Sets The retry policy that will attempt to retry failed requests, if applicable.
@@ -224,18 +263,17 @@ public IngestionUsingDataCollectionRulesClientBuilder retryPolicy(RetryPolicy re
@Generated
private IngestionUsingDataCollectionRulesClientImpl buildInnerClient() {
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();
- IngestionUsingDataCollectionRulesServiceVersion localServiceVersion =
- (serviceVersion != null) ? serviceVersion : IngestionUsingDataCollectionRulesServiceVersion.getLatest();
- IngestionUsingDataCollectionRulesClientImpl client =
- new IngestionUsingDataCollectionRulesClientImpl(
- localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, localServiceVersion);
+ IngestionUsingDataCollectionRulesServiceVersion localServiceVersion
+ = (serviceVersion != null) ? serviceVersion : IngestionUsingDataCollectionRulesServiceVersion.getLatest();
+ IngestionUsingDataCollectionRulesClientImpl client = new IngestionUsingDataCollectionRulesClientImpl(
+ localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint, localServiceVersion);
return client;
}
@Generated
private HttpPipeline createHttpPipeline() {
- Configuration buildConfiguration =
- (configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
+ Configuration buildConfiguration
+ = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions;
ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions;
List policies = new ArrayList<>();
@@ -246,33 +284,30 @@ private HttpPipeline createHttpPipeline() {
policies.add(new RequestIdPolicy());
policies.add(new AddHeadersFromContextPolicy());
HttpHeaders headers = new HttpHeaders();
- localClientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue()));
+ localClientOptions.getHeaders()
+ .forEach(header -> headers.set(HttpHeaderName.fromString(header.getName()), header.getValue()));
if (headers.getSize() > 0) {
policies.add(new AddHeadersPolicy(headers));
}
- policies.addAll(
- this.pipelinePolicies.stream()
- .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
- .collect(Collectors.toList()));
+ this.pipelinePolicies.stream()
+ .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
+ .forEach(p -> policies.add(p));
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy()));
policies.add(new AddDatePolicy());
- policies.add(new CookiePolicy());
if (tokenCredential != null) {
- policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
+ policies.add(new BearerTokenAuthenticationPolicy(tokenCredential,
+ audience == null ? DEFAULT_SCOPES : new String[] { audience.toString() }));
}
- policies.addAll(
- this.pipelinePolicies.stream()
- .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
- .collect(Collectors.toList()));
+ this.pipelinePolicies.stream()
+ .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
+ .forEach(p -> policies.add(p));
HttpPolicyProviders.addAfterRetryPolicies(policies);
- policies.add(new HttpLoggingPolicy(httpLogOptions));
- HttpPipeline httpPipeline =
- new HttpPipelineBuilder()
- .policies(policies.toArray(new HttpPipelinePolicy[0]))
- .httpClient(httpClient)
- .clientOptions(localClientOptions)
- .build();
+ policies.add(new HttpLoggingPolicy(localHttpLogOptions));
+ HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0]))
+ .httpClient(httpClient)
+ .clientOptions(localClientOptions)
+ .build();
return httpPipeline;
}
@@ -293,7 +328,26 @@ public IngestionUsingDataCollectionRulesAsyncClient buildAsyncClient() {
*/
@Generated
public IngestionUsingDataCollectionRulesClient buildClient() {
- return new IngestionUsingDataCollectionRulesClient(
- buildInnerClient());
+ return new IngestionUsingDataCollectionRulesClient(buildInnerClient());
+ }
+
+ private static final ClientLogger LOGGER = new ClientLogger(IngestionUsingDataCollectionRulesClientBuilder.class);
+
+ /**
+ * The audience indicating the authorization scope of log ingestion clients.
+ */
+ @Generated()
+ private LogsIngestionAudience audience;
+
+ /**
+ * Sets The audience.
+ *
+ * @param audience the audience indicating the authorization scope of log ingestion clients.
+ * @return the IngestionUsingDataCollectionRulesClientBuilder.
+ */
+ @Generated()
+ public IngestionUsingDataCollectionRulesClientBuilder audience(LogsIngestionAudience audience) {
+ this.audience = audience;
+ return this;
}
}
diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientImpl.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientImpl.java
index f563f013c9cd..0ae66b24f53a 100644
--- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientImpl.java
+++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientImpl.java
@@ -22,7 +22,6 @@
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
-import com.azure.core.http.policy.CookiePolicy;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.rest.RequestOptions;
@@ -36,57 +35,65 @@
import com.azure.core.util.serializer.SerializerAdapter;
import reactor.core.publisher.Mono;
-/** Initializes a new instance of the IngestionUsingDataCollectionRulesClient type. */
+/**
+ * Initializes a new instance of the IngestionUsingDataCollectionRulesClient type.
+ */
public final class IngestionUsingDataCollectionRulesClientImpl {
- /** The proxy service used to perform REST calls. */
+ /**
+ * The proxy service used to perform REST calls.
+ */
private final IngestionUsingDataCollectionRulesClientService service;
/**
- * The Data Collection Endpoint for the Data Collection Rule, for example
- * https://dce-name.eastus-2.ingest.monitor.azure.com.
+ * The Data Collection Endpoint for the Data Collection Rule, for example https://dce-name.eastus-2.ingest.monitor.azure.com.
*/
private final String endpoint;
/**
- * Gets The Data Collection Endpoint for the Data Collection Rule, for example
- * https://dce-name.eastus-2.ingest.monitor.azure.com.
- *
+ * Gets The Data Collection Endpoint for the Data Collection Rule, for example https://dce-name.eastus-2.ingest.monitor.azure.com.
+ *
* @return the endpoint value.
*/
public String getEndpoint() {
return this.endpoint;
}
- /** Service version. */
+ /**
+ * Service version.
+ */
private final IngestionUsingDataCollectionRulesServiceVersion serviceVersion;
/**
* Gets Service version.
- *
+ *
* @return the serviceVersion value.
*/
public IngestionUsingDataCollectionRulesServiceVersion getServiceVersion() {
return this.serviceVersion;
}
- /** The HTTP pipeline to send requests through. */
+ /**
+ * The HTTP pipeline to send requests through.
+ */
private final HttpPipeline httpPipeline;
/**
* Gets The HTTP pipeline to send requests through.
- *
+ *
* @return the httpPipeline value.
*/
public HttpPipeline getHttpPipeline() {
return this.httpPipeline;
}
- /** The serializer to serialize an object into a string. */
+ /**
+ * The serializer to serialize an object into a string.
+ */
private final SerializerAdapter serializerAdapter;
/**
* Gets The serializer to serialize an object into a string.
- *
+ *
* @return the serializerAdapter value.
*/
public SerializerAdapter getSerializerAdapter() {
@@ -95,138 +102,94 @@ public SerializerAdapter getSerializerAdapter() {
/**
* Initializes an instance of IngestionUsingDataCollectionRulesClient client.
- *
- * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example
- * https://dce-name.eastus-2.ingest.monitor.azure.com.
+ *
+ * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example https://dce-name.eastus-2.ingest.monitor.azure.com.
* @param serviceVersion Service version.
*/
- public IngestionUsingDataCollectionRulesClientImpl(
- String endpoint, IngestionUsingDataCollectionRulesServiceVersion serviceVersion) {
- this(
- new HttpPipelineBuilder()
- .policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
- .build(),
- JacksonAdapter.createDefaultSerializerAdapter(),
- endpoint,
- serviceVersion);
+ IngestionUsingDataCollectionRulesClientImpl(String endpoint,
+ IngestionUsingDataCollectionRulesServiceVersion serviceVersion) {
+ this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(),
+ JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion);
}
/**
* Initializes an instance of IngestionUsingDataCollectionRulesClient client.
- *
+ *
* @param httpPipeline The HTTP pipeline to send requests through.
- * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example
- * https://dce-name.eastus-2.ingest.monitor.azure.com.
+ * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example https://dce-name.eastus-2.ingest.monitor.azure.com.
* @param serviceVersion Service version.
*/
- public IngestionUsingDataCollectionRulesClientImpl(
- HttpPipeline httpPipeline,
- String endpoint,
+ IngestionUsingDataCollectionRulesClientImpl(HttpPipeline httpPipeline, String endpoint,
IngestionUsingDataCollectionRulesServiceVersion serviceVersion) {
this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion);
}
/**
* Initializes an instance of IngestionUsingDataCollectionRulesClient client.
- *
+ *
* @param httpPipeline The HTTP pipeline to send requests through.
* @param serializerAdapter The serializer to serialize an object into a string.
- * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example
- * https://dce-name.eastus-2.ingest.monitor.azure.com.
+ * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example https://dce-name.eastus-2.ingest.monitor.azure.com.
* @param serviceVersion Service version.
*/
- public IngestionUsingDataCollectionRulesClientImpl(
- HttpPipeline httpPipeline,
- SerializerAdapter serializerAdapter,
- String endpoint,
- IngestionUsingDataCollectionRulesServiceVersion serviceVersion) {
+ IngestionUsingDataCollectionRulesClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter,
+ String endpoint, IngestionUsingDataCollectionRulesServiceVersion serviceVersion) {
this.httpPipeline = httpPipeline;
this.serializerAdapter = serializerAdapter;
this.endpoint = endpoint;
this.serviceVersion = serviceVersion;
- this.service =
- RestProxy.create(
- IngestionUsingDataCollectionRulesClientService.class,
- this.httpPipeline,
- this.getSerializerAdapter());
+ this.service = RestProxy.create(IngestionUsingDataCollectionRulesClientService.class, this.httpPipeline,
+ this.getSerializerAdapter());
}
/**
- * The interface defining all the services for IngestionUsingDataCollectionRulesClient to be used by the proxy
- * service to perform REST calls.
+ * The interface defining all the services for IngestionUsingDataCollectionRulesClient to be used by the proxy service to perform REST calls.
*/
@Host("{endpoint}")
@ServiceInterface(name = "IngestionUsingDataCo")
public interface IngestionUsingDataCollectionRulesClientService {
@Post("/dataCollectionRules/{ruleId}/streams/{stream}")
- @ExpectedResponses({204})
- @UnexpectedResponseExceptionType(
- value = ClientAuthenticationException.class,
- code = {401})
- @UnexpectedResponseExceptionType(
- value = ResourceNotFoundException.class,
- code = {404})
- @UnexpectedResponseExceptionType(
- value = ResourceModifiedException.class,
- code = {409})
+ @ExpectedResponses({ 204 })
+ @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
+ @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
+ @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
@UnexpectedResponseExceptionType(HttpResponseException.class)
- Mono> upload(
- @HostParam("endpoint") String endpoint,
- @PathParam("ruleId") String ruleId,
- @PathParam("stream") String stream,
- @QueryParam("api-version") String apiVersion,
- @BodyParam("application/json") BinaryData body,
- @HeaderParam("Accept") String accept,
- RequestOptions requestOptions,
- Context context);
+ Mono> upload(@HostParam("endpoint") String endpoint, @PathParam("ruleId") String ruleId,
+ @PathParam("stream") String stream, @QueryParam("api-version") String apiVersion,
+ @BodyParam("application/json") BinaryData body, @HeaderParam("Accept") String accept,
+ RequestOptions requestOptions, Context context);
@Post("/dataCollectionRules/{ruleId}/streams/{stream}")
- @ExpectedResponses({204})
- @UnexpectedResponseExceptionType(
- value = ClientAuthenticationException.class,
- code = {401})
- @UnexpectedResponseExceptionType(
- value = ResourceNotFoundException.class,
- code = {404})
- @UnexpectedResponseExceptionType(
- value = ResourceModifiedException.class,
- code = {409})
+ @ExpectedResponses({ 204 })
+ @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
+ @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
+ @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
@UnexpectedResponseExceptionType(HttpResponseException.class)
- Response uploadSync(
- @HostParam("endpoint") String endpoint,
- @PathParam("ruleId") String ruleId,
- @PathParam("stream") String stream,
- @QueryParam("api-version") String apiVersion,
- @BodyParam("application/json") BinaryData body,
- @HeaderParam("Accept") String accept,
- RequestOptions requestOptions,
- Context context);
+ Response uploadSync(@HostParam("endpoint") String endpoint, @PathParam("ruleId") String ruleId,
+ @PathParam("stream") String stream, @QueryParam("api-version") String apiVersion,
+ @BodyParam("application/json") BinaryData body, @HeaderParam("Accept") String accept,
+ RequestOptions requestOptions, Context context);
}
/**
* Ingestion API used to directly ingest data using Data Collection Rules
- *
- * See error response code and error response message for more detail.
- *
- *
Header Parameters
- *
+ *
+ * See error response code and error response message for more detail.
+ *
Header Parameters
*
* Header Parameters
* | Name | Type | Required | Description |
* | Content-Encoding | String | No | gzip |
* | x-ms-client-request-id | String | No | Client request Id |
*
- *
* You can add these to a request with {@link RequestOptions#addHeader}
- *
- * Request Body Schema
- *
+ *
Request Body Schema
* {@code
* [
* Object (Required)
* ]
* }
- *
+ *
* @param ruleId The immutable Id of the Data Collection Rule resource.
* @param stream The streamDeclaration name as defined in the Data Collection Rule.
* @param body An array of objects matching the schema defined by the provided stream.
@@ -238,58 +201,44 @@ Response uploadSync(
* @return the {@link Response} on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> uploadWithResponseAsync(
- String ruleId, String stream, BinaryData body, RequestOptions requestOptions) {
+ public Mono> uploadWithResponseAsync(String ruleId, String stream, BinaryData body,
+ RequestOptions requestOptions) {
if (ruleId == null) {
- throw LOGGER.logExceptionAsError(
- new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
+ throw LOGGER
+ .logExceptionAsError(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
}
if (stream == null) {
- throw LOGGER.logExceptionAsError(
- new IllegalArgumentException("Parameter stream is required and cannot be null."));
+ throw LOGGER
+ .logExceptionAsError(new IllegalArgumentException("Parameter stream is required and cannot be null."));
}
if (body == null) {
- throw LOGGER.logExceptionAsError(
- new IllegalArgumentException("Parameter body is required and cannot be null."));
+ throw LOGGER
+ .logExceptionAsError(new IllegalArgumentException("Parameter body is required and cannot be null."));
}
final String accept = "application/json";
- return FluxUtil.withContext(
- context ->
- service.upload(
- this.getEndpoint(),
- ruleId,
- stream,
- this.getServiceVersion().getVersion(),
- body,
- accept,
- requestOptions,
- context));
+ return FluxUtil.withContext(context -> service.upload(this.getEndpoint(), ruleId, stream,
+ this.getServiceVersion().getVersion(), body, accept, requestOptions, context));
}
/**
* Ingestion API used to directly ingest data using Data Collection Rules
- *
- * See error response code and error response message for more detail.
- *
- *
Header Parameters
- *
+ *
+ * See error response code and error response message for more detail.
+ *
Header Parameters
*
* Header Parameters
* | Name | Type | Required | Description |
* | Content-Encoding | String | No | gzip |
* | x-ms-client-request-id | String | No | Client request Id |
*
- *
* You can add these to a request with {@link RequestOptions#addHeader}
- *
- * Request Body Schema
- *
+ *
Request Body Schema
* {@code
* [
* Object (Required)
* ]
* }
- *
+ *
* @param ruleId The immutable Id of the Data Collection Rule resource.
* @param stream The streamDeclaration name as defined in the Data Collection Rule.
* @param body An array of objects matching the schema defined by the provided stream.
@@ -301,30 +250,23 @@ public Mono> uploadWithResponseAsync(
* @return the {@link Response}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Response uploadWithResponse(
- String ruleId, String stream, BinaryData body, RequestOptions requestOptions) {
+ public Response uploadWithResponse(String ruleId, String stream, BinaryData body,
+ RequestOptions requestOptions) {
if (ruleId == null) {
- throw LOGGER.logExceptionAsError(
- new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
+ throw LOGGER
+ .logExceptionAsError(new IllegalArgumentException("Parameter ruleId is required and cannot be null."));
}
if (stream == null) {
- throw LOGGER.logExceptionAsError(
- new IllegalArgumentException("Parameter stream is required and cannot be null."));
+ throw LOGGER
+ .logExceptionAsError(new IllegalArgumentException("Parameter stream is required and cannot be null."));
}
if (body == null) {
- throw LOGGER.logExceptionAsError(
- new IllegalArgumentException("Parameter body is required and cannot be null."));
+ throw LOGGER
+ .logExceptionAsError(new IllegalArgumentException("Parameter body is required and cannot be null."));
}
final String accept = "application/json";
- return service.uploadSync(
- this.getEndpoint(),
- ruleId,
- stream,
- this.getServiceVersion().getVersion(),
- body,
- accept,
- requestOptions,
- requestOptions.getContext());
+ return service.uploadSync(this.getEndpoint(), ruleId, stream, this.getServiceVersion().getVersion(), body,
+ accept, requestOptions, Context.NONE);
}
private static final ClientLogger LOGGER = new ClientLogger(IngestionUsingDataCollectionRulesClientImpl.class);
diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesServiceVersion.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesServiceVersion.java
index 706e1f3a0340..1a6e5ef84d75 100644
--- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesServiceVersion.java
+++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesServiceVersion.java
@@ -6,9 +6,13 @@
import com.azure.core.util.ServiceVersion;
-/** Service version of IngestionUsingDataCollectionRulesClient. */
+/**
+ * Service version of IngestionUsingDataCollectionRulesClient.
+ */
public enum IngestionUsingDataCollectionRulesServiceVersion implements ServiceVersion {
- /** Enum value 2023-01-01. */
+ /**
+ * Enum value 2023-01-01.
+ */
V2023_01_01("2023-01-01");
private final String version;
@@ -17,7 +21,9 @@ public enum IngestionUsingDataCollectionRulesServiceVersion implements ServiceVe
this.version = version;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override
public String getVersion() {
return this.version;
@@ -25,7 +31,7 @@ public String getVersion() {
/**
* Gets the latest service version supported by this client library.
- *
+ *
* @return The latest {@link IngestionUsingDataCollectionRulesServiceVersion}.
*/
public static IngestionUsingDataCollectionRulesServiceVersion getLatest() {
diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/package-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/package-info.java
index f4ceffac4b6b..e7584cdc91ee 100644
--- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/package-info.java
+++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/package-info.java
@@ -2,5 +2,8 @@
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.
-/** Package containing the classes for IngestionUsingDataCollectionRules. null. */
+/**
+ * Package containing the classes for IngestionUsingDataCollectionRules.
+ * null.
+ */
package com.azure.monitor.ingestion.implementation;
diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/LogsIngestionAudience.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/LogsIngestionAudience.java
new file mode 100644
index 000000000000..4b3ed2c370b9
--- /dev/null
+++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/LogsIngestionAudience.java
@@ -0,0 +1,56 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.azure.monitor.ingestion.models;
+
+import com.azure.core.util.ExpandableStringEnum;
+
+import java.util.Collection;
+
+/**
+ * The audience indicating the authorization scope of log ingestion clients.
+ */
+public class LogsIngestionAudience extends ExpandableStringEnum {
+
+ /**
+ * Static value for Azure Public Cloud.
+ */
+ public static final LogsIngestionAudience AZURE_PUBLIC_CLOUD = fromString("https://monitor.azure.com//.default");
+
+ /**
+ * Static value for Azure US Government.
+ */
+ private static final LogsIngestionAudience AZURE_GOVERNMENT = fromString("https://monitor.azure.us//.default");
+
+ /**
+ * Static value for Azure China.
+ */
+ private static final LogsIngestionAudience AZURE_CHINA = fromString("https://monitor.azure.cn//.default");
+
+ /**
+ * @deprecated Creates an instance of LogsIngestionAudience.
+ */
+ @Deprecated
+ LogsIngestionAudience() {
+ }
+
+ /**
+ * Creates an instance of LogsIngestionAudience.
+ *
+ * @param name the string value.
+ * @return the LogsIngestionAudience.
+ */
+ public static LogsIngestionAudience fromString(String name) {
+ return fromString(name, LogsIngestionAudience.class);
+ }
+
+ /**
+ * Get the collection of LogsIngestionAudience values.
+ *
+ * @return the collection of LogsIngestionAudience values.
+ */
+ public static Collection values() {
+ return values(LogsIngestionAudience.class);
+ }
+
+}
diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java
index d392257ae5dd..2b4903531d62 100644
--- a/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java
+++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
+// Code generated by Microsoft (R) AutoRest Code Generator.
module com.azure.monitor.ingestion {
requires transitive com.azure.core;
-
exports com.azure.monitor.ingestion;
exports com.azure.monitor.ingestion.models;
diff --git a/sdk/monitor/azure-monitor-ingestion/swagger/README.md b/sdk/monitor/azure-monitor-ingestion/swagger/README.md
index 4610d90a0839..b42ec32ab982 100644
--- a/sdk/monitor/azure-monitor-ingestion/swagger/README.md
+++ b/sdk/monitor/azure-monitor-ingestion/swagger/README.md
@@ -2,13 +2,19 @@
## Code generation settings
+### Manual Modifications
+
+The following edits need to be made manually after code generation:
+- Rollback the edits to `module-info` file
+
```yaml
java: true
-use: '@autorest/java@4.1.9'
+use: '@autorest/java@4.26.2'
output-folder: ../
license-header: MICROSOFT_MIT_SMALL
input-file: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/monitor/data-plane/ingestion/stable/2023-01-01/DataCollectionRules.json
namespace: com.azure.monitor.ingestion.implementation
+implementation-subpackage: ""
generate-client-interfaces: false
sync-methods: all
add-context-parameter: true
@@ -21,4 +27,5 @@ client-side-validations: true
artifact-id: azure-monitor-ingestion
data-plane: true
enable-sync-stack: true
+customization-class: src/main/java/MonitorIngestionCustomizations.java
```
diff --git a/sdk/monitor/azure-monitor-ingestion/swagger/pom.xml b/sdk/monitor/azure-monitor-ingestion/swagger/pom.xml
new file mode 100644
index 000000000000..8876e3dcaf2d
--- /dev/null
+++ b/sdk/monitor/azure-monitor-ingestion/swagger/pom.xml
@@ -0,0 +1,30 @@
+
+
+ 4.0.0
+
+ Microsoft Azure Monitor Ingestion client for Java
+ This package contains client functionality for Microsoft Monitor Ingestion
+
+ com.azure.tools
+ azure-monitor-ingestion-autorest-customization
+ 1.0.0-beta.1
+ jar
+
+
+ com.azure
+ azure-code-customization-parent
+ 1.0.0-beta.1
+ ../../../parents/azure-code-customization-parent
+
+
+
+
+ com.azure.tools
+ azure-autorest-customization
+ 1.0.0-beta.8
+
+
+
+
diff --git a/sdk/monitor/azure-monitor-ingestion/swagger/src/main/java/MonitorIngestionCustomizations.java b/sdk/monitor/azure-monitor-ingestion/swagger/src/main/java/MonitorIngestionCustomizations.java
new file mode 100644
index 000000000000..fec434fbc647
--- /dev/null
+++ b/sdk/monitor/azure-monitor-ingestion/swagger/src/main/java/MonitorIngestionCustomizations.java
@@ -0,0 +1,150 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+import com.azure.autorest.customization.ClassCustomization;
+import com.azure.autorest.customization.Customization;
+import com.azure.autorest.customization.LibraryCustomization;
+import com.azure.autorest.customization.PackageCustomization;
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
+import com.github.javaparser.ast.body.TypeDeclaration;
+import com.github.javaparser.ast.stmt.BlockStmt;
+import org.slf4j.Logger;
+
+import java.util.function.Consumer;
+
+/**
+ * Customization class for Monitor. These customizations will be applied on top of the generated code.
+ */
+public class MonitorIngestionCustomizations extends Customization {
+
+ /**
+ * Customizes the generated code.
+ *
+ *
+ *
+ * The following customizations are applied:
+ *
+ *
+ * - The package customization for the package `com.azure.monitor.ingestion.implementation`.
+ *
+ *
+ * @param libraryCustomization The library customization.
+ * @param logger The logger.
+ */
+ @Override
+ public void customize(LibraryCustomization libraryCustomization, Logger logger) {
+ monitorIngestionImplementation(libraryCustomization.getPackage("com.azure.monitor.ingestion.implementation"), logger);
+ }
+
+ /**
+ * Customizes the generated code for the package com.azure.monitor.ingestion.implementation.
+ *
+ *
+ *
+ * The following classes are customized:
+ *
+ * - IngestionUsingDataCollectionRulesClientBuilder
+ *
+ *
+ * @param packageCustomization The package customization.
+ * @param logger The logger.
+ */
+ private void monitorIngestionImplementation(PackageCustomization packageCustomization, Logger logger) {
+ IngestionUsingDataCollectionRulesClientBuilderCustomization(packageCustomization.getClass("IngestionUsingDataCollectionRulesClientBuilder"), logger);
+ }
+
+ /**
+ * Customizes the generated code for `IngestionUsingDataCollectionRulesClientBuilder`.
+ *
+ *
+ *
+ * The following customizations are applied:
+ *
+ *
+ * - Adds an import statement for the class `LogsIngestionAudience`.
+ * - Adds a field `audience` of type `LogsIngestionAudience` to the class.
+ * - Adds a Javadoc for the field `audience`.
+ * - Adds the generated annotation to the field `audience`.
+ * - Adds a setter for the field `audience`.
+ * - Adds a Javadoc for the setter.
+ * - Adds the generated annotation to the setter.
+ * - Replaces the body of the method `createHttpPipeline()` with a custom implementation that sets the
+ * audience in the `BearerTokenAuthenticationPolicy`.
+ *
+ *
+ * @param classCustomization The class customization.
+ * @param logger The logger.
+ */
+ private void IngestionUsingDataCollectionRulesClientBuilderCustomization(ClassCustomization classCustomization, Logger logger) {
+ classCustomization.addImports("com.azure.monitor.ingestion.models.LogsIngestionAudience");
+
+
+
+ customizeAst(classCustomization, clazz -> {
+ clazz.addPrivateField("LogsIngestionAudience", "audience")
+ .addAnnotation("Generated")
+ .setJavadocComment("The audience indicating the authorization scope of log ingestion clients.")
+ .createSetter()
+ .setName("audience")
+ .setType("IngestionUsingDataCollectionRulesClientBuilder")
+ .setBody(new BlockStmt()
+ .addStatement("this.audience = audience;")
+ .addStatement("return this;"))
+ .addAnnotation("Generated")
+ .setJavadocComment("Sets The audience.\n" +
+ " *\n" +
+ " * @param audience the audience indicating the authorization scope of log ingestion clients.\n" +
+ " * @return the IngestionUsingDataCollectionRulesClientBuilder.");
+ });
+
+
+ classCustomization.getMethod("createHttpPipeline").replaceBody("Configuration buildConfiguration\n" +
+ " = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration;\n" +
+ " HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions;\n" +
+ " ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions;\n" +
+ " List policies = new ArrayList<>();\n" +
+ " String clientName = PROPERTIES.getOrDefault(SDK_NAME, \"UnknownName\");\n" +
+ " String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, \"UnknownVersion\");\n" +
+ " String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions);\n" +
+ " policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration));\n" +
+ " policies.add(new RequestIdPolicy());\n" +
+ " policies.add(new AddHeadersFromContextPolicy());\n" +
+ " HttpHeaders headers = new HttpHeaders();\n" +
+ " localClientOptions.getHeaders()\n" +
+ " .forEach(header -> headers.set(HttpHeaderName.fromString(header.getName()), header.getValue()));\n" +
+ " if (headers.getSize() > 0) {\n" +
+ " policies.add(new AddHeadersPolicy(headers));\n" +
+ " }\n" +
+ " this.pipelinePolicies.stream()\n" +
+ " .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)\n" +
+ " .forEach(p -> policies.add(p));\n" +
+ " HttpPolicyProviders.addBeforeRetryPolicies(policies);\n" +
+ " policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy()));\n" +
+ " policies.add(new AddDatePolicy());\n" +
+ " if (tokenCredential != null) {\n" +
+ " policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, audience == null ? DEFAULT_SCOPES : new String[] { audience.toString() }));\n" +
+ " }\n" +
+ " this.pipelinePolicies.stream()\n" +
+ " .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)\n" +
+ " .forEach(p -> policies.add(p));\n" +
+ " HttpPolicyProviders.addAfterRetryPolicies(policies);\n" +
+ " policies.add(new HttpLoggingPolicy(localHttpLogOptions));\n" +
+ " HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0]))\n" +
+ " .httpClient(httpClient)\n" +
+ " .clientOptions(localClientOptions)\n" +
+ " .build();\n" +
+ " return httpPipeline;");
+
+ }
+
+
+ /**
+ * Customizes the abstract syntax tree of a class.
+ * @param classCustomization The class customization.
+ * @param consumer The consumer.
+ */
+ private static void customizeAst(ClassCustomization classCustomization, Consumer consumer) {
+ classCustomization.customizeAst(ast -> consumer.accept(ast.getClassByName(classCustomization.getClassName())
+ .orElseThrow(() -> new RuntimeException("Class not found. " + classCustomization.getClassName()))));
+ }
+}