|
1 | 1 | using Aikido.Zen.Core.Models; |
2 | 2 | using System; |
| 3 | +using System.Linq; |
3 | 4 | using System.Runtime.CompilerServices; |
4 | 5 | using System.Runtime.InteropServices; |
5 | 6 | [assembly: InternalsVisibleTo("Aikido.Zen.Tests")] |
6 | 7 | namespace Aikido.Zen.Core.Helpers |
7 | 8 | { |
8 | | - /// <summary> |
9 | | - /// Helper class for retrieving agent information about the current runtime environment. |
10 | | - /// </summary> |
11 | | - internal class AgentInfoHelper |
12 | | - { |
13 | | - // Cache the AgentInfo object to avoid repeated creation |
14 | | - private static readonly AgentInfo _cachedAgentInfo = new AgentInfo |
15 | | - { |
16 | | - Hostname = Environment.MachineName, |
17 | | - Os = new Os |
18 | | - { |
19 | | - Version = Environment.OSVersion.VersionString, |
20 | | - Name = Environment.OSVersion.Platform.ToString() |
21 | | - }, |
22 | | - Platform = new Platform |
23 | | - { |
24 | | - Version = Environment.Version.ToString(), |
25 | | - Arch = RuntimeInformation.ProcessArchitecture.ToString() |
26 | | - }, |
27 | | - IpAddress = IPHelper.Server, |
28 | | - Library = "firewall-dotnet", |
29 | | - Version = typeof(AgentInfoHelper).Assembly.GetName().Version.ToString(), |
30 | | - // Determine if running in a serverless environment |
31 | | - Serverless = Environment.GetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME") != null || Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID") != null |
32 | | - }; |
| 9 | + /// <summary> |
| 10 | + /// Helper class for retrieving agent information about the current runtime environment. |
| 11 | + /// </summary> |
| 12 | + internal class AgentInfoHelper |
| 13 | + { |
| 14 | + // Cache the AgentInfo object to avoid repeated creation |
| 15 | + private static readonly AgentInfo _cachedAgentInfo = new AgentInfo |
| 16 | + { |
| 17 | + Hostname = Environment.MachineName, |
| 18 | + Os = new Os |
| 19 | + { |
| 20 | + Version = Environment.OSVersion.VersionString, |
| 21 | + Name = Environment.OSVersion.Platform.ToString() |
| 22 | + }, |
| 23 | + Platform = new Platform |
| 24 | + { |
| 25 | + Version = Environment.Version.ToString(), |
| 26 | + Arch = RuntimeInformation.ProcessArchitecture.ToString() |
| 27 | + }, |
| 28 | + IpAddress = IPHelper.Server, |
| 29 | + Library = "firewall-dotnet", |
| 30 | + Version = CleanVersion(typeof(AgentInfoHelper).Assembly.GetName().Version.ToString()), |
| 31 | + // Determine if running in a serverless environment |
| 32 | + Serverless = Environment.GetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME") != null || Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID") != null |
| 33 | + }; |
33 | 34 |
|
34 | | - /// <summary> |
35 | | - /// Gets information about the current runtime environment including OS, platform, and configuration details. |
36 | | - /// </summary> |
37 | | - /// <returns>An AgentInfo object containing the environment information.</returns> |
38 | | - public static AgentInfo GetInfo() |
39 | | - { |
40 | | - // Update only the fields that can change |
41 | | - _cachedAgentInfo.DryMode = EnvironmentHelper.DryMode; |
42 | | - _cachedAgentInfo.Serverless = Environment.GetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME") != null || Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID") != null; |
| 35 | + /// <summary> |
| 36 | + /// Gets information about the current runtime environment including OS, platform, and configuration details. |
| 37 | + /// </summary> |
| 38 | + /// <returns>An AgentInfo object containing the environment information.</returns> |
| 39 | + public static AgentInfo GetInfo() |
| 40 | + { |
| 41 | + // Update only the fields that can change |
| 42 | + _cachedAgentInfo.DryMode = EnvironmentHelper.DryMode; |
| 43 | + _cachedAgentInfo.Serverless = Environment.GetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME") != null || Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID") != null; |
43 | 44 |
|
44 | | - return _cachedAgentInfo; |
45 | | - } |
46 | | - } |
| 45 | + return _cachedAgentInfo; |
| 46 | + } |
| 47 | + |
| 48 | + internal static string CleanVersion(string version) |
| 49 | + { |
| 50 | + // remove the build number |
| 51 | + version = version.Split('+')[0]; |
| 52 | + // remove 4th version number, not used by nuget |
| 53 | + version = string.Join(".", version.Split('.').Take(3)); |
| 54 | + // remove the prerelease version |
| 55 | + version = version.Split('-')[0]; |
| 56 | + return version; |
| 57 | + } |
| 58 | + } |
47 | 59 | } |
0 commit comments