Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Migrating QueueTaskHeartbeat (#1777)
Browse files Browse the repository at this point in the history
* Migrating QueueTaskHeartbeat

* changing the name of the input queue

* rename type alias Tasks to Async

* Fix property casing

* fixing types

* Removing IStorageProvider

* fix function name

* address PR comments
  • Loading branch information
chkeita authored and AdamL-Microsoft committed Apr 18, 2022
1 parent 6235e5d commit 95dc487
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 180 deletions.
126 changes: 6 additions & 120 deletions src/ApiService/ApiService/OneFuzzTypes/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
using System;
using System.Collections.Generic;
using PoolName = System.String;
using Endpoint = System.String;
using GroupId = System.Guid;
using PrincipalId = System.Guid;
using Region = System.String;
using Container = System.String;

namespace Microsoft.OneFuzz.Service;

Expand Down Expand Up @@ -94,7 +93,7 @@ public enum NodeState

public record ProxyHeartbeat
(
string Region,
Region Region,
Guid ProxyId,
List<ProxyForward> Forwards,
DateTimeOffset TimeStamp
Expand All @@ -118,7 +117,7 @@ bool DebugKeepNode

public partial record ProxyForward
(
[PartitionKey] string Region,
[PartitionKey] Region Region,
[RowKey] int DstPort,
int SrcPort,
string DstIp
Expand All @@ -128,7 +127,7 @@ public partial record ProxyConfig
(
Uri Url,
string Notification,
string Region,
Region Region,
Guid? ProxyId,
List<ProxyForward> Forwards,
string InstanceTelemetryKey,
Expand All @@ -138,7 +137,7 @@ string MicrosoftTelemetryKey

public partial record Proxy
(
[PartitionKey] string Region,
[PartitionKey] Region Region,
[RowKey] Guid ProxyId,
DateTimeOffset? CreatedTimestamp,
VmState State,
Expand Down Expand Up @@ -260,118 +259,5 @@ public record Task(
{
List<TaskEventSummary> Events { get; set; } = new List<TaskEventSummary>();
List<NodeAssignment> Nodes { get; set; } = new List<NodeAssignment>();
}
public record AzureSecurityExtensionConfig();
public record GenevaExtensionConfig();


public record KeyvaultExtensionConfig(
string KeyVaultName,
string CertName,
string CertPath,
string ExtensionStore
);

public record AzureMonitorExtensionConfig(
string ConfigVersion,
string Moniker,
string Namespace,
[property: JsonPropertyName("monitoringGSEnvironment")] string MonitoringGSEnvironment,
[property: JsonPropertyName("monitoringGCSAccount")] string MonitoringGCSAccount,
[property: JsonPropertyName("monitoringGCSAuthId")] string MonitoringGCSAuthId,
[property: JsonPropertyName("monitoringGCSAuthIdType")] string MonitoringGCSAuthIdType
);

public record AzureVmExtensionConfig(
KeyvaultExtensionConfig? Keyvault,
AzureMonitorExtensionConfig AzureMonitor
);

public record NetworkConfig(
string AddressSpace,
string Subnet
)
{
public NetworkConfig() : this("10.0.0.0/8", "10.0.0.0/16") { }
}

public record NetworkSecurityGroupConfig(
string[] AllowedServiceTags,
string[] AllowedIps
)
{
public NetworkSecurityGroupConfig() : this(Array.Empty<string>(), Array.Empty<string>()) { }
}

public record ApiAccessRule(
string[] Methods,
Guid[] AllowedGroups
);

public record InstanceConfig
(
[PartitionKey, RowKey] string InstanceName,
//# initial set of admins can only be set during deployment.
//# if admins are set, only admins can update instance configs.
Guid[]? Admins,
//# if set, only admins can manage pools or scalesets
bool AllowPoolManagement,
string[] AllowedAadTenants,
NetworkConfig NetworkConfig,
NetworkSecurityGroupConfig ProxyNsgConfig,
AzureVmExtensionConfig? Extensions,
string ProxyVmSku,
IDictionary<Endpoint, ApiAccessRule>? ApiAccessRules,
IDictionary<PrincipalId, GroupId[]>? GroupMembership,

IDictionary<string, string>? VmTags,
IDictionary<string, string>? VmssTags
) : EntityBase()
{
public InstanceConfig(string instanceName) : this(
instanceName,
null,
true,
Array.Empty<string>(),
new NetworkConfig(),
new NetworkSecurityGroupConfig(),
null,
"Standard_B2s",
null,
null,
null,
null)
{ }

public List<Guid>? CheckAdmins(List<Guid>? value)
{
if (value is not null && value.Count == 0)
{
throw new ArgumentException("admins must be null or contain at least one UUID");
}
else
{
return value;
}
}


//# At the moment, this only checks allowed_aad_tenants, however adding
//# support for 3rd party JWT validation is anticipated in a future release.
public ResultOk<List<string>> CheckInstanceConfig()
{
List<string> errors = new();
if (AllowedAadTenants.Length == 0)
{
errors.Add("allowed_aad_tenants must not be empty");
}
if (errors.Count == 0)
{
return ResultOk<List<string>>.Ok();
}
else
{
return ResultOk<List<string>>.Error(errors);
}
}
}
4 changes: 3 additions & 1 deletion src/ApiService/ApiService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Microsoft.Azure.Functions.Worker.Middleware;
using Microsoft.Azure.Functions.Worker;



namespace Microsoft.OneFuzz.Service;

public class Program
Expand Down Expand Up @@ -66,11 +68,11 @@ public static void Main()
.ConfigureServices((context, services) =>
services
.AddSingleton<ILogTracerFactory>(_ => new LogTracerFactory(GetLoggers()))
.AddSingleton<IStorageProvider>(_ => new StorageProvider(EnvironmentVariables.OneFuzz.FuncStorage ?? throw new InvalidOperationException("Missing account id")))
.AddSingleton<INodeOperations, NodeOperations>()
.AddSingleton<IEvents, Events>()
.AddSingleton<IWebhookOperations, WebhookOperations>()
.AddSingleton<IWebhookMessageLogOperations, WebhookMessageLogOperations>()
.AddSingleton<ITaskOperations, TaskOperations>()
.AddSingleton<IQueue, Queue>()
.AddSingleton<ICreds>(_ => new Creds())
.AddSingleton<IStorage, Storage>()
Expand Down
6 changes: 2 additions & 4 deletions src/ApiService/ApiService/QueueFileChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ public class QueueFileChanges
const int MAX_DEQUEUE_COUNT = 5;

private readonly ILogTracerFactory _loggerFactory;
private readonly IStorageProvider _storageProvider;

private readonly IStorage _storage;

public QueueFileChanges(ILogTracerFactory loggerFactory, IStorageProvider storageProvider, IStorage storage)
public QueueFileChanges(ILogTracerFactory loggerFactory, IStorage storage)
{
_loggerFactory = loggerFactory;
_storageProvider = storageProvider;
_storage = storage;
}

Expand Down Expand Up @@ -52,7 +50,7 @@ public Async.Task Run(
}

file_added(log, fileChangeEvent, lastTry);
return Task.CompletedTask;
return Async.Task.CompletedTask;
}

private void file_added(ILogTracer log, Dictionary<string, string> fileChangeEvent, bool failTaskOnTransientError)
Expand Down
3 changes: 1 addition & 2 deletions src/ApiService/ApiService/QueueProxyHeartbeat.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Microsoft.Azure.Functions.Worker;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;

namespace Microsoft.OneFuzz.Service;
Expand All @@ -19,7 +18,7 @@ public QueueProxyHearbeat(ILogTracerFactory loggerFactory, IProxyOperations prox
}

[Function("QueueProxyHearbeat")]
public async Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string msg)
public async Async.Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string msg)
{
var log = _loggerFactory.MakeLogTracer(Guid.NewGuid());

Expand Down
53 changes: 0 additions & 53 deletions src/ApiService/ApiService/onefuzzlib/orm/StorageProvider.cs

This file was deleted.

0 comments on commit 95dc487

Please sign in to comment.