-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as core from '@actions/core'; | ||
import * as exec from '@actions/exec'; | ||
|
||
async function cleanup() { | ||
try { | ||
core.info("Cleaning subscriptions from the local cache.") | ||
await exec.exec("az", ["account", "clear"]); | ||
} | ||
catch (error) { | ||
core.setFailed(`Login cleanup failed with ${error}.`); | ||
core.debug(error.stack); | ||
} | ||
} | ||
|
||
cleanup(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
import * as core from '@actions/core'; | ||
import { AzPSLogin } from './PowerShell/AzPSLogin'; | ||
import { LoginConfig } from './common/LoginConfig'; | ||
import { AzureCliLogin } from './Cli/AzureCliLogin'; | ||
|
||
var prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : ""; | ||
var azPSHostEnv = !!process.env.AZUREPS_HOST_ENVIRONMENT ? `${process.env.AZUREPS_HOST_ENVIRONMENT}` : ""; | ||
|
||
async function main() { | ||
try { | ||
let usrAgentRepo = `${process.env.GITHUB_REPOSITORY}`; | ||
let actionName = 'AzureLogin'; | ||
let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`; | ||
let azurePSHostEnv = (!!azPSHostEnv ? `${azPSHostEnv}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`; | ||
core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString); | ||
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv); | ||
|
||
// prepare the login configuration | ||
var loginConfig = new LoginConfig(); | ||
await loginConfig.initialize(); | ||
await loginConfig.validate(); | ||
|
||
// login to Azure CLI | ||
var cliLogin = new AzureCliLogin(loginConfig); | ||
await cliLogin.login(); | ||
|
||
//login to Azure PowerShell | ||
if (loginConfig.enableAzPSSession) { | ||
var psLogin: AzPSLogin = new AzPSLogin(loginConfig); | ||
await psLogin.login(); | ||
} | ||
} | ||
catch (error) { | ||
core.setFailed(`Login failed with ${error}. Make sure 'az' is installed on the runner. If 'enable-AzPSSession' is true, make sure 'pwsh' is installed on the runner together with Azure PowerShell module. Double check if the 'auth-type' is correct. Refer to https://github.com/Azure/login#readme for more information.`); | ||
core.debug(error.stack); | ||
} | ||
finally { | ||
// Reset AZURE_HTTP_USER_AGENT | ||
core.exportVariable('AZURE_HTTP_USER_AGENT', prefix); | ||
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azPSHostEnv); | ||
} | ||
} | ||
|
||
main(); | ||
|
||
import * as core from '@actions/core'; | ||
import { AzPSLogin } from './PowerShell/AzPSLogin'; | ||
import { LoginConfig } from './common/LoginConfig'; | ||
import { AzureCliLogin } from './Cli/AzureCliLogin'; | ||
|
||
var prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : ""; | ||
var azPSHostEnv = !!process.env.AZUREPS_HOST_ENVIRONMENT ? `${process.env.AZUREPS_HOST_ENVIRONMENT}` : ""; | ||
|
||
async function main() { | ||
try { | ||
let usrAgentRepo = `${process.env.GITHUB_REPOSITORY}`; | ||
let actionName = 'AzureLogin'; | ||
let userAgentString = (!!prefix ? `${prefix}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`; | ||
let azurePSHostEnv = (!!azPSHostEnv ? `${azPSHostEnv}+` : '') + `GITHUBACTIONS/${actionName}@v1_${usrAgentRepo}`; | ||
core.exportVariable('AZURE_HTTP_USER_AGENT', userAgentString); | ||
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azurePSHostEnv); | ||
|
||
// prepare the login configuration | ||
var loginConfig = new LoginConfig(); | ||
await loginConfig.initialize(); | ||
await loginConfig.validate(); | ||
|
||
// login to Azure CLI | ||
var cliLogin = new AzureCliLogin(loginConfig); | ||
await cliLogin.login(); | ||
|
||
//login to Azure PowerShell | ||
if (loginConfig.enableAzPSSession) { | ||
var psLogin: AzPSLogin = new AzPSLogin(loginConfig); | ||
await psLogin.login(); | ||
} | ||
} | ||
catch (error) { | ||
core.setFailed(`Login failed with ${error}. If 'enable-AzPSSession' is true, make sure 'pwsh' is installed on the runner together with Azure PowerShell module. Double check if the 'auth-type' is correct. Refer to https://github.com/Azure/login#readme for more information.`); | ||
core.debug(error.stack); | ||
} | ||
finally { | ||
// Reset AZURE_HTTP_USER_AGENT | ||
core.exportVariable('AZURE_HTTP_USER_AGENT', prefix); | ||
core.exportVariable('AZUREPS_HOST_ENVIRONMENT', azPSHostEnv); | ||
} | ||
} | ||
|
||
main(); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as core from '@actions/core'; | ||
import * as exec from '@actions/exec'; | ||
import * as io from '@actions/io'; | ||
|
||
async function setup() { | ||
try { | ||
this.azPath = await io.which("az", true); | ||
if (!this.azPath) { | ||
throw new Error("Azure CLI is not found in the runner."); | ||
} | ||
core.debug(`Azure CLI path: ${this.azPath}`); | ||
|
||
core.info("Cleaning subscriptions from the local cache.") | ||
await exec.exec("az", ["account", "clear"]); | ||
} | ||
catch (error) { | ||
core.setFailed(`Login setup failed with ${error}. Make sure 'az' is installed on the runner.`); | ||
core.debug(error.stack); | ||
} | ||
} | ||
|
||
setup(); |