azure-maven-plugins icon indicating copy to clipboard operation
azure-maven-plugins copied to clipboard

Support AZURE_CONFIG_DIR

Open alexandrospanagiotidis opened this issue 5 years ago • 7 comments

Plugin name and version

azure-webapp-maven-plugin 1.6.0

Plugin configuration in your pom.xml

            <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-webapp-maven-plugin</artifactId>
                <version>1.6.0</version>
                <configuration>
                    <allowTelemetry>false</allowTelemetry>
                    <appName>${deployment.appName}</appName>
                    <resourceGroup>${deployment.resourceGroup}</resourceGroup>
                    <pricingTier>F1</pricingTier>
                    <javaVersion>1.8</javaVersion>
                    <stopAppDuringDeployment>true</stopAppDuringDeployment>
                </configuration>
            </plugin>

Expected behavior

The Maven plugin uses the right configuration directory, set via AZURE_CONFIG_DIR as described in the documentation for Azure CLI.

Actual behavior

The plugin always uses the configuration in $HOME/.azure if present. If that is missing, an error is thrown:

[INFO] Authenticate with Azure CLI 2.0
Cannot read files .../.azure/azureProfile.json and .../.azure/accessTokens.json. Are you logged in Azure CLI?

Steps to reproduce the problem

  1. Ensure $HOME/.azure is missing (e.g., move it away, or delete it)
  2. Set AZURE_CONFIG_DIR to something else than $HOME, e.g., export AZURE_CONFIG_DIR="$(mktemp)" (under Linux in a Bash)
  3. Run mvn azure-webapp:deploy

alexandrospanagiotidis avatar Jun 11 '19 16:06 alexandrospanagiotidis

As far as I can tell, the Maven plugin uses System.getProperty("user.home") to find the Azure CLI configuration files in two places:

  1. src/main/java/com/microsoft/azure/maven/AbstractAzureMojo.java
  2. src/main/java/com/microsoft/azure/maven/auth/AzureAuthHelper.java

It might be feasible to replace that with a helper method that looks up System.getenv(AZURE_CONFIG_DIR) first with a fallback to System.getProperty("user.home").

Alternatively, it might be a good idea to expose the path as Maven property.

alexandrospanagiotidis avatar Jun 11 '19 16:06 alexandrospanagiotidis

FWIW, I created a quick hack and opened PR #674 for this issue. I hope that is okay.

alexandrospanagiotidis avatar Jun 11 '19 17:06 alexandrospanagiotidis

@alexandrospanagiotidis Thanks for your report and your contribution! Maven Plugin use $HOME/.azure as the config folder to save some configurations, and we use AzureCliCredentials.create() to get the Authenticated object from Azure CLI, which uses $HOME/.azure as the path for cli config folder. I've opened an issue here.

Codes which refers $HOME/.azure in AzureAuthHelper is the workaround to solve AzureCliCredentials can't get the correct subscription in azure cloud shell or cli authed with service principal, we will fix them once the issue is fixed.

Flanker32 avatar Jun 12 '19 02:06 Flanker32

Hi @Flanker32, thank you for your reply. Should I delete my PR, since this is something that needs to be fixed via the other issue?

alexandrospanagiotidis avatar Jun 12 '19 08:06 alexandrospanagiotidis

@alexandrospanagiotidis Yes, thanks for your support, I'll track this issue and fixed it once the related one is done.

Flanker32 avatar Jun 12 '19 09:06 Flanker32

Hi @alexandrospanagiotidis, we have already solve this issue by adopting azure-identity, could you please take a try again.

andxu avatar Nov 25 '21 08:11 andxu

Dear @andxu,

Thank you for your reply! I am no longer able to test your changes, as I am no longer involved in that particular project.

As a side-note: we moved away from deploying via azure-maven-plugin (in favor of az-cli) as we needed to set a higher timeout for deployments to Azure China, which was not possible with the plugin at that time.

Thank you for your efforts!

All the best Alex

alexandrospanagiotidis avatar Nov 25 '21 10:11 alexandrospanagiotidis