/** * Creates an instance of ResourcesManager that exposes Resources resource management API entry points. * * @param credentials the credentials to use * @param subscriptionId the subscription UUID * @return the ResourcesManager */ public static ResourcesManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { return new ResourcesManager(new RestClient.Builder() .withBaseUrl(credentials.environment(), AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withCredentials(credentials) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .build(), subscriptionId); } /**
/** * Creates an instance of KeyVaultManager that exposes KeyVault resource management API entry points. * * @param credentials the credentials to use * @param subscriptionId the subscription UUID * @return the KeyVaultManager */ public static KeyVaultManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { return new KeyVaultManager(new RestClient.Builder() .withBaseUrl(credentials.environment(), AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withCredentials(credentials) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withInterceptor(new ProviderRegistrationInterceptor(credentials)) .withInterceptor(new ResourceManagerThrottlingInterceptor()) .build(), credentials.domain(), subscriptionId); }
protected AzureConfigurableImpl() { this.restClientBuilder = new RestClient.Builder() .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()); }
protected RestClient buildRestClient(AzureTokenCredentials credentials, AzureEnvironment.Endpoint endpoint) { RestClient client = restClientBuilder .withBaseUrl(credentials.environment(), endpoint) .withCredentials(credentials) .withInterceptor(new ResourceManagerThrottlingInterceptor()) .build(); if (client.httpClient().proxy() != null) { credentials.withProxy(client.httpClient().proxy()); } return client; }
if (!response.isSuccessful()) { String content = errorBody(response.body()); AzureJacksonAdapter jacksonAdapter = new AzureJacksonAdapter(); CloudError cloudError = jacksonAdapter.deserialize(content, CloudError.class); if (cloudError != null && "MissingSubscriptionRegistration".equals(cloudError.code())) { Pattern pattern = Pattern.compile("/subscriptions/([\\w-]+)/", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(chain.request().url().toString()); matcher.find(); RestClient restClient = new RestClient.Builder() .withBaseUrl("https://" + chain.request().url().host()) .withCredentials(credentials) .withSerializerAdapter(jacksonAdapter) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .build(); ResourceManager resourceManager = ResourceManager.authenticate(restClient) .withSubscription(matcher.group(1));
private GraphRbacManager(RestClient restClient, String tenantId) { String graphEndpoint = AzureEnvironment.AZURE.graphEndpoint(); if (restClient.credentials() instanceof AzureTokenCredentials) { graphEndpoint = ((AzureTokenCredentials) restClient.credentials()).environment().graphEndpoint(); } this.graphRbacManagementClient = new GraphRbacManagementClientImpl( restClient.newBuilder().withBaseUrl(graphEndpoint).build()).withTenantID(tenantId); this.authorizationManagementClient = new AuthorizationManagementClientImpl(restClient); this.tenantId = tenantId; }
@SuppressWarnings("unchecked") @Override public T withInterceptor(Interceptor interceptor) { this.restClientBuilder = this.restClientBuilder.withInterceptor(interceptor); return (T) this; }
/** * Create a new builder for a new Rest Client with the same configurations on this one. * @return a RestClient builder */ public RestClient.Builder newBuilder() { return new Builder(this); }
@SuppressWarnings("unchecked") @Override public T withInterceptor(Interceptor interceptor) { this.restClientBuilder = this.restClientBuilder.withInterceptor(interceptor); return (T) this; }
@SuppressWarnings("unchecked") @Override public T withInterceptor(Interceptor interceptor) { this.restClientBuilder = this.restClientBuilder.withInterceptor(interceptor); return (T) this; }
VaultImpl(String key, VaultInner innerObject, KeyVaultManager manager, GraphRbacManager graphRbacManager) { super(key, innerObject, manager); this.graphRbacManager = graphRbacManager; this.accessPolicies = new ArrayList<>(); if (innerObject != null && innerObject.properties() != null && innerObject.properties().accessPolicies() != null) { for (AccessPolicyEntry entry : innerObject.properties().accessPolicies()) { this.accessPolicies.add(new AccessPolicyImpl(entry, this)); } } this.client = new KeyVaultClient( manager.inner().restClient().newBuilder().withBaseUrl("https://{vaultBaseUrl}").build()); }
VaultImpl(String key, VaultInner innerObject, KeyVaultManager manager, GraphRbacManager graphRbacManager) { super(key, innerObject, manager); this.graphRbacManager = graphRbacManager; this.accessPolicies = new ArrayList<>(); if (innerObject != null && innerObject.properties() != null && innerObject.properties().accessPolicies() != null) { for (AccessPolicyEntry entry : innerObject.properties().accessPolicies()) { this.accessPolicies.add(new AccessPolicyImpl(entry, this)); } } this.client = new KeyVaultClient( manager.inner().restClient().newBuilder().withBaseUrl("https://{vaultBaseUrl}").build()); }
/** * Initializes a new instance of the ServiceClient class. * * @param baseUrl the service base uri * @param clientBuilder the http client builder * @param restBuilder the retrofit rest client builder */ protected ServiceClient(String baseUrl, OkHttpClient.Builder clientBuilder, Retrofit.Builder restBuilder) { this(new RestClient.Builder(clientBuilder, restBuilder) .withBaseUrl(baseUrl) .withResponseBuilderFactory(new ServiceResponseBuilder.Factory()) .withSerializerAdapter(new JacksonAdapter()) .build()); }
protected RestClient buildRestClient(RestClient.Builder builder, boolean isMocked) { return builder.build(); }
private void initializeFunctionService() { if (functionService == null) { HttpUrl defaultHostName = HttpUrl.parse(defaultHostName()); if (defaultHostName == null) { defaultHostName = new HttpUrl.Builder().host(defaultHostName()).scheme("http").build(); } functionService = manager().restClient().newBuilder() .withBaseUrl(defaultHostName.toString()) .withCredentials(new FunctionCredentials(this)) .withLogLevel(LogLevel.BODY_AND_HEADERS) .build() .retrofit().create(FunctionService.class); } }
KuduClient(WebAppBase webAppBase) { if (webAppBase.defaultHostName() == null) { throw new UnsupportedOperationException("Cannot initialize kudu client before web app is created"); } String host = webAppBase.defaultHostName().toLowerCase() .replace("http://", "") .replace("https://", ""); String[] parts = host.split("\\.", 2); host = Joiner.on('.').join(parts[0], "scm", parts[1]); service = webAppBase.manager().restClient().newBuilder() .withBaseUrl("https://" + host) .withConnectionTimeout(3, TimeUnit.MINUTES) .withReadTimeout(3, TimeUnit.MINUTES) .build() .retrofit().create(KuduService.class); }
this.withCallbackExecutor(restClient.retrofit.callbackExecutor()); this.customHeadersInterceptor.addHeaderMultimap(((CustomHeadersInterceptor) interceptor).headers()); } else if (interceptor != restClient.builder.credentialsInterceptor) { this.withInterceptor(interceptor); this.loggingInterceptor = new LoggingInterceptor(old.logLevel()); } else { this.withNetworkInterceptor(interceptor);
protected AzureConfigurableImpl() { this.restClientBuilder = new RestClient.Builder() .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()); }
protected RestClient buildRestClient(AzureTokenCredentials credentials, AzureEnvironment.Endpoint endpoint) { RestClient client = restClientBuilder .withBaseUrl(credentials.environment(), endpoint) .withCredentials(credentials) .withInterceptor(new ProviderRegistrationInterceptor(credentials)) .withInterceptor(new ResourceManagerThrottlingInterceptor()) .build(); if (client.httpClient().proxy() != null) { credentials.withProxy(client.httpClient().proxy()); } return client; }
if (!response.isSuccessful()) { String content = errorBody(response.body()); AzureJacksonAdapter jacksonAdapter = new AzureJacksonAdapter(); CloudError cloudError = jacksonAdapter.deserialize(content, CloudError.class); if (cloudError != null && "MissingSubscriptionRegistration".equals(cloudError.code())) { Pattern pattern = Pattern.compile("/subscriptions/([\\w-]+)/", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(chain.request().url().toString()); matcher.find(); RestClient restClient = new RestClient.Builder() .withBaseUrl("https://" + chain.request().url().host()) .withCredentials(credentials) .withSerializerAdapter(jacksonAdapter) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .build(); ResourceManager resourceManager = ResourceManager.authenticate(restClient) .withSubscription(matcher.group(1));