Search in sources :

Example 1 with FunctionApp

use of com.azure.resourcemanager.appservice.models.FunctionApp in project vividus by vividus-framework.

the class FunctionServiceTests method shouldExecuteAFunction.

@Test
void shouldExecuteAFunction() {
    try (MockedStatic<AppServiceManager> appServiceMock = mockStatic(AppServiceManager.class);
        MockedConstruction<ResponseCapturingHttpPipelinePolicy> policy = mockConstruction(ResponseCapturingHttpPipelinePolicy.class)) {
        when(azureProfile.getEnvironment()).thenReturn(azureEnvironment);
        when(azureEnvironment.getActiveDirectoryEndpoint()).thenReturn(ENDPOINT);
        Configurable configurable = mock(Configurable.class);
        appServiceMock.when(AppServiceManager::configure).thenReturn(configurable);
        when(configurable.withLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)).thenReturn(configurable);
        when(configurable.withPolicy(any(ResponseCapturingHttpPipelinePolicy.class))).thenReturn(configurable);
        AppServiceManager serviceManager = mock(AppServiceManager.class);
        when(configurable.authenticate(any(TokenCredential.class), eq(azureProfile))).thenReturn(serviceManager);
        FunctionApps functionApps = mock(FunctionApps.class);
        when(serviceManager.functionApps()).thenReturn(functionApps);
        FunctionApp functionApp = mock(FunctionApp.class);
        when(functionApps.getByResourceGroup(RESOURCE_GROUP, FUNCTION_APP)).thenReturn(functionApp);
        functionService.triggerFunction(RESOURCE_GROUP, FUNCTION_APP, FUNCTION, PAYLOAD);
        verify(azureProfile).getEnvironment();
        verify(azureEnvironment).getActiveDirectoryEndpoint();
        verify(functionApp).triggerFunction(FUNCTION, PAYLOAD);
        verify(policy.constructed().get(0)).getResponses();
    }
}
Also used : AppServiceManager(com.azure.resourcemanager.appservice.AppServiceManager) FunctionApps(com.azure.resourcemanager.appservice.models.FunctionApps) Configurable(com.azure.resourcemanager.appservice.AppServiceManager.Configurable) TokenCredential(com.azure.core.credential.TokenCredential) FunctionApp(com.azure.resourcemanager.appservice.models.FunctionApp) Test(org.junit.jupiter.api.Test)

Example 2 with FunctionApp

use of com.azure.resourcemanager.appservice.models.FunctionApp in project azure-maven-plugins by microsoft.

the class FTPFunctionDeployHandler method deploy.

@Override
public void deploy(final File file, final WebAppBase webAppBase) {
    final FTPUploader uploader = new FTPUploader();
    final PublishingProfile profile = webAppBase.getPublishingProfile();
    final String serverUrl = profile.ftpUrl().split("/", 2)[0];
    try {
        uploader.uploadDirectoryWithRetries(serverUrl, profile.ftpUsername(), profile.ftpPassword(), file.getAbsolutePath(), DEFAULT_WEBAPP_ROOT, DEFAULT_MAX_RETRY_TIMES);
    } catch (AzureExecutionException e) {
        throw new AzureToolkitRuntimeException("Failed to upload artifact to azure", e);
    }
    if (webAppBase instanceof FunctionApp) {
        ((FunctionApp) webAppBase).syncTriggers();
    }
    AzureMessager.getMessager().info(String.format(DEPLOY_FINISH, webAppBase.defaultHostname()));
}
Also used : AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) FTPUploader(com.microsoft.azure.toolkit.lib.legacy.appservice.handlers.artifact.FTPUploader) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) PublishingProfile(com.azure.resourcemanager.appservice.models.PublishingProfile) FunctionApp(com.azure.resourcemanager.appservice.models.FunctionApp)

Example 3 with FunctionApp

use of com.azure.resourcemanager.appservice.models.FunctionApp 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

FunctionApp (com.azure.resourcemanager.appservice.models.FunctionApp)3 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)2 TokenCredential (com.azure.core.credential.TokenCredential)1 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 AppServiceManager (com.azure.resourcemanager.appservice.AppServiceManager)1 Configurable (com.azure.resourcemanager.appservice.AppServiceManager.Configurable)1 FunctionApps (com.azure.resourcemanager.appservice.models.FunctionApps)1 FunctionDeploymentSlot (com.azure.resourcemanager.appservice.models.FunctionDeploymentSlot)1 PublishingProfile (com.azure.resourcemanager.appservice.models.PublishingProfile)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 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)1 FTPUploader (com.microsoft.azure.toolkit.lib.legacy.appservice.handlers.artifact.FTPUploader)1 Test (org.junit.jupiter.api.Test)1