|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | +// Code generated by Microsoft (R) AutoRest Code Generator. |
| 4 | + |
| 5 | +package com.azure.resourcemanager.confluent; |
| 6 | + |
| 7 | +import com.azure.core.credential.TokenCredential; |
| 8 | +import com.azure.core.http.HttpClient; |
| 9 | +import com.azure.core.http.HttpPipeline; |
| 10 | +import com.azure.core.http.HttpPipelineBuilder; |
| 11 | +import com.azure.core.http.policy.AddDatePolicy; |
| 12 | +import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; |
| 13 | +import com.azure.core.http.policy.HttpLogOptions; |
| 14 | +import com.azure.core.http.policy.HttpLoggingPolicy; |
| 15 | +import com.azure.core.http.policy.HttpPipelinePolicy; |
| 16 | +import com.azure.core.http.policy.HttpPolicyProviders; |
| 17 | +import com.azure.core.http.policy.RequestIdPolicy; |
| 18 | +import com.azure.core.http.policy.RetryPolicy; |
| 19 | +import com.azure.core.http.policy.UserAgentPolicy; |
| 20 | +import com.azure.core.management.profile.AzureProfile; |
| 21 | +import com.azure.core.util.Configuration; |
| 22 | +import com.azure.core.util.logging.ClientLogger; |
| 23 | +import com.azure.resourcemanager.confluent.fluent.ConfluentManagementClient; |
| 24 | +import com.azure.resourcemanager.confluent.implementation.ConfluentManagementClientBuilder; |
| 25 | +import com.azure.resourcemanager.confluent.implementation.MarketplaceAgreementsImpl; |
| 26 | +import com.azure.resourcemanager.confluent.implementation.OrganizationOperationsImpl; |
| 27 | +import com.azure.resourcemanager.confluent.implementation.OrganizationsImpl; |
| 28 | +import com.azure.resourcemanager.confluent.models.MarketplaceAgreements; |
| 29 | +import com.azure.resourcemanager.confluent.models.OrganizationOperations; |
| 30 | +import com.azure.resourcemanager.confluent.models.Organizations; |
| 31 | +import java.time.Duration; |
| 32 | +import java.time.temporal.ChronoUnit; |
| 33 | +import java.util.ArrayList; |
| 34 | +import java.util.List; |
| 35 | +import java.util.Objects; |
| 36 | + |
| 37 | +/** Entry point to ConfluentManager. */ |
| 38 | +public final class ConfluentManager { |
| 39 | + private MarketplaceAgreements marketplaceAgreements; |
| 40 | + |
| 41 | + private OrganizationOperations organizationOperations; |
| 42 | + |
| 43 | + private Organizations organizations; |
| 44 | + |
| 45 | + private final ConfluentManagementClient clientObject; |
| 46 | + |
| 47 | + private ConfluentManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) { |
| 48 | + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); |
| 49 | + Objects.requireNonNull(profile, "'profile' cannot be null."); |
| 50 | + this.clientObject = |
| 51 | + new ConfluentManagementClientBuilder() |
| 52 | + .pipeline(httpPipeline) |
| 53 | + .endpoint(profile.getEnvironment().getResourceManagerEndpoint()) |
| 54 | + .subscriptionId(profile.getSubscriptionId()) |
| 55 | + .defaultPollInterval(defaultPollInterval) |
| 56 | + .buildClient(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Creates an instance of Confluent service API entry point. |
| 61 | + * |
| 62 | + * @param credential the credential to use. |
| 63 | + * @param profile the Azure profile for client. |
| 64 | + * @return the Confluent service API instance. |
| 65 | + */ |
| 66 | + public static ConfluentManager authenticate(TokenCredential credential, AzureProfile profile) { |
| 67 | + Objects.requireNonNull(credential, "'credential' cannot be null."); |
| 68 | + Objects.requireNonNull(profile, "'profile' cannot be null."); |
| 69 | + return configure().authenticate(credential, profile); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Gets a Configurable instance that can be used to create ConfluentManager with optional configuration. |
| 74 | + * |
| 75 | + * @return the Configurable instance allowing configurations. |
| 76 | + */ |
| 77 | + public static Configurable configure() { |
| 78 | + return new ConfluentManager.Configurable(); |
| 79 | + } |
| 80 | + |
| 81 | + /** The Configurable allowing configurations to be set. */ |
| 82 | + public static final class Configurable { |
| 83 | + private final ClientLogger logger = new ClientLogger(Configurable.class); |
| 84 | + |
| 85 | + private HttpClient httpClient; |
| 86 | + private HttpLogOptions httpLogOptions; |
| 87 | + private final List<HttpPipelinePolicy> policies = new ArrayList<>(); |
| 88 | + private RetryPolicy retryPolicy; |
| 89 | + private Duration defaultPollInterval; |
| 90 | + |
| 91 | + private Configurable() { |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Sets the http client. |
| 96 | + * |
| 97 | + * @param httpClient the HTTP client. |
| 98 | + * @return the configurable object itself. |
| 99 | + */ |
| 100 | + public Configurable withHttpClient(HttpClient httpClient) { |
| 101 | + this.httpClient = Objects.requireNonNull(httpClient, "'httpClient' cannot be null."); |
| 102 | + return this; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Sets the logging options to the HTTP pipeline. |
| 107 | + * |
| 108 | + * @param httpLogOptions the HTTP log options. |
| 109 | + * @return the configurable object itself. |
| 110 | + */ |
| 111 | + public Configurable withLogOptions(HttpLogOptions httpLogOptions) { |
| 112 | + this.httpLogOptions = Objects.requireNonNull(httpLogOptions, "'httpLogOptions' cannot be null."); |
| 113 | + return this; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Adds the pipeline policy to the HTTP pipeline. |
| 118 | + * |
| 119 | + * @param policy the HTTP pipeline policy. |
| 120 | + * @return the configurable object itself. |
| 121 | + */ |
| 122 | + public Configurable withPolicy(HttpPipelinePolicy policy) { |
| 123 | + this.policies.add(Objects.requireNonNull(policy, "'policy' cannot be null.")); |
| 124 | + return this; |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Sets the retry policy to the HTTP pipeline. |
| 129 | + * |
| 130 | + * @param retryPolicy the HTTP pipeline retry policy. |
| 131 | + * @return the configurable object itself. |
| 132 | + */ |
| 133 | + public Configurable withRetryPolicy(RetryPolicy retryPolicy) { |
| 134 | + this.retryPolicy = Objects.requireNonNull(retryPolicy, "'retryPolicy' cannot be null."); |
| 135 | + return this; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Sets the default poll interval, used when service does not provide "Retry-After" header. |
| 140 | + * |
| 141 | + * @param defaultPollInterval the default poll interval. |
| 142 | + * @return the configurable object itself. |
| 143 | + */ |
| 144 | + public Configurable withDefaultPollInterval(Duration defaultPollInterval) { |
| 145 | + this.defaultPollInterval = Objects.requireNonNull(defaultPollInterval, "'retryPolicy' cannot be null."); |
| 146 | + if (this.defaultPollInterval.isNegative()) { |
| 147 | + throw logger.logExceptionAsError(new IllegalArgumentException("'httpPipeline' cannot be negative")); |
| 148 | + } |
| 149 | + return this; |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Creates an instance of Confluent service API entry point. |
| 154 | + * |
| 155 | + * @param credential the credential to use. |
| 156 | + * @param profile the Azure profile for client. |
| 157 | + * @return the Confluent service API instance. |
| 158 | + */ |
| 159 | + public ConfluentManager authenticate(TokenCredential credential, AzureProfile profile) { |
| 160 | + Objects.requireNonNull(credential, "'credential' cannot be null."); |
| 161 | + Objects.requireNonNull(profile, "'profile' cannot be null."); |
| 162 | + |
| 163 | + if (retryPolicy == null) { |
| 164 | + retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS); |
| 165 | + } |
| 166 | + List<HttpPipelinePolicy> policies = new ArrayList<>(); |
| 167 | + policies |
| 168 | + .add( |
| 169 | + new UserAgentPolicy( |
| 170 | + null, |
| 171 | + "com.azure.resourcemanager.confluent", |
| 172 | + "1.0.0-beta.1", |
| 173 | + Configuration.getGlobalConfiguration())); |
| 174 | + policies.add(new RequestIdPolicy()); |
| 175 | + HttpPolicyProviders.addBeforeRetryPolicies(policies); |
| 176 | + policies.add(retryPolicy); |
| 177 | + policies.add(new AddDatePolicy()); |
| 178 | + policies |
| 179 | + .add( |
| 180 | + new BearerTokenAuthenticationPolicy( |
| 181 | + credential, profile.getEnvironment().getManagementEndpoint() + "/.default")); |
| 182 | + HttpPolicyProviders.addAfterRetryPolicies(policies); |
| 183 | + policies.add(new HttpLoggingPolicy(httpLogOptions)); |
| 184 | + HttpPipeline httpPipeline = |
| 185 | + new HttpPipelineBuilder() |
| 186 | + .httpClient(httpClient) |
| 187 | + .policies(policies.toArray(new HttpPipelinePolicy[0])) |
| 188 | + .build(); |
| 189 | + return new ConfluentManager(httpPipeline, profile, defaultPollInterval); |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + /** @return Resource collection API of MarketplaceAgreements. */ |
| 194 | + public MarketplaceAgreements marketplaceAgreements() { |
| 195 | + if (this.marketplaceAgreements == null) { |
| 196 | + this.marketplaceAgreements = new MarketplaceAgreementsImpl(clientObject.getMarketplaceAgreements(), this); |
| 197 | + } |
| 198 | + return marketplaceAgreements; |
| 199 | + } |
| 200 | + |
| 201 | + /** @return Resource collection API of OrganizationOperations. */ |
| 202 | + public OrganizationOperations organizationOperations() { |
| 203 | + if (this.organizationOperations == null) { |
| 204 | + this.organizationOperations = |
| 205 | + new OrganizationOperationsImpl(clientObject.getOrganizationOperations(), this); |
| 206 | + } |
| 207 | + return organizationOperations; |
| 208 | + } |
| 209 | + |
| 210 | + /** @return Resource collection API of Organizations. */ |
| 211 | + public Organizations organizations() { |
| 212 | + if (this.organizations == null) { |
| 213 | + this.organizations = new OrganizationsImpl(clientObject.getOrganizations(), this); |
| 214 | + } |
| 215 | + return organizations; |
| 216 | + } |
| 217 | + |
| 218 | + /** |
| 219 | + * @return Wrapped service client ConfluentManagementClient providing direct access to the underlying auto-generated |
| 220 | + * API implementation, based on Azure REST API. |
| 221 | + */ |
| 222 | + public ConfluentManagementClient serviceClient() { |
| 223 | + return this.clientObject; |
| 224 | + } |
| 225 | +} |
0 commit comments