Skip to content

Commit 8750593

Browse files
author
Christian
committed
fixing broken implementation for ips
1 parent 25073c2 commit 8750593

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/ServiceControl.Config/UI/InstanceEdit/MonitoringEditViewModelValidator.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ public MonitoringEditViewModelValidator()
1212
.NotEmpty()
1313
.When(x => x.SubmitAttempted);
1414

15-
RuleFor(x => x.HostName)
16-
.NotEmpty()
17-
.When(x => x.SubmitAttempted);
18-
1915
RuleFor(x => x.PortNumber)
2016
.NotEmpty()
2117
.ValidPort()

src/ServiceControl.Config/UI/SharedInstanceEditor/SharedMonitoringEditorViewModelValidator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ protected SharedMonitoringEditorViewModelValidator()
99
{
1010
RuleFor(x => x.HostName)
1111
.NotEmpty()
12-
.ValidHostname()
13-
.When(x => x.SubmitAttempted);
12+
.ValidHostname(); // Removed the .When(x => x.SubmitAttempted) condition
1413

1514
RuleFor(x => x.LogPath)
1615
.NotEmpty()

src/ServiceControl.Config/Validation/Validations.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,16 @@ public static IRuleBuilderOptions<T, string> MustBeUniqueWindowsServiceName<T>(t
205205
public static IRuleBuilderOptions<T, string> ValidHostname<T>(this IRuleBuilder<T, string> ruleBuilder)
206206
{
207207
return ruleBuilder.Must((t, hostname) =>
208-
!string.IsNullOrWhiteSpace(hostname) &&
209-
Uri.CheckHostName(hostname) == UriHostNameType.Dns)
210-
.WithMessage(MSG_INVALID_HOSTNAME);
208+
{
209+
if (string.IsNullOrWhiteSpace(hostname))
210+
{
211+
return false;
212+
}
213+
214+
var hostNameType = Uri.CheckHostName(hostname);
215+
return hostNameType is UriHostNameType.Dns or UriHostNameType.IPv4 or UriHostNameType.IPv6;
216+
})
217+
.WithMessage(MSG_INVALID_HOSTNAME);
211218
}
212219

213220
public const string MSG_EMAIL_NOT_VALID = "Not Valid.";

0 commit comments

Comments
 (0)