Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Agent.Listener/CommandLine/RemoveAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ namespace Agent.Listener.CommandLine
[Verb(Constants.Agent.CommandLine.Commands.Remove)]
public class RemoveAgent : ConfigureOrRemoveBase
{
[Option(Constants.Agent.CommandLine.Args.Url)]
public string Url { get; set; }
}
}
9 changes: 6 additions & 3 deletions src/Agent.Listener/CommandSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,18 @@ public string GetToken()

public string GetUrl(bool suppressPromptIfEmpty = false)
{
// Check for URL from either Configure or Remove commands
string urlValue = Configure?.Url ?? Remove?.Url;

// Note, GetArg does not consume the arg (like GetArgOrPrompt does).
if (suppressPromptIfEmpty &&
string.IsNullOrEmpty(GetArg(Configure?.Url, Constants.Agent.CommandLine.Args.Url)))
string.IsNullOrEmpty(GetArg(urlValue, Constants.Agent.CommandLine.Args.Url)))
{
return string.Empty;
}

return GetArgOrPrompt(
argValue: Configure?.Url,
argValue: urlValue,
name: Constants.Agent.CommandLine.Args.Url,
description: StringUtil.Loc("ServerUrl"),
defaultValue: string.Empty,
Expand Down
9 changes: 9 additions & 0 deletions src/Agent.Listener/Configuration/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ public async Task UnconfigureAsync(CommandSettings command)
if (isConfigured && hasCredentials)
{
AgentSettings settings = _store.GetSettings();

var credentialManager = HostContext.GetService<ICredentialManager>();

// Get the credentials
Expand All @@ -602,6 +603,14 @@ public async Task UnconfigureAsync(CommandSettings command)
IConfigurationProvider agentProvider = (extensionManager.GetExtensions<IConfigurationProvider>()).FirstOrDefault(x => x.ConfigurationProviderType == agentType);
ArgUtil.NotNull(agentProvider, agentType);

// If a URL is provided via command line, override the stored ServerUrl BEFORE checking if hosted
string commandUrl = command.GetUrl(suppressPromptIfEmpty: true);
if (!string.IsNullOrEmpty(commandUrl))
{
Trace.Info($"Overriding stored ServerUrl '{settings.ServerUrl}' with command line URL '{commandUrl}' for removal operation");
settings.ServerUrl = commandUrl;
}

bool isHostedServer = await CheckIsHostedServer(agentProvider, settings, credProvider, agentCertManager.SkipServerCertificateValidation);
VssCredentials creds = credProvider.GetVssCredentials(HostContext);

Expand Down
Loading