Search in sources :

Example 1 with AddHeadersPolicy

use of com.azure.core.http.policy.AddHeadersPolicy in project azure-maven-plugins by microsoft.

the class AzureFunctionsResourceManager method getClient.

public static AzureFunctionsResourceManager getClient(@Nonnull WebAppBase functionApp, @Nonnull IFunctionAppBase appService) {
    // com/azure/resourcemanager/appservice/implementation/KuduClient.java
    if (!(functionApp instanceof FunctionApp || functionApp instanceof FunctionDeploymentSlot)) {
        throw new AzureToolkitRuntimeException("Functions resource manager only applies to Azure Functions");
    }
    final List<HttpPipelinePolicy> policies = Utils.getPolicyFromPipeline(functionApp.manager().httpPipeline(), policy -> !(policy instanceof AuthenticationPolicy || policy instanceof ProviderRegistrationPolicy || policy instanceof AuxiliaryAuthenticationPolicy));
    policies.add(new AddHeadersPolicy(new HttpHeaders(Collections.singletonMap("x-functions-key", appService.getMasterKey()))));
    final HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])).httpClient(functionApp.manager().httpPipeline().getHttpClient()).build();
    final FunctionsService functionsService = RestProxy.create(FunctionsService.class, httpPipeline, SerializerFactory.createDefaultManagementSerializerAdapter());
    return new AzureFunctionsResourceManager(functionsService, appService);
}
Also used : HttpHeaders(com.azure.core.http.HttpHeaders) AuxiliaryAuthenticationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.AuxiliaryAuthenticationPolicy) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) ProviderRegistrationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) FunctionApp(com.azure.resourcemanager.appservice.models.FunctionApp) HttpPipelinePolicy(com.azure.core.http.policy.HttpPipelinePolicy) FunctionDeploymentSlot(com.azure.resourcemanager.appservice.models.FunctionDeploymentSlot) AuthenticationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.AuthenticationPolicy) AuxiliaryAuthenticationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.AuxiliaryAuthenticationPolicy) HttpPipeline(com.azure.core.http.HttpPipeline) AddHeadersPolicy(com.azure.core.http.policy.AddHeadersPolicy)

Aggregations

HttpHeaders (com.azure.core.http.HttpHeaders)1 HttpPipeline (com.azure.core.http.HttpPipeline)1 HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)1 AddHeadersPolicy (com.azure.core.http.policy.AddHeadersPolicy)1 HttpPipelinePolicy (com.azure.core.http.policy.HttpPipelinePolicy)1 FunctionApp (com.azure.resourcemanager.appservice.models.FunctionApp)1 FunctionDeploymentSlot (com.azure.resourcemanager.appservice.models.FunctionDeploymentSlot)1 AuthenticationPolicy (com.azure.resourcemanager.resources.fluentcore.policy.AuthenticationPolicy)1 AuxiliaryAuthenticationPolicy (com.azure.resourcemanager.resources.fluentcore.policy.AuxiliaryAuthenticationPolicy)1 ProviderRegistrationPolicy (com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy)1 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)1