Skip to content

Commit 0f14e8a

Browse files
authored
Remove PATVAR from PipelineGenerator (#8369)
* Remove PATVAR from PipelineGenerator * Add temporarily hacked up yml to test and add output before/after connection auth * indent working directory * add / to beginning of the working directory * change working directory again * trying full path for working directory * try packing/installing separately * try packing/installing separately * try packing/installing separately * Use Azure.Identity and setup a ChainedTokenCred using AzureCLI and AzurePowerShell credentials * do the ConnectAsync in GetConnectionAsync because if there's a failure, it'll happen there not some random place * revert changes from pipeline-generation.yml
1 parent 2615dd3 commit 0f14e8a

4 files changed

Lines changed: 16 additions & 30 deletions

File tree

tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/Azure.Sdk.Tools.PipelineGenerator.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="CommandLineParser" Version="2.9.1" />
17+
<PackageReference Include="Azure.Identity" Version="1.11.3" />
1718
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.6.2" />
1819
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
1920
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
2021

21-
<PackageReference Include="Microsoft.TeamFoundation.DistributedTask.WebApi" Version="16.170.0" />
22-
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.170.0" />
23-
<PackageReference Include="Microsoft.VisualStudio.Services.InteractiveClient" Version="16.170.0" />
24-
<PackageReference Include="Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi" Version="16.170.0" />
22+
<PackageReference Include="Microsoft.TeamFoundation.DistributedTask.WebApi" Version="19.232.0-preview" />
23+
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="19.232.0-preview" />
24+
<PackageReference Include="Microsoft.VisualStudio.Services.InteractiveClient" Version="19.232.0-preview" />
25+
<PackageReference Include="Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi" Version="19.232.0-preview" />
2526
</ItemGroup>
2627
</Project>

tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/CommandParserOptions/DefaultOptions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ public string Organization
2525
[Option('p', "project", Required = false, Default = "internal", HelpText = "Azure DevOps project name. Default: internal")]
2626
public string Project { get; set; }
2727

28-
[Option('t', "patvar", Required = false, HelpText = "Environment variable name containing a Personal Access Token.")]
29-
public string Patvar { get; set; }
30-
3128
[Option("whatif", Required = false, HelpText = "Dry Run changes")]
3229
public bool WhatIf { get; set; }
3330
}
34-
}
31+
}

tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/PipelineGenerationContext.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Azure.Services.AppAuthentication;
1+
using Azure.Identity;
2+
using Microsoft.Azure.Services.AppAuthentication;
23
using Microsoft.Extensions.Logging;
34
using Microsoft.TeamFoundation.Build.WebApi;
45
using Microsoft.TeamFoundation.Core.WebApi;
@@ -20,7 +21,6 @@ public class PipelineGenerationContext
2021
{
2122
private string organization;
2223
private string project;
23-
private string patvar;
2424
private string endpoint;
2525
private string agentPool;
2626
private int[] variableGroups;
@@ -30,7 +30,6 @@ public PipelineGenerationContext(
3030
ILogger logger,
3131
string organization,
3232
string project,
33-
string patvar,
3433
string endpoint,
3534
string repository,
3635
string branch,
@@ -46,7 +45,6 @@ public PipelineGenerationContext(
4645
this.logger = logger;
4746
this.organization = organization;
4847
this.project = project;
49-
this.patvar = patvar;
5048
this.endpoint = endpoint;
5149
this.Repository = repository;
5250
this.Branch = branch;
@@ -76,20 +74,13 @@ private async Task<VssConnection> GetConnectionAsync()
7674
{
7775
if (cachedConnection == null)
7876
{
79-
VssCredentials credentials;
80-
if (string.IsNullOrWhiteSpace(patvar))
81-
{
82-
var azureTokenProvider = new AzureServiceTokenProvider();
83-
var authenticationResult = await azureTokenProvider.GetAuthenticationResultAsync("499b84ac-1321-427f-aa17-267ca6975798");
84-
credentials = new VssAadCredential(new VssAadToken(authenticationResult.TokenType, authenticationResult.AccessToken));
85-
}
86-
else
87-
{
88-
var pat = Environment.GetEnvironmentVariable(patvar);
89-
credentials = new VssBasicCredential("nobody", pat);
90-
}
91-
92-
cachedConnection = new VssConnection(new Uri(organization), credentials);
77+
var azureCredential = new ChainedTokenCredential(
78+
new AzureCliCredential(),
79+
new AzurePowerShellCredential()
80+
);
81+
var devopsCredential = new VssAzureIdentityCredential(azureCredential);
82+
cachedConnection = new VssConnection(new Uri(organization), devopsCredential);
83+
await cachedConnection.ConnectAsync();
9384
}
9485

9586
return cachedConnection;

tools/pipeline-generator/Azure.Sdk.Tools.PipelineGenerator/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
@@ -43,7 +43,6 @@ public static async Task Run(object commandObj, CancellationTokenSource cancella
4343
g.Project,
4444
g.Prefix,
4545
g.Path,
46-
g.Patvar,
4746
g.Endpoint,
4847
g.Repository,
4948
g.Branch,
@@ -127,7 +126,6 @@ public async Task<ExitCondition> RunAsync(
127126
string project,
128127
string prefix,
129128
string path,
130-
string patvar,
131129
string endpoint,
132130
string repository,
133131
string branch,
@@ -154,7 +152,6 @@ public async Task<ExitCondition> RunAsync(
154152
this.logger,
155153
organization,
156154
project,
157-
patvar,
158155
endpoint,
159156
repository,
160157
branch,

0 commit comments

Comments
 (0)