Merge pull request #146 from microsoft/feature-function-java17

Task #1974372] Add Java 17 support for Azure Functions
This commit is contained in:
Miller Wang 2022-09-01 09:41:50 +08:00 коммит произвёл GitHub
Родитель 5ca0bd73ac 2728ab9b77
Коммит d45f7bd394
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 47 добавлений и 79 удалений

Просмотреть файл

@ -1,6 +1,7 @@
# Change Log
All notable changes to the "Azure Function Plugin for Gradle" will be documented in this file.
- [Change Log](#change-log)
- [1.11.0](#1110)
- [1.10.0](#1100)
- [1.9.0](#190)
- [1.8.0](#180)
@ -13,6 +14,10 @@ All notable changes to the "Azure Function Plugin for Gradle" will be documented
- [1.1.0](#110)
- [1.0.0](#100)
## 1.11.0
- Support Java 17 for Function App
- Improve stability/reliability of Authentication
## 1.10.0
- Support Managed Identity for authentication
- Support azure-functions-java-library 2.*

Просмотреть файл

@ -21,7 +21,7 @@
# SOFTWARE.
group = com.microsoft.azure
version = 1.10.0
version = 1.11.0
pluginId = com.microsoft.azure.azurefunctions
pluginShortName = azurefunctions

Просмотреть файл

@ -92,7 +92,7 @@ public class PackageHandler {
private static final String DEFAULT_LOCAL_SETTINGS_JSON = "{ \"IsEncrypted\": false, \"Values\": " +
"{ \"FUNCTIONS_WORKER_RUNTIME\": \"java\" } }";
private static final String DEFAULT_HOST_JSON = "{\"version\":\"2.0\",\"extensionBundle\":" +
"{\"id\":\"Microsoft.Azure.Functions.ExtensionBundle\",\"version\":\"[2.*, 3.0.0)\"}}\n";
"{\"id\":\"Microsoft.Azure.Functions.ExtensionBundle\",\"version\":\"[3.*, 4.0.0)\"}}\n";
private static final String TRIGGER_TYPE = "triggerType";
private final IProject project;

Просмотреть файл

@ -21,4 +21,4 @@
# SOFTWARE.
group = com.microsoft.azure
version = 1.4.0
version = 1.5.0

Просмотреть файл

@ -6,26 +6,24 @@
package com.microsoft.azure.gradle.auth;
import com.azure.core.management.AzureEnvironment;
import com.azure.identity.DeviceCodeInfo;
import com.microsoft.azure.gradle.temeletry.TelemetryAgent;
import com.microsoft.azure.gradle.temeletry.TelemetryConstants;
import com.microsoft.azure.toolkit.lib.Azure;
import com.microsoft.azure.toolkit.lib.auth.Account;
import com.microsoft.azure.toolkit.lib.auth.AuthConfiguration;
import com.microsoft.azure.toolkit.lib.auth.AuthType;
import com.microsoft.azure.toolkit.lib.auth.AzureAccount;
import com.microsoft.azure.toolkit.lib.auth.AzureCloud;
import com.microsoft.azure.toolkit.lib.auth.core.devicecode.DeviceCodeAccount;
import com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException;
import com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException;
import com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration;
import com.microsoft.azure.toolkit.lib.auth.model.AuthType;
import com.microsoft.azure.toolkit.lib.auth.util.AzureEnvironmentUtils;
import com.microsoft.azure.toolkit.lib.auth.AzureEnvironmentUtils;
import com.microsoft.azure.toolkit.lib.auth.AzureToolkitAuthenticationException;
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
import com.microsoft.azure.toolkit.lib.common.exception.InvalidConfigurationException;
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
import com.microsoft.azure.toolkit.lib.common.model.Subscription;
import com.microsoft.azure.toolkit.lib.common.utils.TextUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import reactor.core.publisher.Mono;
import javax.annotation.Nonnull;
import java.util.Collections;
@ -47,7 +45,7 @@ public class GradleAuthHelper {
final List<Subscription> subscriptions = account.getSubscriptions();
final String targetSubscriptionId = getTargetSubscriptionId(subscriptionId, subscriptions, account.getSelectedSubscriptions());
checkSubscription(subscriptions, targetSubscriptionId);
Azure.az(AzureAccount.class).account().selectSubscription(Collections.singletonList(targetSubscriptionId));
Azure.az(AzureAccount.class).account().setSelectedSubscriptions(Collections.singletonList(targetSubscriptionId));
printCurrentSubscription(account);
return targetSubscriptionId;
} catch (InvalidConfigurationException e) {
@ -92,17 +90,18 @@ public class GradleAuthHelper {
}
private static Account login(@Nonnull AuthConfiguration auth) {
promptAzureEnvironment(auth.getEnvironment());
final AzureEnvironment azureEnvironment = AzureEnvironmentUtils.stringToAzureEnvironment(auth.getEnvironment());
promptAzureEnvironment(azureEnvironment);
final Account account = accountLogin(auth);
final boolean isInteractiveLogin = account.getAuthType() == AuthType.OAUTH2 || account.getAuthType() == AuthType.DEVICE_CODE;
final boolean isInteractiveLogin = account.getType() == AuthType.OAUTH2 || account.getType() == AuthType.DEVICE_CODE;
final AzureEnvironment env = account.getEnvironment();
final String environmentName = AzureEnvironmentUtils.azureEnvironmentToString(env);
if (env != AzureEnvironment.AZURE && env != auth.getEnvironment()) {
if (env != AzureEnvironment.AZURE && env != azureEnvironment) {
AzureMessager.getMessager().info(AzureString.format(USING_AZURE_ENVIRONMENT, environmentName));
}
printCredentialDescription(account, isInteractiveLogin);
TelemetryAgent.getInstance().addDefaultProperty(TelemetryConstants.AUTH_TYPE_KEY, Objects.toString(auth.getType()));
TelemetryAgent.getInstance().addDefaultProperty(TelemetryConstants.AUTH_METHOD_KEY, Objects.toString(account.getAuthType()));
TelemetryAgent.getInstance().addDefaultProperty(TelemetryConstants.AUTH_METHOD_KEY, Objects.toString(account.getType()));
TelemetryAgent.getInstance().addDefaultProperty(TelemetryConstants.AZURE_ENVIRONMENT_KEY, environmentName);
return account;
}
@ -117,8 +116,8 @@ public class GradleAuthHelper {
selectedSubscriptions.get(0).getId()));
}
}
if (StringUtils.isNotEmpty(account.getEntity().getEmail())) {
AzureMessager.getMessager().info(AzureString.format("Username: %s", account.getEntity().getEmail()));
if (StringUtils.isNotEmpty(account.getUsername())) {
AzureMessager.getMessager().info(AzureString.format("Username: %s", account.getUsername()));
}
} else {
AzureMessager.getMessager().info(account.toString());
@ -132,79 +131,39 @@ public class GradleAuthHelper {
}
private static Account accountLogin(AuthConfiguration auth) {
if (auth.getEnvironment() != null) {
Azure.az(AzureCloud.class).set(auth.getEnvironment());
final AzureAccount azureAccount = Azure.az(AzureAccount.class);
if (azureAccount.isLoggedIn() || azureAccount.isLoggingIn()) {
azureAccount.logout();
}
if (auth.getType() == null || auth.getType() == AuthType.AUTO) {
if (auth.getEnvironment() != null) {
Azure.az(AzureCloud.class).set(AzureEnvironmentUtils.stringToAzureEnvironment(auth.getEnvironment()));
}
if (auth.getType() == AuthType.DEVICE_CODE) {
auth.setDeviceCodeConsumer(info -> {
final String message = StringUtils.replace(info.getMessage(), info.getUserCode(), TextUtils.cyan(info.getUserCode()));
AzureMessager.getMessager().info(message);
});
}
if (auth.getType() == AuthType.AUTO) {
if (StringUtils.isAllBlank(auth.getCertificate(), auth.getCertificatePassword(), auth.getKey())) {
final Account account = findFirstAvailableAccount(auth).block();
if (account == null) {
throw new AzureToolkitAuthenticationException("There are no accounts available.");
}
promptForOAuthOrDeviceCodeLogin(account.getAuthType());
return handleDeviceCodeAccount(Azure.az(AzureAccount.class).loginAsync(account, false).block());
return azureAccount.login(auth, false);
} else {
return doServicePrincipalLogin(auth);
auth.setType(AuthType.SERVICE_PRINCIPAL);
return azureAccount.login(auth);
}
} else {
promptForOAuthOrDeviceCodeLogin(auth.getType());
return handleDeviceCodeAccount(Azure.az(AzureAccount.class).loginAsync(auth, false).block());
return azureAccount.login(auth, false);
}
}
private static Account doServicePrincipalLogin(AuthConfiguration auth) {
auth.setType(AuthType.SERVICE_PRINCIPAL);
return Azure.az(AzureAccount.class).login(auth).account();
}
private static Account handleDeviceCodeAccount(Account account) {
if (account instanceof DeviceCodeAccount) {
final DeviceCodeAccount deviceCodeAccount = (DeviceCodeAccount) account;
final DeviceCodeInfo challenge = deviceCodeAccount.getDeviceCode();
AzureMessager.getMessager().info(
AzureString.format(StringUtils.replace(challenge.getMessage(), challenge.getUserCode(), "%s"), challenge.getUserCode()));
}
return account.continueLogin().block();
}
private static void promptForOAuthOrDeviceCodeLogin(AuthType authType) {
if (authType == AuthType.OAUTH2 || authType == AuthType.DEVICE_CODE) {
AzureMessager.getMessager().info(AzureString.format("Auth type: %s", authType.toString()));
}
}
private static Mono<Account> findFirstAvailableAccount(AuthConfiguration auth) {
final List<Account> accounts = Azure.az(AzureAccount.class).initAccounts(auth);
if (accounts.isEmpty()) {
return Mono.error(new AzureToolkitAuthenticationException("There are no accounts available."));
}
Mono<Account> current = checkAccountAvailable(accounts.get(0));
for (int i = 1; i < accounts.size(); i++) {
final Account ac = accounts.get(i);
current = current.onErrorResume(e -> checkAccountAvailable(ac));
}
return current;
}
private static Mono<Account> checkAccountAvailable(Account account) {
return account.checkAvailable().map(avail -> {
if (avail) {
return account;
}
throw new AzureToolkitAuthenticationException(String.format("Cannot login with auth type: %s", account.getAuthType()));
});
}
private static AuthConfiguration toAuthConfiguration(GradleAuthConfig gradleAuthConfig) throws InvalidConfigurationException {
final AuthConfiguration authConfiguration = new AuthConfiguration();
final AuthConfiguration authConfiguration = new AuthConfiguration(AuthType.parseAuthType(gradleAuthConfig.getType()));
authConfiguration.setClient(gradleAuthConfig.getClient());
authConfiguration.setTenant(gradleAuthConfig.getTenant());
authConfiguration.setCertificate(gradleAuthConfig.getCertificate());
authConfiguration.setCertificatePassword(gradleAuthConfig.getCertificatePassword());
authConfiguration.setKey(gradleAuthConfig.getKey());
final String authTypeStr = gradleAuthConfig.getType();
authConfiguration.setType(AuthType.parseAuthType(authTypeStr));
authConfiguration.setEnvironment(AzureEnvironmentUtils.stringToAzureEnvironment(gradleAuthConfig.getEnvironment()));
authConfiguration.setEnvironment(gradleAuthConfig.getEnvironment());
if (StringUtils.isNotBlank(gradleAuthConfig.getEnvironment()) && Objects.isNull(authConfiguration.getEnvironment())) {
throw new InvalidConfigurationException(String.format(INVALID_AZURE_ENVIRONMENT, gradleAuthConfig.getEnvironment()));
}

Просмотреть файл

@ -1,6 +1,7 @@
# Change Log
All notable changes to the "Azure WebApp Plugin for Gradle" will be documented in this file.
- [Change Log](#change-log)
- [1.6.0](#160)
- [1.5.0](#150)
- [1.4.0](#140)
- [1.3.0](#130)
@ -8,6 +9,9 @@ All notable changes to the "Azure WebApp Plugin for Gradle" will be documented i
- [1.1.0](#110)
- [1.0.0](#100)
## 1.6.0
- Improve stability/reliability of Authentication
## 1.5.0
- Support Managed Identity for authentication

Просмотреть файл

@ -21,7 +21,7 @@
# SOFTWARE.
group = com.microsoft.azure
version = 1.5.0
version = 1.6.0
pluginId = com.microsoft.azure.azurewebapp
pluginShortName = azurewebapp

Просмотреть файл

@ -33,7 +33,7 @@ subprojects {
targetCompatibility = 1.8
ext {
azureToolkitVersion = "0.22.0"
azureToolkitVersion = "0.24.0"
}
checkstyle {