diff --git a/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/Azure.Sdk.Tools.PipelineGenerator.csproj b/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/Azure.Sdk.Tools.PipelineGenerator.csproj index f9daf50eae2..46365ac1404 100644 --- a/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/Azure.Sdk.Tools.PipelineGenerator.csproj +++ b/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/Azure.Sdk.Tools.PipelineGenerator.csproj @@ -14,13 +14,14 @@ + - - - - + + + + diff --git a/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/CommandParserOptions/DefaultOptions.cs b/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/CommandParserOptions/DefaultOptions.cs index e52c6c95fc5..38708fb19eb 100644 --- a/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/CommandParserOptions/DefaultOptions.cs +++ b/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/CommandParserOptions/DefaultOptions.cs @@ -25,10 +25,7 @@ public string Organization [Option('p', "project", Required = false, Default = "internal", HelpText = "Azure DevOps project name. Default: internal")] public string Project { get; set; } - [Option('t', "patvar", Required = false, HelpText = "Environment variable name containing a Personal Access Token.")] - public string Patvar { get; set; } - [Option("whatif", Required = false, HelpText = "Dry Run changes")] public bool WhatIf { get; set; } } -} \ No newline at end of file +} diff --git a/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/PipelineGenerationContext.cs b/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/PipelineGenerationContext.cs index 9d5588f6963..1ae76ea16fd 100644 --- a/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/PipelineGenerationContext.cs +++ b/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/PipelineGenerationContext.cs @@ -1,4 +1,5 @@ -using Microsoft.Azure.Services.AppAuthentication; +using Azure.Identity; +using Microsoft.Azure.Services.AppAuthentication; using Microsoft.Extensions.Logging; using Microsoft.TeamFoundation.Build.WebApi; using Microsoft.TeamFoundation.Core.WebApi; @@ -20,7 +21,6 @@ public class PipelineGenerationContext { private string organization; private string project; - private string patvar; private string endpoint; private string agentPool; private int[] variableGroups; @@ -30,7 +30,6 @@ public PipelineGenerationContext( ILogger logger, string organization, string project, - string patvar, string endpoint, string repository, string branch, @@ -46,7 +45,6 @@ public PipelineGenerationContext( this.logger = logger; this.organization = organization; this.project = project; - this.patvar = patvar; this.endpoint = endpoint; this.Repository = repository; this.Branch = branch; @@ -76,20 +74,13 @@ private async Task GetConnectionAsync() { if (cachedConnection == null) { - VssCredentials credentials; - if (string.IsNullOrWhiteSpace(patvar)) - { - var azureTokenProvider = new AzureServiceTokenProvider(); - var authenticationResult = await azureTokenProvider.GetAuthenticationResultAsync("499b84ac-1321-427f-aa17-267ca6975798"); - credentials = new VssAadCredential(new VssAadToken(authenticationResult.TokenType, authenticationResult.AccessToken)); - } - else - { - var pat = Environment.GetEnvironmentVariable(patvar); - credentials = new VssBasicCredential("nobody", pat); - } - - cachedConnection = new VssConnection(new Uri(organization), credentials); + var azureCredential = new ChainedTokenCredential( + new AzureCliCredential(), + new AzurePowerShellCredential() + ); + var devopsCredential = new VssAzureIdentityCredential(azureCredential); + cachedConnection = new VssConnection(new Uri(organization), devopsCredential); + await cachedConnection.ConnectAsync(); } return cachedConnection; diff --git a/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/Program.cs b/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/Program.cs index 3c6d7bcf5b1..e46c463ad9a 100644 --- a/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/Program.cs +++ b/tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -43,7 +43,6 @@ public static async Task Run(object commandObj, CancellationTokenSource cancella g.Project, g.Prefix, g.Path, - g.Patvar, g.Endpoint, g.Repository, g.Branch, @@ -127,7 +126,6 @@ public async Task RunAsync( string project, string prefix, string path, - string patvar, string endpoint, string repository, string branch, @@ -154,7 +152,6 @@ public async Task RunAsync( this.logger, organization, project, - patvar, endpoint, repository, branch,