Skip to content

Commit

Permalink
Clean up warnings in agent (#4622)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnSchmeichel committed Feb 9, 2024
1 parent fdac1ad commit f25a7cd
Show file tree
Hide file tree
Showing 36 changed files with 114 additions and 31 deletions.
2 changes: 2 additions & 0 deletions src/Agent.Listener/CommandSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using CommandLine;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using System.Runtime.Versioning;

namespace Microsoft.VisualStudio.Services.Agent.Listener
{
Expand Down Expand Up @@ -430,6 +431,7 @@ public string GetUserName()
validator: Validators.NonEmptyValidator);
}

[SupportedOSPlatform("windows")]
public string GetWindowsLogonAccount(string defaultValue, string descriptionMsg)
{
return GetArgOrPrompt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using Microsoft.VisualStudio.Services.Agent.Util;

namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration
{
[ServiceLocator(Default = typeof(SystemDControlManager))]
[SupportedOSPlatform("linux")]
public interface ILinuxServiceControlManager : IAgentService
{
void GenerateScripts(AgentSettings settings);
}


[SupportedOSPlatform("linux")]
public class SystemDControlManager : ServiceControlManager, ILinuxServiceControlManager
{
// This is the name you would see when you do `systemctl list-units | grep vsts`
Expand Down
3 changes: 3 additions & 0 deletions src/Agent.Listener/Configuration.Windows/AutoLogonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.DistributedTask.WebApi;
Expand All @@ -12,12 +13,14 @@
namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration
{
[ServiceLocator(Default = typeof(AutoLogonManager))]
[SupportedOSPlatform("windows")]
public interface IAutoLogonManager : IAgentService
{
Task ConfigureAsync(CommandSettings command);
void Unconfigure();
}

[SupportedOSPlatform("windows")]
public class AutoLogonManager : AgentService, IAutoLogonManager
{
private ITerminal _terminal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration
{
[ServiceLocator(Default = typeof(AutoLogonRegistryManager))]
[SupportedOSPlatform("windows")]
public interface IAutoLogonRegistryManager : IAgentService
{
void GetAutoLogonUserDetails(out string domainName, out string userName);
Expand All @@ -20,6 +22,7 @@ public interface IAutoLogonRegistryManager : IAgentService
void DumpAutoLogonRegistrySettings();
}

[SupportedOSPlatform("windows")]
public class AutoLogonRegistryManager : AgentService, IAutoLogonRegistryManager
{
private IWindowsRegistryManager _registryManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.AccessControl;
using System.Security.Principal;
Expand All @@ -19,6 +20,7 @@
namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration
{
[ServiceLocator(Default = typeof(NativeWindowsServiceHelper))]
[SupportedOSPlatform("windows")]
public interface INativeWindowsServiceHelper : IAgentService
{
string GetUniqueBuildGroupName();
Expand Down Expand Up @@ -82,6 +84,7 @@ public interface INativeWindowsServiceHelper : IAgentService
bool IsManagedServiceAccount(string accountName);
}

[SupportedOSPlatform("windows")]
public class NativeWindowsServiceHelper : AgentService, INativeWindowsServiceHelper
{
private const string AgentServiceLocalGroupPrefix = "VSTS_AgentService_G";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
// Licensed under the MIT License.

using System.IO;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.Services.Agent.Util;

namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration
{
[SupportedOSPlatform("windows")]
public class RSAEncryptedFileKeyManager : AgentService, IRSAKeyManager
{
private string _keyFile;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Runtime.Versioning;
using Microsoft.Win32;


namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration
{
[ServiceLocator(Default = typeof(WindowsRegistryManager))]
[SupportedOSPlatform("windows")]
public interface IWindowsRegistryManager : IAgentService
{
string GetValue(RegistryHive hive, string subKeyName, string name);
Expand All @@ -15,6 +17,7 @@ public interface IWindowsRegistryManager : IAgentService
bool SubKeyExists(RegistryHive hive, string subKeyName);
}

[SupportedOSPlatform("windows")]
public class WindowsRegistryManager : AgentService, IWindowsRegistryManager
{
public void DeleteValue(RegistryHive hive, string subKeyName, string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.IO;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Principal;
using System.Text;
Expand All @@ -11,13 +12,15 @@
namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration
{
[ServiceLocator(Default = typeof(WindowsServiceControlManager))]
[SupportedOSPlatform("windows")]
public interface IWindowsServiceControlManager : IAgentService
{
void ConfigureService(AgentSettings settings, CommandSettings command);

void UnconfigureService();
}

[SupportedOSPlatform("windows")]
public class WindowsServiceControlManager : ServiceControlManager, IWindowsServiceControlManager
{
public const string WindowsServiceControllerName = "AgentService.exe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.Services.Agent.Util;
using System.Runtime.Versioning;

namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration
{
[ServiceLocator(Default = typeof(MacOSServiceControlManager))]
[SupportedOSPlatform("macos")]
public interface IMacOSServiceControlManager : IAgentService
{
void GenerateScripts(AgentSettings settings);
}

[SupportedOSPlatform("macos")]
public class MacOSServiceControlManager : ServiceControlManager, IMacOSServiceControlManager
{
// This is the name you would see when you do `systemctl list-units | grep vsts`
Expand Down
5 changes: 4 additions & 1 deletion src/Agent.Listener/Configuration/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.VisualStudio.Services.Agent.Util;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.OAuth;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -18,6 +17,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.AccessControl;
using System.Security.Principal;
using Newtonsoft.Json;
Expand Down Expand Up @@ -120,11 +120,13 @@ public async Task ConfigureAsync(CommandSettings command)
break;
case PlatformUtil.OS.Windows:
// Warn and continue if .NET 4.6 is not installed.
#pragma warning disable CA1416 // SupportedOSPlatformGuard not honored on enum members
if (!NetFrameworkUtil.Test(new Version(4, 6), Trace))
{
WriteSection(StringUtil.Loc("PrerequisitesSectionHeader")); // Section header.
_term.WriteLine(StringUtil.Loc("MinimumNetFrameworkTfvc")); // Warning.
}
#pragma warning restore CA1416

break;
default:
Expand Down Expand Up @@ -699,6 +701,7 @@ private void WriteSection(string message)
_term.WriteLine();
}

[SupportedOSPlatform("windows")]
private void CheckAgentRootDirectorySecure()
{
Trace.Info(nameof(CheckAgentRootDirectorySecure));
Expand Down
2 changes: 1 addition & 1 deletion src/Agent.Listener/Configuration/CredentialProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private async Task<AuthenticationResult> GetTokenUsingDeviceCodeFlowAsync(IHostC
term.WriteLine($"Please finish AAD device code flow in browser ({deviceCodeCallback.VerificationUrl}), user code: {deviceCodeCallback.UserCode}"); return Task.FromResult(0);
}).ExecuteAsync().ConfigureAwait(false);
}
catch (MsalServiceException ex)
catch (MsalServiceException)
{
// AADSTS50059: No tenant-identifying information found in either the request or implied by any provided credentials.
// AADSTS90133: Device Code flow is not supported under /common or /consumers endpoint.
Expand Down
2 changes: 2 additions & 0 deletions src/Agent.Listener/Configuration/Validators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.VisualStudio.Services.Agent.Util;
using System;
using System.IO;
using System.Runtime.Versioning;
using System.Security.Principal;

namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration
Expand Down Expand Up @@ -72,6 +73,7 @@ public static bool NonEmptyValidator(string value)
return !string.IsNullOrEmpty(value);
}

[SupportedOSPlatform("windows")]
public static bool NTAccountValidator(string arg)
{
if (string.IsNullOrEmpty(arg) || String.IsNullOrEmpty(arg.TrimStart('.', '\\')))
Expand Down
2 changes: 1 addition & 1 deletion src/Agent.Plugins/PipelineCache/FingerprintCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal struct Enumeration

internal class MatchedFile
{
private static readonly SHA256Managed s_sha256 = new SHA256Managed();
private static readonly SHA256 s_sha256 = SHA256.Create();

public MatchedFile(string displayPath, long fileLength, string hash)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Agent.Plugins/PipelineCache/PipelineCacheServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ await AsyncHttpRetryHelper.InvokeVoidAsync(
{
try
{
IOUtil.DeleteFileWithRetry(manifestPath, cancellationToken);
await IOUtil.DeleteFileWithRetry(manifestPath, cancellationToken);
}
catch (Exception ex)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Agent.Sdk/Util/NetFrameworkUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using System.Threading;

namespace Microsoft.VisualStudio.Services.Agent.Util
{
[SupportedOSPlatform("windows")]
public static class NetFrameworkUtil
{
private static List<Version> _versions;
Expand Down
Loading

0 comments on commit f25a7cd

Please sign in to comment.