Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public boolean isDisableAppInsights() {
}

@Nullable
public FunctionApp getFunctionApp() throws AzureAuthFailureException {
public FunctionApp getFunctionApp() throws AzureAuthFailureException, AzureExecutionException {
return getAzureClient().appServices().functionApps().getByResourceGroup(getResourceGroup(), getAppName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.microsoft.azure.common.handlers.artifact.ZIPArtifactHandlerImpl;
import com.microsoft.azure.common.logging.Log;
import com.microsoft.azure.common.utils.AppServiceUtils;
import com.microsoft.azure.credentials.AzureTokenCredentials;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent;
import com.microsoft.azure.management.appservice.AppServicePlan;
Expand All @@ -46,6 +45,7 @@
import com.microsoft.azure.maven.MavenDockerCredentialProvider;
import com.microsoft.azure.maven.ProjectUtils;
import com.microsoft.azure.maven.auth.AzureAuthFailureException;
import com.microsoft.azure.tools.auth.model.AzureCredentialWrapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -75,9 +75,9 @@ public class DeployMojo extends AbstractFunctionMojo {
private static final int LIST_TRIGGERS_RETRY_PERIOD_IN_SECONDS = 10;
private static final String DEPLOY_START = "Starting deployment...";
private static final String DEPLOY_FINISH =
"Deployment done, you may access your resource through %s";
"Deployment done, you may access your resource through %s";
private static final String FUNCTION_APP_CREATE_START = "The specified function app does not exist. " +
"Creating a new function app...";
"Creating a new function app...";
private static final String FUNCTION_APP_CREATED = "Successfully created the function app: %s.";
private static final String FUNCTION_SLOT_CREATE_START = "The specified function slot does not exist. " +
"Creating a new slot...";
Expand Down Expand Up @@ -141,7 +141,7 @@ protected void doExecute() throws AzureExecutionException {

if (target == null) {
throw new AzureExecutionException(
String.format("Failed to get the deploy target with name: %s", getAppName()));
String.format("Failed to get the deploy target with name: %s", getAppName()));
}

deployArtifact(new DeployTarget(target, DeployTargetType.FUNCTION));
Expand Down Expand Up @@ -387,8 +387,8 @@ private File getArtifactToDeploy() throws AzureExecutionException {
.findFirst()
.orElseThrow(() -> new AzureExecutionException(
String.format("Failed to find function artifact '%s.jar' in folder '%s', please re-package the project and try again.",
this.getFinalName(),
stagingFolder))
this.getFinalName(),
stagingFolder))
);
}

Expand Down Expand Up @@ -461,14 +461,15 @@ private boolean isDeployToSlot() {
return slotSetting != null && StringUtils.isNotEmpty(slotSetting.getName());
}

private ApplicationInsightsComponent getOrCreateApplicationInsights(boolean enableCreation) throws AzureAuthFailureException {
final AzureTokenCredentials credentials = getAzureTokenWrapper();
private ApplicationInsightsComponent getOrCreateApplicationInsights(boolean enableCreation) throws AzureAuthFailureException, AzureExecutionException {
final AzureCredentialWrapper credentials = getAzureCredentialWrapper();
if (credentials == null) {
Log.warn(APPLICATION_INSIGHTS_NOT_SUPPORTED);
return null;
}
final String subscriptionId = getAzureClient().subscriptionId();
final ApplicationInsightsManager applicationInsightsManager = new ApplicationInsightsManager(credentials, subscriptionId, getUserAgent());
final ApplicationInsightsManager applicationInsightsManager = new ApplicationInsightsManager(credentials.getAzureTokenCredentials(),
subscriptionId, getUserAgent());
return StringUtils.isNotEmpty(getAppInsightsInstance()) ?
getApplicationInsights(applicationInsightsManager, getAppInsightsInstance()) :
enableCreation ? createApplicationInsights(applicationInsightsManager, getAppName()) : null;
Expand Down
14 changes: 10 additions & 4 deletions azure-maven-plugin-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-auth-helper</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down Expand Up @@ -167,6 +163,16 @@
<groupId>org.jtwig</groupId>
<artifactId>jtwig-core</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-toolkit-auth-lib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
package com.microsoft.azure.maven;

import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.auth.AzureAuthHelper;
import com.microsoft.azure.auth.AzureTokenWrapper;
import com.microsoft.azure.common.appservice.DeploymentSlotSetting;
import com.microsoft.azure.common.appservice.DeploymentType;
import com.microsoft.azure.common.exceptions.AzureExecutionException;

import com.microsoft.azure.management.appservice.WebAppBase;
import com.microsoft.azure.maven.auth.AzureAuthFailureException;
import com.microsoft.azure.tools.auth.model.AzureCredentialWrapper;
import org.apache.maven.model.Resource;
import org.apache.maven.plugins.annotations.Parameter;

Expand Down Expand Up @@ -142,30 +141,29 @@ public List<Resource> getResources() {
public String getDeploymentStagingDirectoryPath() {
final String outputFolder = this.getPluginName().replaceAll(MAVEN_PLUGIN_POSTFIX, "");
return Paths.get(
this.getBuildDirectoryAbsolutePath(),
outputFolder, this.getAppName()
this.getBuildDirectoryAbsolutePath(),
outputFolder, this.getAppName()
).toString();
}

public void setDeploymentSlot(DeploymentSlotSetting slotSetting) {
this.deploymentSlotSetting = slotSetting;
}

public String getResourcePortalUrl(WebAppBase resource) throws AzureAuthFailureException {
final AzureTokenWrapper azureTokenWrapper = getAzureTokenWrapper();
final AzureEnvironment environment = azureTokenWrapper == null ?
AzureAuthHelper.getAzureEnvironment(auth.getEnvironment()) : azureTokenWrapper.environment();
public String getResourcePortalUrl(WebAppBase resource) throws AzureAuthFailureException, AzureExecutionException {
final AzureCredentialWrapper azureCredentialWrapper = getAzureCredentialWrapper();
final AzureEnvironment environment = azureCredentialWrapper.getEnv();
final String tenantId = getAzureClient().tenantId();
return String.format(PORTAL_URL_PATTERN, getPortalUrl(environment), tenantId, resource.id());
}

private static String getPortalUrl(AzureEnvironment azureEnvironment) {
if (azureEnvironment == AzureEnvironment.AZURE) {
if (azureEnvironment == null || azureEnvironment == AzureEnvironment.AZURE) {
return "https://ms.portal.azure.com";
} else if (azureEnvironment == AzureEnvironment.AZURE_CHINA) {
}
if (azureEnvironment == AzureEnvironment.AZURE_CHINA) {
return "https://portal.azure.cn";
} else {
return azureEnvironment.portal();
}
return azureEnvironment.portal();
}
}
Loading