Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AZURE_CONFIG_DIR #673

Closed
alexandrospanagiotidis opened this issue Jun 11, 2019 · 7 comments
Closed

Support AZURE_CONFIG_DIR #673

alexandrospanagiotidis opened this issue Jun 11, 2019 · 7 comments

Comments

@alexandrospanagiotidis
Copy link

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
Copy link
Author

alexandrospanagiotidis commented Jun 11, 2019

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
Copy link
Author

alexandrospanagiotidis commented Jun 11, 2019

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

@Flanker32
Copy link
Member

Flanker32 commented Jun 12, 2019

@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 Flanker32 self-assigned this Jun 12, 2019
@alexandrospanagiotidis
Copy link
Author

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?

@Flanker32
Copy link
Member

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

@andxu
Copy link
Contributor

andxu commented Nov 25, 2021

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

@alexandrospanagiotidis
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants