/** * Creates an instance of AzureCliCredentials with the default Azure CLI configuration. * * @return an instance of AzureCliCredentials * @throws IOException if the Azure CLI token files are not accessible */ public static AzureCliCredentials create() throws IOException { return create( Paths.get(System.getProperty("user.home"), ".azure", "azureProfile.json").toFile(), Paths.get(System.getProperty("user.home"), ".azure", "accessTokens.json").toFile()); }
/** * Get Authenticated object using authentication file from Azure CLI 2.0 * * Note: The integrated Azure CLI in Azure Cloud Shell does not have the accessToken.json, * so we need to use MSI to authenticate in the Cloud Shell. * * @return Authenticated object if Azure CLI 2.0 is logged in correctly; otherwise return null. */ protected Authenticated getAuthObjFromAzureCli() { try { final Azure.Configurable azureConfigurable = azureConfigure(); final Authenticated auth; if (isInCloudShell()) { getLog().info(AUTH_WITH_MSI); auth = azureConfigurable.authenticate(new MSICredentials()); } else { getLog().info(AUTH_WITH_AZURE_CLI); auth = azureConfigurable.authenticate(AzureCliCredentials.create()); } return auth; } catch (Exception e) { getLog().debug(AZURE_CLI_AUTH_FAIL); getLog().debug(e); } return null; }
/** * Get Authenticated object using authentication file from Azure CLI 2.0 * * Note: The integrated Azure CLI in Azure Cloud Shell does not have the accessToken.json, * so we need to use MSI to authenticate in the Cloud Shell. * * @return Authenticated object if Azure CLI 2.0 is logged in correctly; otherwise return null. */ protected Authenticated getAuthObjFromAzureCli() { try { final Azure.Configurable azureConfigurable = azureConfigure(); final Authenticated auth; if (isInCloudShell()) { getLog().info(AUTH_WITH_MSI); auth = azureConfigurable.authenticate(new MSICredentials()); } else { getLog().info(AUTH_WITH_AZURE_CLI); auth = azureConfigurable.authenticate(AzureCliCredentials.create()); } return auth; } catch (Exception e) { getLog().debug(AZURE_CLI_AUTH_FAIL); getLog().debug(e); } return null; }