Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.
Merged
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
4 changes: 2 additions & 2 deletions src/ApiService/ApiService/GroupMembershipChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async ValueTask<bool> IsMember(IEnumerable<Guid> groupIds, Guid memberId)
}
}

class AzureADGroupMembership : GroupMembershipChecker {
sealed class AzureADGroupMembership : GroupMembershipChecker {
private readonly GraphServiceClient _graphClient;
public AzureADGroupMembership(GraphServiceClient graphClient) => _graphClient = graphClient;
protected override async IAsyncEnumerable<Guid> GetGroups(Guid memberId) {
Expand All @@ -30,7 +30,7 @@ protected override async IAsyncEnumerable<Guid> GetGroups(Guid memberId) {
}
}

class StaticGroupMembership : GroupMembershipChecker {
sealed class StaticGroupMembership : GroupMembershipChecker {
private readonly IReadOnlyDictionary<Guid, IReadOnlyList<Guid>> _memberships;
public StaticGroupMembership(IDictionary<Guid, Guid[]> memberships) {
_memberships = memberships.ToDictionary(kvp => kvp.Key, kvp => (IReadOnlyList<Guid>)kvp.Value.ToList());
Expand Down
4 changes: 2 additions & 2 deletions src/ApiService/ApiService/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public interface ILog {
void Flush();
}

class AppInsights : ILog {
sealed class AppInsights : ILog {
private readonly TelemetryClient _telemetryClient;

public AppInsights(TelemetryClient client) {
Expand Down Expand Up @@ -128,7 +128,7 @@ public void Flush() {
}

//TODO: Should we write errors and Exception to std err ?
class Console : ILog {
sealed class Console : ILog {

private static string DictToString<T>(IReadOnlyDictionary<string, T>? d) {
if (d is null) {
Expand Down
16 changes: 8 additions & 8 deletions src/ApiService/ApiService/OneFuzzTypes/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ TaskConfig Config


[EventType(EventType.JobCreated)]
record EventJobCreated(
sealed record EventJobCreated(
Guid JobId,
JobConfig Config,
UserInfo? UserInfo
Expand All @@ -146,7 +146,7 @@ List<JobTaskStopped> TaskInfo


[EventType(EventType.TaskCreated)]
record EventTaskCreated(
sealed record EventTaskCreated(
Guid JobId,
Guid TaskId,
TaskConfig Config,
Expand Down Expand Up @@ -177,7 +177,7 @@ Guid PingId


[EventType(EventType.ScalesetCreated)]
record EventScalesetCreated(
sealed record EventScalesetCreated(
Guid ScalesetId,
PoolName PoolName,
string VmSku,
Expand All @@ -187,15 +187,15 @@ record EventScalesetCreated(


[EventType(EventType.ScalesetFailed)]
public record EventScalesetFailed(
public sealed record EventScalesetFailed(
Guid ScalesetId,
PoolName PoolName,
Error Error
) : BaseEvent();


[EventType(EventType.ScalesetDeleted)]
record EventScalesetDeleted(
sealed record EventScalesetDeleted(
Guid ScalesetId,
PoolName PoolName

Expand All @@ -211,13 +211,13 @@ long size


[EventType(EventType.PoolDeleted)]
record EventPoolDeleted(
sealed record EventPoolDeleted(
PoolName PoolName
) : BaseEvent();


[EventType(EventType.PoolCreated)]
record EventPoolCreated(
sealed record EventPoolCreated(
PoolName PoolName,
Os Os,
Architecture Arch,
Expand Down Expand Up @@ -289,7 +289,7 @@ ScalesetState State
) : BaseEvent();

[EventType(EventType.NodeStateUpdated)]
record EventNodeStateUpdated(
sealed record EventNodeStateUpdated(
Guid MachineId,
Guid? ScalesetId,
PoolName PoolName,
Expand Down
10 changes: 5 additions & 5 deletions src/ApiService/ApiService/TestHooks/NodeOperationsTestHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#if DEBUG
namespace ApiService.TestHooks {

record MarkTasks(Node node, Error? error);
sealed record MarkTasks(Node node, Error? error);

public class NodeOperationsTestHooks {
private readonly ILogTracer _log;
Expand Down Expand Up @@ -162,8 +162,8 @@ public async Task<HttpResponseData> SearchStates([HttpTrigger(AuthorizationLevel
Guid? scaleSetId = UriExtension.GetGuid("scaleSetId", query);

List<NodeState>? states = default;
if (query.ContainsKey("states")) {
states = query["states"].Split('-').Select(s => Enum.Parse<NodeState>(s)).ToList();
if (query.TryGetValue("states", out var value)) {
states = value.Split('-').Select(s => Enum.Parse<NodeState>(s)).ToList();
}
string? poolNameString = UriExtension.GetString("poolName", query);

Expand Down Expand Up @@ -214,8 +214,8 @@ public async Task<HttpResponseData> CreateNode([HttpTrigger(AuthorizationLevel.A
Guid machineId = Guid.Parse(query["machineId"]);

Guid? scaleSetId = default;
if (query.ContainsKey("scaleSetId")) {
scaleSetId = Guid.Parse(query["scaleSetId"]);
if (query.TryGetValue("scaleSetId", out var value)) {
scaleSetId = Guid.Parse(value);
}

string version = query["version"];
Expand Down
16 changes: 8 additions & 8 deletions src/ApiService/ApiService/TestHooks/UriExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ from cs in queryComponents

public static bool GetBool(string key, IDictionary<string, string> query, bool defaultValue = false) {
bool v;
if (query.ContainsKey(key)) {
v = bool.Parse(query[key]);
if (query.TryGetValue(key, out var value)) {
v = bool.Parse(value);
} else {
v = defaultValue;
}
Expand All @@ -25,8 +25,8 @@ public static bool GetBool(string key, IDictionary<string, string> query, bool d

public static int? GetInt(string key, IDictionary<string, string> query, int? defaultValue = null) {
int? v;
if (query.ContainsKey(key)) {
v = int.Parse(query[key]);
if (query.TryGetValue(key, out var value)) {
v = int.Parse(value);
} else {
v = defaultValue;
}
Expand All @@ -35,16 +35,16 @@ public static bool GetBool(string key, IDictionary<string, string> query, bool d


public static string? GetString(string key, IDictionary<string, string> query, string? defaultValue = null) {
if (query.ContainsKey(key)) {
return query[key];
if (query.TryGetValue(key, out var value)) {
return value;
} else {
return defaultValue;
}
}

public static Guid? GetGuid(string key, IDictionary<string, string> query, Guid? defaultValue = null) {
if (query.ContainsKey(key)) {
return Guid.Parse(query[key]);
if (query.TryGetValue(key, out var value)) {
return Guid.Parse(value);
} else {
return defaultValue;
}
Expand Down
3 changes: 1 addition & 2 deletions src/ApiService/ApiService/onefuzzlib/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,7 @@ private async Task<ResultVoid<TaskConfigError>> CheckContainers(TaskDefinition d
}

private static ResultVoid<TaskConfigError> CheckContainer(Compare compare, long expected, ContainerType containerType, Dictionary<ContainerType, List<Container>> containers) {
var actual = containers.ContainsKey(containerType) ? containers[containerType].Count : 0;

var actual = containers.TryGetValue(containerType, out var v) ? v.Count : 0;
if (!CheckVal(compare, expected, actual)) {
return ResultVoid<TaskConfigError>.Error(
new TaskConfigError($"container type {containerType}: expected {compare} {expected}, got {actual}"));
Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/ApiService/onefuzzlib/Creds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public Task<IReadOnlyList<Region>> GetRegions()
}


class GraphQueryException : Exception {
sealed class GraphQueryException : Exception {
public GraphQueryException(string? message) : base(message) {
}
}
2 changes: 1 addition & 1 deletion src/ApiService/ApiService/onefuzzlib/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static VMExtensionWrapper AzSecExtension(AzureLocation region) {
};
}

private class Settings {
private sealed class Settings {
[JsonPropertyName("GCS_AUTO_CONFIG")]
public bool GCS_AUTO_CONFIG { get; set; } = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/ApiService/onefuzzlib/ImageOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ImageOperations(ILogTracer logTracer, IOnefuzzContext context, IMemoryCac
_cache = cache;
}

record class GetOsKey(Region Region, string Image);
sealed record class GetOsKey(Region Region, string Image);

public Task<OneFuzzResult<Os>> GetOs(Region region, string image)
=> _cache.GetOrCreateAsync<OneFuzzResult<Os>>(new GetOsKey(region, image), entry => GetOsInternal(region, image));
Expand Down
12 changes: 6 additions & 6 deletions src/ApiService/ApiService/onefuzzlib/IpOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,16 @@ public async Async.Task CreateIp(string resourceGroup, string name, Region regio
/// the api does not seems to support this :
/// https://github.com/Azure/azure-sdk-for-net/issues/30253#issuecomment-1202447362
/// </summary>
class NetworkInterfaceQuery {
record IpConfigurationsProperties(string privateIPAddress);
sealed class NetworkInterfaceQuery {
sealed record IpConfigurationsProperties(string privateIPAddress);

record IpConfigurations(IpConfigurationsProperties properties);
sealed record IpConfigurations(IpConfigurationsProperties properties);

record NetworkInterfaceProperties(List<IpConfigurations> ipConfigurations);
sealed record NetworkInterfaceProperties(List<IpConfigurations> ipConfigurations);

record NetworkInterface(NetworkInterfaceProperties properties);
sealed record NetworkInterface(NetworkInterfaceProperties properties);

record ValueList<T>(List<T> value);
sealed record ValueList<T>(List<T> value);

private readonly IOnefuzzContext _context;

Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/ApiService/onefuzzlib/NodeOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ await TryGetNodeInfo(node) is NodeInfo nodeInfo) {
return OneFuzzResultVoid.Ok;
}

record NodeInfo(Node Node, Scaleset Scaleset, string InstanceId);
sealed record NodeInfo(Node Node, Scaleset Scaleset, string InstanceId);
private async Async.Task<NodeInfo?> TryGetNodeInfo(Node node) {
var scalesetId = node.ScalesetId;
if (scalesetId is null) {
Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/ApiService/onefuzzlib/RequestAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class RequestAccess {
private readonly Node _root = new();

public record Rules(IReadOnlyList<Guid> AllowedGroupsIds);
record Node(
sealed record Node(
// HTTP Method -> Rules
Dictionary<HttpMethod, Rules> Rules,
// Path Segment -> Node
Expand Down
4 changes: 2 additions & 2 deletions src/ApiService/ApiService/onefuzzlib/Scheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ private async Async.Task<bool> ScheduleWorkset(WorkSet workSet, Pool pool, long
}


record BucketConfig(long count, bool reboot, Container setupContainer, string? setupScript, Pool pool);
sealed record BucketConfig(long count, bool reboot, Container setupContainer, string? setupScript, Pool pool);

record PoolKey(
sealed record PoolKey(
PoolName? poolName = null,
(string sku, string image)? vm = null);

Expand Down
8 changes: 4 additions & 4 deletions src/ApiService/ApiService/onefuzzlib/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public ResourceIdentifier GetPrimaryAccount(StorageType storageType)
var x => throw new NotSupportedException($"invalid StorageType: {x}"),
};

record GetStorageAccountKey_CacheKey(ResourceIdentifier Identifier);
sealed record GetStorageAccountKey_CacheKey(ResourceIdentifier Identifier);
public Async.Task<string?> GetStorageAccountKey(string accountName) {
var resourceGroupId = _creds.GetResourceGroupResourceIdentifier();
var storageAccountId = StorageAccountResource.CreateResourceIdentifier(resourceGroupId.SubscriptionId, resourceGroupId.Name, accountName);
Expand Down Expand Up @@ -187,7 +187,7 @@ private static Uri GetBlobEndpoint(string accountName)
// According to guidance these should be reused as they manage HttpClients,
// so we cache them all by account:

record BlobClientKey(string AccountName);
sealed record BlobClientKey(string AccountName);
public Task<BlobServiceClient> GetBlobServiceClientForAccountName(string accountName) {
return _cache.GetOrCreate(new BlobClientKey(accountName), async cacheEntry => {
cacheEntry.Priority = CacheItemPriority.NeverRemove;
Expand All @@ -197,7 +197,7 @@ public Task<BlobServiceClient> GetBlobServiceClientForAccountName(string account
});
}

record TableClientKey(string AccountName);
sealed record TableClientKey(string AccountName);
public Task<TableServiceClient> GetTableServiceClientForAccountName(string accountName)
=> _cache.GetOrCreate(new TableClientKey(accountName), async cacheEntry => {
cacheEntry.Priority = CacheItemPriority.NeverRemove;
Expand All @@ -206,7 +206,7 @@ public Task<TableServiceClient> GetTableServiceClientForAccountName(string accou
return new TableServiceClient(GetTableEndpoint(accountName), skc);
});

record QueueClientKey(string AccountName);
sealed record QueueClientKey(string AccountName);
private static readonly QueueClientOptions _queueClientOptions = new() { MessageEncoding = QueueMessageEncoding.Base64 };
public Task<QueueServiceClient> GetQueueServiceClientForAccountName(string accountName)
=> _cache.GetOrCreateAsync(new QueueClientKey(accountName), async cacheEntry => {
Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/ApiService/onefuzzlib/VmssOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public async Async.Task<IDictionary<Guid, string>> ListInstanceIds(Guid name) {
}
}

private record InstanceIdKey(Guid Scaleset, Guid VmId);
private sealed record InstanceIdKey(Guid Scaleset, Guid VmId);
private Task<string> GetInstanceIdForVmId(Guid scaleset, Guid vmId)
=> _cache.GetOrCreateAsync(new InstanceIdKey(scaleset, vmId), async entry => {
var scalesetResource = GetVmssResource(scaleset);
Expand Down
8 changes: 4 additions & 4 deletions src/ApiService/ApiService/onefuzzlib/notifications/Ado.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static bool IsTransient(Exception e) {
return errorCodes.Any(code => errorStr.Contains(code));
}

class AdoConnector {
sealed class AdoConnector {
private readonly AdoTemplate _config;
private readonly Renderer _renderer;
private readonly string _project;
Expand Down Expand Up @@ -187,7 +187,7 @@ public async Async.Task<bool> UpdateExisting(WorkItem item, (string, string)[] n

var document = new JsonPatchDocument();
foreach (var field in _config.OnDuplicate.Increment) {
var value = item.Fields.ContainsKey(field) ? int.Parse(JsonSerializer.Serialize(item.Fields[field])) : 0;
var value = item.Fields.TryGetValue(field, out var fieldValue) ? int.Parse(JsonSerializer.Serialize(fieldValue)) : 0;
value++;
document.Add(new JsonPatchOperation() {
Operation = VisualStudio.Services.WebApi.Patch.Operation.Replace,
Expand All @@ -207,11 +207,11 @@ public async Async.Task<bool> UpdateExisting(WorkItem item, (string, string)[] n

var systemState = JsonSerializer.Serialize(item.Fields["System.State"]);
var stateUpdated = false;
if (_config.OnDuplicate.SetState.ContainsKey(systemState)) {
if (_config.OnDuplicate.SetState.TryGetValue(systemState, out var v)) {
document.Add(new JsonPatchOperation() {
Operation = VisualStudio.Services.WebApi.Patch.Operation.Replace,
Path = "/fields/System.State",
Value = _config.OnDuplicate.SetState[systemState]
Value = v
});

stateUpdated = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private async Async.Task Process(GithubIssuesTemplate config, Container containe
var handler = await GithubConnnector.GithubConnnectorCreator(config, container, filename, renderer, _context.Creds.GetInstanceUrl(), _context, _logTracer);
await handler.Process();
}
class GithubConnnector {
sealed class GithubConnnector {
private readonly GitHubClient _gh;
private readonly GithubIssuesTemplate _config;
private readonly Renderer _renderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ParameterInfo parameterInfo
);
public record EntityInfo(Type type, ILookup<string, EntityProperty> properties, Func<object?[], object> constructor);

class OnefuzzNamingPolicy : JsonNamingPolicy {
sealed class OnefuzzNamingPolicy : JsonNamingPolicy {
public override string ConvertName(string name) {
return CaseConverter.PascalToSnake(name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/FunctionalTests/1f-api/ApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace FunctionalTests {
class ApiClient {
sealed class ApiClient {
static Uri endpoint = new Uri(System.Environment.GetEnvironmentVariable("ONEFUZZ_ENDPOINT") ?? "http://localhost:7071");

static Microsoft.Morse.AuthenticationConfig authConfig =
Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/FunctionalTests/1f-api/Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class InfoResponse : IFromJsonElement<InfoResponse> {
}


class InfoApi : ApiBase {
sealed class InfoApi : ApiBase {

public InfoApi(Uri endpoint, Microsoft.OneFuzz.Service.Request request, ITestOutputHelper output) :
base(endpoint, "/api/Info", request, output) {
Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/IntegrationTests/Fakes/TestContainers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.OneFuzz.Service;

// TestContainers class allows use of InstanceID without having to set it up in blob storage
class TestContainers : Containers {
sealed class TestContainers : Containers {
public TestContainers(ILogTracer log, IStorage storage, IServiceConfig config)
: base(log, storage, config) { }

Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/IntegrationTests/Fakes/TestCreds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace IntegrationTests.Fakes;

class TestCreds : ICreds {
sealed class TestCreds : ICreds {

private readonly Guid _subscriptionId;
private readonly string _resourceGroup;
Expand Down
Loading