diff --git a/src/ApiService/ApiService/Functions/Info.cs b/src/ApiService/ApiService/Functions/Info.cs index 39601bf57..7eefc8d2e 100644 --- a/src/ApiService/ApiService/Functions/Info.cs +++ b/src/ApiService/ApiService/Functions/Info.cs @@ -31,13 +31,13 @@ public class Info { var asm = Assembly.GetExecutingAssembly(); var gitVersion = ReadResource(asm, "ApiService.onefuzzlib.git.version"); var buildId = ReadResource(asm, "ApiService.onefuzzlib.build.id"); - var versionString = asm.GetCustomAttribute()?.InformationalVersion; + var versionString = context.ServiceConfiguration.OneFuzzVersion; return new InfoResponse( ResourceGroup: resourceGroup, Subscription: subscription, Region: region, - Versions: new Dictionary { { "onefuzz", new(gitVersion, buildId, versionString ?? "") } }, + Versions: new Dictionary { { "onefuzz", new(gitVersion, buildId, versionString) } }, InstanceId: await _context.Containers.GetInstanceId(), InsightsAppid: config.ApplicationInsightsAppId, InsightsInstrumentationKey: config.ApplicationInsightsInstrumentationKey); diff --git a/src/ApiService/ApiService/ServiceConfiguration.cs b/src/ApiService/ApiService/ServiceConfiguration.cs index 3a5839d84..5c55ccb62 100644 --- a/src/ApiService/ApiService/ServiceConfiguration.cs +++ b/src/ApiService/ApiService/ServiceConfiguration.cs @@ -1,4 +1,6 @@ -namespace Microsoft.OneFuzz.Service; +using System.Reflection; + +namespace Microsoft.OneFuzz.Service; public enum LogDestination { Console, @@ -49,6 +51,11 @@ public interface IServiceConfig { public class ServiceConfiguration : IServiceConfig { + // Version is baked into the assembly by the build process: + private static readonly string? _oneFuzzVersion = + Assembly.GetExecutingAssembly() + .GetCustomAttribute()?.InformationalVersion; + public ServiceConfiguration() { #if DEBUG LogDestinations = new LogDestination[] { LogDestination.AppInsights, LogDestination.Console }; @@ -86,7 +93,16 @@ public class ServiceConfiguration : IServiceConfig { public string? OneFuzzOwner { get => Environment.GetEnvironmentVariable("ONEFUZZ_OWNER"); } public string? OneFuzzResourceGroup { get => Environment.GetEnvironmentVariable("ONEFUZZ_RESOURCE_GROUP"); } public string? OneFuzzTelemetry { get => Environment.GetEnvironmentVariable("ONEFUZZ_TELEMETRY"); } - public string OneFuzzVersion { get => Environment.GetEnvironmentVariable("ONEFUZZ_VERSION") ?? "0.0.0"; } + + public string OneFuzzVersion { + get { + // version can be overridden by config: + return Environment.GetEnvironmentVariable("ONEFUZZ_VERSION") + ?? _oneFuzzVersion + ?? throw new InvalidOperationException("Unable to read OneFuzz version from assembly"); + } + } + public string? OneFuzzAllowOutdatedAgent => Environment.GetEnvironmentVariable("ONEFUZZ_ALLOW_OUTDATED_AGENT"); public string OneFuzzNodeDisposalStrategy { get => Environment.GetEnvironmentVariable("ONEFUZZ_NODE_DISPOSAL_STRATEGY") ?? "scale_in"; } diff --git a/src/ApiService/ApiService/onefuzzlib/ReproOperations.cs b/src/ApiService/ApiService/onefuzzlib/ReproOperations.cs index b073d001c..f972556e4 100644 --- a/src/ApiService/ApiService/onefuzzlib/ReproOperations.cs +++ b/src/ApiService/ApiService/onefuzzlib/ReproOperations.cs @@ -31,8 +31,8 @@ public interface IReproOperations : IStatefulOrm { public class ReproOperations : StatefulOrm, IReproOperations { private static readonly Dictionary DEFAULT_OS = new() { - {Os.Linux, "Canonical:UbuntuServer:18.04-LTS:latest"}, - {Os.Windows, "MicrosoftWindowsDesktop:Windows-10:20h2-pro:latest"} + { Os.Linux, "Canonical:UbuntuServer:18.04-LTS:latest" }, + { Os.Windows, "MicrosoftWindowsDesktop:Windows-10:20h2-pro:latest" } }; const string DEFAULT_SKU = "Standard_DS1_v2";