Skip to content

Commit

Permalink
Format agent source code (#4101)
Browse files Browse the repository at this point in the history
* Run dotnet format

* Remove extra semicolons
  • Loading branch information
KonstantinTyukalov authored Dec 26, 2022
1 parent e76a890 commit df73f63
Show file tree
Hide file tree
Showing 202 changed files with 1,003 additions and 922 deletions.
10 changes: 5 additions & 5 deletions src/Agent.Listener/CommandSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public CommandSettings(IHostContext context, string[] args, IScopedEnvironment e

// Store and remove any args passed via environment variables.
var environment = environmentScope.GetEnvironmentVariables();

string envPrefix = "VSTS_AGENT_INPUT_";
foreach (DictionaryEntry entry in environment)
{
Expand Down Expand Up @@ -449,7 +449,7 @@ public string GetStartupType()
{
return GetArg(Run?.StartupType, Constants.Agent.CommandLine.Args.StartupType);
}

public string GetProxyUrl()
{
return GetArg(Configure?.ProxyUrl, Constants.Agent.CommandLine.Args.ProxyUrl);
Expand All @@ -467,7 +467,7 @@ public string GetProxyPassword()

public bool GetSkipCertificateValidation()
{
return TestFlag(Configure?.SslSkipCertValidation , Constants.Agent.CommandLine.Flags.SslSkipCertValidation);
return TestFlag(Configure?.SslSkipCertValidation, Constants.Agent.CommandLine.Flags.SslSkipCertValidation);
}

public string GetCACertificate()
Expand Down Expand Up @@ -518,7 +518,7 @@ public bool GetDeploymentPool()

public bool GetDeploymentOrMachineGroup()
{
if (TestFlag(Configure?.DeploymentGroup, Constants.Agent.CommandLine.Flags.DeploymentGroup) ||
if (TestFlag(Configure?.DeploymentGroup, Constants.Agent.CommandLine.Flags.DeploymentGroup) ||
(Configure?.MachineGroup == true))
{
return true;
Expand Down Expand Up @@ -802,7 +802,7 @@ private void PrintArguments()
{
if (Configure != null)
{
_trace.Info(string.Concat(nameof(Configure)," ",ObjectAsJson(Configure)));
_trace.Info(string.Concat(nameof(Configure), " ", ObjectAsJson(Configure)));
}

if (Remove != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ public void UpdateRegistrySettings(CommandSettings command, string domainName, s
try
{
string securityId = _windowsServiceHelper.GetSecurityId(domainName, userName);
if(string.IsNullOrEmpty(securityId))
if (string.IsNullOrEmpty(securityId))
{
Trace.Error($"Could not find the Security ID for the user '{domainName}\\{userName}'. AutoLogon will not be configured.");
throw new ArgumentException(StringUtil.Loc("InvalidSIDForUser", domainName, userName));
}

//check if the registry exists for the user, if not load the user profile
if(!_registryManager.SubKeyExists(RegistryHive.Users, securityId))
if (!_registryManager.SubKeyExists(RegistryHive.Users, securityId))
{
userProfile.dwSize = Marshal.SizeOf(typeof(PROFILEINFO));
userProfile.lpUserName = userName;

_windowsServiceHelper.LoadUserProfile(domainName, userName, logonPassword, out userHandler, out userProfile);
}

if(!_registryManager.SubKeyExists(RegistryHive.Users, securityId))
if (!_registryManager.SubKeyExists(RegistryHive.Users, securityId))
{
throw new InvalidOperationException(StringUtil.Loc("ProfileLoadFailure", domainName, userName));
}
Expand All @@ -90,7 +90,7 @@ public void UpdateRegistrySettings(CommandSettings command, string domainName, s
}
finally
{
if(userHandler != IntPtr.Zero)
if (userHandler != IntPtr.Zero)
{
_windowsServiceHelper.UnloadUserProfile(userHandler, userProfile);
}
Expand All @@ -100,7 +100,7 @@ public void UpdateRegistrySettings(CommandSettings command, string domainName, s
public void ResetRegistrySettings(string domainName, string userName)
{
string securityId = _windowsServiceHelper.GetSecurityId(domainName, userName);
if(string.IsNullOrEmpty(securityId))
if (string.IsNullOrEmpty(securityId))
{
Trace.Error($"Could not find the Security ID for the user '{domainName}\\{userName}'. Unconfiguration of AutoLogon is not possible.");
throw new ArgumentException(StringUtil.Loc("InvalidSIDForUser", domainName, userName));
Expand Down Expand Up @@ -140,7 +140,7 @@ public void DumpAutoLogonRegistrySettings()
Trace.Info($"Legal notice caption - Subkey - {legalNoticeSubKey} ValueName - {captionValueName}. Is defined - {isLegalNoticeCaptionDefined}");

var textValueName = RegistryConstants.MachineSettings.ValueNames.LegalNoticeText;
var legalNoticeText = _registryManager.GetValue(RegistryHive.LocalMachine, legalNoticeSubKey, textValueName);
var legalNoticeText = _registryManager.GetValue(RegistryHive.LocalMachine, legalNoticeSubKey, textValueName);
var isLegalNoticeTextDefined = !string.IsNullOrEmpty(legalNoticeCaption);
Trace.Info($"Legal notice text - Subkey - {legalNoticeSubKey} ValueName - {textValueName}. Is defined - {isLegalNoticeTextDefined}");
}
Expand All @@ -164,7 +164,7 @@ public void DumpAutoLogonRegistrySettings()
Trace.Info("****User specific policies/settings****");
var screenSaverPolicySubKeyName = RegistryConstants.UserSettings.SubKeys.ScreenSaverDomainPolicy;
var screenSaverValueName = RegistryConstants.UserSettings.ValueNames.ScreenSaver;
if(_registryManager.SubKeyExists(RegistryHive.CurrentUser, screenSaverPolicySubKeyName))
if (_registryManager.SubKeyExists(RegistryHive.CurrentUser, screenSaverPolicySubKeyName))
{
var screenSaverSettingValue = _registryManager.GetValue(RegistryHive.CurrentUser, screenSaverPolicySubKeyName, screenSaverValueName);
Trace.Info($"Screensaver policy. SubKey - {screenSaverPolicySubKeyName} ValueName - {screenSaverValueName} : {screenSaverSettingValue} (1- enabled)");
Expand All @@ -176,7 +176,7 @@ public void DumpAutoLogonRegistrySettings()

Trace.Info("****User specific settings****");

var screenSaverSettingSubKeyName = RegistryConstants.UserSettings.SubKeys.ScreenSaver;
var screenSaverSettingSubKeyName = RegistryConstants.UserSettings.SubKeys.ScreenSaver;
var screenSaverSettingValueName = RegistryConstants.UserSettings.ValueNames.ScreenSaver;
var screenSaverValue = _registryManager.GetValue(RegistryHive.CurrentUser, screenSaverSettingSubKeyName, screenSaverSettingValueName);
Trace.Info($"Screensaver - SubKey - {screenSaverSettingSubKeyName}, ValueName - {screenSaverSettingValueName} : {screenSaverValue} (0-disabled, 1-enabled)");
Expand Down Expand Up @@ -256,7 +256,7 @@ private void InspectAutoLogonRelatedPolicies()
var legalNoticeCaption = _registryManager.GetValue(RegistryHive.LocalMachine,
RegistryConstants.MachineSettings.SubKeys.LegalNotice,
RegistryConstants.MachineSettings.ValueNames.LegalNoticeCaption);
var legalNoticeText = _registryManager.GetValue(RegistryHive.LocalMachine,
var legalNoticeText = _registryManager.GetValue(RegistryHive.LocalMachine,
RegistryConstants.MachineSettings.SubKeys.LegalNotice,
RegistryConstants.MachineSettings.ValueNames.LegalNoticeText);
if (!string.IsNullOrEmpty(legalNoticeCaption) || !string.IsNullOrEmpty(legalNoticeText))
Expand All @@ -269,7 +269,7 @@ private void InspectAutoLogonRelatedPolicies()
{
Trace.Warning("Following policies may affect the autologon:");
_terminal.WriteError(StringUtil.Loc("AutoLogonPoliciesWarningsHeader"));
for (int i=0; i < warningReasons.Count; i++)
for (int i = 0; i < warningReasons.Count; i++)
{
var msg = String.Format("{0} - {1}", i + 1, warningReasons[i]);
Trace.Warning(msg);
Expand All @@ -295,7 +295,7 @@ private void UpdateScreenSaverSettings(CommandSettings command, string securityI
_terminal.WriteLine(StringUtil.Loc("ScreenSaverPoliciesInspection"));

string subKeyName = $"{securityId}\\{RegistryConstants.UserSettings.SubKeys.ScreenSaverDomainPolicy}";
if(_registryManager.SubKeyExists(RegistryHive.Users, subKeyName))
if (_registryManager.SubKeyExists(RegistryHive.Users, subKeyName))
{
var screenSaverValue = _registryManager.GetValue(RegistryHive.Users, subKeyName, RegistryConstants.UserSettings.ValueNames.ScreenSaver);
if (int.TryParse(screenSaverValue, out int isScreenSaverDomainPolicySet)
Expand Down Expand Up @@ -351,7 +351,7 @@ private void ResetUserSpecificSettings(string securityId)
var screenSaverSubKey = $"{securityId}\\{RegistryConstants.UserSettings.SubKeys.ScreenSaver}";
var currentValue = _registryManager.GetValue(targetHive, screenSaverSubKey, RegistryConstants.UserSettings.ValueNames.ScreenSaver);

if(string.Equals(currentValue, "0", StringComparison.CurrentCultureIgnoreCase))
if (string.Equals(currentValue, "0", StringComparison.CurrentCultureIgnoreCase))
{
//we only take the backup of screensaver setting at present, reverting it back if it exists
RevertOriginalValue(targetHive, screenSaverSubKey, RegistryConstants.UserSettings.ValueNames.ScreenSaver);
Expand All @@ -369,7 +369,7 @@ private void DeleteStartupCommand(RegistryHive targetHive, string securityId)
var actualStartupCmd = _registryManager.GetValue(targetHive, startupProcessSubKeyName, RegistryConstants.UserSettings.ValueNames.StartupProcess);

// Use StartWith() instead of Equals() because we don't know if the startupCmd should include the runOnce parameter
if(actualStartupCmd != null &&
if (actualStartupCmd != null &&
actualStartupCmd.StartsWith(expectedStartupCmd, StringComparison.CurrentCultureIgnoreCase))
{
_registryManager.DeleteValue(RegistryHive.Users, startupProcessSubKeyName, RegistryConstants.UserSettings.ValueNames.StartupProcess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class WindowsRegistryManager : AgentService, IWindowsRegistryManager
{
public void DeleteValue(RegistryHive hive, string subKeyName, string name)
{
using(RegistryKey key = OpenRegistryKey(hive, subKeyName, true))
using (RegistryKey key = OpenRegistryKey(hive, subKeyName, true))
{
if (key != null)
{
Expand All @@ -30,9 +30,9 @@ public void DeleteValue(RegistryHive hive, string subKeyName, string name)

public string GetValue(RegistryHive hive, string subKeyName, string name)
{
using(RegistryKey key = OpenRegistryKey(hive, subKeyName, false))
using (RegistryKey key = OpenRegistryKey(hive, subKeyName, false))
{
if(key == null)
if (key == null)
{
return null;
}
Expand All @@ -44,7 +44,7 @@ public string GetValue(RegistryHive hive, string subKeyName, string name)

public void SetValue(RegistryHive hive, string subKeyName, string name, string value)
{
using(RegistryKey key = OpenRegistryKey(hive, subKeyName, true))
using (RegistryKey key = OpenRegistryKey(hive, subKeyName, true))
{
if (key == null)
{
Expand All @@ -64,7 +64,7 @@ public void SetValue(RegistryHive hive, string subKeyName, string name, string v

public bool SubKeyExists(RegistryHive hive, string subKeyName)
{
using(RegistryKey key = OpenRegistryKey(hive, subKeyName, false))
using (RegistryKey key = OpenRegistryKey(hive, subKeyName, false))
{
return key != null;
}
Expand All @@ -75,10 +75,10 @@ private RegistryKey OpenRegistryKey(RegistryHive hive, string subKeyName, bool w
RegistryKey key = null;
switch (hive)
{
case RegistryHive.CurrentUser :
case RegistryHive.CurrentUser:
key = Registry.CurrentUser.OpenSubKey(subKeyName, writable);
break;
case RegistryHive.Users :
case RegistryHive.Users:
key = Registry.Users.OpenSubKey(subKeyName, writable);
break;
case RegistryHive.LocalMachine:
Expand All @@ -93,10 +93,10 @@ private RegistryKey CreateRegistryKey(RegistryHive hive, string subKeyName, bool
RegistryKey key = null;
switch (hive)
{
case RegistryHive.CurrentUser :
case RegistryHive.CurrentUser:
key = Registry.CurrentUser.CreateSubKey(subKeyName, writable);
break;
case RegistryHive.Users :
case RegistryHive.Users:
key = Registry.Users.CreateSubKey(subKeyName, writable);
break;
case RegistryHive.LocalMachine:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ public void ConfigureService(AgentSettings settings, CommandSettings command)
_windowsServiceHelper.CreateVstsAgentRegistryKey();

Trace.Info("Configuration was successful, trying to start the service");
if(!command.GetPreventServiceStart())
if (!command.GetPreventServiceStart())
{
_windowsServiceHelper.StartService(serviceName);
}

}

public void UnconfigureService()
Expand Down
30 changes: 18 additions & 12 deletions src/Agent.Listener/Configuration/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task ConfigureAsync(CommandSettings command)
ArgUtil.NotNull(command, nameof(command));

if (PlatformUtil.RunningOnWindows)
{
{
CheckAgentRootDirectorySecure();
}

Expand Down Expand Up @@ -374,7 +374,7 @@ public async Task ConfigureAsync(CommandSettings command)
agentSettings.DisableLogUploads = command.GetDisableLogUploads();

agentSettings.AlwaysExtractTask = command.GetAlwaysExtractTask();

_store.SaveSettings(agentSettings);

if (saveProxySetting)
Expand Down Expand Up @@ -503,7 +503,7 @@ public async Task UnconfigureAsync(CommandSettings command)

bool isEnvironmentVMResource = false;
bool isDeploymentGroup = (settings.MachineGroupId > 0) || (settings.DeploymentGroupId > 0);
if(!isDeploymentGroup)
if (!isDeploymentGroup)
{
isEnvironmentVMResource = settings.EnvironmentId > 0;
}
Expand All @@ -520,7 +520,7 @@ public async Task UnconfigureAsync(CommandSettings command)
IConfigurationProvider agentProvider = (extensionManager.GetExtensions<IConfigurationProvider>()).FirstOrDefault(x => x.ConfigurationProviderType == agentType);
ArgUtil.NotNull(agentProvider, agentType);

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

await agentProvider.TestConnectionAsync(settings, creds, isHostedServer);
Expand Down Expand Up @@ -708,21 +708,23 @@ private void CheckAgentRootDirectorySecure()
_term.Write(StringUtil.Loc("agentRootFolderInsecure", bulitInUsersGroup.ToString()));
}
}
else
else
{
Trace.Warning("Can't get path to the agent root folder, check was skipped.");
}
}
catch (Exception ex) {
catch (Exception ex)
{
Trace.Warning("Can't check permissions for agent root folder:");
Trace.Warning(ex.Message);
_term.Write(StringUtil.Loc("agentRootFolderCheckError"));
}
}

private bool SetupVstsProxySetting(IVstsAgentWebProxy vstsProxy, CommandSettings command) {
private bool SetupVstsProxySetting(IVstsAgentWebProxy vstsProxy, CommandSettings command)
{
ArgUtil.NotNull(command, nameof(command));

bool saveProxySetting = false;
string proxyUrl = command.GetProxyUrl();
if (!string.IsNullOrEmpty(proxyUrl))
Expand All @@ -742,7 +744,8 @@ private bool SetupVstsProxySetting(IVstsAgentWebProxy vstsProxy, CommandSettings
return saveProxySetting;
}

private bool SetupCertSettings(IAgentCertificateManager agentCertManager, CommandSettings command) {
private bool SetupCertSettings(IAgentCertificateManager agentCertManager, CommandSettings command)
{
bool saveCertSetting = false;
bool skipCertValidation = command.GetSkipCertificateValidation();
string caCert = command.GetCACertificate();
Expand Down Expand Up @@ -792,7 +795,8 @@ private bool SetupCertSettings(IAgentCertificateManager agentCertManager, Comman
return saveCertSetting;
}

private string GetAgentTypeFromCommand(CommandSettings command) {
private string GetAgentTypeFromCommand(CommandSettings command)
{
string agentType = Constants.Agent.AgentConfigurationProvider.BuildReleasesAgentConfiguration;

if (command.GetDeploymentOrMachineGroup())
Expand All @@ -811,7 +815,8 @@ private string GetAgentTypeFromCommand(CommandSettings command) {
return agentType;
}

private async Task<bool> checkIsHostedServer(IConfigurationProvider agentProvider, AgentSettings agentSettings, ICredentialProvider credProvider) {
private async Task<bool> checkIsHostedServer(IConfigurationProvider agentProvider, AgentSettings agentSettings, ICredentialProvider credProvider)
{
bool isHostedServer = false;
VssCredentials creds = credProvider.GetVssCredentials(HostContext);

Expand All @@ -820,7 +825,8 @@ private async Task<bool> checkIsHostedServer(IConfigurationProvider agentProvide
// Determine the service deployment type based on connection data. (Hosted/OnPremises)
await _serverUtil.DetermineDeploymentType(agentSettings.ServerUrl, creds, _locationServer);
}
catch (VssUnauthorizedException) {
catch (VssUnauthorizedException)
{
// In case if GetConnectionData returned some auth problem need to check
// maybe connect will be successfull with CollectionName
// (as example PAT was generated for url/CollectionName)
Expand Down
Loading

0 comments on commit df73f63

Please sign in to comment.