Skip to content

Commit

Permalink
Remove PATVAR from PipelineGenerator (#8369)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JimSuplizio authored Jun 4, 2024
1 parent 2615dd3 commit 0f14e8a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Azure.Identity" Version="1.11.3" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.6.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />

<PackageReference Include="Microsoft.TeamFoundation.DistributedTask.WebApi" Version="16.170.0" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.170.0" />
<PackageReference Include="Microsoft.VisualStudio.Services.InteractiveClient" Version="16.170.0" />
<PackageReference Include="Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi" Version="16.170.0" />
<PackageReference Include="Microsoft.TeamFoundation.DistributedTask.WebApi" Version="19.232.0-preview" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="19.232.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Services.InteractiveClient" Version="19.232.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi" Version="19.232.0-preview" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -30,7 +30,6 @@ public PipelineGenerationContext(
ILogger logger,
string organization,
string project,
string patvar,
string endpoint,
string repository,
string branch,
Expand All @@ -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;
Expand Down Expand Up @@ -76,20 +74,13 @@ private async Task<VssConnection> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -127,7 +126,6 @@ public async Task<ExitCondition> RunAsync(
string project,
string prefix,
string path,
string patvar,
string endpoint,
string repository,
string branch,
Expand All @@ -154,7 +152,6 @@ public async Task<ExitCondition> RunAsync(
this.logger,
organization,
project,
patvar,
endpoint,
repository,
branch,
Expand Down

0 comments on commit 0f14e8a

Please sign in to comment.