Skip to content

Commit

Permalink
add taskhub name validation (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianburckhardt authored Aug 22, 2022
1 parent 38b75d7 commit 6130f04
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public void Validate(Func<string,string> nameResolver = null)
throw new InvalidOperationException($"Must specify {nameof(this.HubName)} for Netherite storage provider.");
}

ValidateTaskhubName(this.HubName);

if (string.IsNullOrEmpty(this.ResolvedStorageConnectionString))
{
if (nameResolver == null)
Expand Down Expand Up @@ -363,6 +365,32 @@ public void Validate(Func<string,string> nameResolver = null)
{
throw new ArgumentOutOfRangeException(nameof(this.MaxConcurrentActivityFunctions));
}
}
}

const int MinTaskHubNameSize = 1;
const int MaxTaskHubNameSize = 45;

public static void ValidateTaskhubName(string taskhubName)
{
if (taskhubName.Length < MinTaskHubNameSize || taskhubName.Length > MaxTaskHubNameSize)
{
throw new ArgumentException(GetTaskHubErrorString(taskhubName));
}

try
{
Microsoft.Azure.Storage.NameValidator.ValidateContainerName(taskhubName.ToLowerInvariant());
Microsoft.Azure.Storage.NameValidator.ValidateBlobName(taskhubName);
}
catch (ArgumentException e)
{
throw new ArgumentException(GetTaskHubErrorString(taskhubName), e);
}
}

static string GetTaskHubErrorString(string hubName)
{
return $"Task hub name '{hubName}' should contain only alphanumeric characters, start with a letter, and have length between {MinTaskHubNameSize} and {MaxTaskHubNameSize}.";
}
}
}

0 comments on commit 6130f04

Please sign in to comment.