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();
}
}
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()));
}
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);
}
Aggregations