Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to define a custom AzureEnvironment. #2579

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 4 additions & 0 deletions src/Promitor.Core/Extensions/AzureCloudExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
return AzureEnvironment.AzureGermanCloud;
case AzureCloud.UsGov:
return AzureEnvironment.AzureUSGovernment;
case AzureCloud.Custom:
return AzureEnvironmentExtensions.AzureCustomCloud;
default:
throw new ArgumentOutOfRangeException(nameof(azureCloud), "No Azure environment is known for in legacy SDK");
}
Expand Down Expand Up @@ -81,6 +83,8 @@
return AzureAuthorityHosts.AzureGermany;
case AzureCloud.UsGov:
return AzureAuthorityHosts.AzureGovernment;
case AzureCloud.Custom:
return new Uri(Environment.GetEnvironmentVariable("PROMITOR_AZURE_AUTH_ENDPOINT"));

Check warning on line 87 in src/Promitor.Core/Extensions/AzureCloudExtensions.cs

View workflow job for this annotation

GitHub Actions / Code Quality (R#)

"[AssignNullToNotNullAttribute] Possible 'null' assignment to non-nullable entity" on /home/runner/work/promitor/promitor/src/Promitor.Core/Extensions/AzureCloudExtensions.cs(87,36)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not do this but move it to the YAML configuration instead please

default:
throw new ArgumentOutOfRangeException(nameof(azureCloud), "No Azure environment is known for");
}
Expand Down
12 changes: 12 additions & 0 deletions src/Promitor.Core/Extensions/AzureEnvironmentExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Humanizer;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using System;

namespace Promitor.Core.Extensions
{
Expand All @@ -14,5 +15,16 @@ public static string GetDisplayName(this AzureEnvironment azureCloud)
{
return azureCloud.Name.Replace("Azure", "").Replace("Cloud", "").Humanize(LetterCasing.Title);
}

public static AzureEnvironment AzureCustomCloud = new AzureEnvironment()
{
Name = nameof(AzureCustomCloud),
AuthenticationEndpoint = Environment.GetEnvironmentVariable("PROMITOR_AUTH_ENDPOINT"),
ResourceManagerEndpoint = Environment.GetEnvironmentVariable("PROMITOR_RESOURCE_MANAGER_ENDPOINT"),
ManagementEndpoint = Environment.GetEnvironmentVariable("PROMITOR_MANAGEMENT_ENDPOINT"),
GraphEndpoint = Environment.GetEnvironmentVariable("PROMITOR_GRAPH_ENDPOINT"),
StorageEndpointSuffix = Environment.GetEnvironmentVariable("PROMITOR_STORAGE_ENDPOINT_SUFFIX"),
KeyVaultSuffix = Environment.GetEnvironmentVariable("PROMITOR_KEY_VAULT_SUFFIX")
Comment on lines +21 to +27
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, let's move this to the YAML configuration instead

};
}
}
3 changes: 2 additions & 1 deletion src/Promitor.Core/Serialization/Enum/AzureCloud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum AzureCloud
Global,
China,
UsGov,
Germany
Germany,
Custom
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
public readonly string ColumnNameResult = "result";
private readonly Uri _defaultEndpoint = new("https://api.loganalytics.io");
private readonly Uri _govEndpoint = new("https://api.loganalytics.us");
private readonly Uri _customEndpoint = new (Environment.GetEnvironmentVariable("PROMITOR_LOG_ANALYTICS_ENDPOINT"));

Check warning on line 18 in src/Promitor.Integrations.LogAnalytics/LogAnalyticsClient.cs

View workflow job for this annotation

GitHub Actions / Code Quality (R#)

"[AssignNullToNotNullAttribute] Possible 'null' assignment to non-nullable entity" on /home/runner/work/promitor/promitor/src/Promitor.Integrations.LogAnalytics/LogAnalyticsClient.cs(18,53)

private readonly LogsQueryClient _logsQueryClient;

Expand All @@ -31,6 +32,7 @@
{
nameof(AzureEnvironment.AzureGlobalCloud) => _defaultEndpoint,
nameof(AzureEnvironment.AzureUSGovernment) => _govEndpoint,
"AzureCustomCloud" => _customEndpoint,
_ => throw new NotSupportedException($"Environment {azureEnvironment.Name} is not supported for scraping Azure Log Analytics resource(s)")
};

Expand Down
Loading